Skip to content

GeoTIFF: migrate eager backends to shared eager finalization helper (PR D of #2162) #2179

@brendancol

Description

@brendancol

Parent: #2162
Depends on: #2177 (adds the eager helper)

Goal

Replace duplicated finalization in the four eager paths with _finalize_eager_read from #2177.

Scope

Four call sites:

  1. xrspatial/geotiff/__init__.py:711-867 — eager numpy in open_geotiff. About 150 lines.
  2. xrspatial/geotiff/_backends/gpu.py:470-508 — GPU CPU-fallback eager (stripped or bps-mismatch path).
  3. xrspatial/geotiff/_backends/gpu.py:861-880 — GPU local eager (main path).
  4. xrspatial/geotiff/_backends/gpu.py:980-1016 — GPU HTTP eager.

Each site is a near-copy of: validate geo_info, populate attrs, mask using a sentinel, compute nodata_pixels_present, cast dtype, record nodata_dtype_cast, call _set_nodata_attrs, construct DataArray.

The three GPU sites derive mask_sentinel three different ways:

  • _backends/gpu.py:470-508: from _cpu_fallback_geo._mask_nodata.
  • _backends/gpu.py:861-880: from _mw_mask_nodata local.
  • _backends/gpu.py:980-1016: from raw nodata.

The helper takes mask_sentinel as an explicit parameter. Callers pass whichever they have.

Preserve all current behavior:

  • attrs['nodata_pixels_present'] is set as a bool from a real scan of the array.
  • Float vs int sentinel branching: integer sources with a sentinel promote to float64; float sources mask in place.
  • MinIsWhite inversion still happens before finalization.
  • GPU paths return CuPy-backed DataArrays.

Tests

Add xrspatial/geotiff/tests/test_eager_finalization_parity_2162.py. Parametrize over numpy and cupy (eager GPU). Assert:

  • Both backends produce the same attrs dict (modulo array backend) for matched inputs.
  • nodata_pixels_present matches as a bool across both.
  • nodata_dtype_cast matches.
  • Float-vs-int sentinel handling matches.
  • georef_status matches.

Skip GPU tests when CUDA is unavailable.

Files

  • xrspatial/geotiff/__init__.py (rewrite 711-867 to call _finalize_eager_read)
  • xrspatial/geotiff/_backends/gpu.py (rewrite three eager sites to call _finalize_eager_read)
  • xrspatial/geotiff/tests/test_eager_finalization_parity_2162.py (new)

Constraints

  • No public API change.
  • Existing eager tests must still pass, especially: test_nodata_lifecycle_attrs_2135.py, test_nodata_semantics_split_1988.py, test_georef_status_2136.py, test_gpu_nodata_1542.py.
  • _validate_read_geo_info runs first. Partial attrs must not leak on validation failure.

Out of scope

  • Dask backends (sibling PR C in wave 2).
  • VRT (PR E in wave 3).

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAPI design and consistencybackend-coverageAdding missing dask/cupy/dask+cupy backend supportenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions