Repository navigation
Conversation
…ibutes netCDF4 writes text attributes that h5py returns as bytes, so from_h5 on a netCDF4 file (an ATL15, for one) passed a bytes grid_mapping name to posixpath.join() and raised "Can't mix strings and bytes in path components". The name and the grid-mapping variable's attributes now go through nc_h5._attribute_value, the conversion the h5py reader of from_nc already uses, so the projection holds str and scalars as from_nc returns them. Files written by to_h5 store str and scalars already and read back unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
grid.data.from_h5crashed on netCDF4 files that have agrid_mappingattribute, e.g. every ATL15:netCDF4 writes text attributes as fixed-length strings, and h5py returns those as
bytes. With this change, thegrid_mappingname and the grid-mapping variable's attributes go throughnc_h5._attribute_value. That is the conversionfrom_nc's h5py reader already uses, soself.projectionholdsstrand scalars, asfrom_ncreturns them. Before, it heldbytesand 1-element arrays.Files written by
to_h5storestrand scalar attributes already, so they read back unchanged.Why
The ATL15 interactive notebook reads the rel006 ATL15s on S3. It had to use h5py directly because
from_h5failed on them.Checked
On
ATL15_A1_0332_3mo_40km_006_02.nc(groupsdelta_handdhdt_012mo,t_axis=0),from_h5now returns the same projection asfrom_nc(15 attributes, same values and types) and the same data.Not changed
from_h5does not read dimension order. ATL15 variables are (t, y, x), so it needst_axis=0; with the default it raises the existing shapeIndexError.from_ncreads ATL15s with eithert_axis.Tests
tests/test_nc_h5.py:from_h5on the packed netCDF4 fixture (root group and a subgroup) returns the projectionfrom_ncreturns. Both cases fail onmainwith theTypeErrorabove.to_h5(srs_epsg=3413)/from_h5round trip returnscrsunchanged. This passes onmaintoo.Full suite: 348 passed, 3 skipped.
🤖 Generated with Claude Code