Skip to content

Commit f5e2317

Browse files
committed
Renamed testfile to match implementation, ruff formatting
1 parent d6c03fe commit f5e2317

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

efast/constants.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ class S3L2SYNCloudFlags(Flag):
66
Flag meanings are described in the SYNERGY Product Data Format Specification [1]
77
Table 23
88
"""
9+
910
CLOUD = 1
1011
CLOUD_AMBIGUOUS = 1 << 1
1112
CLOUD_MARGIN = 1 << 2
1213
SNOW_ICE = 1 << 3
1314

15+
1416
class S3L2SYNClassificationAerosolFlags(Flag):
1517
"""
1618
Flag meanings are described in the SYNERGY Product Data Format Specification [1]
@@ -19,12 +21,14 @@ class S3L2SYNClassificationAerosolFlags(Flag):
1921
2022
[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
2123
"""
24+
2225
SYN_AOT_climato = 1 << 3
2326
SYN_land = 1 << 4
2427
SYN_no_olc = 1 << 5
25-
SYN_no_sln = 1
28+
SYN_no_sln = 1
2629
# TODO ...
2730

31+
2832
class S2L2ASCFlags(Enum):
2933
NO_DATA = 0
3034
SATURATED_OR_DEFECTIVE = 1
@@ -38,4 +42,3 @@ class S2L2ASCFlags(Enum):
3842
CLOUD_HIGH_PROBABILITY = 9
3943
THIN_CIRRUS = 10
4044
SNOW_ICE = 11
41-

efast/openeo/preprocessing/s2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def extract_cloud_mask(cube: openeo.DataCube) -> openeo.DataCube:
1818
]
1919
},
2020
operations={
21-
("SCL", 7): operator.gt, # consider flags higher than 7 as clouds
21+
("SCL", 7): operator.gt, # consider flags higher than 7 as clouds
2222
},
2323
)
2424

efast/openeo/preprocessing/s3.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from datetime import datetime
2+
23
import openeo
3-
from openeo import processes, UDF
4+
5+
from openeo import UDF, processes
46

57
from efast.constants import S3L2SYNClassificationAerosolFlags, S3L2SYNCloudFlags
68
from efast.openeo.preprocessing.general import _extract_bit_mask

tests/test_temporal_score_udf.py renamed to tests/test_compute_s3_composite_weights.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,3 @@ def test_time_difference_score():
6565
res = execute_local_udf(udf, data, fmt="netcdf")
6666

6767
return True
68-
69-
70-

tests/test_preprocessing_openeo.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
from collections.abc import Generator
21
import shutil
32
import time
4-
import pytest
53

4+
from collections.abc import Generator
65
from contextlib import contextmanager
76
from pathlib import Path
87
from tempfile import TemporaryDirectory
98

109
import numpy as np
1110
import openeo
12-
import rasterio
13-
import xarray as xr
1411
import pyproj
12+
import pytest
13+
import rasterio
1514
import shapely
16-
from shapely import wkt
17-
from enhancement_tools.time_measurement import Timer
15+
import xarray as xr
1816

17+
from enhancement_tools.time_measurement import Timer
1918
from openeo.udf import execute_local_udf
19+
from shapely import wkt
2020

21-
from efast.constants import S3L2SYNClassificationAerosolFlags
21+
from efast import s2_processing, s3_processing
2222
from efast.openeo import preprocessing
23+
2324
# TODO this should live somewhere else
2425
from efast.openeo.preprocessing import connect
25-
from efast import s2_processing, s3_processing
2626
from efast.openeo.preprocessing.s3 import extract_clear_land_mask
2727

28-
2928
TEST_DATA_ROOT = Path(__file__).parent.parent / "test_data"
3029
TEST_DATA_S2 = TEST_DATA_ROOT / "S2"
3130

@@ -46,6 +45,7 @@
4645

4746
VISUAL_OUTPUT_PATH = Path(__file__).parent.parent / "visual_test_results"
4847

48+
4949
@contextmanager
5050
def create_temp_dir_and_copy_files(
5151
source, sub=".", pattern: str | None = "*"
@@ -116,7 +116,7 @@ def test_distance_to_cloud():
116116

117117
print("openEO execution")
118118
before = time.perf_counter()
119-
#dtc.download(download_path)
119+
# dtc.download(download_path)
120120
elapsed = time.perf_counter() - before
121121
print(f"executed and downloaded in {elapsed:.2f}s")
122122

@@ -125,11 +125,10 @@ def test_distance_to_cloud():
125125
BASE_DIR.mkdir(exist_ok=True)
126126
print("downloading input") # TMP
127127
(dtc_input * 1.0).download(BASE_DIR / "dtc_input.tif")
128-
#shutil.copy(download_path, BASE_DIR)
129-
print("downloading result") # TMP
130-
dtc.download(download_path) # TMP
131-
shutil.copy(download_path, BASE_DIR) # TMP
132-
128+
# shutil.copy(download_path, BASE_DIR)
129+
print("downloading result") # TMP
130+
dtc.download(download_path) # TMP
131+
shutil.copy(download_path, BASE_DIR) # TMP
133132

134133
with rasterio.open(download_path, "r") as ds:
135134
dtc_openeo = ds.read(1)
@@ -152,8 +151,10 @@ def test_distance_to_cloud_synthetic_cube():
152151
.mean(1)
153152
) < tolerance
154153
cube = xr.DataArray(cube, dims=["x", "y"])
155-
#cube = cube.add_dimension(name="bands", label="mask", type="bands")
156-
cube_resampled = xr.DataArray(cube_resampled[np.newaxis, np.newaxis], dims=["bands", "t", "x", "y"])
154+
# cube = cube.add_dimension(name="bands", label="mask", type="bands")
155+
cube_resampled = xr.DataArray(
156+
cube_resampled[np.newaxis, np.newaxis], dims=["bands", "t", "x", "y"]
157+
)
157158

158159
udf = openeo.UDF.from_file("efast/distance_transform_udf.py")
159160
dtc_local_udf = (
@@ -194,8 +195,10 @@ def extract_epsg_code_from_rasterio_crs(crs: rasterio.CRS) -> int:
194195

195196
def test_data_acquisition_s3():
196197
with create_temp_dir_and_copy_files(
197-
TEST_DATA_S3, sub="raw/", pattern=f"raw/*SY_2_SYN____2022061*"
198-
#TEST_DATA_S3, sub="raw/", pattern=f"raw/*SY_2_SYN____*"
198+
TEST_DATA_S3,
199+
sub="raw/",
200+
pattern=f"raw/*SY_2_SYN____2022061*",
201+
# TEST_DATA_S3, sub="raw/", pattern=f"raw/*SY_2_SYN____*"
199202
) as tmp:
200203
inner_data_acquisition_s3(tmp)
201204

@@ -309,6 +312,7 @@ def transform_bounds_to_wkt(bounds: dict):
309312
)
310313
return wkt.dumps(bbox)
311314

315+
312316
METADATA_UDF = openeo.UDF("""
313317
import numpy as np
314318
import xarray as xr
@@ -320,6 +324,7 @@ def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
320324
return XarrayDataCube(xr.DataArray(array, dims=["bands", "x", "y"]))
321325
""")
322326

327+
323328
def test_extract_clear_land_mask_s3():
324329
out_path = VISUAL_OUTPUT_PATH / "extract_clear_land_mask"
325330
out_path.mkdir(exist_ok=True, parents=True)
@@ -347,9 +352,8 @@ def test_extract_clear_land_mask_s3():
347352
)
348353
cube = test_area.get_s3_cube(conn)
349354

350-
351355
print("Downloading input")
352-
#cube.download(out_path / "input.nc")
356+
# cube.download(out_path / "input.nc")
353357
mask = extract_clear_land_mask(cube)
354358
print("Downloading mask")
355359
mask.download(out_path / "mask.nc")

0 commit comments

Comments
 (0)