Skip to content

Improve case_input.nc output handling#2

Open
Sandro-Meier-Empa wants to merge 3 commits into
microhh:mainfrom
Sandro-Meier-Empa:feature-improved-io-handling
Open

Improve case_input.nc output handling#2
Sandro-Meier-Empa wants to merge 3 commits into
microhh:mainfrom
Sandro-Meier-Empa:feature-improved-io-handling

Conversation

@Sandro-Meier-Empa
Copy link
Copy Markdown

This MR improves save_case_input() by allowing overwrites and preserving metadata from xarray inputs.

Changes

  • Preserve xarray.DataArray.attrs when writing variables to NetCDF.
  • Add an overwrite=False argument to save_case_input().
  • Raise FileExistsError when the target input file already exists unless overwrite=True.
  • Use pathlib.Path for output file path handling.

Copilot AI review requested due to automatic review settings June 4, 2026 08:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR enhances save_case_input() to better support xarray metadata and safer file writes by adding an overwrite guard and propagating .attrs into the generated NetCDF output.

Changes:

  • Replace os.path path handling with pathlib.Path, and add an overwrite flag to control clobbering existing output files.
  • Introduce add_attrs() to persist xarray-style attributes onto NetCDF variables/groups.
  • Update variable writing to extract .values for xarray.DataArray inputs and attach attributes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread microhhpy/io/case_input.py
Comment thread microhhpy/io/case_input.py
Comment thread microhhpy/io/case_input.py Outdated
Comment thread microhhpy/io/case_input.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants