Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions xrspatial/geotiff/_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,7 @@ def _finalize_lazy_read_attrs(
band_nodata: str | None = None,
band_nodata_values: list | None = None,
attrs_in: dict | None = None,
pixels_present: bool | None = None,
):
"""Validate and populate attrs for dask-style lazy reads.

Expand All @@ -1369,10 +1370,14 @@ def _finalize_lazy_read_attrs(
3. :func:`_set_nodata_attrs` -- ``masked`` is True iff the caller
opted into masking AND the graph dtype is float.
``dtype_cast`` is recorded when ``caller_dtype`` is not ``None``
and ``nodata`` is declared. ``pixels_present=None`` is the
documented dask contract from issue #2135: a strict per-chunk
reduction would force an eager ``.compute()`` and break the
lazy contract, so the attr is left absent on lazy outputs.
and ``nodata`` is declared. ``pixels_present`` defaults to
``None`` per the documented dask contract from issue #2135 (a
strict per-chunk reduction would force eager ``.compute()`` and
break the lazy contract, so the attr stays absent on lazy
outputs). Eager-VRT callers that already computed the presence
bool via a single decode pass can pass it through this kwarg so
the attr is stamped via the same finalization helper rather
than written ad-hoc post-call (PR-D of #2211).

Returns the attrs ``dict`` only; the caller assembles the dask graph
and builds the :class:`xarray.DataArray` itself, so this helper
Expand Down Expand Up @@ -1448,7 +1453,7 @@ def _finalize_lazy_read_attrs(
_set_nodata_attrs(
attrs, nodata,
masked=masked,
pixels_present=None,
pixels_present=pixels_present,
dtype_cast=dtype_cast_attr,
)

Expand Down
3 changes: 0 additions & 3 deletions xrspatial/geotiff/_backends/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
from .._attrs import (
_finalize_eager_read,
_finalize_lazy_read_attrs,
_populate_attrs_from_geo_info,
_set_nodata_attrs,
_validate_read_geo_info,
)
from .._coords import (
coords_from_geo_info as _coords_from_geo_info,
Expand Down
10 changes: 6 additions & 4 deletions xrspatial/geotiff/_backends/vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,11 @@ def read_vrt(source: str, *,
# * Per-band nodata selection happens above this call, not inside
# the helper. ``_apply_eager_nodata_mask`` is single-sentinel.
# * ``nodata_pixels_present`` is computed above (VRT-aware scan)
# and stamped post-helper because ``_finalize_lazy_read_attrs``
# passes ``pixels_present=None`` unconditionally.
# and threaded through the helper's ``pixels_present`` kwarg so
# the attr is stamped by ``_set_nodata_attrs`` rather than
# written ad-hoc post-call (PR-D of #2211). The kwarg defaults
# to ``None`` so the dask backends keep the lazy contract from
# issue #2135 unchanged.
synth_geo_info = _vrt_to_synthetic_geo_info(vrt)
attrs_seed: dict = {}
if vrt.holes:
Expand All @@ -576,9 +579,8 @@ def read_vrt(source: str, *,
band_nodata=band_nodata,
band_nodata_values=_band_nodata_values,
attrs_in=attrs_seed,
pixels_present=nodata_pixels_present,
)
if nodata is not None and nodata_pixels_present is not None:
attrs['nodata_pixels_present'] = bool(nodata_pixels_present)

if arr.ndim == 3:
dims = ['y', 'x', 'band']
Expand Down
Loading
Loading