|
| 1 | +from datetime import datetime |
1 | 2 | import shutil |
2 | 3 | import time |
3 | 4 |
|
|
23 | 24 |
|
24 | 25 | # TODO this should live somewhere else |
25 | 26 | 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 |
27 | 29 |
|
28 | 30 | TEST_DATA_ROOT = Path(__file__).parent.parent / "test_data" |
29 | 31 | TEST_DATA_S2 = TEST_DATA_ROOT / "S2" |
|
41 | 43 |
|
42 | 44 | SKIP_LOCAL = True |
43 | 45 | DOWNLOAD_INTERMEDIATE_RESULTS = True |
44 | | -SMALL_AREA = False |
| 46 | +SMALL_AREA = True |
45 | 47 |
|
46 | 48 | VISUAL_OUTPUT_PATH = Path(__file__).parent.parent / "visual_test_results" |
47 | 49 |
|
@@ -353,8 +355,59 @@ def test_extract_clear_land_mask_s3(): |
353 | 355 | cube = test_area.get_s3_cube(conn) |
354 | 356 |
|
355 | 357 | print("Downloading input") |
356 | | - # cube.download(out_path / "input.nc") |
| 358 | + cube.download(out_path / "input.nc") |
357 | 359 | mask = extract_clear_land_mask(cube) |
358 | 360 | print("Downloading mask") |
359 | 361 | mask.download(out_path / "mask.nc") |
360 | 362 | 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