Skip to content

Commit 69b179c

Browse files
committed
Added test for openeo weighted composites
1 parent e4444f4 commit 69b179c

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

tests/test_preprocessing_openeo.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
import shutil
23
import time
34

@@ -23,7 +24,8 @@
2324

2425
# TODO this should live somewhere else
2526
from efast.openeo.preprocessing import connect
26-
from efast.openeo.preprocessing.s3 import extract_clear_land_mask
27+
from efast.openeo.preprocessing.general import distance_to_clouds
28+
from efast.openeo.preprocessing.s3 import DATE_FORMAT, compute_combined_score, compute_distance_to_cloud_score, extract_clear_land_mask
2729

2830
TEST_DATA_ROOT = Path(__file__).parent.parent / "test_data"
2931
TEST_DATA_S2 = TEST_DATA_ROOT / "S2"
@@ -41,7 +43,7 @@
4143

4244
SKIP_LOCAL = True
4345
DOWNLOAD_INTERMEDIATE_RESULTS = True
44-
SMALL_AREA = False
46+
SMALL_AREA = True
4547

4648
VISUAL_OUTPUT_PATH = Path(__file__).parent.parent / "visual_test_results"
4749

@@ -353,8 +355,59 @@ def test_extract_clear_land_mask_s3():
353355
cube = test_area.get_s3_cube(conn)
354356

355357
print("Downloading input")
356-
# cube.download(out_path / "input.nc")
358+
cube.download(out_path / "input.nc")
357359
mask = extract_clear_land_mask(cube)
358360
print("Downloading mask")
359361
mask.download(out_path / "mask.nc")
360362
print("Done")
363+
364+
365+
def test_s3_weighted_composites():
366+
out_path = VISUAL_OUTPUT_PATH / "s3_weighted_composites"
367+
out_path.mkdir(exist_ok=True, parents=True)
368+
conn = connect()
369+
conn = conn.authenticate_oidc()
370+
bounds = {
371+
"west": 399960.0,
372+
"south": 1590240.0,
373+
"east": 509760.0,
374+
"north": 1700040.0,
375+
"crs": 32628,
376+
}
377+
if SMALL_AREA:
378+
dist = 3600
379+
bounds["east"] = bounds["west"] + dist
380+
bounds["north"] = bounds["south"] + dist
381+
382+
bands = [
383+
"Syn_Oa17_reflectance",
384+
"CLOUD_flags",
385+
"SYN_flags",
386+
]
387+
test_area = preprocessing.TestArea(
388+
bbox=bounds, s3_bands=bands, temporal_extent=(TEST_DATE_DASH, TEST_DATE_DASH)
389+
)
390+
391+
# steps
392+
# get data
393+
# compute distance to cloud
394+
# compute distance score
395+
# compute combined score
396+
# collapse weighted inputs into a single composite
397+
398+
cube = test_area.get_s3_cube(conn)
399+
dtc = distance_to_clouds(cube)
400+
distance_score = compute_distance_to_cloud_score(dtc, transition_region_extent=20)
401+
402+
score = preprocessing.s3.compute_combined_score(distance_score, target_date=datetime.strptime(TEST_DATE_DASH, DATE_FORMAT))
403+
404+
405+
print("Downloading input")
406+
cube.download(out_path / "input.nc")
407+
print("Downloading distance to clouds")
408+
dtc.download(out_path / "dtc.nc")
409+
print("type of dtc: ", type(dtc))
410+
print("Downloading score")
411+
score.download(out_path / "score.nc")
412+
413+
return True

0 commit comments

Comments
 (0)