rioxarray 0.15.4__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.
Files changed (30) hide show
  1. {rioxarray-0.15.4/rioxarray.egg-info → rioxarray-0.15.6}/PKG-INFO +1 -1
  2. {rioxarray-0.15.4 → rioxarray-0.15.6}/pyproject.toml +1 -1
  3. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/_io.py +19 -9
  4. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/merge.py +4 -17
  5. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/raster_writer.py +11 -9
  6. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/rioxarray.py +21 -8
  7. {rioxarray-0.15.4 → rioxarray-0.15.6/rioxarray.egg-info}/PKG-INFO +1 -1
  8. {rioxarray-0.15.4 → rioxarray-0.15.6}/AUTHORS.rst +0 -0
  9. {rioxarray-0.15.4 → rioxarray-0.15.6}/CONTRIBUTING.rst +0 -0
  10. {rioxarray-0.15.4 → rioxarray-0.15.6}/LICENSE +0 -0
  11. {rioxarray-0.15.4 → rioxarray-0.15.6}/LICENSE_datacube +0 -0
  12. {rioxarray-0.15.4 → rioxarray-0.15.6}/LICENSE_xarray +0 -0
  13. {rioxarray-0.15.4 → rioxarray-0.15.6}/MANIFEST.in +0 -0
  14. {rioxarray-0.15.4 → rioxarray-0.15.6}/README.rst +0 -0
  15. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/__init__.py +0 -0
  16. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/_options.py +0 -0
  17. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/_show_versions.py +0 -0
  18. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/crs.py +0 -0
  19. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/exceptions.py +0 -0
  20. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/py.typed +0 -0
  21. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/raster_array.py +0 -0
  22. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/raster_dataset.py +0 -0
  23. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray/xarray_plugin.py +0 -0
  24. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray.egg-info/SOURCES.txt +0 -0
  25. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray.egg-info/dependency_links.txt +0 -0
  26. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray.egg-info/entry_points.txt +0 -0
  27. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray.egg-info/requires.txt +0 -0
  28. {rioxarray-0.15.4 → rioxarray-0.15.6}/rioxarray.egg-info/top_level.txt +0 -0
  29. {rioxarray-0.15.4 → rioxarray-0.15.6}/setup.cfg +0 -0
  30. {rioxarray-0.15.4 → rioxarray-0.15.6}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rioxarray
3
- Version: 0.15.4
3
+ Version: 0.15.6
4
4
  Summary: geospatial xarray extension powered by rasterio
5
5
  Maintainer: rioxarray Contributors
6
6
  License: Apache
@@ -4,7 +4,7 @@ requires = ["setuptools", "wheel"]
4
4
 
5
5
  [project]
6
6
  name = "rioxarray"
7
- version = "0.15.4"
7
+ version = "0.15.6"
8
8
  description = "geospatial xarray extension powered by rasterio"
