tifs_to_geozarr: propagate GDAL Unit Type + long_name into zarr attrs#53
Merged
scottstanie merged 1 commit intoopera-adt:mainfrom Apr 24, 2026
Merged
Conversation
rasterio exposes the source GeoTIFF's GDAL Unit Type (set by `SetUnitType`) as `src.units[0]`; on the palos-verdes velocity.tif it reads as `'m/year'`. The converter was dropping it — variables in the output zarr had only `grid_mapping: spatial_ref` attrs. The backend already surfaces `attrs["units"]` as `dsInfo.unit` on the `/datasets` endpoint, and the frontend `ColormapBar` already has a `unit` slot next to the colorbar that was always empty because no variable ever set the attr. Writing it at conversion time fills it in automatically. Also sets `long_name` to the RasterGroup's human-readable `display_name` (e.g. `"Velocity"`) so the colorbar title is "Velocity" instead of the sanitized zarr variable name `"velocity"`. Both are CF-conventions attrs, so other zarr readers benefit too. Note: existing cubes must be rebuilt with `bowser tifs-to-geozarr` to pick up the attrs — the fix is at write time. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
When
bowser tifs-to-geozarrconverts a stack of GeoTIFFs whose band has a GDALUnit Typeset (e.g. dolphin'svelocity.tif→m/year), that unit was getting dropped on the floor. Every variable in the output zarr ended up with just{grid_mapping: spatial_ref}attrs.Meanwhile the backend has been surfacing
attrs["units"]asdsInfo.uniton/datasetsfor a while, and the frontendColormapBarhas aunitslot next to the colorbar that was always empty because no variable ever set the attr.What changes
_Loadeddataclass gains aunits: str | Nonefield._load_groupreadssrc.units[0]from the first file of the group at the same time it sniffs dtype (one extra line, same rasterio context). Empty-string units normalised toNone._write_variable_to_all_levelsstampsda.attrs["units"]when present and always stampsda.attrs["long_name"] = lv.display_name. Both are CF-conventions attrs, so other zarr readers benefit too.Side effect: the colorbar title now reads
Velocity(the RasterGroup'sdisplay_name) instead of the sanitized zarr variable namevelocity.Verified
Against
/Volumes/.../velocity.tif(GDALUnit Type: m/year):Caveat
Existing cubes must be rebuilt with
bowser tifs-to-geozarrto pick up the new attrs — this is a write-time fix, not a back-fill.Test plan
_load_groupreturns the expectedunitson a real file (see above)m/yearunder the velocity bar in the UI🤖 Generated with Claude Code