Skip to content

geotiff: extract coord/transform helpers to _coords.py#1841

Merged
brendancol merged 1 commit into
mainfrom
issue-1813-coords
May 14, 2026
Merged

geotiff: extract coord/transform helpers to _coords.py#1841
brendancol merged 1 commit into
mainfrom
issue-1813-coords

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Part of #1813.

First slice of the xrspatial/geotiff/__init__.py split 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

  • Adds xrspatial/geotiff/_coords.py holding 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__.py re-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.
  • Collapses six inline copies of the windowed coord / transform-tuple arithmetic in:
    • _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_vrt eager + _read_vrt_dask_internal (VRT coords and transform tuple)
  • __init__.py shrinks by ~280 lines.

Public API is unchanged. Behaviour is unchanged: the helpers reproduce the existing branch-by-branch logic verbatim, including the has_georef=False integer-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 on main and 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, and coords_from_geo_info wrapper variants.

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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 14, 2026
@brendancol brendancol requested a review from Copilot May 14, 2026 16:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.py with coords_from_pixel_geometry, transform_tuple_from_pixel_geometry, coords_from_geo_info, and the moved geo_to_coords / transform_tuple / transform_from_attr / coords_to_transform helpers.
  • __init__.py collapses six inline windowed-coord / transform-tuple snippets to calls into the new helpers (~280-line net reduction); also unifies the has_georef=False integer-pixel fallback used by #1710 / #1753 across all backends.
  • New test_coords_1813.py with 13 unit tests covering area vs point, north-up vs south-up, windowed reads, no-georef fallback, and the coords_from_geo_info wrapper.

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.

@brendancol brendancol merged commit 6c0c2d8 into main May 14, 2026
16 checks passed
@brendancol brendancol deleted the issue-1813-coords branch May 15, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants