rioxarray 0.15.6__tar.gz → 0.16.0__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.6 → rioxarray-0.16.0}/AUTHORS.rst +2 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/CONTRIBUTING.rst +2 -2
- {rioxarray-0.15.6/rioxarray.egg-info → rioxarray-0.16.0}/PKG-INFO +1 -1
- {rioxarray-0.15.6 → rioxarray-0.16.0}/pyproject.toml +1 -1
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/raster_array.py +12 -4
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/raster_dataset.py +5 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/rioxarray.py +50 -10
- {rioxarray-0.15.6 → rioxarray-0.16.0/rioxarray.egg-info}/PKG-INFO +1 -1
- {rioxarray-0.15.6 → rioxarray-0.16.0}/LICENSE +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/LICENSE_datacube +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/LICENSE_xarray +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/MANIFEST.in +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/README.rst +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/__init__.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/_io.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/_options.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/_show_versions.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/crs.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/exceptions.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/merge.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/py.typed +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/raster_writer.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray/xarray_plugin.py +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray.egg-info/SOURCES.txt +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray.egg-info/dependency_links.txt +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray.egg-info/entry_points.txt +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray.egg-info/requires.txt +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/rioxarray.egg-info/top_level.txt +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/setup.cfg +0 -0
- {rioxarray-0.15.6 → rioxarray-0.16.0}/setup.py +0 -0
|
@@ -59,6 +59,8 @@ Thanks goes to these wonderful people (`emoji key <https://allcontributors.org/d
|
|
|
59
59
|
<tr>
|
|
60
60
|
<td align="center"><a href="https://github.com/xaviernogueira"><img src="https://avatars.githubusercontent.com/u/58796351?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Xavier Nogueira</b></sub></a><br /><a href="https://github.com/corteva/rioxarray/issues?q=author%3Axaviernogueira" title="Bug reports">🐛</a></td>
|
|
61
61
|
<td align="center"><a href="https://github.com/valanm22"><img src="https://avatars.githubusercontent.com/u/84893551?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Valan Baptist Mathuranayagam</b></sub></a><br /><a href="https://github.com/corteva/rioxarray/commits?author=valanm22" title="Documentation">📖</a></td>
|
|
62
|
+
<td align="center"><a href="https://github.com/peterm790"><img src="https://avatars.githubusercontent.com/u/52179978?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Peter Marsh</b></sub></a><br /><a href="https://github.com/corteva/rioxarray/commits?author=peterm790" title="Code">💻</a> <a href="https://github.com/corteva/rioxarray/commits?author=peterm790" title="Tests">⚠️</a></td>
|
|
63
|
+
<td align="center"><a href="https://github.com/dluks"><img src="https://avatars.githubusercontent.com/u/4911680?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Daniel Lusk</b></sub></a><br /><a href="https://github.com/corteva/rioxarray/commits?author=dluks" title="Code">💻</a> <a href="https://github.com/corteva/rioxarray/commits?author=dluks" title="Documentation">📖</a></td>
|
|
62
64
|
</tr>
|
|
63
65
|
</table>
|
|
64
66
|
|
|
@@ -78,9 +78,9 @@ Using python::
|
|
|
78
78
|
$ python -m venv venv
|
|
79
79
|
$ . venv/bin/activate
|
|
80
80
|
|
|
81
|
-
4. Install your local copy into a virtualenv
|
|
81
|
+
4. Install your local copy into a virtualenv::
|
|
82
82
|
|
|
83
|
-
$ python -m pip install -e .[all]
|
|
83
|
+
$ python -m pip install -e ".[all]"
|
|
84
84
|
$ python -m pip install -r requirements/dev.txt
|
|
85
85
|
|
|
86
86
|
5. Setup pre-commit hooks::
|
|
@@ -713,10 +713,12 @@ class RasterArray(XRasterBase):
|
|
|
713
713
|
auto_expand: Union[bool, int] = False,
|
|
714
714
|
auto_expand_limit: int = 3,
|
|
715
715
|
crs: Optional[Any] = None,
|
|
716
|
+
allow_one_dimensional_raster: bool = False,
|
|
716
717
|
) -> xarray.DataArray:
|
|
717
718
|
"""Clip the :obj:`xarray.DataArray` by a bounding box.
|
|
718
719
|
|
|
719
720
|
.. versionadded:: 0.12 crs
|
|
721
|
+
.. versionadded:: 0.16 allow_one_dimensional_raster
|
|
720
722
|
|
|
721
723
|
Parameters
|
|
722
724
|
----------
|
|
@@ -736,16 +738,19 @@ class RasterArray(XRasterBase):
|
|
|
736
738
|
crs: :obj:`rasterio.crs.CRS`, optional
|
|
737
739
|
The CRS of the bounding box. Default is to assume it is the same
|
|
738
740
|
as the dataset.
|
|
741
|
+
allow_one_dimensional_raster: bool, optional
|
|
742
|
+
If True, allow clipping to/from a one dimensional raster.
|
|
739
743
|
|
|
740
744
|
Returns
|
|
741
745
|
-------
|
|
742
746
|
xarray.DataArray:
|
|
743
747
|
The clipped object.
|
|
744
748
|
"""
|
|
745
|
-
if self.width == 1 or self.height == 1:
|
|
749
|
+
if not allow_one_dimensional_raster and (self.width == 1 or self.height == 1):
|
|
746
750
|
raise OneDimensionalRaster(
|
|
747
751
|
"At least one of the raster x,y coordinates has only one point."
|
|
748
|
-
f"{_get_data_var_message(self._obj)}"
|
|
752
|
+
f"{_get_data_var_message(self._obj)}. "
|
|
753
|
+
"Set allow_one_dimensional_raster=True to disable this error."
|
|
749
754
|
)
|
|
750
755
|
|
|
751
756
|
if crs is not None and self.crs is None:
|
|
@@ -819,11 +824,14 @@ class RasterArray(XRasterBase):
|
|
|
819
824
|
raise NoDataInBounds(
|
|
820
825
|
f"No data found in bounds.{_get_data_var_message(self._obj)}"
|
|
821
826
|
)
|
|
822
|
-
if
|
|
827
|
+
if not allow_one_dimensional_raster and (
|
|
828
|
+
cl_array.rio.width == 1 or cl_array.rio.height == 1
|
|
829
|
+
):
|
|
823
830
|
raise OneDimensionalRaster(
|
|
824
831
|
"At least one of the clipped raster x,y coordinates"
|
|
825
832
|
" has only one point."
|
|
826
|
-
f"{_get_data_var_message(self._obj)}"
|
|
833
|
+
f"{_get_data_var_message(self._obj)}. "
|
|
834
|
+
"Set allow_one_dimensional_raster=True to disable this error."
|
|
827
835
|
)
|
|
828
836
|
|
|
829
837
|
# make sure correct attributes preserved & projection added
|
|
@@ -256,12 +256,14 @@ class RasterDataset(XRasterBase):
|
|
|
256
256
|
auto_expand: Union[bool, int] = False,
|
|
257
257
|
auto_expand_limit: int = 3,
|
|
258
258
|
crs: Optional[Any] = None,
|
|
259
|
+
allow_one_dimensional_raster: bool = False,
|
|
259
260
|
) -> xarray.Dataset:
|
|
260
261
|
"""Clip the :class:`xarray.Dataset` by a bounding box in dimensions 'x'/'y'.
|
|
261
262
|
|
|
262
263
|
.. warning:: Clips variables that have dimensions 'x'/'y'. Others are appended as is.
|
|
263
264
|
|
|
264
265
|
.. versionadded:: 0.12 crs
|
|
266
|
+
.. versionadded:: 0.16 allow_one_dimensional_raster
|
|
265
267
|
|
|
266
268
|
Parameters
|
|
267
269
|
----------
|
|
@@ -281,6 +283,8 @@ class RasterDataset(XRasterBase):
|
|
|
281
283
|
crs: :obj:`rasterio.crs.CRS`, optional
|
|
282
284
|
The CRS of the bounding box. Default is to assume it is the same
|
|
283
285
|
as the dataset.
|
|
286
|
+
allow_one_dimensional_raster: bool, optional
|
|
287
|
+
If True, allow clipping to/from a one dimensional raster.
|
|
284
288
|
|
|
285
289
|
Returns
|
|
286
290
|
-------
|
|
@@ -302,6 +306,7 @@ class RasterDataset(XRasterBase):
|
|
|
302
306
|
auto_expand=auto_expand,
|
|
303
307
|
auto_expand_limit=auto_expand_limit,
|
|
304
308
|
crs=crs,
|
|
309
|
+
allow_one_dimensional_raster=allow_one_dimensional_raster,
|
|
305
310
|
)
|
|
306
311
|
)
|
|
307
312
|
except MissingSpatialDimensionError:
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
This module is an extension for xarray to provide rasterio capabilities
|
|
3
3
|
to xarray datasets/dataarrays.
|
|
4
4
|
"""
|
|
5
|
+
|
|
5
6
|
# pylint: disable=too-many-lines
|
|
6
7
|
import json
|
|
7
8
|
import math
|
|
@@ -305,7 +306,7 @@ class XRasterBase:
|
|
|
305
306
|
# pyproj CRS if possible for performance
|
|
306
307
|
for crs_attr in ("spatial_ref", "crs_wkt"):
|
|
307
308
|
try:
|
|
308
|
-
self.
|
|
309
|
+
self._set_crs(
|
|
309
310
|
self._obj.coords[self.grid_mapping].attrs[crs_attr],
|
|
310
311
|
inplace=True,
|
|
311
312
|
)
|
|
@@ -315,14 +316,14 @@ class XRasterBase:
|
|
|
315
316
|
|
|
316
317
|
# look in grid_mapping
|
|
317
318
|
try:
|
|
318
|
-
self.
|
|
319
|
+
self._set_crs(
|
|
319
320
|
pyproj.CRS.from_cf(self._obj.coords[self.grid_mapping].attrs),
|
|
320
321
|
inplace=True,
|
|
321
322
|
)
|
|
322
323
|
except (KeyError, pyproj.exceptions.CRSError):
|
|
323
324
|
try:
|
|
324
325
|
# look in attrs for 'crs'
|
|
325
|
-
self.
|
|
326
|
+
self._set_crs(self._obj.attrs["crs"], inplace=True)
|
|
326
327
|
except KeyError:
|
|
327
328
|
self._crs = False
|
|
328
329
|
return None
|
|
@@ -360,6 +361,10 @@ class XRasterBase:
|
|
|
360
361
|
Set the CRS value for the Dataset/DataArray without modifying
|
|
361
362
|
the dataset/data array.
|
|
362
363
|
|
|
364
|
+
.. deprecated:: 0.15.8
|
|
365
|
+
It is recommended to use `rio.write_crs()` instead. This
|
|
366
|
+
method will likely be removed in a future release.
|
|
367
|
+
|
|
363
368
|
Parameters
|
|
364
369
|
----------
|
|
365
370
|
input_crs: object
|
|
@@ -372,6 +377,34 @@ class XRasterBase:
|
|
|
372
377
|
:obj:`xarray.Dataset` | :obj:`xarray.DataArray`:
|
|
373
378
|
Dataset with crs attribute.
|
|
374
379
|
"""
|
|
380
|
+
warnings.warn(
|
|
381
|
+
"It is recommended to use 'rio.write_crs()' instead. 'rio.set_crs()' will likely"
|
|
382
|
+
"be removed in a future release.",
|
|
383
|
+
FutureWarning,
|
|
384
|
+
stacklevel=2,
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
return self._set_crs(input_crs, inplace=inplace)
|
|
388
|
+
|
|
389
|
+
def _set_crs(
|
|
390
|
+
self, input_crs: Any, inplace: bool = True
|
|
391
|
+
) -> Union[xarray.Dataset, xarray.DataArray]:
|
|
392
|
+
"""
|
|
393
|
+
Set the CRS value for the Dataset/DataArray without modifying
|
|
394
|
+
the dataset/data array.
|
|
395
|
+
|
|
396
|
+
Parameters
|
|
397
|
+
----------
|
|
398
|
+
input_crs: object
|
|
399
|
+
Anything accepted by `rasterio.crs.CRS.from_user_input`.
|
|
400
|
+
inplace: bool, optional
|
|
401
|
+
If True, it will write to the existing dataset. Default is False.
|
|
402
|
+
|
|
403
|
+
Returns
|
|
404
|
+
-------
|
|
405
|
+
xarray.Dataset | xarray.DataArray
|
|
406
|
+
Dataset with crs attribute.
|
|
407
|
+
"""
|
|
375
408
|
crs = crs_from_user_input(input_crs)
|
|
376
409
|
obj = self._get_obj(inplace=inplace)
|
|
377
410
|
obj.rio._crs = crs
|
|
@@ -435,7 +468,7 @@ class XRasterBase:
|
|
|
435
468
|
new_attrs.pop("grid_mapping", None)
|
|
436
469
|
data_obj[var].rio.update_encoding(
|
|
437
470
|
{"grid_mapping": grid_mapping_name}, inplace=True
|
|
438
|
-
).rio.
|
|
471
|
+
).rio.set_attrs(new_attrs, inplace=True).rio.set_spatial_dims(
|
|
439
472
|
x_dim=x_dim, y_dim=y_dim, inplace=True
|
|
440
473
|
)
|
|
441
474
|
# remove grid_mapping from attributes if it exists
|
|
@@ -444,7 +477,7 @@ class XRasterBase:
|
|
|
444
477
|
new_attrs.pop("grid_mapping", None)
|
|
445
478
|
return data_obj.rio.update_encoding(
|
|
446
479
|
{"grid_mapping": grid_mapping_name}, inplace=True
|
|
447
|
-
).rio.
|
|
480
|
+
).rio.set_attrs(new_attrs, inplace=True)
|
|
448
481
|
|
|
449
482
|
def write_crs(
|
|
450
483
|
self,
|
|
@@ -483,7 +516,7 @@ class XRasterBase:
|
|
|
483
516
|
>>> raster = raster.rio.write_crs("epsg:4326")
|
|
484
517
|
"""
|
|
485
518
|
if input_crs is not None:
|
|
486
|
-
data_obj = self.
|
|
519
|
+
data_obj = self._set_crs(input_crs, inplace=inplace)
|
|
487
520
|
else:
|
|
488
521
|
data_obj = self._get_obj(inplace=inplace)
|
|
489
522
|
|
|
@@ -1235,11 +1268,18 @@ class XRasterBase:
|
|
|
1235
1268
|
)
|
|
1236
1269
|
data_obj = self._get_obj(inplace=True)
|
|
1237
1270
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1271
|
+
if gcp_crs:
|
|
1272
|
+
data_obj = data_obj.rio.write_crs(
|
|
1273
|
+
gcp_crs, grid_mapping_name=grid_mapping_name, inplace=inplace
|
|
1274
|
+
)
|
|
1275
|
+
try:
|
|
1276
|
+
grid_map_attrs = data_obj.coords[grid_mapping_name].attrs.copy()
|
|
1277
|
+
except KeyError:
|
|
1278
|
+
data_obj.coords[grid_mapping_name] = xarray.Variable((), 0)
|
|
1279
|
+
grid_map_attrs = data_obj.coords[grid_mapping_name].attrs.copy()
|
|
1241
1280
|
geojson_gcps = _convert_gcps_to_geojson(gcps)
|
|
1242
|
-
|
|
1281
|
+
grid_map_attrs["gcps"] = json.dumps(geojson_gcps)
|
|
1282
|
+
data_obj.coords[grid_mapping_name].rio.set_attrs(grid_map_attrs, inplace=True)
|
|
1243
1283
|
self._gcps = list(gcps)
|
|
1244
1284
|
return data_obj
|
|
1245
1285
|
|
|
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
|