rio-tiler 7.4.0__py3-none-any.whl → 7.5.1__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.4.0"
3
+ __version__ = "7.5.1"
4
4
 
5
5
  from . import ( # noqa
6
6
  colormap,
rio_tiler/errors.py CHANGED
@@ -91,3 +91,7 @@ class MissingCRS(RioTilerError):
91
91
 
92
92
  class InvalidGeographicBounds(RioTilerError):
93
93
  """Invalid Geographic bounds."""
94
+
95
+
96
+ class RioTilerExperimentalWarning(UserWarning):
97
+ """A rio-tiler specific experimental functionality warning."""
@@ -0,0 +1,10 @@
1
+ """The "experimental" module of rio-tiler contains potential new features that are subject to change."""
2
+
3
+ import warnings
4
+
5
+ from rio_tiler.errors import RioTilerExperimentalWarning
6
+
7
+ warnings.warn(
8
+ "This module is experimental, its contents are subject to change and deprecation.",
9
+ category=RioTilerExperimentalWarning,
10
+ )
@@ -0,0 +1,36 @@
1
+ """rio_tiler.io.Reader with VSIFILE/Obstore Opener."""
2
+
3
+ from typing import Union
4
+
5
+ import attr
6
+ import rasterio
7
+ from rasterio.io import DatasetReader, DatasetWriter, MemoryFile
8
+ from rasterio.vrt import WarpedVRT
9
+
10
+ from rio_tiler.io import Reader
11
+
12
+ try:
13
+ import vsifile
14
+ from vsifile.rasterio import opener
15
+ except ImportError: # pragma: nocover
16
+ vsifile = None # type: ignore
17
+ opener = None # type: ignore
18
+
19
+
20
+ @attr.s
21
+ class VSIReader(Reader):
22
+ """Rasterio Reader with VSIFILE opener."""
23
+
24
+ dataset: Union[DatasetReader, DatasetWriter, MemoryFile, WarpedVRT] = attr.ib(
25
+ default=None, init=False
26
+ )
27
+
28
+ def __attrs_post_init__(self):
29
+ """Use vsifile.rasterio.opener as Python file opener."""
30
+ assert vsifile is not None, "VSIFILE must be installed to use VSIReader"
31
+
32
+ self.dataset = self._ctx_stack.enter_context(
33
+ rasterio.open(self.input, opener=opener)
34
+ )
35
+
36
+ super().__attrs_post_init__()
rio_tiler/utils.py CHANGED
@@ -59,8 +59,8 @@ def _weighted_stdev(
59
59
  values: NDArray[numpy.floating],
60
60
  weights: NDArray[numpy.floating],
61
61
  ) -> float:
62
- average = numpy.average(values, weights=weights)
63
- variance = numpy.average((values - average) ** 2, weights=weights)
62
+ average = numpy.ma.average(values, weights=weights)
63
+ variance = numpy.ma.average((values - average) ** 2, weights=weights)
64
64
  return float(math.sqrt(variance))
65
65
 
66
66
 
@@ -174,35 +174,44 @@ def get_array_statistics(
174
174
  _weighted_quantiles(data_comp, masked_coverage.compressed(), pp / 100.0)
175
175
  for pp in percentiles
176
176
  ]
177
- else:
178
- percentiles_values = [numpy.nan] * len(percentiles_names)
179
-
180
- if valid_pixels:
181
177
  majority = float(keys[counts.tolist().index(counts.max())].tolist())
182
178
  minority = float(keys[counts.tolist().index(counts.min())].tolist())
179
+ std = _weighted_stdev(data_comp, masked_coverage.compressed())
180
+ med = _weighted_quantiles(data_comp, masked_coverage.compressed())
181
+ _min = float(data[b].min())
182
+ _max = float(data[b].max())
183
+ _mean = float(data_cov.sum() / masked_coverage.sum())
184
+ _count = float(masked_coverage.sum())
185
+ _sum = float(data_cov.sum())
186
+
183
187
  else:
188
+ percentiles_values = [numpy.nan] * len(percentiles_names)
184
189
  majority = numpy.nan
185
190
  minority = numpy.nan
186
-
187
- _count = masked_coverage.sum()
188
- _sum = data_cov.sum()
191
+ std = numpy.nan
192
+ med = numpy.nan
193
+ _min = numpy.nan
194
+ _max = numpy.nan
195
+ _count = 0
196
+ _sum = 0
197
+ _mean = numpy.nan
189
198
 
190
199
  output.append(
191
200
  {
192
201
  # Minimum value, not taking coverage fractions into account.
193
- "min": float(data[b].min()),
202
+ "min": _min,
194
203
  # Maximum value, not taking coverage fractions into account.
195
- "max": float(data[b].max()),
204
+ "max": _max,
196
205
  # Mean value, weighted by the percent of each cell that is covered.
197
- "mean": float(_sum / _count),
206
+ "mean": _mean,
198
207
  # Sum of all non-masked cell coverage fractions.
199
- "count": float(_count),
208
+ "count": _count,
200
209
  # Sum of values, weighted by their coverage fractions.
201
- "sum": float(_sum),
210
+ "sum": _sum,
202
211
  # Population standard deviation of cell values, taking into account coverage fraction.
203
- "std": _weighted_stdev(data_comp, masked_coverage.compressed()),
212
+ "std": std,
204
213
  # Median value of cells, weighted by the percent of each cell that is covered.
205
- "median": _weighted_quantiles(data_comp, masked_coverage.compressed()),
214
+ "median": med,
206
215
  # The value occupying the greatest number of cells.
207
216
  "majority": majority,
208
217
  # The value occupying the least number of cells.
@@ -773,14 +782,15 @@ def resize_array(
773
782
  category=NotGeoreferencedWarning,
774
783
  module="rasterio",
775
784
  )
776
- with rasterio.open(datasetname, "r+") as src:
777
- # if a 2D array is passed, using indexes=1 makes sure we return an 2D array
778
- indexes = 1 if len(data.shape) == 2 else None
779
- return src.read(
780
- out_shape=out_shape,
781
- indexes=indexes,
782
- resampling=Resampling[resampling_method],
783
- )
785
+ with rasterio.Env(GDAL_MEM_ENABLE_OPEN=True):
786
+ with rasterio.open(datasetname, "r+") as src:
787
+ # if a 2D array is passed, using indexes=1 makes sure we return an 2D array
788
+ indexes = 1 if len(data.shape) == 2 else None
789
+ return src.read(
790
+ out_shape=out_shape,
791
+ indexes=indexes,
792
+ resampling=Resampling[resampling_method],
793
+ )
784
794
 
785
795
 
786
796
  def normalize_bounds(bounds: BBox) -> BBox:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rio-tiler
3
- Version: 7.4.0
3
+ Version: 7.5.1
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/
@@ -83,6 +83,7 @@ Requires-Dist: morecantile<7.0,>=6.0; extra == 'test'
83
83
  Requires-Dist: pytest; extra == 'test'
84
84
  Requires-Dist: pytest-cov; extra == 'test'
85
85
  Requires-Dist: rioxarray; extra == 'test'
86
+ Requires-Dist: vsifile>=0.2; extra == 'test'
86
87
  Requires-Dist: xarray; extra == 'test'
87
88
  Provides-Extra: tilebench
88
89
  Requires-Dist: pytest; extra == 'tilebench'
@@ -1,7 +1,7 @@
1
- rio_tiler/__init__.py,sha256=BvFwlq-YnpN-xK81FF1u6lp6RAmoMHikPDvhcTELbdo,192
1
+ rio_tiler/__init__.py,sha256=F5UhzpbBi4ZXUWqnpllv1a9P6HKq42umdO-eaGbWoGI,192
2
2
  rio_tiler/colormap.py,sha256=E2FYp6AysmnSAhj2901XUrgB2q-8OvO8zoe_hmM_UZU,11186
3
3
  rio_tiler/constants.py,sha256=55i-7JZDupTXZdLgxL03KsgM4lAzuGuIVP1zZKktzp0,426
4
- rio_tiler/errors.py,sha256=4I3i0e1FtkLX5sIX6dfhUMUj3SWWoKqkjCkSG7k5i2M,1901
4
+ rio_tiler/errors.py,sha256=dnaAHPc5VL7SNKXm00gzlrU_4XIuw5rwzD-9Q2kFJsc,2018
5
5
  rio_tiler/expression.py,sha256=EVHWgjMqIn4TTPfqT_HV1RWCQlxqOj3OtEr1iUDiFHE,2282
6
6
  rio_tiler/logger.py,sha256=RR8lnW3uVXkFkPa3nNJS_tTndmdiNNDVXpCDGDxGf0A,81
7
7
  rio_tiler/models.py,sha256=jZl-AWiCVYgOtws640kB8_XrzBn7ID32CHTL9lOP_KM,27724
@@ -10,7 +10,7 @@ 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
12
  rio_tiler/types.py,sha256=wrGiiGBQ-WdzHf-lEypiH3cub7Knu_rXJw7EWZ2FAS8,1632
13
- rio_tiler/utils.py,sha256=okDKTIKitoDMefhpz3XiAZeR1JWcw9Br9BrVMlmmzxM,29858
13
+ rio_tiler/utils.py,sha256=uX8C0RxB_u1sJI3MCvQMdlolDJcWW5G4waU08VfYRF4,30249
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
@@ -223,6 +223,8 @@ rio_tiler/cmap_data/ylorbr.npy,sha256=Pr15CJLR4-U1cWG4HbaFo5WzSH9mHTNzMZYckKOgzo
223
223
  rio_tiler/cmap_data/ylorbr_r.npy,sha256=LjRoulX86uju7woCI_m4zzmAJMDpg-ky7p4f9vUktjc,1152
224
224
  rio_tiler/cmap_data/ylorrd.npy,sha256=9ImXljw40oe60w8uV4EMDPY4aFFVkGbyCBi6SlTX83w,1152
225
225
  rio_tiler/cmap_data/ylorrd_r.npy,sha256=K5uiHNHbLxV5SizyT09cSVAxldE-BW5GpOXxUp7UsTE,1152
226
+ rio_tiler/experimental/__init__.py,sha256=dgW817h5U9OQt4V68L912g3DivPfhoWKvS-mI83sqio,328
227
+ rio_tiler/experimental/vsifile.py,sha256=t1tJviPmFkjWIbr86BEnsK7pU4iiqLh1pKYZyNNb1AY,960
226
228
  rio_tiler/io/__init__.py,sha256=_L4iILm6vSiJ14GEDDOvkuUHRtbWC9oqx6Bu8PxHhvA,270
227
229
  rio_tiler/io/base.py,sha256=nyaAtfodM-5fXd1WsGG5Qh544PNv9Hy4FLQ_nPj8hw8,52154
228
230
  rio_tiler/io/rasterio.py,sha256=9GtbUPialsFMnxVUKrJ8ZItC3sWS8zddrO8aiPG07AU,29011
@@ -233,8 +235,8 @@ rio_tiler/mosaic/reader.py,sha256=_YBwTJwHvXOzKwpNpOmmh0F4yicyxgWo9vHyof3w_Do,96
233
235
  rio_tiler/mosaic/methods/__init__.py,sha256=tgkXM9skaTLXIm5QFoheOEznQXM97KGflcAWHfkrt1g,612
234
236
  rio_tiler/mosaic/methods/base.py,sha256=9YZJWVRwH5Fk9KO9q5CW52Q8Mf60tAJ21oM4ixEDXBo,1424
235
237
  rio_tiler/mosaic/methods/defaults.py,sha256=z34lna2wGXnAPwculjk_6hDrloqS8wzer68FFoIo7pg,6744
236
- rio_tiler-7.4.0.dist-info/METADATA,sha256=GSELKmvEixjRVwxCc8EmgpmyqGFzoCCbuEyornup0FY,12185
237
- rio_tiler-7.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
238
- rio_tiler-7.4.0.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
239
- rio_tiler-7.4.0.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
240
- rio_tiler-7.4.0.dist-info/RECORD,,
238
+ rio_tiler-7.5.1.dist-info/METADATA,sha256=bfMelVekvdymq27sGan75xpgbLgFRQWfuK3suHSOF4U,12230
239
+ rio_tiler-7.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
240
+ rio_tiler-7.5.1.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
241
+ rio_tiler-7.5.1.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
242
+ rio_tiler-7.5.1.dist-info/RECORD,,