1- from collections .abc import Generator
21import shutil
32import time
4- import pytest
53
4+ from collections .abc import Generator
65from contextlib import contextmanager
76from pathlib import Path
87from tempfile import TemporaryDirectory
98
109import numpy as np
1110import openeo
12- import rasterio
13- import xarray as xr
1411import pyproj
12+ import pytest
13+ import rasterio
1514import 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
1918from 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
2222from efast .openeo import preprocessing
23+
2324# TODO this should live somewhere else
2425from efast .openeo .preprocessing import connect
25- from efast import s2_processing , s3_processing
2626from efast .openeo .preprocessing .s3 import extract_clear_land_mask
2727
28-
2928TEST_DATA_ROOT = Path (__file__ ).parent .parent / "test_data"
3029TEST_DATA_S2 = TEST_DATA_ROOT / "S2"
3130
4645
4746VISUAL_OUTPUT_PATH = Path (__file__ ).parent .parent / "visual_test_results"
4847
48+
4949@contextmanager
5050def 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
195196def 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+
312316METADATA_UDF = openeo .UDF ("""
313317import numpy as np
314318import 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+
323328def 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