(0.110.2) Fix reading reduced fields from NetCDF as FieldTimeSeries#5682
Conversation
Covers reading a dimensionally-reduced field (Average over x, (x,y), and (y,z)) back as a FieldTimeSeries from NetCDF, asserting location, times, sizes, and values round-trip. This path was previously uncovered, which let the inflate_nothing_dimensions bug go unnoticed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes a NetCDF FieldTimeSeries read path for dimensionally-reduced fields (with Nothing/nothing in the location tuple) by ensuring squeezed dimensions are properly re-inflated before offset_data constructs the expected 3D OffsetArray. It also bumps the package patch version and adds a regression test covering reduced-field round-trips.
Changes:
- Fix
inflate_nothing_dimensionsto treat reduced locations represented as either the typeNothingor the instancenothing. - Add a regression test that writes reduced fields to NetCDF and reads them back via
FieldTimeSeries, comparing locations and values. - Bump version from
0.110.1to0.110.2.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ext/OceananigansNCDatasetsExt/output_readers.jl |
Fixes dimension re-inflation by correctly detecting Nothing/nothing reduced dimensions; updates docstring. |
test/test_netcdf_writer.jl |
Adds a regression test for NetCDF round-trip of reduced fields read back as FieldTimeSeries. |
Project.toml |
Patch version bump to 0.110.2. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Can I get a review on this PR? Tests should be passing and I'd like to merge this soon. (#5684 would also be helpful) |
Summary
FieldTimeSeries("file.nc", "var")threwArgumentError: tuple length should be ≥ 0, got -1when reading a NetCDF variable written from a dimensionally-reduced field (e.g.Average(c, dims=1), location(Nothing, Center, Center)).The reader re-inflates squeezed dimensions via
inflate_nothing_dimensions, but that check usedloc == Nothingwhile the caller passes instantiated locations (nothing), andnothing == Nothingisfalse. So no dimension was inflated and a lower-dimensional array reachedoffset_data, wherentuple(Val(ndims - length(grid_size)))went negative.Fix: test for both the type and the instance —
loc === Nothing || loc === nothing.Test
Adds a regression test reading reduced fields (averaged over x, (x,y), and (y,z)) back as a
FieldTimeSeries, asserting location, times, sizes, and values round-trip. This path was previously uncovered.🤖 Generated with Claude Code