rio-tiler 8.0.4__py3-none-any.whl → 8.0.5__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 +1 -1
- rio_tiler/colormap.py +6 -6
- rio_tiler/experimental/vsifile.py +1 -3
- rio_tiler/experimental/zarr.py +29 -28
- rio_tiler/expression.py +3 -3
- rio_tiler/io/base.py +73 -72
- rio_tiler/io/rasterio.py +67 -70
- rio_tiler/io/stac.py +25 -35
- rio_tiler/io/xarray.py +9 -9
- rio_tiler/models.py +46 -46
- rio_tiler/mosaic/backend.py +2 -2
- rio_tiler/mosaic/methods/base.py +3 -4
- rio_tiler/mosaic/methods/defaults.py +18 -19
- rio_tiler/mosaic/reader.py +20 -19
- rio_tiler/reader.py +41 -40
- rio_tiler/tasks.py +9 -8
- rio_tiler/types.py +16 -19
- rio_tiler/utils.py +33 -42
- {rio_tiler-8.0.4.dist-info → rio_tiler-8.0.5.dist-info}/METADATA +1 -1
- {rio_tiler-8.0.4.dist-info → rio_tiler-8.0.5.dist-info}/RECORD +23 -23
- {rio_tiler-8.0.4.dist-info → rio_tiler-8.0.5.dist-info}/WHEEL +0 -0
- {rio_tiler-8.0.4.dist-info → rio_tiler-8.0.5.dist-info}/licenses/AUTHORS.txt +0 -0
- {rio_tiler-8.0.4.dist-info → rio_tiler-8.0.5.dist-info}/licenses/LICENSE +0 -0
rio_tiler/mosaic/methods/base.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import abc
|
|
4
4
|
from dataclasses import dataclass, field
|
|
5
|
-
from typing import Optional
|
|
6
5
|
|
|
7
6
|
import numpy
|
|
8
7
|
|
|
@@ -11,9 +10,9 @@ import numpy
|
|
|
11
10
|
class MosaicMethodBase(abc.ABC):
|
|
12
11
|
"""Abstract base class for rio-tiler-mosaic methods objects."""
|
|
13
12
|
|
|
14
|
-
mosaic:
|
|
13
|
+
mosaic: numpy.ma.MaskedArray | None = field(default=None, init=False)
|
|
15
14
|
exit_when_filled: bool = field(default=False, init=False)
|
|
16
|
-
cutline_mask:
|
|
15
|
+
cutline_mask: numpy.ndarray | None = field(default=None, init=False)
|
|
17
16
|
width: int = field(init=False)
|
|
18
17
|
height: int = field(init=False)
|
|
19
18
|
count: int = field(init=False)
|
|
@@ -42,7 +41,7 @@ class MosaicMethodBase(abc.ABC):
|
|
|
42
41
|
return False
|
|
43
42
|
|
|
44
43
|
@property
|
|
45
|
-
def data(self) ->
|
|
44
|
+
def data(self) -> numpy.ma.MaskedArray | None:
|
|
46
45
|
"""Return data."""
|
|
47
46
|
return self.mosaic
|
|
48
47
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""rio_tiler.mosaic.methods.defaults: default mosaic filling methods."""
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
|
-
from typing import List, Optional
|
|
5
4
|
|
|
6
5
|
import numpy
|
|
7
6
|
|
|
@@ -18,7 +17,7 @@ class FirstMethod(MosaicMethodBase):
|
|
|
18
17
|
"""Mosaic Method repr."""
|
|
19
18
|
return "<Mosaic: FirstMethod>"
|
|
20
19
|
|
|
21
|
-
def feed(self, array:
|
|
20
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
22
21
|
"""Add data to the mosaic array."""
|
|
23
22
|
if self.mosaic is None:
|
|
24
23
|
self.mosaic = array
|
|
@@ -39,7 +38,7 @@ class HighestMethod(MosaicMethodBase):
|
|
|
39
38
|
"""Mosaic Method repr."""
|
|
40
39
|
return "<Mosaic: HighestMethod>"
|
|
41
40
|
|
|
42
|
-
def feed(self, array:
|
|
41
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
43
42
|
"""Add data to the mosaic array."""
|
|
44
43
|
if self.mosaic is None:
|
|
45
44
|
self.mosaic = array
|
|
@@ -63,7 +62,7 @@ class LowestMethod(MosaicMethodBase):
|
|
|
63
62
|
"""Mosaic Method repr."""
|
|
64
63
|
return "<Mosaic: LowestMethod>"
|
|
65
64
|
|
|
66
|
-
def feed(self, array:
|
|
65
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
67
66
|
"""Add data to the mosaic array."""
|
|
68
67
|
if self.mosaic is None:
|
|
69
68
|
self.mosaic = array
|
|
@@ -84,14 +83,14 @@ class MeanMethod(MosaicMethodBase):
|
|
|
84
83
|
"""Stack the arrays and return the Mean pixel value."""
|
|
85
84
|
|
|
86
85
|
enforce_data_type: bool = True
|
|
87
|
-
stack:
|
|
86
|
+
stack: list[numpy.ma.MaskedArray] = field(default_factory=list, init=False)
|
|
88
87
|
|
|
89
88
|
def __repr__(self):
|
|
90
89
|
"""Mosaic Method repr."""
|
|
91
90
|
return "<Mosaic: MeanMethod>"
|
|
92
91
|
|
|
93
92
|
@property
|
|
94
|
-
def data(self) ->
|
|
93
|
+
def data(self) -> numpy.ma.MaskedArray | None:
|
|
95
94
|
"""Return Mean of the data stack."""
|
|
96
95
|
if self.stack:
|
|
97
96
|
array = numpy.ma.mean(numpy.ma.stack(self.stack, axis=0), axis=0)
|
|
@@ -112,14 +111,14 @@ class MedianMethod(MosaicMethodBase):
|
|
|
112
111
|
"""Stack the arrays and return the Median pixel value."""
|
|
113
112
|
|
|
114
113
|
enforce_data_type: bool = True
|
|
115
|
-
stack:
|
|
114
|
+
stack: list[numpy.ma.MaskedArray] = field(default_factory=list, init=False)
|
|
116
115
|
|
|
117
116
|
def __repr__(self):
|
|
118
117
|
"""Mosaic Method repr."""
|
|
119
118
|
return "<Mosaic: MedianMethod>"
|
|
120
119
|
|
|
121
120
|
@property
|
|
122
|
-
def data(self) ->
|
|
121
|
+
def data(self) -> numpy.ma.MaskedArray | None:
|
|
123
122
|
"""Return Median of the data stack."""
|
|
124
123
|
if self.stack:
|
|
125
124
|
array = numpy.ma.median(numpy.ma.stack(self.stack, axis=0), axis=0)
|
|
@@ -130,7 +129,7 @@ class MedianMethod(MosaicMethodBase):
|
|
|
130
129
|
|
|
131
130
|
return None
|
|
132
131
|
|
|
133
|
-
def feed(self, array:
|
|
132
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
134
133
|
"""Add array to the stack."""
|
|
135
134
|
self.stack.append(array)
|
|
136
135
|
|
|
@@ -139,21 +138,21 @@ class MedianMethod(MosaicMethodBase):
|
|
|
139
138
|
class StdevMethod(MosaicMethodBase):
|
|
140
139
|
"""Stack the arrays and return the Standard Deviation value."""
|
|
141
140
|
|
|
142
|
-
stack:
|
|
141
|
+
stack: list[numpy.ma.MaskedArray] = field(default_factory=list, init=False)
|
|
143
142
|
|
|
144
143
|
def __repr__(self):
|
|
145
144
|
"""Mosaic Method repr."""
|
|
146
145
|
return "<Mosaic: StdevMethod>"
|
|
147
146
|
|
|
148
147
|
@property
|
|
149
|
-
def data(self) ->
|
|
148
|
+
def data(self) -> numpy.ma.MaskedArray | None:
|
|
150
149
|
"""Return STDDEV of the data stack."""
|
|
151
150
|
if self.stack:
|
|
152
151
|
return numpy.ma.std(numpy.ma.stack(self.stack, axis=0), axis=0)
|
|
153
152
|
|
|
154
153
|
return None
|
|
155
154
|
|
|
156
|
-
def feed(self, array:
|
|
155
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
157
156
|
"""Add array to the stack."""
|
|
158
157
|
self.stack.append(array)
|
|
159
158
|
|
|
@@ -167,14 +166,14 @@ class LastBandHighMethod(MosaicMethodBase):
|
|
|
167
166
|
return "<Mosaic: LastBandHighMethod>"
|
|
168
167
|
|
|
169
168
|
@property
|
|
170
|
-
def data(self) ->
|
|
169
|
+
def data(self) -> numpy.ma.MaskedArray | None:
|
|
171
170
|
"""Return data."""
|
|
172
171
|
if self.mosaic is not None:
|
|
173
172
|
return self.mosaic[:-1].copy()
|
|
174
173
|
|
|
175
174
|
return None
|
|
176
175
|
|
|
177
|
-
def feed(self, array:
|
|
176
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
178
177
|
"""Add data to the mosaic array."""
|
|
179
178
|
if self.mosaic is None:
|
|
180
179
|
self.mosaic = array
|
|
@@ -199,14 +198,14 @@ class LastBandLowMethod(MosaicMethodBase):
|
|
|
199
198
|
return "<Mosaic: LastBandLowMethod>"
|
|
200
199
|
|
|
201
200
|
@property
|
|
202
|
-
def data(self) ->
|
|
201
|
+
def data(self) -> numpy.ma.MaskedArray | None:
|
|
203
202
|
"""Return data."""
|
|
204
203
|
if self.mosaic is not None:
|
|
205
204
|
return self.mosaic[:-1].copy()
|
|
206
205
|
|
|
207
206
|
return None
|
|
208
207
|
|
|
209
|
-
def feed(self, array:
|
|
208
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
210
209
|
"""Add data to the mosaic array."""
|
|
211
210
|
if self.mosaic is None:
|
|
212
211
|
self.mosaic = array
|
|
@@ -226,14 +225,14 @@ class LastBandLowMethod(MosaicMethodBase):
|
|
|
226
225
|
class CountMethod(MosaicMethodBase):
|
|
227
226
|
"""Stack the arrays and return the valid pixel count."""
|
|
228
227
|
|
|
229
|
-
stack:
|
|
228
|
+
stack: list[numpy.ma.MaskedArray] = field(default_factory=list, init=False)
|
|
230
229
|
|
|
231
230
|
def __repr__(self):
|
|
232
231
|
"""Mosaic Method repr."""
|
|
233
232
|
return "<Mosaic: CountMethod>"
|
|
234
233
|
|
|
235
234
|
@property
|
|
236
|
-
def data(self) ->
|
|
235
|
+
def data(self) -> numpy.ma.MaskedArray | None:
|
|
237
236
|
"""Return valid data count of the data stack."""
|
|
238
237
|
if self.stack:
|
|
239
238
|
data = numpy.ma.count(numpy.ma.stack(self.stack, axis=0), axis=0)
|
|
@@ -254,6 +253,6 @@ class CountMethod(MosaicMethodBase):
|
|
|
254
253
|
|
|
255
254
|
return None
|
|
256
255
|
|
|
257
|
-
def feed(self, array:
|
|
256
|
+
def feed(self, array: numpy.ma.MaskedArray | None):
|
|
258
257
|
"""Add array to the stack."""
|
|
259
258
|
self.stack.append(array)
|
rio_tiler/mosaic/reader.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"""rio_tiler.mosaic: create tile from multiple assets."""
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
|
+
from collections.abc import Callable, Sequence
|
|
4
5
|
from inspect import isclass
|
|
5
|
-
from typing import Any,
|
|
6
|
+
from typing import Any, cast
|
|
6
7
|
|
|
7
8
|
import numpy
|
|
8
9
|
from rasterio.crs import CRS
|
|
@@ -26,12 +27,12 @@ def mosaic_reader( # noqa: C901
|
|
|
26
27
|
mosaic_assets: Sequence,
|
|
27
28
|
reader: Callable[..., ImageData],
|
|
28
29
|
*args: Any,
|
|
29
|
-
pixel_selection:
|
|
30
|
-
chunk_size:
|
|
30
|
+
pixel_selection: type[MosaicMethodBase] | MosaicMethodBase = FirstMethod,
|
|
31
|
+
chunk_size: int | None = None,
|
|
31
32
|
threads: int = MAX_THREADS,
|
|
32
|
-
allowed_exceptions:
|
|
33
|
+
allowed_exceptions: tuple = (TileOutsideBounds,),
|
|
33
34
|
**kwargs,
|
|
34
|
-
) ->
|
|
35
|
+
) -> tuple[ImageData, list]:
|
|
35
36
|
"""Merge multiple assets.
|
|
36
37
|
|
|
37
38
|
Args:
|
|
@@ -65,7 +66,7 @@ def mosaic_reader( # noqa: C901
|
|
|
65
66
|
|
|
66
67
|
"""
|
|
67
68
|
if isclass(pixel_selection):
|
|
68
|
-
pixel_selection = cast(
|
|
69
|
+
pixel_selection = cast(type[MosaicMethodBase], pixel_selection)
|
|
69
70
|
|
|
70
71
|
if issubclass(pixel_selection, MosaicMethodBase):
|
|
71
72
|
pixel_selection = pixel_selection()
|
|
@@ -79,10 +80,10 @@ def mosaic_reader( # noqa: C901
|
|
|
79
80
|
if not chunk_size:
|
|
80
81
|
chunk_size = threads if threads > 1 else len(mosaic_assets)
|
|
81
82
|
|
|
82
|
-
assets_used:
|
|
83
|
-
crs:
|
|
84
|
-
bounds:
|
|
85
|
-
band_names:
|
|
83
|
+
assets_used: list = []
|
|
84
|
+
crs: CRS | None
|
|
85
|
+
bounds: BBox | None
|
|
86
|
+
band_names: list[str]
|
|
86
87
|
|
|
87
88
|
for chunks in _chunks(mosaic_assets, chunk_size):
|
|
88
89
|
tasks = create_tasks(reader, chunks, threads, *args, **kwargs)
|
|
@@ -171,12 +172,12 @@ def mosaic_point_reader(
|
|
|
171
172
|
mosaic_assets: Sequence,
|
|
172
173
|
reader: Callable[..., PointData],
|
|
173
174
|
*args: Any,
|
|
174
|
-
pixel_selection:
|
|
175
|
-
chunk_size:
|
|
175
|
+
pixel_selection: type[MosaicMethodBase] | MosaicMethodBase = FirstMethod,
|
|
176
|
+
chunk_size: int | None = None,
|
|
176
177
|
threads: int = MAX_THREADS,
|
|
177
|
-
allowed_exceptions:
|
|
178
|
+
allowed_exceptions: tuple = (PointOutsideBounds,),
|
|
178
179
|
**kwargs,
|
|
179
|
-
) ->
|
|
180
|
+
) -> tuple[PointData, list]:
|
|
180
181
|
"""Merge multiple assets.
|
|
181
182
|
|
|
182
183
|
Args:
|
|
@@ -202,7 +203,7 @@ def mosaic_point_reader(
|
|
|
202
203
|
|
|
203
204
|
"""
|
|
204
205
|
if isclass(pixel_selection):
|
|
205
|
-
pixel_selection = cast(
|
|
206
|
+
pixel_selection = cast(type[MosaicMethodBase], pixel_selection)
|
|
206
207
|
|
|
207
208
|
if issubclass(pixel_selection, MosaicMethodBase):
|
|
208
209
|
pixel_selection = pixel_selection()
|
|
@@ -216,10 +217,10 @@ def mosaic_point_reader(
|
|
|
216
217
|
if not chunk_size:
|
|
217
218
|
chunk_size = threads if threads > 1 else len(mosaic_assets)
|
|
218
219
|
|
|
219
|
-
assets_used:
|
|
220
|
-
crs:
|
|
221
|
-
coordinates:
|
|
222
|
-
band_names:
|
|
220
|
+
assets_used: list = []
|
|
221
|
+
crs: CRS | None
|
|
222
|
+
coordinates: tuple[float, float] | None
|
|
223
|
+
band_names: list[str]
|
|
223
224
|
|
|
224
225
|
for chunks in _chunks(mosaic_assets, chunk_size):
|
|
225
226
|
tasks = create_tasks(reader, chunks, threads, *args, **kwargs)
|
rio_tiler/reader.py
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import contextlib
|
|
4
4
|
import math
|
|
5
5
|
import warnings
|
|
6
|
-
from
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import TypedDict, cast
|
|
7
8
|
|
|
8
9
|
import numpy
|
|
9
10
|
from affine import Affine
|
|
@@ -34,12 +35,12 @@ from rio_tiler.utils import (
|
|
|
34
35
|
class Options(TypedDict, total=False):
|
|
35
36
|
"""Reader Options."""
|
|
36
37
|
|
|
37
|
-
nodata:
|
|
38
|
-
vrt_options:
|
|
39
|
-
resampling_method:
|
|
40
|
-
reproject_method:
|
|
41
|
-
unscale:
|
|
42
|
-
post_process:
|
|
38
|
+
nodata: NoData | None
|
|
39
|
+
vrt_options: dict | None
|
|
40
|
+
resampling_method: RIOResampling | None
|
|
41
|
+
reproject_method: WarpResampling | None
|
|
42
|
+
unscale: bool | None
|
|
43
|
+
post_process: Callable[[numpy.ma.MaskedArray], numpy.ma.MaskedArray] | None
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
def _apply_buffer(
|
|
@@ -47,7 +48,7 @@ def _apply_buffer(
|
|
|
47
48
|
bounds: BBox,
|
|
48
49
|
height: int,
|
|
49
50
|
width: int,
|
|
50
|
-
) ->
|
|
51
|
+
) -> tuple[BBox, int, int]:
|
|
51
52
|
"""Apply buffer on bounds."""
|
|
52
53
|
x_res = (bounds[2] - bounds[0]) / width
|
|
53
54
|
y_res = (bounds[3] - bounds[1]) / height
|
|
@@ -68,20 +69,20 @@ def _apply_buffer(
|
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
def read(
|
|
71
|
-
src_dst:
|
|
72
|
-
dst_crs:
|
|
73
|
-
height:
|
|
74
|
-
width:
|
|
75
|
-
max_size:
|
|
76
|
-
indexes:
|
|
77
|
-
window:
|
|
78
|
-
nodata:
|
|
79
|
-
vrt_options:
|
|
80
|
-
out_dtype:
|
|
72
|
+
src_dst: DatasetReader | DatasetWriter | WarpedVRT,
|
|
73
|
+
dst_crs: CRS | None = None,
|
|
74
|
+
height: int | None = None,
|
|
75
|
+
width: int | None = None,
|
|
76
|
+
max_size: int | None = None,
|
|
77
|
+
indexes: Indexes | None = None,
|
|
78
|
+
window: windows.Window | None = None,
|
|
79
|
+
nodata: NoData | None = None,
|
|
80
|
+
vrt_options: dict | None = None,
|
|
81
|
+
out_dtype: str | numpy.dtype | None = None,
|
|
81
82
|
resampling_method: RIOResampling = "nearest",
|
|
82
83
|
reproject_method: WarpResampling = "nearest",
|
|
83
84
|
unscale: bool = False,
|
|
84
|
-
post_process:
|
|
85
|
+
post_process: Callable[[numpy.ma.MaskedArray], numpy.ma.MaskedArray] | None = None,
|
|
85
86
|
) -> ImageData:
|
|
86
87
|
"""Low level read function.
|
|
87
88
|
|
|
@@ -309,25 +310,25 @@ def read(
|
|
|
309
310
|
|
|
310
311
|
# flake8: noqa: C901
|
|
311
312
|
def part(
|
|
312
|
-
src_dst:
|
|
313
|
+
src_dst: DatasetReader | DatasetWriter | WarpedVRT,
|
|
313
314
|
bounds: BBox,
|
|
314
|
-
height:
|
|
315
|
-
width:
|
|
316
|
-
max_size:
|
|
317
|
-
dst_crs:
|
|
318
|
-
bounds_crs:
|
|
319
|
-
indexes:
|
|
320
|
-
minimum_overlap:
|
|
321
|
-
padding:
|
|
322
|
-
buffer:
|
|
323
|
-
nodata:
|
|
324
|
-
vrt_options:
|
|
325
|
-
out_dtype:
|
|
315
|
+
height: int | None = None,
|
|
316
|
+
width: int | None = None,
|
|
317
|
+
max_size: int | None = None,
|
|
318
|
+
dst_crs: CRS | None = None,
|
|
319
|
+
bounds_crs: CRS | None = None,
|
|
320
|
+
indexes: Indexes | None = None,
|
|
321
|
+
minimum_overlap: float | None = None,
|
|
322
|
+
padding: int | None = None,
|
|
323
|
+
buffer: float | None = None,
|
|
324
|
+
nodata: NoData | None = None,
|
|
325
|
+
vrt_options: dict | None = None,
|
|
326
|
+
out_dtype: str | numpy.dtype | None = None,
|
|
326
327
|
align_bounds_with_dataset: bool = False,
|
|
327
328
|
resampling_method: RIOResampling = "nearest",
|
|
328
329
|
reproject_method: WarpResampling = "nearest",
|
|
329
330
|
unscale: bool = False,
|
|
330
|
-
post_process:
|
|
331
|
+
post_process: Callable[[numpy.ma.MaskedArray], numpy.ma.MaskedArray] | None = None,
|
|
331
332
|
) -> ImageData:
|
|
332
333
|
"""Read part of a dataset.
|
|
333
334
|
|
|
@@ -533,18 +534,18 @@ def part(
|
|
|
533
534
|
|
|
534
535
|
|
|
535
536
|
def point(
|
|
536
|
-
src_dst:
|
|
537
|
-
coordinates:
|
|
538
|
-
indexes:
|
|
537
|
+
src_dst: DatasetReader | DatasetWriter | WarpedVRT,
|
|
538
|
+
coordinates: tuple[float, float],
|
|
539
|
+
indexes: Indexes | None = None,
|
|
539
540
|
coord_crs: CRS = WGS84_CRS,
|
|
540
|
-
nodata:
|
|
541
|
-
vrt_options:
|
|
542
|
-
out_dtype:
|
|
541
|
+
nodata: NoData | None = None,
|
|
542
|
+
vrt_options: dict | None = None,
|
|
543
|
+
out_dtype: str | numpy.dtype | None = None,
|
|
543
544
|
resampling_method: RIOResampling = "nearest",
|
|
544
545
|
reproject_method: WarpResampling = "nearest",
|
|
545
546
|
interpolate: bool = False,
|
|
546
547
|
unscale: bool = False,
|
|
547
|
-
post_process:
|
|
548
|
+
post_process: Callable[[numpy.ma.MaskedArray], numpy.ma.MaskedArray] | None = None,
|
|
548
549
|
) -> PointData:
|
|
549
550
|
"""Read a pixel value for a point.
|
|
550
551
|
|
rio_tiler/tasks.py
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"""rio_tiler.tasks: tools for handling rio-tiler's future tasks."""
|
|
2
2
|
|
|
3
|
+
from collections.abc import Callable, Generator, Sequence
|
|
3
4
|
from concurrent import futures
|
|
4
5
|
from functools import partial
|
|
5
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
6
7
|
|
|
7
8
|
from rio_tiler.constants import MAX_THREADS
|
|
8
9
|
from rio_tiler.logger import logger
|
|
9
10
|
from rio_tiler.models import ImageData, PointData
|
|
10
11
|
|
|
11
|
-
TaskType = Sequence[
|
|
12
|
+
TaskType = Sequence[tuple[futures.Future | Callable, Any]]
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
def filter_tasks(
|
|
15
16
|
tasks: TaskType,
|
|
16
|
-
allowed_exceptions:
|
|
17
|
+
allowed_exceptions: tuple | None = None,
|
|
17
18
|
) -> Generator:
|
|
18
19
|
"""Filter Tasks to remove Exceptions.
|
|
19
20
|
|
|
@@ -60,7 +61,7 @@ def multi_arrays(
|
|
|
60
61
|
reader: Callable[..., ImageData],
|
|
61
62
|
*args: Any,
|
|
62
63
|
threads: int = MAX_THREADS,
|
|
63
|
-
allowed_exceptions:
|
|
64
|
+
allowed_exceptions: tuple | None = None,
|
|
64
65
|
**kwargs: Any,
|
|
65
66
|
) -> ImageData:
|
|
66
67
|
"""Merge arrays returned from tasks."""
|
|
@@ -75,7 +76,7 @@ def multi_points(
|
|
|
75
76
|
reader: Callable[..., PointData],
|
|
76
77
|
*args: Any,
|
|
77
78
|
threads: int = MAX_THREADS,
|
|
78
|
-
allowed_exceptions:
|
|
79
|
+
allowed_exceptions: tuple | None = None,
|
|
79
80
|
**kwargs: Any,
|
|
80
81
|
) -> PointData:
|
|
81
82
|
"""Merge points returned from tasks."""
|
|
@@ -90,9 +91,9 @@ def multi_values(
|
|
|
90
91
|
reader: Callable,
|
|
91
92
|
*args: Any,
|
|
92
93
|
threads: int = MAX_THREADS,
|
|
93
|
-
allowed_exceptions:
|
|
94
|
+
allowed_exceptions: tuple | None = None,
|
|
94
95
|
**kwargs: Any,
|
|
95
|
-
) ->
|
|
96
|
+
) -> dict:
|
|
96
97
|
"""Merge values returned from tasks."""
|
|
97
98
|
tasks = create_tasks(reader, asset_list, threads, *args, **kwargs)
|
|
98
99
|
return {
|
|
@@ -106,7 +107,7 @@ def multi_values_list(
|
|
|
106
107
|
reader: Callable,
|
|
107
108
|
*args: Any,
|
|
108
109
|
threads: int = MAX_THREADS,
|
|
109
|
-
allowed_exceptions:
|
|
110
|
+
allowed_exceptions: tuple | None = None,
|
|
110
111
|
**kwargs: Any,
|
|
111
112
|
) -> list[tuple[Any, Any]]:
|
|
112
113
|
"""Merge values returned from tasks."""
|
rio_tiler/types.py
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
"""rio-tiler types."""
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from typing import Any, Literal, TypedDict
|
|
4
5
|
|
|
5
6
|
import numpy
|
|
6
7
|
|
|
7
|
-
NumType =
|
|
8
|
+
NumType = float | int
|
|
8
9
|
|
|
9
|
-
BBox =
|
|
10
|
-
NoData =
|
|
11
|
-
Indexes =
|
|
10
|
+
BBox = tuple[float, float, float, float]
|
|
11
|
+
NoData = float | int | str
|
|
12
|
+
Indexes = Sequence[int] | int
|
|
12
13
|
|
|
13
|
-
DataMaskType =
|
|
14
|
+
DataMaskType = tuple[numpy.ndarray, numpy.ndarray]
|
|
14
15
|
|
|
15
|
-
ColorTuple =
|
|
16
|
-
IntervalTuple =
|
|
16
|
+
ColorTuple = tuple[int, int, int, int] # (red, green, blue, alpha)
|
|
17
|
+
IntervalTuple = tuple[NumType, NumType] # (0, 100)
|
|
17
18
|
|
|
18
19
|
# ColorMap Dict: {1: (0, 0, 0, 255), ...}
|
|
19
|
-
GDALColorMapType =
|
|
20
|
+
GDALColorMapType = dict[int, ColorTuple]
|
|
20
21
|
|
|
21
22
|
# Discrete Colormap, like GDALColorMapType but accept Float: {0.1: (0, 0, 0, 255), ...}
|
|
22
|
-
DiscreteColorMapType =
|
|
23
|
+
DiscreteColorMapType = dict[NumType, ColorTuple]
|
|
23
24
|
|
|
24
25
|
# Intervals ColorMap: [((0, 1), (0, 0, 0, 0)), ...]
|
|
25
|
-
IntervalColorMapType = Sequence[
|
|
26
|
+
IntervalColorMapType = Sequence[tuple[IntervalTuple, ColorTuple]]
|
|
26
27
|
|
|
27
|
-
ColorMapType =
|
|
28
|
-
GDALColorMapType,
|
|
29
|
-
DiscreteColorMapType,
|
|
30
|
-
IntervalColorMapType,
|
|
31
|
-
]
|
|
28
|
+
ColorMapType = GDALColorMapType | DiscreteColorMapType | IntervalColorMapType
|
|
32
29
|
|
|
33
30
|
# RasterIO() resampling method.
|
|
34
31
|
# ref: https://gdal.org/api/raster_c_api.html#_CPPv418GDALRIOResampleAlg
|
|
@@ -69,6 +66,6 @@ class AssetInfo(TypedDict, total=False):
|
|
|
69
66
|
|
|
70
67
|
url: Any
|
|
71
68
|
media_type: str
|
|
72
|
-
env:
|
|
73
|
-
metadata:
|
|
74
|
-
dataset_statistics:
|
|
69
|
+
env: dict | None
|
|
70
|
+
metadata: dict | None
|
|
71
|
+
dataset_statistics: Sequence[tuple[float, float]] | None
|