geotiff: extract coord/transform helpers to _coords.py#1841
Conversation
First slice of the __init__.py split tracked in #1813. Moves the GeoTransform-to-(y, x) coord builders and the rasterio-style transform tuple builders out of __init__.py into a new private module xrspatial/geotiff/_coords.py and collapses six inline copies of the windowed-coord arithmetic in the eager, dask, GPU, and VRT read paths down to single helper calls. Public API unchanged. The existing private symbols (_geo_to_coords, _transform_tuple, _transform_from_attr, _coords_to_transform, _BAND_DIM_NAMES) are still importable from xrspatial.geotiff for tests and downstream callers. __init__.py shrinks by ~280 lines.
There was a problem hiding this comment.
Pull request overview
Lowest-risk first slice of the xrspatial/geotiff/__init__.py split tracked in issue #1813. Extracts the GeoTransform-to-coord and transform-tuple helpers — previously inlined in six different backend read paths — into a new internal _coords.py module, and replaces each inline copy with a call to the shared helpers. Public API is unchanged, and pre-existing private names (_geo_to_coords, _transform_tuple, _transform_from_attr, _coords_to_transform, _BAND_DIM_NAMES) are re-exported under the same names so existing tests keep working.
Changes:
- New
xrspatial/geotiff/_coords.pywithcoords_from_pixel_geometry,transform_tuple_from_pixel_geometry,coords_from_geo_info, and the movedgeo_to_coords/transform_tuple/transform_from_attr/coords_to_transformhelpers. __init__.pycollapses six inline windowed-coord / transform-tuple snippets to calls into the new helpers (~280-line net reduction); also unifies thehas_georef=Falseinteger-pixel fallback used by #1710 / #1753 across all backends.- New
test_coords_1813.pywith 13 unit tests covering area vs point, north-up vs south-up, windowed reads, no-georef fallback, and thecoords_from_geo_infowrapper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
xrspatial/geotiff/_coords.py |
New module holding the shared coord / transform helpers. |
xrspatial/geotiff/__init__.py |
Replaces six inline coord/transform blocks with calls into _coords; re-exports helpers under their old underscore names. |
xrspatial/geotiff/tests/test_coords_1813.py |
New unit tests for the extracted helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Part of #1813.
First slice of the
xrspatial/geotiff/__init__.pysplit tracked in #1813. The full split lays out per-backend modules; this PR only does the lowest-risk extraction so it can land independently.Summary
xrspatial/geotiff/_coords.pyholding the shared GeoTransform-to-coord builders:coords_from_pixel_geometry,transform_tuple_from_pixel_geometry,coords_from_geo_info,geo_to_coords,transform_tuple,transform_from_attr,coords_to_transform.__init__.pyre-imports those helpers under the same leading-underscore names (_geo_to_coords,_transform_tuple,_transform_from_attr,_coords_to_transform,_BAND_DIM_NAMES) so existing test imports keep working._populate_attrs_from_geo_info(windowed transform tuple)open_geotiff(windowed eager coords)read_geotiff_dask(windowed dask coords)_gpu_apply_window_band(windowed GPU coords for tiled reads)read_geotiff_gpu(windowed GPU coords for stripped reads)read_vrteager +_read_vrt_dask_internal(VRT coords and transform tuple)__init__.pyshrinks by ~280 lines.Public API is unchanged. Behaviour is unchanged: the helpers reproduce the existing branch-by-branch logic verbatim, including the
has_georef=Falseinteger-pixel fallback (#1710, #1753) and the windowed-origin clamp used by the VRT path.Test plan
pytest xrspatial/geotiff/tests/— same 2507 passing / 11 pre-existing failing as baseline before the refactor (the 11 failures reproduce onmainand are unrelated to this PR).pytest xrspatial/geotiff/tests/test_coords_1813.py -v— 13 new unit tests covering basic affine, windowed read, AREA vs POINT half-pixel shift, negative y-resolution north-up, no-georef fallback, andcoords_from_geo_infowrapper variants.