Repository navigation
Skip ismip7_forcing steps when final output already exists #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4eeada9
30c3cad
90fc71a
9994e92
aa20937
fd5ee59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,10 @@ | |
| mapping_file_name, | ||
| resolve_atmosphere_source, | ||
| ) | ||
| from compass.landice.ismip7.remap import extrapolate_source | ||
| from compass.landice.ismip7.remap import ( | ||
| extrapolate_source, | ||
| netcdf_file_is_valid, | ||
| ) | ||
| from compass.step import Step | ||
|
|
||
|
|
||
|
|
@@ -93,6 +96,16 @@ def run(self): | |
| logger.info(f"Found {len(input_files)} SMB files for years " | ||
| f"{start_year}-{end_year}") | ||
|
|
||
| # Check if final output already exists; skip if so | ||
| output_file = (f"{mali_mesh_name}_SMB_{model}_{scenario}_" | ||
| f"{source.version}_{start_year}-{end_year}.nc") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the version in the name, a new version writes a second file next to the old one, but
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "When I went from v1 to v2, its setup exited for SMB, temperature and shelf collapse, and gave runoff and the gradients an empty filename." Was this for "Output written before this commit also won't be recognized, so a resume reprocesses everything and leaves both files." I don't think I care about backward compatibility before this commit, since we can easily manually rename previously processed files if necessary to avoid reprocessing. However, I'll think a little more about it.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is The gap is in Agreed on outputs from before this commit; renaming by hand is fine. Posted by Claude Code on @xylar's behalf. The testing, analysis and wording above are AI-authored; please check them accordingly.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trhille, if this is just Claude misusing the tool, feel free to ignore this advice. |
||
| output_path = os.path.join(output_base_path, forcing_group, | ||
| "atmosphere") | ||
| dst = os.path.join(output_path, output_file) | ||
| if os.path.exists(dst): | ||
| logger.info(f"Output already exists, skipping: {dst}") | ||
| return | ||
|
|
||
| # The mapping file is supplied by the build_mapping_file step. | ||
| mapping_file = mapping_file_name( | ||
| config, "atm", source.source_grid, method_remap) | ||
|
|
@@ -104,14 +117,24 @@ def run(self): | |
| remapped_file = f"remapped_{basename}" | ||
| remapped_files.append(remapped_file) | ||
|
|
||
| if os.path.exists(remapped_file): | ||
| if netcdf_file_is_valid(remapped_file, "acabf", | ||
| require_time=True, logger=logger): | ||
| logger.info(f" Remapped file exists, skipping: {basename}") | ||
| continue | ||
| # Incomplete remapped file from an interrupted run: drop and | ||
| # redo | ||
| if os.path.exists(remapped_file): | ||
| logger.info(f" Reprocessing incomplete remapped file: " | ||
| f"{basename}") | ||
| os.remove(remapped_file) | ||
|
|
||
| # Extrapolate fill values on source grid before remapping | ||
| # so they don't pollute neighboring cells during interpolation | ||
| extrap_file = f"extrap_{basename}" | ||
| if not os.path.exists(extrap_file): | ||
| if not netcdf_file_is_valid(extrap_file, "acabf", | ||
| logger=logger): | ||
| if os.path.exists(extrap_file): | ||
| os.remove(extrap_file) | ||
| extrapolate_source(input_file, extrap_file, "acabf", logger) | ||
|
|
||
| logger.info(f" Remapping: {basename}") | ||
|
|
@@ -128,9 +151,6 @@ def run(self): | |
|
|
||
| # Combine remapped files and rename to MALI conventions | ||
| logger.info("Combining remapped files and renaming variables...") | ||
| output_file = (f"{mali_mesh_name}_SMB_{model}_{scenario}_" | ||
| f"{start_year}-{end_year}.nc") | ||
|
|
||
| self._combine_and_rename(remapped_files, output_file) | ||
|
|
||
| # Clean up remapped files | ||
|
|
@@ -140,12 +160,9 @@ def run(self): | |
| os.remove(f) | ||
|
|
||
| # Place output in appropriate directory | ||
| output_path = os.path.join(output_base_path, forcing_group, | ||
| "atmosphere") | ||
| if not os.path.exists(output_path): | ||
| os.makedirs(output_path) | ||
|
|
||
| dst = os.path.join(output_path, output_file) | ||
| shutil.copy(output_file, dst) | ||
|
|
||
| logger.info(f"Done. Output: {dst}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,10 @@ | |
| mapping_file_name, | ||
| resolve_atmosphere_source, | ||
| ) | ||
| from compass.landice.ismip7.remap import extrapolate_source | ||
| from compass.landice.ismip7.remap import ( | ||
| extrapolate_source, | ||
| netcdf_file_is_valid, | ||
| ) | ||
| from compass.step import Step | ||
|
|
||
|
|
||
|
|
@@ -93,6 +96,16 @@ def run(self): | |
| logger.info(f"Found {len(input_files)} temperature files for years " | ||
| f"{start_year}-{end_year}") | ||
|
|
||
| # Check if final output already exists; skip if so | ||
| output_file = (f"{mali_mesh_name}_temperature_{model}_{scenario}_" | ||
| f"{source.version}_{start_year}-{end_year}.nc") | ||
| output_path = os.path.join(output_base_path, forcing_group, | ||
| "atmosphere") | ||
| dst = os.path.join(output_path, output_file) | ||
| if os.path.exists(dst): | ||
| logger.info(f"Output already exists, skipping: {dst}") | ||
| return | ||
|
Comment on lines
+105
to
+107
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in aa20937 |
||
|
|
||
| # The mapping file is supplied by the build_mapping_file step. | ||
| mapping_file = mapping_file_name( | ||
| config, "atm", source.source_grid, method_remap) | ||
|
|
@@ -104,14 +117,23 @@ def run(self): | |
| remapped_file = f"remapped_{basename}" | ||
| remapped_files.append(remapped_file) | ||
|
|
||
| if os.path.exists(remapped_file): | ||
| if netcdf_file_is_valid(remapped_file, "ts", require_time=True, | ||
| logger=logger): | ||
| logger.info(f" Remapped file exists, skipping: {basename}") | ||
| continue | ||
| # Incomplete remapped file from an interrupted run: drop and | ||
| # redo | ||
| if os.path.exists(remapped_file): | ||
| logger.info(f" Reprocessing incomplete remapped file: " | ||
| f"{basename}") | ||
| os.remove(remapped_file) | ||
|
|
||
| # Extrapolate fill values on source grid before remapping | ||
| # so they don't pollute neighboring cells during interpolation | ||
| extrap_file = f"extrap_{basename}" | ||
| if not os.path.exists(extrap_file): | ||
| if not netcdf_file_is_valid(extrap_file, "ts", logger=logger): | ||
| if os.path.exists(extrap_file): | ||
| os.remove(extrap_file) | ||
| extrapolate_source(input_file, extrap_file, "ts", logger) | ||
|
|
||
| logger.info(f" Remapping: {basename}") | ||
|
|
@@ -128,9 +150,6 @@ def run(self): | |
|
|
||
| # Combine remapped files and rename to MALI conventions | ||
| logger.info("Combining remapped files and renaming variables...") | ||
| output_file = (f"{mali_mesh_name}_temperature_{model}_{scenario}_" | ||
| f"{start_year}-{end_year}.nc") | ||
|
|
||
| self._combine_and_rename(remapped_files, output_file) | ||
|
|
||
| # Clean up remapped files | ||
|
|
@@ -140,12 +159,9 @@ def run(self): | |
| os.remove(f) | ||
|
|
||
| # Place output in appropriate directory | ||
| output_path = os.path.join(output_base_path, forcing_group, | ||
| "atmosphere") | ||
| if not os.path.exists(output_path): | ||
| os.makedirs(output_path) | ||
|
|
||
| dst = os.path.join(output_path, output_file) | ||
| shutil.copy(output_file, dst) | ||
|
|
||
| logger.info(f"Done. Output: {dst}") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in aa20937