rioxarray 0.15.5__tar.gz → 0.15.6__tar.gz
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.
- {rioxarray-0.15.5/rioxarray.egg-info → rioxarray-0.15.6}/PKG-INFO +1 -1
- {rioxarray-0.15.5 → rioxarray-0.15.6}/pyproject.toml +1 -1
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/_io.py +19 -9
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/merge.py +4 -17
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/raster_writer.py +11 -9
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/rioxarray.py +11 -4
- {rioxarray-0.15.5 → rioxarray-0.15.6/rioxarray.egg-info}/PKG-INFO +1 -1
- {rioxarray-0.15.5 → rioxarray-0.15.6}/AUTHORS.rst +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/CONTRIBUTING.rst +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/LICENSE +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/LICENSE_datacube +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/LICENSE_xarray +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/MANIFEST.in +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/README.rst +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/__init__.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/_options.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/_show_versions.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/crs.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/exceptions.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/py.typed +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/raster_array.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/raster_dataset.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray/xarray_plugin.py +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray.egg-info/SOURCES.txt +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray.egg-info/dependency_links.txt +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray.egg-info/entry_points.txt +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray.egg-info/requires.txt +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/rioxarray.egg-info/top_level.txt +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/setup.cfg +0 -0
- {rioxarray-0.15.5 → rioxarray-0.15.6}/setup.py +0 -0
|
@@ -7,7 +7,6 @@ Source file: https://github.com/pydata/xarray/blob/1d7bcbdc75b6d556c04e2c7d7a042
|
|
|
7
7
|
"""
|
|
8
8
|
# pylint: disable=too-many-lines
|
|
9
9
|
import contextlib
|
|
10
|
-
import functools
|
|
11
10
|
import importlib.metadata
|
|
12
11
|
import os
|
|
13
12
|
import re
|
|
@@ -145,7 +144,11 @@ class SingleBandDatasetReader:
|
|
|
145
144
|
"""
|
|
146
145
|
read data for the band
|
|
147
146
|
"""
|
|
148
|
-
|
|
147
|
+
if numpy.isscalar(indexes):
|
|
148
|
+
indexes = self._bidx + 1
|
|
149
|
+
else:
|
|
150
|
+
indexes = [self._bidx + 1]
|
|
151
|
+
return self._riods.read(indexes=indexes, **kwargs)
|
|
149
152
|
|
|
150
153
|
def tags(self, bidx=None, **kwargs): # pylint: disable=unused-argument
|
|
151
154
|
"""
|
|
@@ -309,7 +312,6 @@ class RasterioArrayWrapper(BackendArray):
|
|
|
309
312
|
riods = _ensure_warped_vrt(manager.acquire(), vrt_params)
|
|
310
313
|
self.vrt_params = vrt_params
|
|
311
314
|
self._shape = (riods.count, riods.height, riods.width)
|
|
312
|
-
|
|
313
315
|
self._dtype = None
|
|
314
316
|
self._unsigned_dtype = None
|
|
315
317
|
self._fill_value = riods.nodata
|
|
@@ -898,6 +900,7 @@ def _prepare_dask(
|
|
|
898
900
|
riods: RasterioReader,
|
|
899
901
|
filename: Union[str, os.PathLike],
|
|
900
902
|
chunks: Union[int, tuple, dict],
|
|
903
|
+
bidx: Optional[int] = None,
|
|
901
904
|
) -> DataArray:
|
|
902
905
|
"""
|
|
903
906
|
Prepare the data for dask computations
|
|
@@ -924,7 +927,10 @@ def _prepare_dask(
|
|
|
924
927
|
dtype=_rasterio_to_numpy_dtype(riods.dtypes),
|
|
925
928
|
previous_chunks=tuple((c,) for c in block_shape),
|
|
926
929
|
)
|
|
927
|
-
|
|
930
|
+
token_filename = filename
|
|
931
|
+
if bidx is not None:
|
|
932
|
+
token_filename = f"{filename}-{bidx}"
|
|
933
|
+
token = tokenize(token_filename, mtime, chunks)
|
|
928
934
|
name_prefix = f"open_rasterio-{token}"
|
|
929
935
|
return result.chunk(chunks, name_prefix=name_prefix, token=token)
|
|
930
936
|
|
|
@@ -1080,10 +1086,8 @@ def open_rasterio(
|
|
|
1080
1086
|
vrt_params = None
|
|
1081
1087
|
file_opener = rasterio.open
|
|
1082
1088
|
if isinstance(filename, SingleBandDatasetReader):
|
|
1083
|
-
file_opener =
|
|
1084
|
-
|
|
1085
|
-
bidx=filename._bidx,
|
|
1086
|
-
)
|
|
1089
|
+
file_opener = _single_band_open
|
|
1090
|
+
open_kwargs.update(bidx=filename._bidx)
|
|
1087
1091
|
vrt_params = filename._vrt_params
|
|
1088
1092
|
if isinstance(filename, (rasterio.io.DatasetReader, SingleBandDatasetReader)):
|
|
1089
1093
|
filename = filename.name
|
|
@@ -1261,7 +1265,13 @@ def open_rasterio(
|
|
|
1261
1265
|
result.rio.write_gcps(*riods.gcps, inplace=True)
|
|
1262
1266
|
|
|
1263
1267
|
if chunks is not None:
|
|
1264
|
-
result = _prepare_dask(
|
|
1268
|
+
result = _prepare_dask(
|
|
1269
|
+
result=result,
|
|
1270
|
+
riods=riods,
|
|
1271
|
+
filename=filename,
|
|
1272
|
+
chunks=chunks,
|
|
1273
|
+
bidx=open_kwargs.get("bidx"),
|
|
1274
|
+
)
|
|
1265
1275
|
else:
|
|
1266
1276
|
result.encoding["preferred_chunks"] = {
|
|
1267
1277
|
result.rio.y_dim: riods.block_shapes[0][0],
|
|
@@ -52,21 +52,8 @@ class RasterioDatasetDuck:
|
|
|
52
52
|
This method is meant to be used by the rasterio.merge.merge function.
|
|
53
53
|
"""
|
|
54
54
|
with MemoryFile() as memfile:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
height=int(self._xds.rio.height),
|
|
58
|
-
width=int(self._xds.rio.width),
|
|
59
|
-
count=self.count,
|
|
60
|
-
dtype=self.dtypes[0],
|
|
61
|
-
crs=self.crs,
|
|
62
|
-
transform=self.transform,
|
|
63
|
-
nodata=self.nodatavals[0],
|
|
64
|
-
) as dataset:
|
|
65
|
-
data = self._xds.values
|
|
66
|
-
if data.ndim == 2:
|
|
67
|
-
dataset.write(data, 1)
|
|
68
|
-
else:
|
|
69
|
-
dataset.write(data)
|
|
55
|
+
self._xds.rio.to_raster(memfile.name)
|
|
56
|
+
with memfile.open() as dataset:
|
|
70
57
|
return dataset.read(*args, **kwargs)
|
|
71
58
|
|
|
72
59
|
|
|
@@ -90,7 +77,7 @@ def merge_arrays(
|
|
|
90
77
|
Parameters
|
|
91
78
|
----------
|
|
92
79
|
dataarrays: list[xarray.DataArray]
|
|
93
|
-
List of xarray.DataArray
|
|
80
|
+
List of multiple xarray.DataArray with all geo attributes.
|
|
94
81
|
The first one is assumed to have the same
|
|
95
82
|
CRS, dtype, and dimensions as the others in the array.
|
|
96
83
|
bounds: tuple, optional
|
|
@@ -200,7 +187,7 @@ def merge_datasets(
|
|
|
200
187
|
Parameters
|
|
201
188
|
----------
|
|
202
189
|
datasets: list[xarray.Dataset]
|
|
203
|
-
List of xarray.Dataset
|
|
190
|
+
List of multiple xarray.Dataset with all geo attributes.
|
|
204
191
|
The first one is assumed to have the same
|
|
205
192
|
CRS, dtype, dimensions, and data_vars as the others in the array.
|
|
206
193
|
bounds: tuple, optional
|
|
@@ -8,8 +8,6 @@ Source file:
|
|
|
8
8
|
- https://github.com/dymaxionlabs/dask-rasterio/blob/8dd7fdece7ad094a41908c0ae6b4fe6ca49cf5e1/dask_rasterio/write.py # noqa: E501
|
|
9
9
|
|
|
10
10
|
"""
|
|
11
|
-
import warnings
|
|
12
|
-
|
|
13
11
|
import numpy
|
|
14
12
|
import rasterio
|
|
15
13
|
from rasterio.windows import Window
|
|
@@ -121,17 +119,21 @@ def _ensure_nodata_dtype(original_nodata, new_dtype):
|
|
|
121
119
|
if the value of the nodata value changed.
|
|
122
120
|
"""
|
|
123
121
|
# Complex-valued rasters can have real-valued nodata
|
|
124
|
-
|
|
122
|
+
new_dtype = numpy.dtype(new_dtype)
|
|
123
|
+
if numpy.issubdtype(new_dtype, numpy.complexfloating):
|
|
125
124
|
nodata = original_nodata
|
|
126
125
|
else:
|
|
127
126
|
original_nodata = float(original_nodata)
|
|
128
|
-
|
|
127
|
+
failure_message = (
|
|
128
|
+
f"Unable to convert nodata value ({original_nodata}) to "
|
|
129
|
+
f"new dtype ({new_dtype})."
|
|
130
|
+
)
|
|
131
|
+
try:
|
|
132
|
+
nodata = new_dtype.type(original_nodata)
|
|
133
|
+
except OverflowError as error:
|
|
134
|
+
raise OverflowError(failure_message) from error
|
|
129
135
|
if not numpy.isnan(nodata) and original_nodata != nodata:
|
|
130
|
-
|
|
131
|
-
f"The nodata value ({original_nodata}) has been automatically "
|
|
132
|
-
f"changed to ({nodata}) to match the dtype of the data."
|
|
133
|
-
)
|
|
134
|
-
|
|
136
|
+
raise OverflowError(failure_message)
|
|
135
137
|
return nodata
|
|
136
138
|
|
|
137
139
|
|
|
@@ -3,6 +3,7 @@ This module is an extension for xarray to provide rasterio capabilities
|
|
|
3
3
|
to xarray datasets/dataarrays.
|
|
4
4
|
"""
|
|
5
5
|
# pylint: disable=too-many-lines
|
|
6
|
+
import json
|
|
6
7
|
import math
|
|
7
8
|
import warnings
|
|
8
9
|
from collections.abc import Hashable, Iterable
|
|
@@ -254,6 +255,7 @@ def _order_bounds(
|
|
|
254
255
|
class XRasterBase:
|
|
255
256
|
"""This is the base class for the GIS extensions for xarray"""
|
|
256
257
|
|
|
258
|
+
# pylint: disable=too-many-instance-attributes
|
|
257
259
|
def __init__(self, xarray_obj: Union[xarray.DataArray, xarray.Dataset]):
|
|
258
260
|
self._obj: Union[xarray.DataArray, xarray.Dataset] = xarray_obj
|
|
259
261
|
|
|
@@ -289,6 +291,7 @@ class XRasterBase:
|
|
|
289
291
|
self._height: Optional[int] = None
|
|
290
292
|
self._width: Optional[int] = None
|
|
291
293
|
self._crs: Union[rasterio.crs.CRS, None, Literal[False]] = None
|
|
294
|
+
self._gcps: Optional[list[GroundControlPoint]] = None
|
|
292
295
|
|
|
293
296
|
@property
|
|
294
297
|
def crs(self) -> Optional[rasterio.crs.CRS]:
|
|
@@ -347,6 +350,7 @@ class XRasterBase:
|
|
|
347
350
|
obj_copy.rio._width = self._width
|
|
348
351
|
obj_copy.rio._height = self._height
|
|
349
352
|
obj_copy.rio._crs = self._crs
|
|
353
|
+
obj_copy.rio._gcps = self._gcps
|
|
350
354
|
return obj_copy
|
|
351
355
|
|
|
352
356
|
def set_crs(
|
|
@@ -1235,7 +1239,8 @@ class XRasterBase:
|
|
|
1235
1239
|
gcp_crs, grid_mapping_name=grid_mapping_name, inplace=inplace
|
|
1236
1240
|
)
|
|
1237
1241
|
geojson_gcps = _convert_gcps_to_geojson(gcps)
|
|
1238
|
-
data_obj.coords[grid_mapping_name].attrs["gcps"] = geojson_gcps
|
|
1242
|
+
data_obj.coords[grid_mapping_name].attrs["gcps"] = json.dumps(geojson_gcps)
|
|
1243
|
+
self._gcps = list(gcps)
|
|
1239
1244
|
return data_obj
|
|
1240
1245
|
|
|
1241
1246
|
def get_gcps(self) -> Optional[list[GroundControlPoint]]:
|
|
@@ -1249,8 +1254,10 @@ class XRasterBase:
|
|
|
1249
1254
|
list of :obj:`rasterio.control.GroundControlPoint` or None
|
|
1250
1255
|
The Ground Control Points from the dataset or None if not applicable
|
|
1251
1256
|
"""
|
|
1257
|
+
if self._gcps is not None:
|
|
1258
|
+
return self._gcps
|
|
1252
1259
|
try:
|
|
1253
|
-
geojson_gcps = self._obj.coords[self.grid_mapping].attrs["gcps"]
|
|
1260
|
+
geojson_gcps = json.loads(self._obj.coords[self.grid_mapping].attrs["gcps"])
|
|
1254
1261
|
except (KeyError, AttributeError):
|
|
1255
1262
|
return None
|
|
1256
1263
|
|
|
@@ -1267,8 +1274,8 @@ class XRasterBase:
|
|
|
1267
1274
|
info=gcp["properties"]["info"],
|
|
1268
1275
|
)
|
|
1269
1276
|
|
|
1270
|
-
|
|
1271
|
-
return
|
|
1277
|
+
self._gcps = [_parse_gcp(gcp) for gcp in geojson_gcps["features"]]
|
|
1278
|
+
return self._gcps
|
|
1272
1279
|
|
|
1273
1280
|
|
|
1274
1281
|
def _convert_gcps_to_geojson(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|