Skip to content

Commit 3917c1a

Browse files
committed
Extracted constants to their own file.
1 parent ee429a7 commit 3917c1a

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

efast/constants.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from enum import Enum, Flag
2+
3+
4+
class S3L2SYNCloudFlags(Flag):
5+
"""
6+
Flag meanings are described in the SYNERGY Product Data Format Specification [1]
7+
Table 23
8+
"""
9+
CLOUD = 1
10+
CLOUD_AMBIGUOUS = 1 << 1
11+
CLOUD_MARGIN = 1 << 2
12+
SNOW_ICE = 1 << 3
13+
14+
class S3L2SYNClassificationAerosolFlags(Flag):
15+
"""
16+
Flag meanings are described in the SYNERGY Product Data Format Specification [1]
17+
Talble 19
18+
19+
20+
[1] https://sentinels.copernicus.eu/documents/247904/1872824/S3IPF+PDS+006+-+i1r15+-+Product+Data+Format+Specification+-+SYNERGY_20221208.pdf/48f4eb8c-ca08-eca1-f8dd-bf00c438ea52?t=1683308328839
21+
"""
22+
SYN_AOT_climato = 1 << 3
23+
SYN_land = 1 << 4
24+
SYN_no_olc = 1 << 5
25+
SYN_no_sln = 1
26+
# TODO ...
27+
28+
class S2L2ASCFlags(Enum):
29+
NO_DATA = 0
30+
SATURATED_OR_DEFECTIVE = 1
31+
CAST_SHADOWS = 2
32+
CLOUD_SHADOWS = 3
33+
VEGETATION = 4
34+
NOT_VEGETATED = 5
35+
WATER = 6
36+
UNCLASSIFIED = 7
37+
CLOUD_MEDIUM_PROBABILITY = 8
38+
CLOUD_HIGH_PROBABILITY = 9
39+
THIN_CIRRUS = 10
40+
SNOW_ICE = 11
41+

efast/openeo/preprocessing/s2.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22

33
import openeo
44

5+
from efast.constants import S2L2ASCFlags
6+
57
from . import extract_mask
68

79

8-
def extract_cloud_mask_s2(cube: openeo.DataCube) -> openeo.DataCube:
10+
def extract_cloud_mask(cube: openeo.DataCube) -> openeo.DataCube:
911
return extract_mask(
1012
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+
},
1220
operations={
13-
("SCL", 7): operator.gt,
21+
("SCL", 7): operator.gt, # consider flags higher than 7 as clouds
1422
},
1523
)
1624

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)
1932
# FIXME check also if there is negative or zero data, otherwise results will differ
20-
33+
2134
# 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
2439
return cloud_mask_resampled < tolerance_percentage

0 commit comments

Comments
 (0)