-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Raster.from_xarray()
to create raster from a xr.DataArray
#521
Conversation
@@ -1523,6 +1529,7 @@ def set_nodata( | |||
|
|||
# Update the nodata value | |||
self._nodata = new_nodata | |||
self.data.fill_value = new_nodata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This little addition was necessary to make raster_equal
(which checks fill_values are equal between raster's masked arrays) happy when set_nodata
is called!
Raster.from_xarray()
to convert from a Xarray.DataArray
Raster.from_xarray()
to create raster from a xr.DataArray
…dd convenience arguments to raster_equal()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice !
This PR adds
Raster.from_xarray()
to create a raster from an Xarray dataset (this loads the data, in the future will be able to cast functions directly on the Xarray object through #446).Correct the behaviour of
to_xarray()
which was not converting the data to floating when converting, and not masking nodata values (as default wasFalse
for reading mask inopen_rasterio()
), leading to unmasked nodata values for integer raster types. Now converts to floating by defaults to mask properly as NaNs (only way of masking with Xarray).Additionally, this function adds two new arguments to
Raster.raster_equal()
:strict_masked
andwarn_failure_reason
. The former allows to check for less strict equality regarding the mask (masked cells can have different underlying values, as those are never used anyway), and the latter is to raise an understandable error whenraster_equal()
assertions fail.We lose information when converting to an Xarray dataset with NaNs (masked values are transformed to NaNs and cannot be retrieved back when re-creating a raster), so we can only check equality with
strict_masked=False
.Resolves #519
Resolves #522