Skip to content

Commit

Permalink
always use masked array for stats
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Sep 24, 2024
1 parent 7a5efaf commit da8af99
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions raster_loader/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ def raster_band_stats(raster_dataset: rasterio.io.DatasetReader, band: int) -> d
and not band_is_float(raster_dataset, band)
):
masked = False
stats = raster_dataset.read(band)
unmasked_data = raster_dataset.read(band)
stats = np.ma.masked_array(data=unmasked_data, mask=False)
else:
masked = True
if alpha_band:
Expand Down Expand Up @@ -369,9 +370,9 @@ def raster_band_stats(raster_dataset: rasterio.io.DatasetReader, band: int) -> d
"quantiles": quantiles,
"top_values": most_common,
"version": version,
"count": np.count_nonzero(stats.mask is False)
if masked
else math.prod(stats.shape), # noqa: E712
"count": (
np.count_nonzero(stats.mask is False) if masked else math.prod(stats.shape)
), # noqa: E712
}


Expand Down

0 comments on commit da8af99

Please sign in to comment.