From 036b94122b7ee48f9c4dd77e41b16ba9722385dc Mon Sep 17 00:00:00 2001 From: Christoph Friedrich Date: Fri, 9 Aug 2024 07:56:34 +1000 Subject: [PATCH 1/2] Fix TIFF statistics in case WCS output has NaNs (#1054) * 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> (cherry picked from commit b2871674426c1e5c74ec6c7e0a6bca7af671a690) --- datacube_ows/wcs1_utils.py | 8 ++++---- datacube_ows/wcs2_utils.py | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/datacube_ows/wcs1_utils.py b/datacube_ows/wcs1_utils.py index 93722529..b42fbe06 100644 --- a/datacube_ows/wcs1_utils.py +++ b/datacube_ows/wcs1_utils.py @@ -450,10 +450,10 @@ def get_tiff(req, data): dst.write(data[band].values, idx) dst.set_band_description(idx, req.layer.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() diff --git a/datacube_ows/wcs2_utils.py b/datacube_ows/wcs2_utils.py index 7911c638..00c671bf 100644 --- a/datacube_ows/wcs2_utils.py +++ b/datacube_ows/wcs2_utils.py @@ -7,6 +7,7 @@ import collections import logging +import numpy from dateutil.parser import parse from odc.geo.geobox import GeoBox from ows.wcs.v20 import ScaleAxis, ScaleExtent, ScaleSize, Slice, Trim @@ -382,10 +383,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() From 3361a14b4e8fd1128f66cd55a20c03023e08fcdd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 08:09:33 +1000 Subject: [PATCH 2/2] [pre-commit.ci] pre-commit autoupdate (#1029) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/PyCQA/flake8: 7.0.0 → 7.1.1](https://github.com/PyCQA/flake8/compare/7.0.0...7.1.1) - [github.com/PyCQA/pylint: v3.2.3 → v3.2.6](https://github.com/PyCQA/pylint/compare/v3.2.3...v3.2.6) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit e3ff31c772e3646cd91fb18d422ced02d6d71ecb) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a7f9c71b..a1fafef5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 + rev: 7.1.1 hooks: - id: flake8 args: ["--ignore=E501", "--select=F401,E201,E202,E203,E502,E241,E225,E306,E231,E226,E123,F811"] @@ -15,7 +15,7 @@ repos: # hooks: # - id: bandit - repo: https://github.com/PyCQA/pylint - rev: v3.2.3 + rev: v3.2.6 hooks: - id: pylint args: ["--disable=C,R,W,E1136"]