|
12 | 12 | from seaice_ecdr.multiprocess_intermediate_daily import get_dates_by_year |
13 | 13 | from seaice_ecdr.platforms.models import SUPPORTED_PLATFORM_ID |
14 | 14 | from seaice_ecdr.util import ( |
| 15 | + clean_outputs_for_date_range, |
15 | 16 | date_range, |
16 | 17 | find_standard_monthly_netcdf_files, |
| 18 | + get_complete_output_dir, |
| 19 | + get_intermediate_output_dir, |
17 | 20 | get_num_missing_pixels, |
18 | 21 | nrt_daily_filename, |
19 | 22 | nrt_monthly_filename, |
@@ -323,3 +326,91 @@ def test_raise_error_for_dates(): |
323 | 326 | # If one or more dates are passed, an error should be raised. |
324 | 327 | with pytest.raises(RuntimeError): |
325 | 328 | raise_error_for_dates(error_dates=[dt.date(2011, 1, 1)]) |
| 329 | + |
| 330 | + |
| 331 | +def test_clean_outputs_for_date_range(fs): |
| 332 | + hemisphere = NORTH |
| 333 | + start_date = dt.date(2025, 1, 1) |
| 334 | + end_date = dt.date(2025, 1, 2) |
| 335 | + |
| 336 | + base_output_dir = Path("/output/") |
| 337 | + complete_output_dir = get_complete_output_dir( |
| 338 | + hemisphere=hemisphere, |
| 339 | + base_output_dir=base_output_dir, |
| 340 | + ) |
| 341 | + |
| 342 | + # for date in start_date, end_date |
| 343 | + complete_files = [ |
| 344 | + complete_output_dir / "sic_psn12.5_20241226_am2_v06r00.nc", |
| 345 | + complete_output_dir / "sic_psn12.5_20241227_am2_v06r00.nc", |
| 346 | + complete_output_dir / "sic_psn12.5_20241228_am2_v06r00.nc", |
| 347 | + complete_output_dir / "sic_psn12.5_20241229_am2_v06r00.nc", |
| 348 | + complete_output_dir / "sic_psn12.5_20241230_am2_v06r00.nc", |
| 349 | + complete_output_dir / "sic_psn12.5_20241231_am2_v06r00.nc", |
| 350 | + complete_output_dir / "sic_psn12.5_20250101_am2_v06r00.nc", # target |
| 351 | + complete_output_dir / "sic_psn12.5_20250102_am2_v06r00.nc", # target |
| 352 | + complete_output_dir / "sic_psn12.5_20250103_am2_v06r00.nc", |
| 353 | + complete_output_dir / "sic_psn12.5_20250104_am2_v06r00.nc", |
| 354 | + complete_output_dir / "sic_psn12.5_20250105_am2_v06r00.nc", |
| 355 | + complete_output_dir / "sic_psn12.5_20250106_am2_v06r00.nc", |
| 356 | + complete_output_dir / "sic_psn12.5_20250107_am2_v06r00.nc", |
| 357 | + complete_output_dir / "sic_psn12.5_20250108_am2_v06r00.nc", |
| 358 | + ] |
| 359 | + for complete_file in complete_files: |
| 360 | + fs.create_file(complete_file) |
| 361 | + |
| 362 | + intermediate_output_dir = get_intermediate_output_dir( |
| 363 | + hemisphere=hemisphere, |
| 364 | + base_output_dir=base_output_dir, |
| 365 | + ) |
| 366 | + intermediate_files = [ |
| 367 | + intermediate_output_dir / "sic_psn12.5_20241226_am2_v06r00.nc", |
| 368 | + intermediate_output_dir / "sic_psn12.5_20241227_am2_v06r00.nc", |
| 369 | + intermediate_output_dir / "sic_psn12.5_20241228_am2_v06r00.nc", |
| 370 | + intermediate_output_dir / "sic_psn12.5_20241229_am2_v06r00.nc", |
| 371 | + intermediate_output_dir / "sic_psn12.5_20241230_am2_v06r00.nc", |
| 372 | + intermediate_output_dir / "sic_psn12.5_20241231_am2_v06r00.nc", |
| 373 | + intermediate_output_dir / "sic_psn12.5_20250101_am2_v06r00.nc", # target |
| 374 | + intermediate_output_dir / "sic_psn12.5_20250102_am2_v06r00.nc", # target |
| 375 | + intermediate_output_dir / "sic_psn12.5_20250103_am2_v06r00.nc", |
| 376 | + intermediate_output_dir / "sic_psn12.5_20250104_am2_v06r00.nc", |
| 377 | + intermediate_output_dir / "sic_psn12.5_20250105_am2_v06r00.nc", |
| 378 | + intermediate_output_dir / "sic_psn12.5_20250106_am2_v06r00.nc", |
| 379 | + intermediate_output_dir / "sic_psn12.5_20250107_am2_v06r00.nc", |
| 380 | + intermediate_output_dir / "sic_psn12.5_20250108_am2_v06r00.nc", |
| 381 | + ] |
| 382 | + for intermediate_file in intermediate_files: |
| 383 | + fs.create_file(intermediate_file) |
| 384 | + |
| 385 | + clean_outputs_for_date_range( |
| 386 | + hemisphere=hemisphere, |
| 387 | + base_output_dir=base_output_dir, |
| 388 | + start_date=start_date, |
| 389 | + end_date=end_date, |
| 390 | + ) |
| 391 | + |
| 392 | + expected_complete_files = [ |
| 393 | + complete_output_dir / "sic_psn12.5_20241226_am2_v06r00.nc", |
| 394 | + complete_output_dir / "sic_psn12.5_20241227_am2_v06r00.nc", |
| 395 | + complete_output_dir / "sic_psn12.5_20241228_am2_v06r00.nc", |
| 396 | + complete_output_dir / "sic_psn12.5_20241229_am2_v06r00.nc", |
| 397 | + complete_output_dir / "sic_psn12.5_20241230_am2_v06r00.nc", |
| 398 | + complete_output_dir / "sic_psn12.5_20241231_am2_v06r00.nc", |
| 399 | + complete_output_dir / "sic_psn12.5_20250103_am2_v06r00.nc", |
| 400 | + complete_output_dir / "sic_psn12.5_20250104_am2_v06r00.nc", |
| 401 | + complete_output_dir / "sic_psn12.5_20250105_am2_v06r00.nc", |
| 402 | + complete_output_dir / "sic_psn12.5_20250106_am2_v06r00.nc", |
| 403 | + complete_output_dir / "sic_psn12.5_20250107_am2_v06r00.nc", |
| 404 | + complete_output_dir / "sic_psn12.5_20250108_am2_v06r00.nc", |
| 405 | + ] |
| 406 | + |
| 407 | + expected_intermediate_files = [ |
| 408 | + intermediate_output_dir / "sic_psn12.5_20241226_am2_v06r00.nc", |
| 409 | + intermediate_output_dir / "sic_psn12.5_20250108_am2_v06r00.nc", |
| 410 | + ] |
| 411 | + |
| 412 | + actual_complete_files = list(complete_output_dir.rglob("*.nc")) |
| 413 | + actual_intermediate_files = list(intermediate_output_dir.rglob("*.nc")) |
| 414 | + |
| 415 | + assert set(actual_complete_files) == set(expected_complete_files) |
| 416 | + assert set(actual_intermediate_files) == set(expected_intermediate_files) |
0 commit comments