How to use the rioxarray.exceptions.DimensionMissingCoordinateError function in rioxarray

To help you get started, we’ve selected a few rioxarray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github corteva / rioxarray / test / integration / test_integration_rioxarray.py View on Github external
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()
github corteva / rioxarray / test / integration / test_integration_rioxarray.py View on Github external
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()
github corteva / rioxarray / rioxarray / rioxarray.py View on Github external
"""
        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
        )
github corteva / rioxarray / rioxarray / rioxarray.py View on Github external
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
github corteva / rioxarray / rioxarray / rioxarray.py View on Github external
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