|
2 | 2 |
|
3 | 3 | import openeo |
4 | 4 |
|
| 5 | +from efast.constants import S2L2ASCFlags |
| 6 | + |
5 | 7 | from . import extract_mask |
6 | 8 |
|
7 | 9 |
|
8 | | -def extract_cloud_mask_s2(cube: openeo.DataCube) -> openeo.DataCube: |
| 10 | +def extract_cloud_mask(cube: openeo.DataCube) -> openeo.DataCube: |
9 | 11 | return extract_mask( |
10 | 12 | cube, |
11 | | - {"SCL": [0, 3, 7]}, |
| 13 | + { |
| 14 | + "SCL": [ |
| 15 | + S2L2ASCFlags.NO_DATA.value, |
| 16 | + S2L2ASCFlags.CLOUD_SHADOWS.value, |
| 17 | + S2L2ASCFlags.UNCLASSIFIED.value, |
| 18 | + ] |
| 19 | + }, |
12 | 20 | operations={ |
13 | | - ("SCL", 7): operator.gt, |
| 21 | + ("SCL", 7): operator.gt, # consider flags higher than 7 as clouds |
14 | 22 | }, |
15 | 23 | ) |
16 | 24 |
|
17 | | -def calculate_large_grid_cloud_mask(cube: openeo.DataCube, tolerance_percentage: float = 0.05, grid_side_length: int=300): |
18 | | - cloud_mask = extract_cloud_mask_s2(cube) |
| 25 | + |
| 26 | +def calculate_large_grid_cloud_mask( |
| 27 | + cube: openeo.DataCube, |
| 28 | + tolerance_percentage: float = 0.05, |
| 29 | + grid_side_length: int = 300, |
| 30 | +): |
| 31 | + cloud_mask = extract_cloud_mask(cube) |
19 | 32 | # FIXME check also if there is negative or zero data, otherwise results will differ |
20 | | - |
| 33 | + |
21 | 34 | # TODO this could better be resample_cube_spatial, because we are matching to a sentinel-3 cube |
22 | | - cloud_mask = cloud_mask * 1.0 # convert to float |
23 | | - cloud_mask_resampled = cloud_mask.resample_spatial(grid_side_length, method="average") # resample to sentinel-3 size |
| 35 | + cloud_mask = cloud_mask * 1.0 # convert to float |
| 36 | + cloud_mask_resampled = cloud_mask.resample_spatial( |
| 37 | + grid_side_length, method="average" |
| 38 | + ) # resample to sentinel-3 size |
24 | 39 | return cloud_mask_resampled < tolerance_percentage |
0 commit comments