Add DataArray.metpy.to_geotiff for GIS raster export#4086
Open
martinguthrie93 wants to merge 1 commit into
Open
Add DataArray.metpy.to_geotiff for GIS raster export#4086martinguthrie93 wants to merge 1 commit into
martinguthrie93 wants to merge 1 commit into
Conversation
MetPy can compute on gridded fields in their native projected coordinates
but has no way to hand those fields to the wider GIS ecosystem as a
georeferenced raster. Add a `.metpy.to_geotiff()` method on the DataArray
accessor that bridges MetPy's CRS (from `parse_cf`/`assign_crs`) and x/y
spatial dimensions to rioxarray, producing a GeoTIFF readable by GIS
software such as QGIS, ArcGIS, and GDAL-based tooling.
rioxarray is added as an optional ("extras") dependency; the method raises
a clear ImportError when it is absent and a clear ValueError when x/y
dimension coordinates cannot be identified. Adds tests covering the
georeferenced round-trip, the missing-rioxarray path, and the
missing-spatial-coordinate path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
HoHo seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
Description of Changes
Adds a
.metpy.to_geotiff()method to the DataArray accessor, giving MetPy afirst-class path to export a gridded field as a georeferenced GeoTIFF that
GIS software (QGIS, ArcGIS, GDAL-based tooling) can read directly.
Today MetPy can read, compute on, and plot gridded data in its native projected
coordinates, but there is no way to write that data back out as a standard GIS
raster. This closes the raster-interoperability gap (item 1 of #4085).
What it does
to_geotiff()is a thin, well-scoped bridge torioxarray:.parse_cf/.assign_crs) and communicatesit to rioxarray via the existing
.metpy.pyproj_crs;.metpy.coordinates('x', 'y');metpy_crsobject coordinate beforewriting;
**kwargsto rioxarray'sto_raster(e.g.compress,dtype,tiled).Error handling
ImportError(with install hint) when the optionalrioxarraydependency is missing.
ValueErrorwhen x/y dimension coordinates cannot be identified.Dependencies
Adds
rioxarray>=0.13.0to the optionalextrasgroup. It is not a harddependency; the method degrades gracefully when it is absent.
Tests
test_to_geotiff— round-trips a parsed field to GeoTIFF and asserts the CRS andspatial dimensions are preserved on read-back.
test_to_geotiff_no_rioxarray— asserts the helpfulImportErrorwhen rioxarrayis unavailable.
test_to_geotiff_no_spatial_coords— asserts the helpfulValueErrorwhen x/ycoordinates are absent.
All new tests pass locally;
flake8is clean on the changed files.Notes / possible follow-ups (out of scope for this PR)
Dataset.metpy.to_geotiff()(multi-band export).the linked issue).