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_spatial_dimensions():
test_ds = xarray.Dataset()
with pytest.raises(DimensionError):
test_ds.rio.shape
with pytest.raises(DimensionError):
test_ds.rio.width
with pytest.raises(DimensionError):
test_ds.rio.height
test_da = xarray.DataArray(1)
with pytest.raises(DimensionError):
test_da.rio.shape
with pytest.raises(DimensionError):
test_da.rio.width
with pytest.raises(DimensionError):
test_da.rio.height
def test_missing_spatial_dimensions():
test_ds = xarray.Dataset()
with pytest.raises(DimensionError):
test_ds.rio.shape
with pytest.raises(DimensionError):
test_ds.rio.width
with pytest.raises(DimensionError):
test_ds.rio.height
test_da = xarray.DataArray(1)
with pytest.raises(DimensionError):
test_da.rio.shape
with pytest.raises(DimensionError):
test_da.rio.width
with pytest.raises(DimensionError):
test_da.rio.height
def set_dims(obj, in_x_dim, in_y_dim):
if in_x_dim in obj.dims:
obj.rio._x_dim = x_dim
else:
raise DimensionError(
f"x dimension ({x_dim}) not found.{_get_data_var_message(obj)}"
)
if y_dim in obj.dims:
obj.rio._y_dim = y_dim
else:
raise DimensionError(
f"y dimension ({x_dim}) not found.{_get_data_var_message(obj)}"
)
"""This is the base exception for errors in the rioxarray extension."""
class NoDataInBounds(RioXarrayError):
"""This is for when there are no data in the bounds for clipping a raster."""
class SingleVariableDataset(RioXarrayError):
"""This is for when you have a dataset with a single variable."""
class DimensionError(RioXarrayError):
"""This is raised when there are more dimensions than is supported by the method"""
class TooManyDimensions(DimensionError):
"""This is raised when there are more dimensions than is supported by the method"""
class InvalidDimensionOrder(DimensionError):
"""This is raised when there the dimensions are not ordered correctly."""
class OneDimensionalRaster(DimensionError):
"""This is an error when you have a 1 dimensional raster."""
class DimensionMissingCoordinateError(RioXarrayError):
"""This is raised when the dimension does not have the supporting coordinate."""
class MissingCRS(RioXarrayError):
"""This is for when there are no data in the bounds for clipping a raster."""
class SingleVariableDataset(RioXarrayError):
"""This is for when you have a dataset with a single variable."""
class DimensionError(RioXarrayError):
"""This is raised when there are more dimensions than is supported by the method"""
class TooManyDimensions(DimensionError):
"""This is raised when there are more dimensions than is supported by the method"""
class InvalidDimensionOrder(DimensionError):
"""This is raised when there the dimensions are not ordered correctly."""
class OneDimensionalRaster(DimensionError):
"""This is an error when you have a 1 dimensional raster."""
class DimensionMissingCoordinateError(RioXarrayError):
"""This is raised when the dimension does not have the supporting coordinate."""
class MissingCRS(RioXarrayError):
"""Missing the CRS in the dataset."""
def set_dims(obj, in_x_dim, in_y_dim):
if in_x_dim in obj.dims:
obj.rio._x_dim = x_dim
else:
raise DimensionError(
f"x dimension ({x_dim}) not found.{_get_data_var_message(obj)}"
)
if y_dim in obj.dims:
obj.rio._y_dim = y_dim
else:
raise DimensionError(
f"y dimension ({x_dim}) not found.{_get_data_var_message(obj)}"
)
"""This is for when you have a dataset with a single variable."""
class DimensionError(RioXarrayError):
"""This is raised when there are more dimensions than is supported by the method"""
class TooManyDimensions(DimensionError):
"""This is raised when there are more dimensions than is supported by the method"""
class InvalidDimensionOrder(DimensionError):
"""This is raised when there the dimensions are not ordered correctly."""
class OneDimensionalRaster(DimensionError):
"""This is an error when you have a 1 dimensional raster."""
class DimensionMissingCoordinateError(RioXarrayError):
"""This is raised when the dimension does not have the supporting coordinate."""
class MissingCRS(RioXarrayError):
"""Missing the CRS in the dataset."""
def x_dim(self):
"""str: The dimension for the X-axis."""
if self._x_dim is not None:
return self._x_dim
raise DimensionError(
"x dimension not found. 'set_spatial_dims()' can address this."
f"{_get_data_var_message(self._obj)}"
def y_dim(self):
"""str: The dimension for the Y-axis."""
if self._y_dim is not None:
return self._y_dim
raise DimensionError(
"x dimension not found. 'set_spatial_dims()' can address this."
f"{_get_data_var_message(self._obj)}"