Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_missing_transform_bounds():
xds = rioxarray.open_rasterio(
os.path.join(TEST_COMPARE_DATA_DIR, "small_dem_3m_merged.tif"),
parse_coordinates=False,
)
xds.coords["spatial_ref"].attrs.pop("GeoTransform")
with pytest.raises(DimensionMissingCoordinateError):
xds.rio.bounds()
def test_missing_transform_resolution():
xds = rioxarray.open_rasterio(
os.path.join(TEST_COMPARE_DATA_DIR, "small_dem_3m_merged.tif"),
parse_coordinates=False,
)
xds.coords["spatial_ref"].attrs.pop("GeoTransform")
with pytest.raises(DimensionMissingCoordinateError):
xds.rio.resolution()
"""
Parameters
----------
recalc: bool, optional
If True, it will re-calculate the transform instead of using
the cached transform.
Returns
-------
:obj:`affine.Afffine`:
The affine of the :obj:`xarray.Dataset` | :obj:`xarray.DataArray`
"""
try:
src_left, _, _, src_top = self.bounds(recalc=recalc)
src_resolution_x, src_resolution_y = self.resolution(recalc=recalc)
except (DimensionMissingCoordinateError, DimensionError):
return Affine.identity()
return Affine.translation(src_left, src_top) * Affine.scale(
src_resolution_x, src_resolution_y
)
def _internal_bounds(self):
"""Determine the internal bounds of the `xarray.DataArray`"""
if self.x_dim not in self._obj.coords:
raise DimensionMissingCoordinateError(f"{self.x_dim} missing coordinates.")
elif self.y_dim not in self._obj.coords:
raise DimensionMissingCoordinateError(f"{self.y_dim} missing coordinates.")
try:
left = float(self._obj[self.x_dim][0])
right = float(self._obj[self.x_dim][-1])
top = float(self._obj[self.y_dim][0])
bottom = float(self._obj[self.y_dim][-1])
except IndexError:
raise NoDataInBounds(
"Unable to determine bounds from coordinates."
f"{_get_data_var_message(self._obj)}"
)
return left, bottom, right, top
def _internal_bounds(self):
"""Determine the internal bounds of the `xarray.DataArray`"""
if self.x_dim not in self._obj.coords:
raise DimensionMissingCoordinateError(f"{self.x_dim} missing coordinates.")
elif self.y_dim not in self._obj.coords:
raise DimensionMissingCoordinateError(f"{self.y_dim} missing coordinates.")
try:
left = float(self._obj[self.x_dim][0])
right = float(self._obj[self.x_dim][-1])
top = float(self._obj[self.y_dim][0])
bottom = float(self._obj[self.y_dim][-1])
except IndexError:
raise NoDataInBounds(
"Unable to determine bounds from coordinates."
f"{_get_data_var_message(self._obj)}"
)
return left, bottom, right, top