Skip to content

Commit

Permalink
skip with warning if filtered sample file already exists
Browse files Browse the repository at this point in the history
rather than blowing up if the directory already exists
  • Loading branch information
henryaddison committed May 9, 2024
1 parent 20a3a46 commit a1dfb34
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ml_downscaling_emulator/bin/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def filter(
split=split,
ensemble_member=ensemble_member,
)
os.makedirs(filtered_samples_dirpath, exist_ok=False)
os.makedirs(filtered_samples_dirpath, exist_ok=True)

samples_filepaths_to_filter = samples_path(
workdir,
Expand All @@ -102,13 +102,17 @@ def filter(
ensemble_member=ensemble_member,
)

logger.info(f"Found for filtering: {samples_filepaths_to_filter}")
logger.debug(f"Found for filtering: {samples_filepaths_to_filter}")
for sample_filepath in samples_glob(samples_filepaths_to_filter):
logger.info(f"Working on {sample_filepath}")
logger.debug(f"Working on {sample_filepath}")
samples_ds = xr.open_dataset(sample_filepath)

filtered_samples_filepath = filtered_samples_dirpath / sample_filepath.name

if filtered_samples_filepath.exists():
logger.warning(f"Skipping {filtered_samples_filepath} as already exists")
continue

logger.info(f"Saving to {filtered_samples_filepath}")
samples_ds.sel(time=slice(*TIME_PERIODS[time_period])).to_netcdf(
filtered_samples_filepath
Expand Down

0 comments on commit a1dfb34

Please sign in to comment.