|
12 | 12 | import openeo |
13 | 13 | from openeo.udf import execute_local_udf |
14 | 14 |
|
15 | | -from efast import efast_openeo, s2_processing |
| 15 | +from efast import s2_processing_openeo, s2_processing |
16 | 16 |
|
17 | 17 | TEST_DATA_ROOT = Path(__file__).parent.parent / "test_data" |
18 | 18 | TEST_DATA_S2 = TEST_DATA_ROOT / "S2" |
@@ -68,45 +68,28 @@ def test_distance_to_cloud(): |
68 | 68 |
|
69 | 69 | # openeo |
70 | 70 |
|
71 | | - conn = efast_openeo.connect() |
| 71 | + conn = s2_processing_openeo.connect() |
72 | 72 | conn.authenticate_oidc() |
73 | 73 |
|
74 | | - test_area = efast_openeo.TestArea(bbox=bounds, s2_bands=["SCL"], temporal_extent=(TEST_DATE_DASH, TEST_DATE_DASH)) |
| 74 | + test_area = s2_processing_openeo.TestArea(bbox=bounds, s2_bands=["SCL"], temporal_extent=(TEST_DATE_DASH, TEST_DATE_DASH)) |
75 | 75 | cube = test_area.get_s2_cube(conn) |
76 | 76 |
|
77 | | - scl = cube.filter_bands(["SCL"]) |
78 | | - cloud_mask = (scl == 0) | (scl == 3) | (scl > 7) |
79 | | - # FIXME check also if there is negative or zero data, otherwise results will differ |
80 | | - |
81 | | - # TODO this could better be resample_cube_spatial, because we are matching to a sentinel-3 cube |
82 | | - cloud_mask = cloud_mask * 1.0 # convert to float |
83 | | - cloud_mask_resampled = cloud_mask.resample_spatial(300, method="average") # resample to sentinel-3 size |
84 | | - |
85 | | - # UDF to apply an element-wise less than operation. Normal "<" does not properly work on openEO datacubes |
86 | | - udf = openeo.UDF(""" |
87 | | -import numpy as np |
88 | | -import xarray as xr |
89 | | -def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube: |
90 | | - array = cube.get_array() |
91 | | - array = array < 0.05 |
92 | | - #return XarrayDataCube(xr.DataArray(array, dims=["t", "x", "y", "bands"])) |
93 | | - return XarrayDataCube(xr.DataArray(array, dims=["bands", "x", "y"])) |
94 | | - """) |
95 | | - dtc_input = cloud_mask_resampled.apply(process=udf) |
96 | | - dtc = efast_openeo.distance_to_clouds(dtc_input, tolerance_percentage=0.05, ratio=30) |
97 | | - download_path = tmp_path / "test_distance_to_cloud.nc" |
| 77 | + dtc_input = s2_processing_openeo.calculate_large_grid_cloud_mask(cube, tolerance_percentage=0.05, grid_side_length=300) |
| 78 | + dtc = s2_processing_openeo.distance_to_clouds(dtc_input, tolerance_percentage=0.05, ratio=30) |
| 79 | + download_path = tmp_path / "test_distance_to_cloud.tif" |
98 | 80 |
|
99 | 81 | print("openEO execution") |
100 | 82 |
|
101 | 83 | # intermediate results for debugging |
102 | | - #BASE_DIR = Path("openeo_results") |
| 84 | + BASE_DIR = Path("openeo_results") |
103 | 85 | #BASE_DIR.mkdir(exist_ok=True) |
104 | 86 | #cloud_mask.download(BASE_DIR / "cloud_mask.tif") |
105 | 87 | #cloud_mask_resampled.download(BASE_DIR / "cloud_mask_resampled.tif") |
106 | 88 | #dtc_input.download(BASE_DIR / "dtc_input.tif") |
107 | 89 |
|
108 | 90 | before = time.perf_counter() |
109 | 91 | dtc.download(download_path) |
| 92 | + shutil.copy(download_path, BASE_DIR) |
110 | 93 | elapsed = time.perf_counter() - before |
111 | 94 | print(f"executed and downloaded in {elapsed:.2f}s") |
112 | 95 |
|
|
0 commit comments