Skip to content

(0.110.2) Fix reading reduced fields from NetCDF as FieldTimeSeries#5682

Merged
tomchor merged 7 commits into
mainfrom
tc/netcdf-fix
Jun 15, 2026
Merged

(0.110.2) Fix reading reduced fields from NetCDF as FieldTimeSeries#5682
tomchor merged 7 commits into
mainfrom
tc/netcdf-fix

Conversation

@tomchor

@tomchor tomchor commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

FieldTimeSeries("file.nc", "var") threw ArgumentError: tuple length should be ≥ 0, got -1 when 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 used loc == Nothing while the caller passes instantiated locations (nothing), and nothing == Nothing is false. So no dimension was inflated and a lower-dimensional array reached offset_data, where ntuple(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

tomchor and others added 3 commits June 13, 2026 21:04
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>
@tomchor tomchor changed the title Fix reading reduced fields from NetCDF as FieldTimeSeries (0.110.2) Fix reading reduced fields from NetCDF as FieldTimeSeries Jun 14, 2026
@tomchor tomchor marked this pull request as draft June 14, 2026 04:09
@tomchor tomchor marked this pull request as ready for review June 14, 2026 23:54
@tomchor tomchor added the bug 🐞 Even a perfect program still has bugs label Jun 15, 2026
@tomchor tomchor requested a review from Copilot June 15, 2026 19:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_dimensions to treat reduced locations represented as either the type Nothing or the instance nothing.
  • 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.1 to 0.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.

Comment thread test/test_netcdf_writer.jl
Comment thread ext/OceananigansNCDatasetsExt/output_readers.jl
@tomchor

tomchor commented Jun 15, 2026

Copy link
Copy Markdown
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)

@glwagner glwagner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note, we may want to make sure the test harness on #5654 includes reduced fields.

@tomchor tomchor merged commit 5f3fb0d into main Jun 15, 2026
87 of 89 checks passed
@tomchor tomchor deleted the tc/netcdf-fix branch June 15, 2026 22:39
@tomchor

tomchor commented Jun 15, 2026

Copy link
Copy Markdown
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)

Thanks for the review. I can push that change to #5654 if you give me the go ahead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Even a perfect program still has bugs extensions 🧬 output 💾

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants