Skip to content

Commit

Permalink
Change RasterReader api, read method
Browse files Browse the repository at this point in the history
Adding extra parameter for selecting subset of
bands to read.
  • Loading branch information
Kirill888 committed May 21, 2024
1 parent e284eae commit 362738a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions odc/loader/_rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def read(
cfg: RasterLoadParams,
dst_geobox: GeoBox,
dst: Optional[np.ndarray] = None,
selection: Optional[slice] = None,
) -> Tuple[NormalizedROI, np.ndarray]:
return rio_read(self._src, cfg, dst_geobox, dst=dst)
return rio_read(self._src, cfg, dst_geobox, dst=dst, selection=selection)


class RioDriver:
Expand Down Expand Up @@ -426,6 +427,7 @@ def rio_read(
cfg: RasterLoadParams,
dst_geobox: GeoBox,
dst: Optional[np.ndarray] = None,
selection: Optional[slice] = None,
) -> Tuple[NormalizedROI, np.ndarray]:
"""
Internal read method.
Expand All @@ -450,7 +452,7 @@ def rio_read(
"""

try:
return _rio_read(src, cfg, dst_geobox, dst)
return _rio_read(src, cfg, dst_geobox, dst, selection=selection)
except (
rasterio.errors.RasterioIOError,
rasterio.errors.RasterBlockError,
Expand Down Expand Up @@ -491,10 +493,12 @@ def _rio_read(
cfg: RasterLoadParams,
dst_geobox: GeoBox,
dst: Optional[np.ndarray] = None,
selection: Optional[slice] = None,
) -> Tuple[NormalizedROI, np.ndarray]:
# if resampling is `nearest` then ignore sub-pixel translation when deciding
# whether we can just paste source into destination
ttol = 0.9 if cfg.nearest else 0.05
assert selection is None, "Band selection not implemented in rio_read"

with rasterio.open(src.uri, "r", sharing=False) as rdr:
assert isinstance(rdr, rasterio.DatasetReader)
Expand Down
3 changes: 3 additions & 0 deletions odc/loader/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ def read(
cfg: RasterLoadParams,
dst_geobox: GeoBox,
dst: Optional[np.ndarray] = None,
selection: Optional[slice] = None,
) -> Tuple[NormalizedROI, np.ndarray]:
meta = self._src.meta
assert meta is not None
# TODO: handle selection
assert selection is None

extra_dims = self._extra_dims()
prefix_dims: Tuple[int, ...] = ()
Expand Down
1 change: 1 addition & 0 deletions odc/loader/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def read(
cfg: RasterLoadParams,
dst_geobox: GeoBox,
dst: Optional[np.ndarray] = None,
selection: Optional[slice] = None,
) -> Tuple[NormalizedROI, np.ndarray]: ...


Expand Down

0 comments on commit 362738a

Please sign in to comment.