Skip to content
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

(0.96.0) Improve the NetCDFOutputWriter experience #4046

Open
wants to merge 54 commits into
base: main
Choose a base branch
from

Conversation

ali-ramadhan
Copy link
Member

@ali-ramadhan ali-ramadhan commented Jan 16, 2025

This PR updates the NetCDFOutputWriter to:

  • Properly work on RectilinearGrid and LatitudeLongitudeGrid (with correct and useful output attributes).
  • Save grid metrics with useful attributes.
  • Save immersed boundary information.
  • Properly support flat grids.
  • Work cleanly with LagrangianParticles output.
  • Allow for flexible dimension naming to satisfy desired naming conventions.
  • Write grid reconstruction metadata into a NetCDF group to support FieldTimeSeries construction from NetCDF (full support to be added in a subsequent PR).

Tests have been added for all these features. Thank you to @tomchor and @almacarolina for helpful discussions during this refactor!

There's still a little bit left to do, but if anyone has any thoughts or feedback and would like to leave a review I'd appreciate it! There are a lot of line additions but thankfully the changes are almost fully isolated to just two files.

TODO:

  • Output grid areas and volumes too? But maybe it would be nice to first have xareas, volumes, etc. via KernelFunctionOperation?
  • Further improve the docstring and documentation for NetCDFOutputWriter to highlight all features.
  • Use NetCDFOutputWriter + some fancier features in an example.
  • Figure out which tests are missing.
  • Watch out for failing tests/examples and fix them.

Some comments:

  • I'm hoping to merge this PR and immediately work on adding support for NetCDF-backed FieldTimeSeries. I was planning on working on it here (as the branch name suggests) but it will involve refactoring field_time_series.jl which seems best suited for a separate PR.
  • Supporting output of the free surface height is a bit hacky. Since it's a regular Field but is kind of a ReducedField we cannot dispatch on its type and work with it correctly. Will open an issue to discuss.
  • I'm tagging v0.96.0 since this PR significantly changes the dimension names used in NetCDF files produced by NetCDFOutputWriter.

Resolves #1334 (via the dimension name generator)
Resolves #2248
Resolves #2770 (Maybe? You can save u, v, w, T, S, and η in the same NetCDF file but it's a bit hacky, see above.)
Resolves #3997

This PR makes progress on issue #3935
This PR supercedes PR #2652

@tomchor
Copy link
Collaborator

tomchor commented Jan 17, 2025

I haven't checked the tests yet, but so far it's looking great! I'll try to check the tests tomorrow.

@glwagner
Copy link
Member

Supporting output of the free surface height is a bit hacky. Since it's a regular Field but is kind of a ReducedField we cannot dispatch on its type and work with it correctly. Will open an issue to discuss.

It's not a ReducedField, its a WindowedField. But properly supporting WindowedField is intrinsic to NetCDF output writing without halos so there should be a general solution to this.

@glwagner
Copy link
Member

I'm tagging v0.96.0 since this PR significantly changes the dimension names used in NetCDF files produced by NetCDFOutputWriter.

I'm not sure a FieldTimeSeries refactor is necessary (note that we also support NetCDF FieldTimeSeries on ClimaOcean, so I don't entirely understand why refactoring is necessary). However, in the case that such a refactor bumps the version again, would it be prudent to be more conservative about version bumping here?

@glwagner
Copy link
Member

Supporting output of the free surface height is a bit hacky. Since it's a regular Field but is kind of a ReducedField we cannot dispatch on its type and work with it correctly. Will open an issue to discuss.

It's not a ReducedField, its a WindowedField. But properly supporting WindowedField is intrinsic to NetCDF output writing without halos so there should be a general solution to this.

In case its helpful: a WindowedField is a Field with non-default indices. We omit halo regions by producing a windowed field with indices between (1:Nx, 1:Ny, 1:Nz) (for example), rather than (:, :, :) which span the entire domain including halos. The free surface has indices (:, :, Nz+1) --- indicating that it is not a reduced field with physical validity throughout the domain at z, but rather a Field that occupies a specific slice of the domain (k=Nz+1).

Thus with a general way of "windowing" dimensions, we should support free surface and with_halos=false. I'm not sure how the latter is supported without supporting the free surface, though.

@ali-ramadhan
Copy link
Member Author

@glwagner Thanks for pointing out that the free surface is a WindowedField. I should be able to add proper/cleaner support now!

@ali-ramadhan
Copy link
Member Author

I'm tagging v0.96.0 since this PR significantly changes the dimension names used in NetCDF files produced by NetCDFOutputWriter.

I'm not sure a FieldTimeSeries refactor is necessary (note that we also support NetCDF FieldTimeSeries on ClimaOcean, so I don't entirely understand why refactoring is necessary). However, in the case that such a refactor bumps the version again, would it be prudent to be more conservative about version bumping here?

Ah I may have just assumed a large refactor would be necessary without digging into FieldTimeSeries first!

I believe that according to semantic versioning which Oceananigans.jl follows (still I think?), this PR would necessitate a minor version bump as it changes the NetCDFOutputWriter interface and any code that interfaces with the NetCDF output files will break.

It's probably not nice to increment the minor version very often, but is there a particular reason to be conservative about version bumping?

@glwagner
Copy link
Member

glwagner commented Mar 3, 2025

I'm tagging v0.96.0 since this PR significantly changes the dimension names used in NetCDF files produced by NetCDFOutputWriter.

I'm not sure a FieldTimeSeries refactor is necessary (note that we also support NetCDF FieldTimeSeries on ClimaOcean, so I don't entirely understand why refactoring is necessary). However, in the case that such a refactor bumps the version again, would it be prudent to be more conservative about version bumping here?

Ah I may have just assumed a large refactor would be necessary without digging into FieldTimeSeries first!

I believe that according to semantic versioning which Oceananigans.jl follows (still I think?), this PR would necessitate a minor version bump as it changes the NetCDFOutputWriter interface and any code that interfaces with the NetCDF output files will break.

It's probably not nice to increment the minor version very often, but is there a particular reason to be conservative about version bumping?

For sure if introduces a breaking change to NetCDFOutputWriter then we need a new minor version.

Re: conservatism, no, I think we just want to try our best to follow the protocol; ie do not bump when not warranted, so as not to confuse interpretation of code changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants