rioxarray 0.17.0__tar.gz → 0.18.1__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.17.0 → rioxarray-0.18.1}/AUTHORS.rst +2 -0
- {rioxarray-0.17.0/rioxarray.egg-info → rioxarray-0.18.1}/PKG-INFO +5 -4
- {rioxarray-0.17.0 → rioxarray-0.18.1}/README.rst +1 -1
- {rioxarray-0.17.0 → rioxarray-0.18.1}/pyproject.toml +4 -3
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/_io.py +32 -17
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/merge.py +72 -48
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/raster_array.py +73 -27
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/raster_dataset.py +45 -16
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/raster_writer.py +28 -19
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/rioxarray.py +24 -13
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/xarray_plugin.py +1 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1/rioxarray.egg-info}/PKG-INFO +5 -4
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray.egg-info/requires.txt +2 -2
- {rioxarray-0.17.0 → rioxarray-0.18.1}/CONTRIBUTING.rst +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/LICENSE +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/LICENSE_datacube +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/LICENSE_xarray +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/MANIFEST.in +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/__init__.py +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/_options.py +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/_show_versions.py +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/crs.py +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/exceptions.py +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray/py.typed +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray.egg-info/SOURCES.txt +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray.egg-info/dependency_links.txt +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray.egg-info/entry_points.txt +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/rioxarray.egg-info/top_level.txt +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/setup.cfg +0 -0
- {rioxarray-0.17.0 → rioxarray-0.18.1}/setup.py +0 -0
|
@@ -61,6 +61,8 @@ Thanks goes to these wonderful people (`emoji key <https://allcontributors.org/d
|
|
|
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
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
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>
|
|
64
|
+
<td align="center"><a href="https://github.com/DahnJ"><img src="https://avatars.githubusercontent.com/u/18722560?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Daniel Jahn (dahn)</b></sub></a><br /><a href="https://github.com/corteva/rioxarray/commits?author=DahnJ" title="Documentation">📖</a></td>
|
|
65
|
+
<td align="center"><a href="https://phofl.github.io/"><img src="https://avatars.githubusercontent.com/u/61934744?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Patrick Hoefler</b></sub></a><br /><a href="https://github.com/corteva/rioxarray/issues?q=author%3Aphofl" title="Bug reports">🐛</a></td>
|
|
64
66
|
</tr>
|
|
65
67
|
</table>
|
|
66
68
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: rioxarray
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.18.1
|
|
4
4
|
Summary: geospatial xarray extension powered by rasterio
|
|
5
5
|
Maintainer: rioxarray Contributors
|
|
6
6
|
License: Apache
|
|
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
23
|
Classifier: Programming Language :: Python :: 3
|
|
23
24
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
25
|
Classifier: Typing :: Typed
|
|
@@ -29,8 +30,8 @@ License-File: LICENSE_datacube
|
|
|
29
30
|
License-File: LICENSE_xarray
|
|
30
31
|
License-File: AUTHORS.rst
|
|
31
32
|
Requires-Dist: packaging
|
|
32
|
-
Requires-Dist: rasterio>=1.3
|
|
33
|
-
Requires-Dist: xarray>=
|
|
33
|
+
Requires-Dist: rasterio>=1.3.7
|
|
34
|
+
Requires-Dist: xarray>=2024.7.0
|
|
34
35
|
Requires-Dist: pyproj>=3.3
|
|
35
36
|
Requires-Dist: numpy>=1.23
|
|
36
37
|
Provides-Extra: interp
|
|
@@ -49,7 +50,7 @@ rasterio xarray extension.
|
|
|
49
50
|
:alt: Join the chat at https://gitter.im/rioxarray/community
|
|
50
51
|
:target: https://gitter.im/rioxarray/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
51
52
|
|
|
52
|
-
.. image:: https://img.shields.io/badge/all_contributors-
|
|
53
|
+
.. image:: https://img.shields.io/badge/all_contributors-39-orange.svg?style=flat-square
|
|
53
54
|
:alt: All Contributors
|
|
54
55
|
:target: https://github.com/corteva/rioxarray/blob/master/AUTHORS.rst
|
|
55
56
|
|
|
@@ -9,7 +9,7 @@ rasterio xarray extension.
|
|
|
9
9
|
:alt: Join the chat at https://gitter.im/rioxarray/community
|
|
10
10
|
:target: https://gitter.im/rioxarray/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
11
11
|
|
|
12
|
-
.. image:: https://img.shields.io/badge/all_contributors-
|
|
12
|
+
.. image:: https://img.shields.io/badge/all_contributors-39-orange.svg?style=flat-square
|
|
13
13
|
:alt: All Contributors
|
|
14
14
|
:target: https://github.com/corteva/rioxarray/blob/master/AUTHORS.rst
|
|
15
15
|
|
|
@@ -4,7 +4,7 @@ requires = ["setuptools", "wheel"]
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rioxarray"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.18.1"
|
|
8
8
|
description = "geospatial xarray extension powered by rasterio"
|
|
9
9
|
maintainers = [
|
|
10
10
|
{name = "rioxarray Contributors"},
|
|
@@ -27,6 +27,7 @@ classifiers = [
|
|
|
27
27
|
"Programming Language :: Python :: 3.10",
|
|
28
28
|
"Programming Language :: Python :: 3.11",
|
|
29
29
|
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
30
31
|
"Programming Language :: Python :: 3",
|
|
31
32
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
32
33
|
"Typing :: Typed",
|
|
@@ -34,8 +35,8 @@ classifiers = [
|
|
|
34
35
|
requires-python = ">=3.10"
|
|
35
36
|
dependencies = [
|
|
36
37
|
"packaging",
|
|
37
|
-
"rasterio>=1.3",
|
|
38
|
-
"xarray>=
|
|
38
|
+
"rasterio>=1.3.7",
|
|
39
|
+
"xarray>=2024.7.0",
|
|
39
40
|
"pyproj>=3.3",
|
|
40
41
|
"numpy>=1.23",
|
|
41
42
|
]
|
|
@@ -295,6 +295,7 @@ class RasterioArrayWrapper(BackendArray):
|
|
|
295
295
|
|
|
296
296
|
def __init__(
|
|
297
297
|
self,
|
|
298
|
+
*,
|
|
298
299
|
manager,
|
|
299
300
|
lock,
|
|
300
301
|
name,
|
|
@@ -327,7 +328,7 @@ class RasterioArrayWrapper(BackendArray):
|
|
|
327
328
|
)
|
|
328
329
|
if self._unsigned_dtype is not None and self._fill_value is not None:
|
|
329
330
|
self._fill_value = self._unsigned_dtype.type(self._fill_value)
|
|
330
|
-
if self._unsigned_dtype is None
|
|
331
|
+
if self._unsigned_dtype is None:
|
|
331
332
|
warnings.warn(
|
|
332
333
|
f"variable {name!r} has _Unsigned attribute but is not "
|
|
333
334
|
"of integer type. Ignoring attribute.",
|
|
@@ -512,7 +513,7 @@ def _to_numeric(value: Any) -> float:
|
|
|
512
513
|
return value
|
|
513
514
|
|
|
514
515
|
|
|
515
|
-
def _parse_tag(key: str, value: Any) -> tuple[str, Any]:
|
|
516
|
+
def _parse_tag(*, key: str, value: Any) -> tuple[str, Any]:
|
|
516
517
|
# NC_GLOBAL is appended to tags with netcdf driver and is not really needed
|
|
517
518
|
key = key.split("NC_GLOBAL#")[-1]
|
|
518
519
|
if value.startswith("{") and value.endswith("}"):
|
|
@@ -530,7 +531,7 @@ def _parse_tag(key: str, value: Any) -> tuple[str, Any]:
|
|
|
530
531
|
def _parse_tags(tags: dict) -> dict:
|
|
531
532
|
parsed_tags = {}
|
|
532
533
|
for key, value in tags.items():
|
|
533
|
-
key, value = _parse_tag(key, value)
|
|
534
|
+
key, value = _parse_tag(key=key, value=value)
|
|
534
535
|
parsed_tags[key] = value
|
|
535
536
|
return parsed_tags
|
|
536
537
|
|
|
@@ -552,7 +553,7 @@ NETCDF_DTYPE_MAP = {
|
|
|
552
553
|
}
|
|
553
554
|
|
|
554
555
|
|
|
555
|
-
def _load_netcdf_attrs(tags: dict, data_array: DataArray) -> None:
|
|
556
|
+
def _load_netcdf_attrs(*, tags: dict, data_array: DataArray) -> None:
|
|
556
557
|
"""
|
|
557
558
|
Loads the netCDF attributes into the data array
|
|
558
559
|
|
|
@@ -560,7 +561,7 @@ def _load_netcdf_attrs(tags: dict, data_array: DataArray) -> None:
|
|
|
560
561
|
- variable_name#attr_name: attr_value
|
|
561
562
|
"""
|
|
562
563
|
for key, value in tags.items():
|
|
563
|
-
key, value = _parse_tag(key, value)
|
|
564
|
+
key, value = _parse_tag(key=key, value=value)
|
|
564
565
|
key_split = key.split("#")
|
|
565
566
|
if len(key_split) != 2:
|
|
566
567
|
continue
|
|
@@ -569,7 +570,7 @@ def _load_netcdf_attrs(tags: dict, data_array: DataArray) -> None:
|
|
|
569
570
|
data_array.coords[variable_name].attrs.update({attr_name: value})
|
|
570
571
|
|
|
571
572
|
|
|
572
|
-
def _parse_netcdf_attr_array(attr: Union[NDArray, str], dtype=None) -> NDArray:
|
|
573
|
+
def _parse_netcdf_attr_array(attr: Union[NDArray, str], *, dtype=None) -> NDArray:
|
|
573
574
|
"""
|
|
574
575
|
Expected format: '{2,6}' or '[2. 6.]'
|
|
575
576
|
"""
|
|
@@ -775,7 +776,7 @@ def _pop_global_netcdf_attrs_from_vars(dataset_to_clean: Dataset) -> Dataset:
|
|
|
775
776
|
|
|
776
777
|
|
|
777
778
|
def _subdataset_groups_to_dataset(
|
|
778
|
-
dim_groups: dict[Hashable, dict[Hashable, DataArray]], global_tags: dict
|
|
779
|
+
*, dim_groups: dict[Hashable, dict[Hashable, DataArray]], global_tags: dict
|
|
779
780
|
) -> Union[Dataset, list[Dataset]]:
|
|
780
781
|
if dim_groups:
|
|
781
782
|
dataset: Union[Dataset, list[Dataset]] = []
|
|
@@ -800,6 +801,7 @@ def _subdataset_groups_to_dataset(
|
|
|
800
801
|
|
|
801
802
|
def _load_subdatasets(
|
|
802
803
|
riods: RasterioReader,
|
|
804
|
+
*,
|
|
803
805
|
group: Optional[Union[str, list[str], tuple[str, ...]]],
|
|
804
806
|
variable: Optional[Union[str, list[str], tuple[str, ...]]],
|
|
805
807
|
parse_coordinates: bool,
|
|
@@ -845,6 +847,7 @@ def _load_subdatasets(
|
|
|
845
847
|
|
|
846
848
|
def _load_bands_as_variables(
|
|
847
849
|
riods: RasterioReader,
|
|
850
|
+
*,
|
|
848
851
|
parse_coordinates: bool,
|
|
849
852
|
chunks: Optional[Union[int, tuple, dict]],
|
|
850
853
|
cache: Optional[bool],
|
|
@@ -896,6 +899,7 @@ def _load_bands_as_variables(
|
|
|
896
899
|
|
|
897
900
|
|
|
898
901
|
def _prepare_dask(
|
|
902
|
+
*,
|
|
899
903
|
result: DataArray,
|
|
900
904
|
riods: RasterioReader,
|
|
901
905
|
filename: Union[str, os.PathLike],
|
|
@@ -925,7 +929,7 @@ def _prepare_dask(
|
|
|
925
929
|
chunks=(1, "auto", "auto"),
|
|
926
930
|
shape=(riods.count, riods.height, riods.width),
|
|
927
931
|
dtype=_rasterio_to_numpy_dtype(riods.dtypes),
|
|
928
|
-
previous_chunks=
|
|
932
|
+
previous_chunks=block_shape,
|
|
929
933
|
)
|
|
930
934
|
token_filename = filename
|
|
931
935
|
if bidx is not None:
|
|
@@ -936,6 +940,7 @@ def _prepare_dask(
|
|
|
936
940
|
|
|
937
941
|
|
|
938
942
|
def _handle_encoding(
|
|
943
|
+
*,
|
|
939
944
|
result: DataArray,
|
|
940
945
|
mask_and_scale: bool,
|
|
941
946
|
masked: bool,
|
|
@@ -952,8 +957,12 @@ def _handle_encoding(
|
|
|
952
957
|
variables.pop_to(
|
|
953
958
|
result.attrs, result.encoding, "scale_factor", name=da_name
|
|
954
959
|
)
|
|
960
|
+
if "scales" in result.attrs:
|
|
961
|
+
variables.pop_to(result.attrs, result.encoding, "scales", name=da_name)
|
|
955
962
|
if "add_offset" in result.attrs:
|
|
956
963
|
variables.pop_to(result.attrs, result.encoding, "add_offset", name=da_name)
|
|
964
|
+
if "offsets" in result.attrs:
|
|
965
|
+
variables.pop_to(result.attrs, result.encoding, "offsets", name=da_name)
|
|
957
966
|
if masked:
|
|
958
967
|
if "_FillValue" in result.attrs:
|
|
959
968
|
variables.pop_to(result.attrs, result.encoding, "_FillValue", name=da_name)
|
|
@@ -991,6 +1000,7 @@ def open_rasterio(
|
|
|
991
1000
|
rasterio.vrt.WarpedVRT,
|
|
992
1001
|
SingleBandDatasetReader,
|
|
993
1002
|
],
|
|
1003
|
+
*,
|
|
994
1004
|
parse_coordinates: Optional[bool] = None,
|
|
995
1005
|
chunks: Optional[Union[int, tuple, dict]] = None,
|
|
996
1006
|
cache: Optional[bool] = None,
|
|
@@ -1010,10 +1020,7 @@ def open_rasterio(
|
|
|
1010
1020
|
|
|
1011
1021
|
This should work with any file that rasterio can open (most often:
|
|
1012
1022
|
geoTIFF). The x and y coordinates are generated automatically from the
|
|
1013
|
-
file's geoinformation
|
|
1014
|
-
`"PixelIsArea" Raster Space
|
|
1015
|
-
<http://web.archive.org/web/20160326194152/http://remotesensing.org/geotiff/spec/geotiff2.5.html#2.5.2>`_
|
|
1016
|
-
for more information).
|
|
1023
|
+
file's geoinformation and refer to the center of the pixel.
|
|
1017
1024
|
|
|
1018
1025
|
.. versionadded:: 0.13 band_as_variable
|
|
1019
1026
|
|
|
@@ -1206,7 +1213,9 @@ def open_rasterio(
|
|
|
1206
1213
|
# Get geospatial coordinates
|
|
1207
1214
|
if parse_coordinates:
|
|
1208
1215
|
coords.update(
|
|
1209
|
-
_generate_spatial_coords(
|
|
1216
|
+
_generate_spatial_coords(
|
|
1217
|
+
affine=riods.transform, width=riods.width, height=riods.height
|
|
1218
|
+
)
|
|
1210
1219
|
)
|
|
1211
1220
|
|
|
1212
1221
|
unsigned = None
|
|
@@ -1220,8 +1229,8 @@ def open_rasterio(
|
|
|
1220
1229
|
da_name = attrs.pop("NETCDF_VARNAME", default_name)
|
|
1221
1230
|
data: Any = indexing.LazilyOuterIndexedArray(
|
|
1222
1231
|
RasterioArrayWrapper(
|
|
1223
|
-
manager,
|
|
1224
|
-
lock,
|
|
1232
|
+
manager=manager,
|
|
1233
|
+
lock=lock,
|
|
1225
1234
|
name=da_name,
|
|
1226
1235
|
vrt_params=vrt_params,
|
|
1227
1236
|
masked=masked,
|
|
@@ -1241,7 +1250,7 @@ def open_rasterio(
|
|
|
1241
1250
|
result.encoding = encoding
|
|
1242
1251
|
|
|
1243
1252
|
# update attributes from NetCDF attributes
|
|
1244
|
-
_load_netcdf_attrs(riods.tags(), result)
|
|
1253
|
+
_load_netcdf_attrs(tags=riods.tags(), data_array=result)
|
|
1245
1254
|
result = _decode_datetime_cf(
|
|
1246
1255
|
result, decode_times=decode_times, decode_timedelta=decode_timedelta
|
|
1247
1256
|
)
|
|
@@ -1251,7 +1260,13 @@ def open_rasterio(
|
|
|
1251
1260
|
result.attrs["_FillValue"] = result.dtype.type(result.attrs["_FillValue"])
|
|
1252
1261
|
|
|
1253
1262
|
# handle encoding
|
|
1254
|
-
_handle_encoding(
|
|
1263
|
+
_handle_encoding(
|
|
1264
|
+
result=result,
|
|
1265
|
+
mask_and_scale=mask_and_scale,
|
|
1266
|
+
masked=masked,
|
|
1267
|
+
da_name=da_name,
|
|
1268
|
+
unsigned=unsigned,
|
|
1269
|
+
)
|
|
1255
1270
|
# Affine transformation matrix (always available)
|
|
1256
1271
|
# This describes coefficients mapping pixel coordinates to CRS
|
|
1257
1272
|
# For serialization store as tuple of 6 floats, the last row being
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
This module allows you to merge xarray Datasets/DataArrays
|
|
3
3
|
geospatially with the `rasterio.merge` module.
|
|
4
4
|
"""
|
|
5
|
-
|
|
6
5
|
from collections.abc import Sequence
|
|
7
6
|
from typing import Callable, Optional, Union
|
|
8
7
|
|
|
@@ -12,7 +11,8 @@ from rasterio.io import MemoryFile
|
|
|
12
11
|
from rasterio.merge import merge as _rio_merge
|
|
13
12
|
from xarray import DataArray, Dataset
|
|
14
13
|
|
|
15
|
-
from rioxarray.
|
|
14
|
+
from rioxarray._io import open_rasterio
|
|
15
|
+
from rioxarray.rioxarray import _get_nonspatial_coords
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class RasterioDatasetDuck:
|
|
@@ -31,13 +31,29 @@ class RasterioDatasetDuck:
|
|
|
31
31
|
self.count = int(xds.rio.count)
|
|
32
32
|
self.dtypes = [xds.dtype]
|
|
33
33
|
self.name = xds.name
|
|
34
|
-
|
|
34
|
+
if xds.rio.encoded_nodata is not None:
|
|
35
|
+
self.nodatavals = [xds.rio.encoded_nodata]
|
|
36
|
+
else:
|
|
37
|
+
self.nodatavals = [xds.rio.nodata]
|
|
35
38
|
res = xds.rio.resolution(recalc=True)
|
|
36
39
|
self.res = (abs(res[0]), abs(res[1]))
|
|
37
40
|
self.transform = xds.rio.transform(recalc=True)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
self.profile: dict = {
|
|
42
|
+
"crs": self.crs,
|
|
43
|
+
"nodata": self.nodatavals[0],
|
|
44
|
+
}
|
|
45
|
+
valid_scale_factor = self._xds.encoding.get("scale_factor", 1) != 1 or any(
|
|
46
|
+
scale != 1 for scale in self._xds.encoding.get("scales", (1,))
|
|
47
|
+
)
|
|
48
|
+
valid_offset = self._xds.encoding.get("add_offset", 0.0) != 0 or any(
|
|
49
|
+
offset != 0 for offset in self._xds.encoding.get("offsets", (0,))
|
|
50
|
+
)
|
|
51
|
+
self._mask_and_scale = (
|
|
52
|
+
self._xds.rio.encoded_nodata is not None
|
|
53
|
+
or valid_scale_factor
|
|
54
|
+
or valid_offset
|
|
55
|
+
or self._xds.encoding.get("_Unsigned") is not None
|
|
56
|
+
)
|
|
41
57
|
|
|
42
58
|
def colormap(self, *args, **kwargs) -> None:
|
|
43
59
|
"""
|
|
@@ -54,11 +70,19 @@ class RasterioDatasetDuck:
|
|
|
54
70
|
with MemoryFile() as memfile:
|
|
55
71
|
self._xds.rio.to_raster(memfile.name)
|
|
56
72
|
with memfile.open() as dataset:
|
|
57
|
-
|
|
73
|
+
if self._mask_and_scale:
|
|
74
|
+
kwargs["masked"] = True
|
|
75
|
+
out = dataset.read(*args, **kwargs)
|
|
76
|
+
if self._mask_and_scale:
|
|
77
|
+
out = out.astype(self._xds.dtype)
|
|
78
|
+
for iii in range(self.count):
|
|
79
|
+
out[iii] = out[iii] * dataset.scales[iii] + dataset.offsets[iii]
|
|
80
|
+
return out
|
|
58
81
|
|
|
59
82
|
|
|
60
83
|
def merge_arrays(
|
|
61
84
|
dataarrays: Sequence[DataArray],
|
|
85
|
+
*,
|
|
62
86
|
bounds: Optional[tuple] = None,
|
|
63
87
|
res: Optional[tuple] = None,
|
|
64
88
|
nodata: Optional[float] = None,
|
|
@@ -131,45 +155,52 @@ def merge_arrays(
|
|
|
131
155
|
rioduckarrays.append(RasterioDatasetDuck(dataarray))
|
|
132
156
|
|
|
133
157
|
# use rasterio to merge
|
|
134
|
-
merged_data, merged_transform = _rio_merge(
|
|
135
|
-
rioduckarrays,
|
|
136
|
-
**{key: val for key, val in input_kwargs.items() if val is not None},
|
|
137
|
-
)
|
|
138
158
|
# generate merged data array
|
|
139
159
|
representative_array = rioduckarrays[0]._xds
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
merged_data.shape[-2],
|
|
160
|
+
with MemoryFile() as memfile:
|
|
161
|
+
_rio_merge(
|
|
162
|
+
rioduckarrays,
|
|
163
|
+
**{key: val for key, val in input_kwargs.items() if val is not None},
|
|
164
|
+
dst_path=memfile.name,
|
|
146
165
|
)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
data
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
with open_rasterio( # type: ignore
|
|
167
|
+
memfile.name,
|
|
168
|
+
parse_coordinates=parse_coordinates,
|
|
169
|
+
mask_and_scale=rioduckarrays[0]._mask_and_scale,
|
|
170
|
+
) as merged_data:
|
|
171
|
+
merged_data = merged_data.load()
|
|
172
|
+
|
|
173
|
+
# make sure old & new coorinate names match & dimensions are correct
|
|
174
|
+
rename_map = {}
|
|
175
|
+
original_extra_dim = representative_array.rio._check_dimensions()
|
|
176
|
+
new_extra_dim = merged_data.rio._check_dimensions()
|
|
177
|
+
# make sure the output merged data shape is 2D if the
|
|
178
|
+
# original data was 2D. this can happen if the
|
|
179
|
+
# xarray datasarray was squeezed.
|
|
180
|
+
if len(merged_data.shape) == 3 and len(representative_array.shape) == 2:
|
|
181
|
+
merged_data = merged_data.squeeze(
|
|
182
|
+
dim=new_extra_dim, drop=original_extra_dim is None
|
|
183
|
+
)
|
|
184
|
+
new_extra_dim = merged_data.rio._check_dimensions()
|
|
185
|
+
if (
|
|
186
|
+
original_extra_dim is not None
|
|
187
|
+
and new_extra_dim is not None
|
|
188
|
+
and original_extra_dim != new_extra_dim
|
|
189
|
+
):
|
|
190
|
+
rename_map[new_extra_dim] = original_extra_dim
|
|
191
|
+
if representative_array.rio.x_dim != merged_data.rio.x_dim:
|
|
192
|
+
rename_map[merged_data.rio.x_dim] = representative_array.rio.x_dim
|
|
193
|
+
if representative_array.rio.y_dim != merged_data.rio.y_dim:
|
|
194
|
+
rename_map[merged_data.rio.y_dim] = representative_array.rio.y_dim
|
|
195
|
+
if rename_map:
|
|
196
|
+
merged_data = merged_data.rename(rename_map)
|
|
197
|
+
merged_data.coords.update(_get_nonspatial_coords(representative_array))
|
|
198
|
+
return merged_data # type: ignore
|
|
169
199
|
|
|
170
200
|
|
|
171
201
|
def merge_datasets(
|
|
172
202
|
datasets: Sequence[Dataset],
|
|
203
|
+
*,
|
|
173
204
|
bounds: Optional[tuple] = None,
|
|
174
205
|
res: Optional[tuple] = None,
|
|
175
206
|
nodata: Optional[float] = None,
|
|
@@ -215,7 +246,7 @@ def merge_datasets(
|
|
|
215
246
|
|
|
216
247
|
representative_ds = datasets[0]
|
|
217
248
|
merged_data = {}
|
|
218
|
-
for data_var in representative_ds.data_vars:
|
|
249
|
+
for iii, data_var in enumerate(representative_ds.data_vars):
|
|
219
250
|
merged_data[data_var] = merge_arrays(
|
|
220
251
|
[dataset[data_var] for dataset in datasets],
|
|
221
252
|
bounds=bounds,
|
|
@@ -224,18 +255,11 @@ def merge_datasets(
|
|
|
224
255
|
precision=precision,
|
|
225
256
|
method=method,
|
|
226
257
|
crs=crs,
|
|
227
|
-
parse_coordinates=
|
|
258
|
+
parse_coordinates=iii == 0,
|
|
228
259
|
)
|
|
229
260
|
data_var = list(representative_ds.data_vars)[0]
|
|
230
261
|
xds = Dataset(
|
|
231
262
|
merged_data,
|
|
232
|
-
coords=_make_coords(
|
|
233
|
-
merged_data[data_var],
|
|
234
|
-
merged_data[data_var].rio.transform(),
|
|
235
|
-
merged_data[data_var].shape[-1],
|
|
236
|
-
merged_data[data_var].shape[-2],
|
|
237
|
-
force_generate=True,
|
|
238
|
-
),
|
|
239
263
|
attrs=representative_ds.attrs,
|
|
240
264
|
)
|
|
241
265
|
xds.rio.write_crs(merged_data[data_var].rio.crs, inplace=True)
|
|
@@ -9,6 +9,7 @@ datacube is licensed under the Apache License, Version 2.0:
|
|
|
9
9
|
- https://github.com/opendatacube/datacube-core/blob/1d345f08a10a13c316f81100936b0ad8b1a374eb/LICENSE # noqa: E501
|
|
10
10
|
|
|
11
11
|
"""
|
|
12
|
+
|
|
12
13
|
import copy
|
|
13
14
|
import os
|
|
14
15
|
from collections.abc import Hashable, Iterable, Mapping
|
|
@@ -68,7 +69,7 @@ _NODATA_DTYPE_MAP = {
|
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
def _generate_attrs(
|
|
71
|
-
src_data_array: xarray.DataArray, dst_nodata: Optional[float]
|
|
72
|
+
*, src_data_array: xarray.DataArray, dst_nodata: Optional[float]
|
|
72
73
|
) -> dict[str, Any]:
|
|
73
74
|
# add original attributes
|
|
74
75
|
new_attrs = copy.deepcopy(src_data_array.attrs)
|
|
@@ -89,7 +90,7 @@ def _generate_attrs(
|
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
def _add_attrs_proj(
|
|
92
|
-
new_data_array: xarray.DataArray, src_data_array: xarray.DataArray
|
|
93
|
+
*, new_data_array: xarray.DataArray, src_data_array: xarray.DataArray
|
|
93
94
|
) -> xarray.DataArray:
|
|
94
95
|
"""Make sure attributes and projection correct"""
|
|
95
96
|
# make sure dimension information is preserved
|
|
@@ -99,7 +100,7 @@ def _add_attrs_proj(
|
|
|
99
100
|
new_data_array.rio._y_dim = src_data_array.rio.y_dim
|
|
100
101
|
|
|
101
102
|
# make sure attributes preserved
|
|
102
|
-
new_attrs = _generate_attrs(src_data_array, None)
|
|
103
|
+
new_attrs = _generate_attrs(src_data_array=src_data_array, dst_nodata=None)
|
|
103
104
|
# remove fill value if it already exists in the encoding
|
|
104
105
|
# this is for data arrays pulling the encoding from a
|
|
105
106
|
# source data array instead of being generated anew.
|
|
@@ -119,6 +120,7 @@ def _add_attrs_proj(
|
|
|
119
120
|
|
|
120
121
|
|
|
121
122
|
def _make_dst_affine(
|
|
123
|
+
*,
|
|
122
124
|
src_data_array: xarray.DataArray,
|
|
123
125
|
src_crs: rasterio.crs.CRS,
|
|
124
126
|
dst_crs: rasterio.crs.CRS,
|
|
@@ -127,7 +129,13 @@ def _make_dst_affine(
|
|
|
127
129
|
**kwargs,
|
|
128
130
|
):
|
|
129
131
|
"""Determine the affine of the new projected `xarray.DataArray`"""
|
|
130
|
-
src_bounds = ()
|
|
132
|
+
src_bounds = ()
|
|
133
|
+
if (
|
|
134
|
+
"gcps" not in kwargs
|
|
135
|
+
and "rpcs" not in kwargs
|
|
136
|
+
and "src_geoloc_array" not in kwargs
|
|
137
|
+
):
|
|
138
|
+
src_bounds = src_data_array.rio.bounds()
|
|
131
139
|
src_height, src_width = src_data_array.rio.shape
|
|
132
140
|
dst_height, dst_width = dst_shape if dst_shape is not None else (None, None)
|
|
133
141
|
# pylint: disable=isinstance-second-argument-not-valid-type
|
|
@@ -156,6 +164,7 @@ def _make_dst_affine(
|
|
|
156
164
|
|
|
157
165
|
def _clip_from_disk(
|
|
158
166
|
xds: xarray.DataArray,
|
|
167
|
+
*,
|
|
159
168
|
geometries: Iterable,
|
|
160
169
|
all_touched: bool,
|
|
161
170
|
drop: bool,
|
|
@@ -182,7 +191,12 @@ def _clip_from_disk(
|
|
|
182
191
|
cropped_ds = xarray.DataArray(
|
|
183
192
|
name=xds.name,
|
|
184
193
|
data=out_image,
|
|
185
|
-
coords=_make_coords(
|
|
194
|
+
coords=_make_coords(
|
|
195
|
+
src_data_array=xds,
|
|
196
|
+
dst_affine=out_transform,
|
|
197
|
+
dst_width=width,
|
|
198
|
+
dst_height=height,
|
|
199
|
+
),
|
|
186
200
|
dims=xds.dims,
|
|
187
201
|
attrs=xds.attrs,
|
|
188
202
|
)
|
|
@@ -194,6 +208,7 @@ def _clip_from_disk(
|
|
|
194
208
|
|
|
195
209
|
def _clip_xarray(
|
|
196
210
|
xds: xarray.DataArray,
|
|
211
|
+
*,
|
|
197
212
|
geometries: Iterable,
|
|
198
213
|
all_touched: bool,
|
|
199
214
|
drop: bool,
|
|
@@ -243,7 +258,7 @@ class RasterArray(XRasterBase):
|
|
|
243
258
|
] = None # https://github.com/corteva/rioxarray/issues/254
|
|
244
259
|
|
|
245
260
|
def set_nodata(
|
|
246
|
-
self, input_nodata: Optional[float], inplace: bool = True
|
|
261
|
+
self, input_nodata: Optional[float], *, inplace: bool = True
|
|
247
262
|
) -> xarray.DataArray:
|
|
248
263
|
"""
|
|
249
264
|
Set the nodata value for the DataArray without modifying
|
|
@@ -266,7 +281,7 @@ class RasterArray(XRasterBase):
|
|
|
266
281
|
return obj
|
|
267
282
|
|
|
268
283
|
def write_nodata(
|
|
269
|
-
self, input_nodata: Optional[float], encoded: bool = False, inplace=False
|
|
284
|
+
self, input_nodata: Optional[float], *, encoded: bool = False, inplace=False
|
|
270
285
|
) -> xarray.DataArray:
|
|
271
286
|
"""
|
|
272
287
|
Write the nodata to the DataArray in a CF compliant manner.
|
|
@@ -308,7 +323,9 @@ class RasterArray(XRasterBase):
|
|
|
308
323
|
data_obj: xarray.DataArray = self._get_obj(inplace=inplace) # type: ignore
|
|
309
324
|
input_nodata = False if input_nodata is None else input_nodata
|
|
310
325
|
if input_nodata is not False:
|
|
311
|
-
input_nodata = _ensure_nodata_dtype(
|
|
326
|
+
input_nodata = _ensure_nodata_dtype(
|
|
327
|
+
original_nodata=input_nodata, new_dtype=self._obj.dtype
|
|
328
|
+
)
|
|
312
329
|
if encoded:
|
|
313
330
|
data_obj.rio.update_encoding({"_FillValue": input_nodata}, inplace=True)
|
|
314
331
|
else:
|
|
@@ -331,7 +348,9 @@ class RasterArray(XRasterBase):
|
|
|
331
348
|
encoded_nodata = self._obj.encoding.get("_FillValue")
|
|
332
349
|
if encoded_nodata is None:
|
|
333
350
|
return None
|
|
334
|
-
return _ensure_nodata_dtype(
|
|
351
|
+
return _ensure_nodata_dtype(
|
|
352
|
+
original_nodata=encoded_nodata, new_dtype=self._obj.dtype
|
|
353
|
+
)
|
|
335
354
|
|
|
336
355
|
@property
|
|
337
356
|
def nodata(self) -> Optional[float]:
|
|
@@ -364,12 +383,15 @@ class RasterArray(XRasterBase):
|
|
|
364
383
|
self._nodata = False
|
|
365
384
|
return None
|
|
366
385
|
|
|
367
|
-
self._nodata = _ensure_nodata_dtype(
|
|
386
|
+
self._nodata = _ensure_nodata_dtype(
|
|
387
|
+
original_nodata=self._nodata, new_dtype=self._obj.dtype
|
|
388
|
+
)
|
|
368
389
|
return self._nodata
|
|
369
390
|
|
|
370
391
|
def reproject(
|
|
371
392
|
self,
|
|
372
393
|
dst_crs: Any,
|
|
394
|
+
*,
|
|
373
395
|
resolution: Optional[Union[float, tuple[float, float]]] = None,
|
|
374
396
|
shape: Optional[tuple[int, int]] = None,
|
|
375
397
|
transform: Optional[Affine] = None,
|
|
@@ -438,11 +460,20 @@ class RasterArray(XRasterBase):
|
|
|
438
460
|
if gcps:
|
|
439
461
|
kwargs.setdefault("gcps", gcps)
|
|
440
462
|
|
|
441
|
-
|
|
442
|
-
|
|
463
|
+
use_affine = (
|
|
464
|
+
"gcps" not in kwargs
|
|
465
|
+
and "rpcs" not in kwargs
|
|
466
|
+
and "src_geoloc_array" not in kwargs
|
|
467
|
+
)
|
|
468
|
+
src_affine = None if not use_affine else self.transform(recalc=True)
|
|
443
469
|
if transform is None:
|
|
444
470
|
dst_affine, dst_width, dst_height = _make_dst_affine(
|
|
445
|
-
self._obj,
|
|
471
|
+
src_data_array=self._obj,
|
|
472
|
+
src_crs=self.crs,
|
|
473
|
+
dst_crs=dst_crs,
|
|
474
|
+
dst_resolution=resolution,
|
|
475
|
+
dst_shape=shape,
|
|
476
|
+
**kwargs,
|
|
446
477
|
)
|
|
447
478
|
else:
|
|
448
479
|
dst_affine = transform
|
|
@@ -451,10 +482,9 @@ class RasterArray(XRasterBase):
|
|
|
451
482
|
else:
|
|
452
483
|
dst_height, dst_width = self.shape
|
|
453
484
|
|
|
454
|
-
dst_data = self._create_dst_data(dst_height, dst_width)
|
|
485
|
+
dst_data = self._create_dst_data(dst_height=dst_height, dst_width=dst_width)
|
|
455
486
|
|
|
456
487
|
dst_nodata = self._get_dst_nodata(nodata)
|
|
457
|
-
|
|
458
488
|
rasterio.warp.reproject(
|
|
459
489
|
source=self._obj.values,
|
|
460
490
|
destination=dst_data,
|
|
@@ -468,7 +498,7 @@ class RasterArray(XRasterBase):
|
|
|
468
498
|
**kwargs,
|
|
469
499
|
)
|
|
470
500
|
# add necessary attributes
|
|
471
|
-
new_attrs = _generate_attrs(self._obj, dst_nodata)
|
|
501
|
+
new_attrs = _generate_attrs(src_data_array=self._obj, dst_nodata=dst_nodata)
|
|
472
502
|
# make sure dimensions with coordinates renamed to x,y
|
|
473
503
|
dst_dims: list[Hashable] = []
|
|
474
504
|
for dim in self._obj.dims:
|
|
@@ -486,7 +516,7 @@ class RasterArray(XRasterBase):
|
|
|
486
516
|
dst_affine=dst_affine,
|
|
487
517
|
dst_width=dst_width,
|
|
488
518
|
dst_height=dst_height,
|
|
489
|
-
force_generate=
|
|
519
|
+
force_generate=not use_affine,
|
|
490
520
|
),
|
|
491
521
|
dims=tuple(dst_dims),
|
|
492
522
|
attrs=new_attrs,
|
|
@@ -506,7 +536,7 @@ class RasterArray(XRasterBase):
|
|
|
506
536
|
dst_nodata = default_nodata if nodata is None else nodata
|
|
507
537
|
return dst_nodata
|
|
508
538
|
|
|
509
|
-
def _create_dst_data(self, dst_height: int, dst_width: int) -> numpy.ndarray:
|
|
539
|
+
def _create_dst_data(self, *, dst_height: int, dst_width: int) -> numpy.ndarray:
|
|
510
540
|
extra_dim = self._check_dimensions()
|
|
511
541
|
if extra_dim:
|
|
512
542
|
dst_data = numpy.zeros(
|
|
@@ -520,6 +550,7 @@ class RasterArray(XRasterBase):
|
|
|
520
550
|
def reproject_match(
|
|
521
551
|
self,
|
|
522
552
|
match_data_array: Union[xarray.DataArray, xarray.Dataset],
|
|
553
|
+
*,
|
|
523
554
|
resampling: Resampling = Resampling.nearest,
|
|
524
555
|
**reproject_kwargs,
|
|
525
556
|
) -> xarray.DataArray:
|
|
@@ -585,6 +616,7 @@ class RasterArray(XRasterBase):
|
|
|
585
616
|
miny: float,
|
|
586
617
|
maxx: float,
|
|
587
618
|
maxy: float,
|
|
619
|
+
*,
|
|
588
620
|
constant_values: Union[
|
|
589
621
|
float, tuple[int, int], Mapping[Any, tuple[int, int]], None
|
|
590
622
|
] = None,
|
|
@@ -664,6 +696,7 @@ class RasterArray(XRasterBase):
|
|
|
664
696
|
miny: float,
|
|
665
697
|
maxx: float,
|
|
666
698
|
maxy: float,
|
|
699
|
+
*,
|
|
667
700
|
constant_values: Union[
|
|
668
701
|
float, tuple[int, int], Mapping[Any, tuple[int, int]], None
|
|
669
702
|
] = None,
|
|
@@ -699,10 +732,16 @@ class RasterArray(XRasterBase):
|
|
|
699
732
|
pad_maxx = maxx + abs(resolution_x) / 2.0
|
|
700
733
|
pad_maxy = maxy + abs(resolution_y) / 2.0
|
|
701
734
|
|
|
702
|
-
pd_array = self.pad_xy(
|
|
735
|
+
pd_array = self.pad_xy(
|
|
736
|
+
minx=pad_minx,
|
|
737
|
+
miny=pad_miny,
|
|
738
|
+
maxx=pad_maxx,
|
|
739
|
+
maxy=pad_maxy,
|
|
740
|
+
constant_values=constant_values,
|
|
741
|
+
)
|
|
703
742
|
|
|
704
743
|
# make sure correct attributes preserved & projection added
|
|
705
|
-
_add_attrs_proj(pd_array, self._obj)
|
|
744
|
+
_add_attrs_proj(new_data_array=pd_array, src_data_array=self._obj)
|
|
706
745
|
|
|
707
746
|
return pd_array
|
|
708
747
|
|
|
@@ -712,6 +751,7 @@ class RasterArray(XRasterBase):
|
|
|
712
751
|
miny: float,
|
|
713
752
|
maxx: float,
|
|
714
753
|
maxy: float,
|
|
754
|
+
*,
|
|
715
755
|
auto_expand: Union[bool, int] = False,
|
|
716
756
|
auto_expand_limit: int = 3,
|
|
717
757
|
crs: Optional[Any] = None,
|
|
@@ -837,13 +877,14 @@ class RasterArray(XRasterBase):
|
|
|
837
877
|
)
|
|
838
878
|
|
|
839
879
|
# make sure correct attributes preserved & projection added
|
|
840
|
-
_add_attrs_proj(cl_array, self._obj)
|
|
880
|
+
_add_attrs_proj(new_data_array=cl_array, src_data_array=self._obj)
|
|
841
881
|
return cl_array
|
|
842
882
|
|
|
843
883
|
def clip(
|
|
844
884
|
self,
|
|
845
885
|
geometries: Iterable,
|
|
846
886
|
crs: Optional[Any] = None,
|
|
887
|
+
*,
|
|
847
888
|
all_touched: bool = False,
|
|
848
889
|
drop: bool = True,
|
|
849
890
|
invert: bool = False,
|
|
@@ -935,12 +976,15 @@ class RasterArray(XRasterBase):
|
|
|
935
976
|
)
|
|
936
977
|
|
|
937
978
|
# make sure correct attributes preserved & projection added
|
|
938
|
-
_add_attrs_proj(cropped_ds, self._obj)
|
|
979
|
+
_add_attrs_proj(new_data_array=cropped_ds, src_data_array=self._obj)
|
|
939
980
|
|
|
940
981
|
return cropped_ds
|
|
941
982
|
|
|
942
983
|
def _interpolate_na(
|
|
943
|
-
self,
|
|
984
|
+
self,
|
|
985
|
+
src_data: Any,
|
|
986
|
+
*,
|
|
987
|
+
method: Literal["linear", "nearest", "cubic"] = "nearest",
|
|
944
988
|
) -> numpy.ndarray:
|
|
945
989
|
"""
|
|
946
990
|
This method uses scipy.interpolate.griddata to interpolate missing data.
|
|
@@ -1020,12 +1064,13 @@ class RasterArray(XRasterBase):
|
|
|
1020
1064
|
interp_data = []
|
|
1021
1065
|
for _, sub_xds in self._obj.groupby(extra_dim):
|
|
1022
1066
|
interp_data.append(
|
|
1023
|
-
self._interpolate_na(
|
|
1067
|
+
self._interpolate_na(
|
|
1068
|
+
sub_xds.squeeze(dim=extra_dim).values, method=method
|
|
1069
|
+
)
|
|
1024
1070
|
)
|
|
1025
1071
|
interp_data = numpy.array(interp_data) # type: ignore
|
|
1026
1072
|
else:
|
|
1027
|
-
interp_data = self._interpolate_na(self._obj.
|
|
1028
|
-
|
|
1073
|
+
interp_data = self._interpolate_na(self._obj.values, method=method) # type: ignore
|
|
1029
1074
|
interp_array = xarray.DataArray(
|
|
1030
1075
|
name=self._obj.name,
|
|
1031
1076
|
data=interp_data,
|
|
@@ -1036,13 +1081,14 @@ class RasterArray(XRasterBase):
|
|
|
1036
1081
|
interp_array.encoding = self._obj.encoding
|
|
1037
1082
|
|
|
1038
1083
|
# make sure correct attributes preserved & projection added
|
|
1039
|
-
_add_attrs_proj(interp_array, self._obj)
|
|
1084
|
+
_add_attrs_proj(new_data_array=interp_array, src_data_array=self._obj)
|
|
1040
1085
|
|
|
1041
1086
|
return interp_array
|
|
1042
1087
|
|
|
1043
1088
|
def to_raster(
|
|
1044
1089
|
self,
|
|
1045
1090
|
raster_path: Union[str, os.PathLike],
|
|
1091
|
+
*,
|
|
1046
1092
|
driver: Optional[str] = None,
|
|
1047
1093
|
dtype: Optional[Union[str, numpy.dtype]] = None,
|
|
1048
1094
|
tags: Optional[dict[str, str]] = None,
|
|
@@ -58,6 +58,7 @@ class RasterDataset(XRasterBase):
|
|
|
58
58
|
def reproject(
|
|
59
59
|
self,
|
|
60
60
|
dst_crs: Any,
|
|
61
|
+
*,
|
|
61
62
|
resolution: Optional[Union[float, tuple[float, float]]] = None,
|
|
62
63
|
shape: Optional[tuple[int, int]] = None,
|
|
63
64
|
transform: Optional[Affine] = None,
|
|
@@ -116,7 +117,7 @@ class RasterDataset(XRasterBase):
|
|
|
116
117
|
resampled_dataset = xarray.Dataset(attrs=self._obj.attrs)
|
|
117
118
|
for var in self.vars:
|
|
118
119
|
try:
|
|
119
|
-
x_dim, y_dim = _get_spatial_dims(self._obj, var)
|
|
120
|
+
x_dim, y_dim = _get_spatial_dims(self._obj, var=var)
|
|
120
121
|
resampled_dataset[var] = (
|
|
121
122
|
self._obj[var]
|
|
122
123
|
.rio.set_spatial_dims(x_dim=x_dim, y_dim=y_dim, inplace=True)
|
|
@@ -141,6 +142,7 @@ class RasterDataset(XRasterBase):
|
|
|
141
142
|
def reproject_match(
|
|
142
143
|
self,
|
|
143
144
|
match_data_array: Union[xarray.DataArray, xarray.Dataset],
|
|
145
|
+
*,
|
|
144
146
|
resampling: Resampling = Resampling.nearest,
|
|
145
147
|
**reproject_kwargs,
|
|
146
148
|
) -> xarray.Dataset:
|
|
@@ -174,7 +176,7 @@ class RasterDataset(XRasterBase):
|
|
|
174
176
|
resampled_dataset = xarray.Dataset(attrs=self._obj.attrs)
|
|
175
177
|
for var in self.vars:
|
|
176
178
|
try:
|
|
177
|
-
x_dim, y_dim = _get_spatial_dims(self._obj, var)
|
|
179
|
+
x_dim, y_dim = _get_spatial_dims(self._obj, var=var)
|
|
178
180
|
resampled_dataset[var] = (
|
|
179
181
|
self._obj[var]
|
|
180
182
|
.rio.set_spatial_dims(x_dim=x_dim, y_dim=y_dim, inplace=True)
|
|
@@ -196,6 +198,7 @@ class RasterDataset(XRasterBase):
|
|
|
196
198
|
miny: float,
|
|
197
199
|
maxx: float,
|
|
198
200
|
maxy: float,
|
|
201
|
+
*,
|
|
199
202
|
constant_values: Union[
|
|
200
203
|
float, tuple[int, int], Mapping[Any, tuple[int, int]], None
|
|
201
204
|
] = None,
|
|
@@ -229,7 +232,7 @@ class RasterDataset(XRasterBase):
|
|
|
229
232
|
padded_dataset = xarray.Dataset(attrs=self._obj.attrs)
|
|
230
233
|
for var in self.vars:
|
|
231
234
|
try:
|
|
232
|
-
x_dim, y_dim = _get_spatial_dims(self._obj, var)
|
|
235
|
+
x_dim, y_dim = _get_spatial_dims(self._obj, var=var)
|
|
233
236
|
padded_dataset[var] = (
|
|
234
237
|
self._obj[var]
|
|
235
238
|
.rio.set_spatial_dims(x_dim=x_dim, y_dim=y_dim, inplace=True)
|
|
@@ -253,6 +256,7 @@ class RasterDataset(XRasterBase):
|
|
|
253
256
|
miny: float,
|
|
254
257
|
maxx: float,
|
|
255
258
|
maxy: float,
|
|
259
|
+
*,
|
|
256
260
|
auto_expand: Union[bool, int] = False,
|
|
257
261
|
auto_expand_limit: int = 3,
|
|
258
262
|
crs: Optional[Any] = None,
|
|
@@ -294,7 +298,7 @@ class RasterDataset(XRasterBase):
|
|
|
294
298
|
clipped_dataset = xarray.Dataset(attrs=self._obj.attrs)
|
|
295
299
|
for var in self.vars:
|
|
296
300
|
try:
|
|
297
|
-
x_dim, y_dim = _get_spatial_dims(self._obj, var)
|
|
301
|
+
x_dim, y_dim = _get_spatial_dims(self._obj, var=var)
|
|
298
302
|
clipped_dataset[var] = (
|
|
299
303
|
self._obj[var]
|
|
300
304
|
.rio.set_spatial_dims(x_dim=x_dim, y_dim=y_dim, inplace=True)
|
|
@@ -323,6 +327,7 @@ class RasterDataset(XRasterBase):
|
|
|
323
327
|
self,
|
|
324
328
|
geometries: Iterable,
|
|
325
329
|
crs: Optional[Any] = None,
|
|
330
|
+
*,
|
|
326
331
|
all_touched: bool = False,
|
|
327
332
|
drop: bool = True,
|
|
328
333
|
invert: bool = False,
|
|
@@ -383,7 +388,7 @@ class RasterDataset(XRasterBase):
|
|
|
383
388
|
clipped_dataset = xarray.Dataset(attrs=self._obj.attrs)
|
|
384
389
|
for var in self.vars:
|
|
385
390
|
try:
|
|
386
|
-
x_dim, y_dim = _get_spatial_dims(self._obj, var)
|
|
391
|
+
x_dim, y_dim = _get_spatial_dims(self._obj, var=var)
|
|
387
392
|
clipped_dataset[var] = (
|
|
388
393
|
self._obj[var]
|
|
389
394
|
.rio.set_spatial_dims(x_dim=x_dim, y_dim=y_dim, inplace=True)
|
|
@@ -429,7 +434,7 @@ class RasterDataset(XRasterBase):
|
|
|
429
434
|
interpolated_dataset = xarray.Dataset(attrs=self._obj.attrs)
|
|
430
435
|
for var in self.vars:
|
|
431
436
|
try:
|
|
432
|
-
x_dim, y_dim = _get_spatial_dims(self._obj, var)
|
|
437
|
+
x_dim, y_dim = _get_spatial_dims(self._obj, var=var)
|
|
433
438
|
interpolated_dataset[var] = (
|
|
434
439
|
self._obj[var]
|
|
435
440
|
.rio.set_spatial_dims(x_dim=x_dim, y_dim=y_dim, inplace=True)
|
|
@@ -448,6 +453,7 @@ class RasterDataset(XRasterBase):
|
|
|
448
453
|
def to_raster(
|
|
449
454
|
self,
|
|
450
455
|
raster_path: Union[str, os.PathLike],
|
|
456
|
+
*,
|
|
451
457
|
driver: Optional[str] = None,
|
|
452
458
|
dtype: Optional[Union[str, numpy.dtype]] = None,
|
|
453
459
|
tags: Optional[dict[str, str]] = None,
|
|
@@ -503,35 +509,58 @@ class RasterDataset(XRasterBase):
|
|
|
503
509
|
is True. Otherwise None is returned.
|
|
504
510
|
|
|
505
511
|
"""
|
|
512
|
+
# pylint: disable=too-many-locals
|
|
506
513
|
variable_dim = f"band_{uuid4()}"
|
|
507
514
|
data_array = self._obj.to_array(dim=variable_dim)
|
|
508
515
|
# ensure raster metadata preserved
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
516
|
+
attr_scales = []
|
|
517
|
+
attr_offsets = []
|
|
518
|
+
attr_nodatavals = []
|
|
519
|
+
encoded_scales = []
|
|
520
|
+
encoded_offsets = []
|
|
521
|
+
encoded_nodatavals = []
|
|
512
522
|
band_tags = []
|
|
513
523
|
long_name = []
|
|
514
524
|
for data_var in data_array[variable_dim].values:
|
|
515
|
-
|
|
516
|
-
|
|
525
|
+
try:
|
|
526
|
+
encoded_scales.append(self._obj[data_var].encoding["scale_factor"])
|
|
527
|
+
except KeyError:
|
|
528
|
+
attr_scales.append(self._obj[data_var].attrs.get("scale_factor", 1.0))
|
|
529
|
+
try:
|
|
530
|
+
encoded_offsets.append(self._obj[data_var].encoding["add_offset"])
|
|
531
|
+
except KeyError:
|
|
532
|
+
attr_offsets.append(self._obj[data_var].attrs.get("add_offset", 0.0))
|
|
517
533
|
long_name.append(self._obj[data_var].attrs.get("long_name", data_var))
|
|
518
|
-
|
|
534
|
+
if self._obj[data_var].rio.encoded_nodata is not None:
|
|
535
|
+
encoded_nodatavals.append(self._obj[data_var].rio.encoded_nodata)
|
|
536
|
+
else:
|
|
537
|
+
attr_nodatavals.append(self._obj[data_var].rio.nodata)
|
|
519
538
|
band_tags.append(self._obj[data_var].attrs.copy())
|
|
520
|
-
|
|
521
|
-
|
|
539
|
+
if encoded_scales:
|
|
540
|
+
data_array.encoding["scales"] = encoded_scales
|
|
541
|
+
else:
|
|
542
|
+
data_array.attrs["scales"] = attr_scales
|
|
543
|
+
if encoded_offsets:
|
|
544
|
+
data_array.encoding["offsets"] = encoded_offsets
|
|
545
|
+
else:
|
|
546
|
+
data_array.attrs["offsets"] = attr_offsets
|
|
522
547
|
data_array.attrs["band_tags"] = band_tags
|
|
523
548
|
data_array.attrs["long_name"] = long_name
|
|
524
549
|
|
|
550
|
+
use_encoded_nodatavals = bool(encoded_nodatavals)
|
|
551
|
+
nodatavals = encoded_nodatavals if use_encoded_nodatavals else attr_nodatavals
|
|
525
552
|
nodata = nodatavals[0]
|
|
526
553
|
if (
|
|
527
554
|
all(nodataval == nodata for nodataval in nodatavals)
|
|
528
555
|
or numpy.isnan(nodatavals).all()
|
|
529
556
|
):
|
|
530
|
-
data_array.rio.write_nodata(
|
|
557
|
+
data_array.rio.write_nodata(
|
|
558
|
+
nodata, inplace=True, encoded=use_encoded_nodatavals
|
|
559
|
+
)
|
|
531
560
|
else:
|
|
532
561
|
raise RioXarrayError(
|
|
533
562
|
"All nodata values must be the same when exporting to raster. "
|
|
534
|
-
f"Current values: {
|
|
563
|
+
f"Current values: {attr_nodatavals}"
|
|
535
564
|
)
|
|
536
565
|
if self.crs is not None:
|
|
537
566
|
data_array.rio.write_crs(self.crs, inplace=True)
|
|
@@ -32,7 +32,7 @@ except ImportError:
|
|
|
32
32
|
# Note: transform & crs are removed in write_transform/write_crs
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def _write_tags(raster_handle, tags):
|
|
35
|
+
def _write_tags(*, raster_handle, tags):
|
|
36
36
|
"""
|
|
37
37
|
Write tags to raster dataset
|
|
38
38
|
"""
|
|
@@ -63,7 +63,7 @@ def _write_tags(raster_handle, tags):
|
|
|
63
63
|
raster_handle.update_tags(iii + 1, **band_tag)
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def _write_band_description(raster_handle, xarray_dataset):
|
|
66
|
+
def _write_band_description(*, raster_handle, xarray_dataset):
|
|
67
67
|
"""
|
|
68
68
|
Write band descriptions using the long name
|
|
69
69
|
"""
|
|
@@ -83,7 +83,7 @@ def _write_band_description(raster_handle, xarray_dataset):
|
|
|
83
83
|
raster_handle.set_band_description(iii + 1, band_description)
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
def _write_metatata_to_raster(raster_handle, xarray_dataset, tags):
|
|
86
|
+
def _write_metatata_to_raster(*, raster_handle, xarray_dataset, tags):
|
|
87
87
|
"""
|
|
88
88
|
Write the metadata stored in the xarray object to raster metadata
|
|
89
89
|
"""
|
|
@@ -94,26 +94,29 @@ def _write_metatata_to_raster(raster_handle, xarray_dataset, tags):
|
|
|
94
94
|
)
|
|
95
95
|
|
|
96
96
|
# write scales and offsets
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
except KeyError:
|
|
97
|
+
scales = tags.get("scales", xarray_dataset.encoding.get("scales"))
|
|
98
|
+
if scales is None:
|
|
100
99
|
scale_factor = tags.get(
|
|
101
100
|
"scale_factor", xarray_dataset.encoding.get("scale_factor")
|
|
102
101
|
)
|
|
103
102
|
if scale_factor is not None:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
raster_handle.
|
|
107
|
-
|
|
103
|
+
scales = (scale_factor,) * raster_handle.count
|
|
104
|
+
if scales is not None:
|
|
105
|
+
raster_handle.scales = scales
|
|
106
|
+
|
|
107
|
+
offsets = tags.get("offsets", xarray_dataset.encoding.get("offsets"))
|
|
108
|
+
if offsets is None:
|
|
108
109
|
add_offset = tags.get("add_offset", xarray_dataset.encoding.get("add_offset"))
|
|
109
110
|
if add_offset is not None:
|
|
110
|
-
|
|
111
|
+
offsets = (add_offset,) * raster_handle.count
|
|
112
|
+
if offsets is not None:
|
|
113
|
+
raster_handle.offsets = offsets
|
|
111
114
|
|
|
112
115
|
_write_tags(raster_handle=raster_handle, tags=tags)
|
|
113
116
|
_write_band_description(raster_handle=raster_handle, xarray_dataset=xarray_dataset)
|
|
114
117
|
|
|
115
118
|
|
|
116
|
-
def _ensure_nodata_dtype(original_nodata, new_dtype):
|
|
119
|
+
def _ensure_nodata_dtype(*, original_nodata, new_dtype):
|
|
117
120
|
"""
|
|
118
121
|
Convert the nodata to the new datatype and raise warning
|
|
119
122
|
if the value of the nodata value changed.
|
|
@@ -141,7 +144,7 @@ def _ensure_nodata_dtype(original_nodata, new_dtype):
|
|
|
141
144
|
return nodata
|
|
142
145
|
|
|
143
146
|
|
|
144
|
-
def _get_dtypes(rasterio_dtype, encoded_rasterio_dtype, dataarray_dtype):
|
|
147
|
+
def _get_dtypes(*, rasterio_dtype, encoded_rasterio_dtype, dataarray_dtype):
|
|
145
148
|
"""
|
|
146
149
|
Determines the rasterio dtype and numpy dtypes based on
|
|
147
150
|
the rasterio dtype and the encoded rasterio dtype.
|
|
@@ -223,7 +226,7 @@ class RasterioWriter:
|
|
|
223
226
|
with rasterio.open(self.raster_path, "r+") as rds:
|
|
224
227
|
rds.write(item, window=Window(chx_off, chy_off, chx, chy), indexes=indexes)
|
|
225
228
|
|
|
226
|
-
def to_raster(self, xarray_dataarray, tags, windowed, lock, compute, **kwargs):
|
|
229
|
+
def to_raster(self, *, xarray_dataarray, tags, windowed, lock, compute, **kwargs):
|
|
227
230
|
"""
|
|
228
231
|
This method writes to the raster on disk.
|
|
229
232
|
|
|
@@ -252,9 +255,11 @@ class RasterioWriter:
|
|
|
252
255
|
"""
|
|
253
256
|
xarray_dataarray = xarray_dataarray.copy()
|
|
254
257
|
kwargs["dtype"], numpy_dtype = _get_dtypes(
|
|
255
|
-
kwargs["dtype"],
|
|
256
|
-
xarray_dataarray.encoding.get("rasterio_dtype"),
|
|
257
|
-
xarray_dataarray.encoding.get(
|
|
258
|
+
rasterio_dtype=kwargs["dtype"],
|
|
259
|
+
encoded_rasterio_dtype=xarray_dataarray.encoding.get("rasterio_dtype"),
|
|
260
|
+
dataarray_dtype=xarray_dataarray.encoding.get(
|
|
261
|
+
"dtype", str(xarray_dataarray.dtype)
|
|
262
|
+
),
|
|
258
263
|
)
|
|
259
264
|
# there is no equivalent for netCDF _Unsigned
|
|
260
265
|
# across output GDAL formats. It is safest to convert beforehand.
|
|
@@ -274,10 +279,14 @@ class RasterioWriter:
|
|
|
274
279
|
# Ensure dtype of output data matches the expected dtype.
|
|
275
280
|
# This check is added here as the dtype of the data is
|
|
276
281
|
# converted right before writing.
|
|
277
|
-
kwargs["nodata"] = _ensure_nodata_dtype(
|
|
282
|
+
kwargs["nodata"] = _ensure_nodata_dtype(
|
|
283
|
+
original_nodata=kwargs["nodata"], new_dtype=numpy_dtype
|
|
284
|
+
)
|
|
278
285
|
|
|
279
286
|
with rasterio.open(self.raster_path, "w", **kwargs) as rds:
|
|
280
|
-
_write_metatata_to_raster(
|
|
287
|
+
_write_metatata_to_raster(
|
|
288
|
+
raster_handle=rds, xarray_dataset=xarray_dataarray, tags=tags
|
|
289
|
+
)
|
|
281
290
|
if not (lock and is_dask_collection(xarray_dataarray.data)):
|
|
282
291
|
# write data to raster immmediately if not dask array
|
|
283
292
|
if windowed:
|
|
@@ -83,7 +83,7 @@ def _resolution(affine: Affine) -> tuple[float, float]:
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
def affine_to_coords(
|
|
86
|
-
affine: Affine, width: int, height: int, x_dim: str = "x", y_dim: str = "y"
|
|
86
|
+
affine: Affine, width: int, height: int, *, x_dim: str = "x", y_dim: str = "y"
|
|
87
87
|
) -> dict[str, numpy.ndarray]:
|
|
88
88
|
"""Generate 1d pixel centered coordinates from affine.
|
|
89
89
|
|
|
@@ -120,7 +120,7 @@ def affine_to_coords(
|
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
def _generate_spatial_coords(
|
|
123
|
-
affine: Affine, width: int, height: int
|
|
123
|
+
*, affine: Affine, width: int, height: int
|
|
124
124
|
) -> dict[Hashable, Any]:
|
|
125
125
|
"""get spatial coords in new transform"""
|
|
126
126
|
new_spatial_coords = affine_to_coords(affine, width, height)
|
|
@@ -162,6 +162,7 @@ def _get_nonspatial_coords(
|
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
def _make_coords(
|
|
165
|
+
*,
|
|
165
166
|
src_data_array: Union[xarray.DataArray, xarray.Dataset],
|
|
166
167
|
dst_affine: Affine,
|
|
167
168
|
dst_width: int,
|
|
@@ -178,7 +179,9 @@ def _make_coords(
|
|
|
178
179
|
)
|
|
179
180
|
or ("xc" in src_data_array.coords and "yc" in src_data_array.coords)
|
|
180
181
|
):
|
|
181
|
-
new_coords = _generate_spatial_coords(
|
|
182
|
+
new_coords = _generate_spatial_coords(
|
|
183
|
+
affine=dst_affine, width=dst_width, height=dst_height
|
|
184
|
+
)
|
|
182
185
|
new_coords.update(coords)
|
|
183
186
|
return new_coords
|
|
184
187
|
return coords
|
|
@@ -195,7 +198,7 @@ def _get_data_var_message(obj: Union[xarray.DataArray, xarray.Dataset]) -> str:
|
|
|
195
198
|
|
|
196
199
|
|
|
197
200
|
def _get_spatial_dims(
|
|
198
|
-
obj: Union[xarray.Dataset, xarray.DataArray], var: Union[Any, Hashable]
|
|
201
|
+
obj: Union[xarray.Dataset, xarray.DataArray], *, var: Union[Any, Hashable]
|
|
199
202
|
) -> tuple[str, str]:
|
|
200
203
|
"""
|
|
201
204
|
Retrieve the spatial dimensions of the dataset
|
|
@@ -213,20 +216,21 @@ def _get_spatial_dims(
|
|
|
213
216
|
|
|
214
217
|
|
|
215
218
|
def _has_spatial_dims(
|
|
216
|
-
obj: Union[xarray.Dataset, xarray.DataArray], var: Union[Any, Hashable]
|
|
219
|
+
obj: Union[xarray.Dataset, xarray.DataArray], *, var: Union[Any, Hashable]
|
|
217
220
|
) -> bool:
|
|
218
221
|
"""
|
|
219
222
|
Check to see if the variable in the Dataset has spatial dimensions
|
|
220
223
|
"""
|
|
221
224
|
try:
|
|
222
225
|
# pylint: disable=pointless-statement
|
|
223
|
-
_get_spatial_dims(obj, var)
|
|
226
|
+
_get_spatial_dims(obj, var=var)
|
|
224
227
|
except MissingSpatialDimensionError:
|
|
225
228
|
return False
|
|
226
229
|
return True
|
|
227
230
|
|
|
228
231
|
|
|
229
232
|
def _order_bounds(
|
|
233
|
+
*,
|
|
230
234
|
minx: float,
|
|
231
235
|
miny: float,
|
|
232
236
|
maxx: float,
|
|
@@ -425,7 +429,7 @@ class XRasterBase:
|
|
|
425
429
|
if hasattr(self._obj, "data_vars"):
|
|
426
430
|
grid_mappings = set()
|
|
427
431
|
for var in self._obj.data_vars:
|
|
428
|
-
if not _has_spatial_dims(self._obj, var):
|
|
432
|
+
if not _has_spatial_dims(self._obj, var=var):
|
|
429
433
|
continue
|
|
430
434
|
var_grid_mapping = self._obj[var].encoding.get(
|
|
431
435
|
"grid_mapping", self._obj[var].attrs.get("grid_mapping")
|
|
@@ -459,7 +463,7 @@ class XRasterBase:
|
|
|
459
463
|
if hasattr(data_obj, "data_vars"):
|
|
460
464
|
for var in data_obj.data_vars:
|
|
461
465
|
try:
|
|
462
|
-
x_dim, y_dim = _get_spatial_dims(data_obj, var)
|
|
466
|
+
x_dim, y_dim = _get_spatial_dims(data_obj, var=var)
|
|
463
467
|
except MissingSpatialDimensionError:
|
|
464
468
|
continue
|
|
465
469
|
# remove grid_mapping from attributes if it exists
|
|
@@ -1088,7 +1092,7 @@ class XRasterBase:
|
|
|
1088
1092
|
|
|
1089
1093
|
return left, bottom, right, top
|
|
1090
1094
|
|
|
1091
|
-
def bounds(self, recalc: bool = False) -> tuple[float, float, float, float]:
|
|
1095
|
+
def bounds(self, *, recalc: bool = False) -> tuple[float, float, float, float]:
|
|
1092
1096
|
"""
|
|
1093
1097
|
Parameters
|
|
1094
1098
|
----------
|
|
@@ -1101,13 +1105,19 @@ class XRasterBase:
|
|
|
1101
1105
|
left, bottom, right, top: float
|
|
1102
1106
|
Outermost coordinates of the `xarray.DataArray` | `xarray.Dataset`.
|
|
1103
1107
|
"""
|
|
1108
|
+
minx, miny, maxx, maxy = self._unordered_bounds(recalc=recalc)
|
|
1109
|
+
resolution_x, resolution_y = self.resolution(recalc=recalc)
|
|
1104
1110
|
return _order_bounds(
|
|
1105
|
-
|
|
1106
|
-
|
|
1111
|
+
minx=minx,
|
|
1112
|
+
miny=miny,
|
|
1113
|
+
maxx=maxx,
|
|
1114
|
+
maxy=maxy,
|
|
1115
|
+
resolution_x=resolution_x,
|
|
1116
|
+
resolution_y=resolution_y,
|
|
1107
1117
|
)
|
|
1108
1118
|
|
|
1109
1119
|
def isel_window(
|
|
1110
|
-
self, window: rasterio.windows.Window, pad: bool = False
|
|
1120
|
+
self, window: rasterio.windows.Window, *, pad: bool = False
|
|
1111
1121
|
) -> Union[xarray.Dataset, xarray.DataArray]:
|
|
1112
1122
|
"""
|
|
1113
1123
|
Use a rasterio.windows.Window to select a subset of the data.
|
|
@@ -1204,7 +1214,7 @@ class XRasterBase:
|
|
|
1204
1214
|
return subset
|
|
1205
1215
|
|
|
1206
1216
|
def transform_bounds(
|
|
1207
|
-
self, dst_crs: Any, densify_pts: int = 21, recalc: bool = False
|
|
1217
|
+
self, dst_crs: Any, *, densify_pts: int = 21, recalc: bool = False
|
|
1208
1218
|
) -> tuple[float, float, float, float]:
|
|
1209
1219
|
"""Transform bounds from src_crs to dst_crs.
|
|
1210
1220
|
|
|
@@ -1238,6 +1248,7 @@ class XRasterBase:
|
|
|
1238
1248
|
self,
|
|
1239
1249
|
gcps: Iterable[GroundControlPoint],
|
|
1240
1250
|
gcp_crs: Any,
|
|
1251
|
+
*,
|
|
1241
1252
|
grid_mapping_name: Optional[str] = None,
|
|
1242
1253
|
inplace: bool = False,
|
|
1243
1254
|
) -> Union[xarray.Dataset, xarray.DataArray]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: rioxarray
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.18.1
|
|
4
4
|
Summary: geospatial xarray extension powered by rasterio
|
|
5
5
|
Maintainer: rioxarray Contributors
|
|
6
6
|
License: Apache
|
|
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
23
|
Classifier: Programming Language :: Python :: 3
|
|
23
24
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
25
|
Classifier: Typing :: Typed
|
|
@@ -29,8 +30,8 @@ License-File: LICENSE_datacube
|
|
|
29
30
|
License-File: LICENSE_xarray
|
|
30
31
|
License-File: AUTHORS.rst
|
|
31
32
|
Requires-Dist: packaging
|
|
32
|
-
Requires-Dist: rasterio>=1.3
|
|
33
|
-
Requires-Dist: xarray>=
|
|
33
|
+
Requires-Dist: rasterio>=1.3.7
|
|
34
|
+
Requires-Dist: xarray>=2024.7.0
|
|
34
35
|
Requires-Dist: pyproj>=3.3
|
|
35
36
|
Requires-Dist: numpy>=1.23
|
|
36
37
|
Provides-Extra: interp
|
|
@@ -49,7 +50,7 @@ rasterio xarray extension.
|
|
|
49
50
|
:alt: Join the chat at https://gitter.im/rioxarray/community
|
|
50
51
|
:target: https://gitter.im/rioxarray/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
51
52
|
|
|
52
|
-
.. image:: https://img.shields.io/badge/all_contributors-
|
|
53
|
+
.. image:: https://img.shields.io/badge/all_contributors-39-orange.svg?style=flat-square
|
|
53
54
|
:alt: All Contributors
|
|
54
55
|
:target: https://github.com/corteva/rioxarray/blob/master/AUTHORS.rst
|
|
55
56
|
|
|
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
|