geotiff: extract GPU helpers to _backends/_gpu_helpers.py (#1884)#1894
Merged
Conversation
Step 6 of #1813's multi-PR refactor of __init__.py. Pure code motion; no public API change. First PR to create the _backends/ subpackage. Created xrspatial/geotiff/_backends/__init__.py (empty placeholder) and moved into _backends/_gpu_helpers.py: - _is_gpu_data: cupy-backed array / DataArray detection. - _apply_nodata_mask_gpu: cupy mirror of the CPU sentinel-to-NaN mask (handles float and integer arrays, with the same out-of-range / fractional / non-finite skips as _resolve_masked_fill in _reader.py). - _gpu_decode_single_band_tiles: two-stage GPU decode (GDS then CPU-extracted bytes) for the PlanarConfiguration=2 path. - _apply_orientation_gpu: cupy mirror of the CPU orientation-flip helper for the eight TIFF Orientation tag values. - _apply_orientation_geo_info: GeoTransform update after an orientation flip, with the #1765 refusal for georeferenced orientations 5-8. - _gpu_apply_window_band: post-decode window + band slice on device. Every helper lazy-imports cupy at call time so the module imports cleanly on numpy-only environments. __init__.py re-imports the helpers from _backends._gpu_helpers so existing callers (read_geotiff_gpu, to_geotiff's GPU branch, write_geotiff_gpu) keep their identical signatures. Leading-underscore module name (_gpu_helpers.py) keeps _backends/gpu.py free for the read_geotiff_gpu entry-point body in step 7. Net __init__.py change: 4271 -> 3969 lines (-302). _gpu_helpers.py is 335 lines. Verification: pixel-parity matrix from #1889 (192 cells, all GPU cells included), runtime identity (9), GPU byteswap (#1508), overview nodata inheritance (#1739) -- 230/230 pass. Refs #1813.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the GeoTIFF GPU backend internals by extracting six GPU-only helper functions out of xrspatial/geotiff/__init__.py into a new private _backends/ subpackage, keeping the public API and existing import paths stable via re-exports.
Changes:
- Added
xrspatial/geotiff/_backends/_gpu_helpers.pycontaining the GPU helper implementations (lazy CuPy imports preserved). - Added
_backends/__init__.pyto establish the new internal subpackage. - Updated
xrspatial/geotiff/__init__.pyto import/re-export the helpers from the new module and removed the inlined implementations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
xrspatial/geotiff/_backends/_gpu_helpers.py |
New internal module hosting the extracted GPU helper implementations with lazy CuPy imports. |
xrspatial/geotiff/_backends/__init__.py |
Introduces the internal _backends subpackage (docstring-only placeholder). |
xrspatial/geotiff/__init__.py |
Re-exports the moved GPU helpers and deletes the previous in-file definitions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Step 6 of #1813's multi-PR refactor of
xrspatial/geotiff/__init__.py. Pure code motion; no public API change. First PR to create the_backends/subpackage.Created
xrspatial/geotiff/_backends/__init__.py(empty placeholder) and moved into_backends/_gpu_helpers.py:_is_gpu_data— cupy-backed array / DataArray detection._apply_nodata_mask_gpu— cupy mirror of the CPU sentinel→NaN mask, with the same out-of-range / fractional / non-finite skips as_resolve_masked_fillin_reader.py._gpu_decode_single_band_tiles— two-stage GPU decode (GDS, then CPU-extracted bytes) for thePlanarConfiguration=2path._apply_orientation_gpu— cupy mirror of the CPU orientation flip for all eight TIFF Orientation values._apply_orientation_geo_info—GeoTransformupdate after an orientation flip, with the geotiff: orientation 5-8 on georeferenced TIFFs returns wrong coords behind a warning #1765 refusal for georeferenced orientations 5–8._gpu_apply_window_band— post-decode window + band slice on device.Every helper lazy-imports cupy at call time so the module imports cleanly on numpy-only environments.
__init__.pyre-imports the six helpers from_backends._gpu_helpersso existing callers (read_geotiff_gpu,to_geotiff's GPU branch,write_geotiff_gpu) keep identical signatures.The leading-underscore module name (
_gpu_helpers.py) is intentional: it keeps_backends/gpu.pyfree for theread_geotiff_gpuentry-point body in step 7.Diff stats
__init__.py: 4271 → 3969 (-302 lines)._backends/__init__.py: 8 lines._backends/_gpu_helpers.py: 335 lines.Test plan
from xrspatial.geotiff import _is_gpu_data, _apply_nodata_mask_gpu, _gpu_decode_single_band_tiles, _apply_orientation_gpu, _apply_orientation_geo_info, _gpu_apply_window_band— every re-export resolves.Closes #1884. Refs #1813.