(0.110.2) Fix reading reduced fields from NetCDF as FieldTimeSeries#5682
Merged
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) <noreply@anthropic.com>
Contributor
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.
Member
Author
|
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) |
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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