Skip to content

Commit

Permalink
Fix TIFF statistics in case WCS output has NaNs (#1054)
Browse files Browse the repository at this point in the history
* Fix TIFF statistics in case WCS output has NaNs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
christophfriedrich and pre-commit-ci[bot] authored Aug 8, 2024
1 parent 75383b9 commit b287167
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions datacube_ows/wcs1_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ def get_tiff(req, data):
dst.write(data[band].values, idx)
dst.set_band_description(idx, req.product.band_idx.band_label(band))
if cfg.wcs_tiff_statistics:
dst.update_tags(idx, STATISTICS_MINIMUM=data[band].values.min())
dst.update_tags(idx, STATISTICS_MAXIMUM=data[band].values.max())
dst.update_tags(idx, STATISTICS_MEAN=data[band].values.mean())
dst.update_tags(idx, STATISTICS_STDDEV=data[band].values.std())
dst.update_tags(idx, STATISTICS_MINIMUM=numpy.nanmin(data[band].values))
dst.update_tags(idx, STATISTICS_MAXIMUM=numpy.nanmax(data[band].values))
dst.update_tags(idx, STATISTICS_MEAN=numpy.nanmean(data[band].values))
dst.update_tags(idx, STATISTICS_STDDEV=numpy.nanstd(data[band].values))
return memfile.read()


Expand Down
9 changes: 5 additions & 4 deletions datacube_ows/wcs2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import collections
import logging

import numpy
from datacube.utils import geometry
from dateutil.parser import parse
from ows.wcs.v20 import ScaleAxis, ScaleExtent, ScaleSize, Slice, Trim
Expand Down Expand Up @@ -386,10 +387,10 @@ def get_tiff(request, data, crs, product, width, height, affine):
dst.write(data[band].values, idx)
dst.set_band_description(idx, product.band_idx.band_label(band))
if cfg.wcs_tiff_statistics:
dst.update_tags(idx, STATISTICS_MINIMUM=data[band].values.min())
dst.update_tags(idx, STATISTICS_MAXIMUM=data[band].values.max())
dst.update_tags(idx, STATISTICS_MEAN=data[band].values.mean())
dst.update_tags(idx, STATISTICS_STDDEV=data[band].values.std())
dst.update_tags(idx, STATISTICS_MINIMUM=numpy.nanmin(data[band].values))
dst.update_tags(idx, STATISTICS_MAXIMUM=numpy.nanmax(data[band].values))
dst.update_tags(idx, STATISTICS_MEAN=numpy.nanmean(data[band].values))
dst.update_tags(idx, STATISTICS_STDDEV=numpy.nanstd(data[band].values))
return memfile.read()


Expand Down

0 comments on commit b287167

Please sign in to comment.