[Git][debian-gis-team/trollimage][upstream] New upstream version 1.18.3
Antonio Valentino (@antonio.valentino)
gitlab at salsa.debian.org
Thu Mar 10 07:20:41 GMT 2022
Antonio Valentino pushed to branch upstream at Debian GIS Project / trollimage
Commits:
a69d7e69 by Antonio Valentino at 2022-03-10T07:07:54+00:00
New upstream version 1.18.3
- - - - -
4 changed files:
- CHANGELOG.md
- trollimage/tests/test_image.py
- trollimage/version.py
- trollimage/xrimage.py
Changes:
=====================================
CHANGELOG.md
=====================================
@@ -1,3 +1,14 @@
+## Version 1.18.3 (2022/03/07)
+
+### Pull Requests Merged
+
+#### Bugs fixed
+
+* [PR 104](https://github.com/pytroll/trollimage/pull/104) - Set scale/offset tags to (NaN, NaN) for incompatible enhancements
+
+In this release 1 pull request was closed.
+
+
## Version 1.18.2 (2022/03/04)
### Pull Requests Merged
=====================================
trollimage/tests/test_image.py
=====================================
@@ -2202,6 +2202,9 @@ class TestXRImageSaveScaleOffset:
data = xr.DataArray(np.arange(25).reshape(5, 5, 1), dims=[
'y', 'x', 'bands'], coords={'bands': ['L']})
self.img = xrimage.XRImage(data)
+ rgb_data = xr.DataArray(np.arange(3 * 25).reshape(5, 5, 3), dims=[
+ 'y', 'x', 'bands'], coords={'bands': ['R', 'G', 'B']})
+ self.rgb_img = xrimage.XRImage(rgb_data)
@pytest.mark.skipif(sys.platform.startswith('win'), reason="'NamedTemporaryFile' not supported on Windows")
def test_save_scale_offset(self):
@@ -2215,10 +2218,26 @@ class TestXRImageSaveScaleOffset:
include_scale_offset_tags=True)
def test_gamma_geotiff_scale_offset(self, tmp_path):
- """Test that saving gamma-enhanced data to a geotiff doesn't fail."""
+ """Test that saving gamma-enhanced data to a geotiff with scale/offset tags doesn't fail."""
self.img.gamma(.5)
out_fn = str(tmp_path / "test.tif")
self.img.save(out_fn, scale_offset_tags=("scale", "offset"))
+ with rio.open(out_fn, "r") as ds:
+ assert np.isnan(float(ds.tags()["scale"]))
+ assert np.isnan(float(ds.tags()["offset"]))
+
+ def test_rgb_geotiff_scale_offset(self, tmp_path):
+ """Test that saving RGB data to a geotiff with scale/offset tags doesn't fail."""
+ self.rgb_img.stretch(
+ stretch="crude",
+ min_stretch=[-25, -40, 243],
+ max_stretch=[0, 5, 208]
+ )
+ out_fn = str(tmp_path / "test.tif")
+ self.rgb_img.save(out_fn, scale_offset_tags=("scale", "offset"))
+ with rio.open(out_fn, "r") as ds:
+ assert np.isnan(float(ds.tags()["scale"]))
+ assert np.isnan(float(ds.tags()["offset"]))
def _save_and_check_tags(self, expected_tags, **kwargs):
with NamedTemporaryFile(suffix='.tif') as tmp:
=====================================
trollimage/version.py
=====================================
@@ -23,9 +23,9 @@ def get_keywords():
# setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call
# get_keywords().
- git_refnames = " (HEAD -> main, tag: v1.18.2)"
- git_full = "e5ddeb0ef5988f307c5f0baa6c8313d6e55a4b64"
- git_date = "2022-03-04 09:37:18 -0600"
+ git_refnames = " (HEAD -> main, tag: v1.18.3)"
+ git_full = "baae46cbe74beffb6cd669978ec92a44396bf5f7"
+ git_date = "2022-03-07 12:29:07 -0600"
keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
return keywords
=====================================
trollimage/xrimage.py
=====================================
@@ -33,6 +33,7 @@ chunks can be saved in parallel.
"""
import logging
+import numbers
import os
import threading
import warnings
@@ -307,7 +308,7 @@ def delayed_pil_save(img, *args, **kwargs):
raise
-class XRImage(object):
+class XRImage:
"""Image class using an :class:`xarray.DataArray` as internal storage.
It can be saved to a variety of image formats, but if Rasterio is
@@ -507,6 +508,12 @@ class XRImage(object):
If set to a ``(str, str)`` tuple, scale and offset will be
stored in GDALMetaData tags. Those can then be used to
retrieve the original data values from pixel values.
+ Scale and offset will be set to (NaN, NaN) for images that had
+ non-linear enhancements applied (ex. gamma) as they can't be
+ represented by a simple scale and offset. Scale and offset
+ are also saved as (NaN, NaN) for multi-band images (ex. RGB)
+ as storing multiple values in a single GDALMetaData tag is not
+ currently supported.
colormap_tag (str or None):
If set and the image was colorized or palettized, a tag will
be added with this name with the value of a comma-separated
@@ -699,12 +706,8 @@ class XRImage(object):
def _add_scale_offset_to_tags(self, scale_offset_tags, data_arr, tags):
scale_label, offset_label = scale_offset_tags
- try:
- scale, offset = self.get_scaling_from_history(data_arr.attrs.get('enhancement_history', []))
- except NotImplementedError:
- logger.debug("Ignoring scale/offset tags for non-scaling enhancement operations")
- else:
- tags[scale_label], tags[offset_label] = invert_scale_offset(scale, offset)
+ scale, offset = self.get_scaling_from_history(data_arr.attrs.get('enhancement_history', []))
+ tags[scale_label], tags[offset_label] = invert_scale_offset(scale, offset)
def get_scaling_from_history(self, history=None):
"""Merge the scales and offsets from the history.
@@ -717,8 +720,18 @@ class XRImage(object):
try:
scaling = [(item['scale'], item['offset']) for item in history]
except KeyError as err:
- raise NotImplementedError('Can only get combine scaling from a list of scaling operations: %s' % str(err))
- return combine_scales_offsets(*scaling)
+ logger.debug("Can only get combine scaling from a list of linear "
+ f"scaling operations: {err}. Setting scale and offset "
+ "to (NaN, NaN).")
+ return np.nan, np.nan
+ scale, offset = combine_scales_offsets(*scaling)
+ scale_is_not_scalar = not isinstance(scale, numbers.Number) and len(scale) != 1
+ offset_is_not_scalar = not isinstance(offset, numbers.Number) and len(offset) != 1
+ if scale_is_not_scalar or offset_is_not_scalar:
+ logger.debug("Multi-band scale/offset tags can't be saved to "
+ "geotiff. Setting scale and offset to (NaN, NaN).")
+ return np.nan, np.nan
+ return scale, offset
@delayed(nout=1, pure=True)
def _delayed_apply_pil(self, fun, pil_image, fun_args, fun_kwargs,
View it on GitLab: https://salsa.debian.org/debian-gis-team/trollimage/-/commit/a69d7e69c210e9224765eea7bdb887c4055b9cde
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/trollimage/-/commit/a69d7e69c210e9224765eea7bdb887c4055b9cde
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20220310/1cdcb744/attachment-0001.htm>
More information about the Pkg-grass-devel
mailing list