Skip to content

Commit

Permalink
refactor: skip band read if no nodata
Browse files Browse the repository at this point in the history
This simplifies the logic in the band read loop for the raster footprints.
  • Loading branch information
gadomski committed Sep 15, 2022
1 parent bb3e1e8 commit 86420c6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/stactools/core/utils/raster_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,16 @@ def data_footprint(
if not bands:
bands = src.indexes

data: npt.NDArray[np.uint8] = np.full(src.shape, 0, dtype=np.uint8)
for index in bands:
band_data = src.read(index, out_shape=src.shape)

if no_data is not None:
if no_data is not None:
data: npt.NDArray[np.uint8] = np.full(src.shape, 0, dtype=np.uint8)
for index in bands:
band_data = src.read(index, out_shape=src.shape)
if np.isnan(no_data):
data[~np.isnan(band_data)] = 1
else:
data[np.where(band_data != no_data)] = 1
else:
data.fill(1)
break
else:
data = np.full(src.shape, 1, dtype=np.uint8)

data_polygons = [
shape(polygon_dict)
Expand Down

0 comments on commit 86420c6

Please sign in to comment.