9
9
  maintainers = [
10
10
  {name = "rioxarray Contributors"},
@@ -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
- return self._riods.read(indexes=self._bidx + 1, **kwargs)
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
- token = tokenize(filename, mtime, chunks)
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 = functools.partial(
1084
- _single_band_open,
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(result, riods, filename, chunks)
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
- with memfile.open(
56
- driver="GTiff",
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's with all geo attributes.
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's with all geo attributes.
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
- if str(new_dtype).startswith("c"):
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
- nodata = numpy.dtype(new_dtype).type(original_nodata)
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
- warnings.warn(
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
@@ -141,8 +142,10 @@ def _get_nonspatial_coords(
141
142
  src_data_array.rio.x_dim,
142
143
  src_data_array.rio.y_dim,
143
144
  DEFAULT_GRID_MAP,
145
+ "xc",
146
+ "yc",
144
147
  }:
145
- if src_data_array[coord].dims:
148
+ if src_data_array[coord].ndim == 1:
146
149
  coords[coord] = xarray.IndexVariable(
147
150
  src_data_array[coord].dims,
148
151
  src_data_array[coord].values,
@@ -166,9 +169,13 @@ def _make_coords(
166
169
  ) -> dict[Hashable, Any]:
167
170
  """Generate the coordinates of the new projected `xarray.DataArray`"""
168
171
  coords = _get_nonspatial_coords(src_data_array)
169
- if force_generate or (
170
- src_data_array.rio.x_dim in src_data_array.coords
171
- and src_data_array.rio.y_dim in src_data_array.coords
172
+ if (
173
+ force_generate
174
+ or (
175
+ src_data_array.rio.x_dim in src_data_array.coords
176
+ and src_data_array.rio.y_dim in src_data_array.coords
177
+ )
178
+ or ("xc" in src_data_array.coords and "yc" in src_data_array.coords)
172
179
  ):
173
180
  new_coords = _generate_spatial_coords(dst_affine, dst_width, dst_height)
174
181
  new_coords.update(coords)
@@ -248,6 +255,7 @@ def _order_bounds(
248
255
  class XRasterBase:
249
256
  """This is the base class for the GIS extensions for xarray"""
250
257
 
258
+ # pylint: disable=too-many-instance-attributes
251
259
  def __init__(self, xarray_obj: Union[xarray.DataArray, xarray.Dataset]):
252
260
  self._obj: Union[xarray.DataArray, xarray.Dataset] = xarray_obj
253
261
 
@@ -283,6 +291,7 @@ class XRasterBase:
283
291
  self._height: Optional[int] = None
284
292
  self._width: Optional[int] = None
285
293
  self._crs: Union[rasterio.crs.CRS, None, Literal[False]] = None
294
+ self._gcps: Optional[list[GroundControlPoint]] = None
286
295
 
287
296
  @property
288
297
  def crs(self) -> Optional[rasterio.crs.CRS]:
@@ -341,6 +350,7 @@ class XRasterBase:
341
350
  obj_copy.rio._width = self._width
342
351
  obj_copy.rio._height = self._height
343
352
  obj_copy.rio._crs = self._crs
353
+ obj_copy.rio._gcps = self._gcps
344
354
  return obj_copy
345
355
 
346
356
  def set_crs(
@@ -1229,7 +1239,8 @@ class XRasterBase:
1229
1239
  gcp_crs, grid_mapping_name=grid_mapping_name, inplace=inplace
1230
1240
  )
1231
1241
  geojson_gcps = _convert_gcps_to_geojson(gcps)
1232
- 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)
1233
1244
  return data_obj
1234
1245
 
1235
1246
  def get_gcps(self) -> Optional[list[GroundControlPoint]]:
@@ -1243,8 +1254,10 @@ class XRasterBase:
1243
1254
  list of :obj:`rasterio.control.GroundControlPoint` or None
1244
1255
  The Ground Control Points from the dataset or None if not applicable
1245
1256
  """
1257
+ if self._gcps is not None:
1258
+ return self._gcps
1246
1259
  try:
1247
- geojson_gcps = self._obj.coords[self.grid_mapping].attrs["gcps"]
1260
+ geojson_gcps = json.loads(self._obj.coords[self.grid_mapping].attrs["gcps"])
1248
1261
  except (KeyError, AttributeError):
1249
1262
  return None
1250
1263
 
@@ -1261,8 +1274,8 @@ class XRasterBase:
1261
1274
  info=gcp["properties"]["info"],
1262
1275
  )
1263
1276
 
1264
- gcps = [_parse_gcp(gcp) for gcp in geojson_gcps["features"]]
1265
- return gcps
1277
+ self._gcps = [_parse_gcp(gcp) for gcp in geojson_gcps["features"]]
1278
+ return self._gcps
1266
1279
 
1267
1280
 
1268
1281
  def _convert_gcps_to_geojson(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rioxarray
3
- Version: 0.15.4
3
+ Version: 0.15.6
4
4
  Summary: geospatial xarray extension powered by rasterio
5
5
  Maintainer: rioxarray Contributors
6
6
  License: Apache
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