rio-tiler 7.2.0__py3-none-any.whl → 7.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rio_tiler/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """rio-tiler."""
2
2
 
3
- __version__ = "7.2.0"
3
+ __version__ = "7.2.2"
4
4
 
5
5
  from . import ( # noqa
6
6
  colormap,
rio_tiler/colormap.py CHANGED
@@ -4,6 +4,7 @@ import json
4
4
  import os
5
5
  import pathlib
6
6
  import re
7
+ import warnings
7
8
  from typing import Dict, List, Sequence, Tuple, Union
8
9
 
9
10
  import attr
@@ -18,6 +19,7 @@ from rio_tiler.errors import (
18
19
  from rio_tiler.types import (
19
20
  ColorMapType,
20
21
  DataMaskType,
22
+ DiscreteColorMapType,
21
23
  GDALColorMapType,
22
24
  IntervalColorMapType,
23
25
  )
@@ -116,28 +118,38 @@ def apply_cmap(data: numpy.ndarray, colormap: ColorMapType) -> DataMaskType:
116
118
  # rio_tiler.colormap.make_lut, because we don't want to create a `lookup table`
117
119
  # with more than 256 entries (256 x 4) array. In this case we use `apply_discrete_cmap`
118
120
  # which can work with arbitrary colormap dict.
119
- if len(colormap) != 256 or max(colormap) >= 256 or min(colormap) < 0:
121
+ if (
122
+ len(colormap) != 256
123
+ or max(colormap) >= 256
124
+ or min(colormap) < 0
125
+ or any(isinstance(k, float) for k in colormap)
126
+ ):
120
127
  return apply_discrete_cmap(data, colormap)
121
128
 
122
- lookup_table = make_lut(colormap)
129
+ # For now we assume ColorMap are in uint8
130
+ if data.dtype != numpy.uint8:
131
+ warnings.warn(
132
+ f"Input array is of type {data.dtype} and `will be converted to Int in order to apply the ColorMap.",
133
+ UserWarning,
134
+ )
135
+ data = data.astype(numpy.uint8)
136
+
137
+ lookup_table = make_lut(colormap) # type: ignore
123
138
  data = lookup_table[data[0], :]
124
139
 
125
140
  data = numpy.transpose(data, [2, 0, 1])
126
141
 
127
- # If the colormap has values between 0-255
128
- # we cast the output array to Uint8.
129
- if data.min() >= 0 and data.max() <= 255:
130
- data = data.astype("uint8")
131
-
132
142
  return data[:-1], data[-1]
133
143
 
134
144
 
135
- def apply_discrete_cmap(data: numpy.ndarray, colormap: GDALColorMapType) -> DataMaskType:
145
+ def apply_discrete_cmap(
146
+ data: numpy.ndarray, colormap: Union[GDALColorMapType, DiscreteColorMapType]
147
+ ) -> DataMaskType:
136
148
  """Apply discrete colormap.
137
149
 
138
150
  Args:
139
151
  data (numpy.ndarray): 1D image array to translate to RGB.
140
- colormap (GDALColorMapType): Discrete ColorMap dictionary.
152
+ colormap (GDALColorMapType or DiscreteColorMapType): Discrete ColorMap dictionary.
141
153
 
142
154
  Returns:
143
155
  tuple: Data (numpy.ndarray) and Alpha band (numpy.ndarray).
rio_tiler/types.py CHANGED
@@ -18,11 +18,15 @@ IntervalTuple = Tuple[NumType, NumType] # (0, 100)
18
18
  # ColorMap Dict: {1: (0, 0, 0, 255), ...}
19
19
  GDALColorMapType = Dict[int, ColorTuple]
20
20
 
21
+ # Discrete Colormap, like GDALColorMapType but accept Float: {0.1: (0, 0, 0, 255), ...}
22
+ DiscreteColorMapType = Dict[NumType, ColorTuple]
23
+
21
24
  # Intervals ColorMap: [((0, 1), (0, 0, 0, 0)), ...]
22
25
  IntervalColorMapType = Sequence[Tuple[IntervalTuple, ColorTuple]]
23
26
 
24
27
  ColorMapType = Union[
25
28
  GDALColorMapType,
29
+ DiscreteColorMapType,
26
30
  IntervalColorMapType,
27
31
  ]
28
32
 
rio_tiler/utils.py CHANGED
@@ -33,7 +33,7 @@ from rasterio.warp import calculate_default_transform, transform_geom
33
33
 
34
34
  from rio_tiler.colormap import apply_cmap
35
35
  from rio_tiler.constants import WEB_MERCATOR_CRS, WGS84_CRS
36
- from rio_tiler.errors import RioTilerError
36
+ from rio_tiler.errors import InvalidFormat, RioTilerError
37
37
  from rio_tiler.types import BBox, ColorMapType, IntervalTuple, RIOResampling
38
38
 
39
39
 
@@ -588,24 +588,30 @@ def render(
588
588
  }
589
589
  output_profile.update(creation_options)
590
590
 
591
- with warnings.catch_warnings():
592
- warnings.filterwarnings(
593
- "ignore",
594
- category=NotGeoreferencedWarning,
595
- module="rasterio",
596
- )
597
- with MemoryFile() as memfile:
598
- with memfile.open(**output_profile) as dst:
599
- dst.write(data, indexes=list(range(1, count + 1)))
591
+ try:
592
+ with warnings.catch_warnings():
593
+ warnings.filterwarnings(
594
+ "ignore",
595
+ category=NotGeoreferencedWarning,
596
+ module="rasterio",
597
+ )
598
+ with MemoryFile() as memfile:
599
+ with memfile.open(**output_profile) as dst:
600
+ dst.write(data, indexes=list(range(1, count + 1)))
601
+
602
+ # Use Mask as an alpha band
603
+ if mask is not None:
604
+ if ColorInterp.alpha not in dst.colorinterp:
605
+ dst.colorinterp = *dst.colorinterp[:-1], ColorInterp.alpha
600
606
 
601
- # Use Mask as an alpha band
602
- if mask is not None:
603
- if ColorInterp.alpha not in dst.colorinterp:
604
- dst.colorinterp = *dst.colorinterp[:-1], ColorInterp.alpha
607
+ dst.write(mask.astype(data.dtype), indexes=count + 1)
605
608
 
606
- dst.write(mask.astype(data.dtype), indexes=count + 1)
609
+ return memfile.read()
607
610
 
608
- return memfile.read()
611
+ except Exception as e:
612
+ raise InvalidFormat(
613
+ f"Could not encode array of shape ({count},{height},{width}) and of datatype `{data.dtype}` using {img_format} driver"
614
+ ) from e
609
615
 
610
616
 
611
617
  def mapzen_elevation_rgb(data: numpy.ndarray) -> numpy.ndarray:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rio-tiler
3
- Version: 7.2.0
3
+ Version: 7.2.2
4
4
  Summary: User friendly Rasterio plugin to read raster datasets.
5
5
  Project-URL: Homepage, https://cogeotiff.github.io/rio-tiler/
6
6
  Project-URL: Documentation, https://cogeotiff.github.io/rio-tiler/
@@ -37,8 +37,6 @@ License: BSD 3-Clause License
37
37
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38
38
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39
39
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
- License-File: AUTHORS.txt
41
- License-File: LICENSE
42
40
  Keywords: COGEO,Cloud Optimized Geotiff,STAC,rasterio,slippy-map
43
41
  Classifier: Intended Audience :: Information Technology
44
42
  Classifier: Intended Audience :: Science/Research
@@ -1,5 +1,5 @@
1
- rio_tiler/__init__.py,sha256=cFeeQM30lOF-m_dZXv9BZHUCAw7and4-T2t9BgNHlRc,192
2
- rio_tiler/colormap.py,sha256=xx43D4A5w3VgYB2CvuKvYFmAsYSuZLWbIfextsVYDB4,11085
1
+ rio_tiler/__init__.py,sha256=dShDwRuOOASdRz5UvqGC61lqPzE1q00kVIkNIEJK6m0,192
2
+ rio_tiler/colormap.py,sha256=Ale0ToTrEKwP3JOhrySYKuQsfeeTgJT1YGBcmdssJ0k,11411
3
3
  rio_tiler/constants.py,sha256=55i-7JZDupTXZdLgxL03KsgM4lAzuGuIVP1zZKktzp0,426
4
4
  rio_tiler/errors.py,sha256=4I3i0e1FtkLX5sIX6dfhUMUj3SWWoKqkjCkSG7k5i2M,1901
5
5
  rio_tiler/expression.py,sha256=EVHWgjMqIn4TTPfqT_HV1RWCQlxqOj3OtEr1iUDiFHE,2282
@@ -9,8 +9,8 @@ rio_tiler/profiles.py,sha256=EAx2JdcaOcMw5PZjxbCqQBXXWMac9mjtpHoVFPJEDNQ,1562
9
9
  rio_tiler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  rio_tiler/reader.py,sha256=FiDQQU_v8mDk2JTxBpLmsTqaCQFOsjOw0LocasLeXjk,22721
11
11
  rio_tiler/tasks.py,sha256=tiQo24rZHBVxids40QkNInuMzDFEei08zYW3I_pkSVE,3157
12
- rio_tiler/types.py,sha256=HbgECLqI4KoYVdMZv2pHSME4aiVvWea1ircqP9jQQCA,1468
13
- rio_tiler/utils.py,sha256=_msIyfmDtvNnk3MGIENfGurTs2_Fb-hJ-YughEi82Rc,29507
12
+ rio_tiler/types.py,sha256=wrGiiGBQ-WdzHf-lEypiH3cub7Knu_rXJw7EWZ2FAS8,1632
13
+ rio_tiler/utils.py,sha256=X3gV8UJGP1LNvFbmFvuNjqeGVV0Iwsgw7-zbCPJwXec,29796
14
14
  rio_tiler/cmap_data/__init__.py,sha256=8FtVmfpTjXlvhxQ5QesN0UC1m_B3MuF3LbGbhMC5Rw4,1039
15
15
  rio_tiler/cmap_data/accent.npy,sha256=Qde1ldOoXghe4L05v1QbVvnMA1ldwNjKWPf5xCBbmI4,1152
16
16
  rio_tiler/cmap_data/accent_r.npy,sha256=ba-GWSMSPRAcm9CGzlXJeNG4ABbBHDCV602hAWV2idc,1152
@@ -233,8 +233,8 @@ rio_tiler/mosaic/reader.py,sha256=_YBwTJwHvXOzKwpNpOmmh0F4yicyxgWo9vHyof3w_Do,96
233
233
  rio_tiler/mosaic/methods/__init__.py,sha256=tgkXM9skaTLXIm5QFoheOEznQXM97KGflcAWHfkrt1g,612
234
234
  rio_tiler/mosaic/methods/base.py,sha256=9YZJWVRwH5Fk9KO9q5CW52Q8Mf60tAJ21oM4ixEDXBo,1424
235
235
  rio_tiler/mosaic/methods/defaults.py,sha256=z34lna2wGXnAPwculjk_6hDrloqS8wzer68FFoIo7pg,6744
236
- rio_tiler-7.2.0.dist-info/METADATA,sha256=JSAvO6nBWZVV0aCG71dm7c26J7PzS5nb11eQ2u336fk,12250
237
- rio_tiler-7.2.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
238
- rio_tiler-7.2.0.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
239
- rio_tiler-7.2.0.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
240
- rio_tiler-7.2.0.dist-info/RECORD,,
236
+ rio_tiler-7.2.2.dist-info/METADATA,sha256=jbfLAj3UTICL7Kr3ax_ow29V_5z_rtMwmW1b6iZ4xnw,12202
237
+ rio_tiler-7.2.2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
238
+ rio_tiler-7.2.2.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
239
+ rio_tiler-7.2.2.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
240
+ rio_tiler-7.2.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.25.0
2
+ Generator: hatchling 1.26.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any