Open darribas opened 2 years ago
This is a helpful reference: https://corteva.github.io/rioxarray/stable/getting_started/nodata_management.html
I've issued a PR (#455 ) that I think should have a more comprehensive approach following @snowman2 suggestion from rioxarray
. If tests pass, I think it should be good to merge.
The
raster
functionality in for weights building currently supportsDataArray
objects created throughxarray.open_rasterio
:The code above correctly picks up that missing data are specified with -200 and removes them from the calculation of the weights:
This is not the case when we use
DataArray
objects build through the (generally recommended)rioxarray.open_rasterio
:which does not pick up the missing data:
My hunch is that this is because the builder picks up missing values only through the
attrs
object:https://github.com/pysal/libpysal/blob/0f03a313896de6af096ff92105e54da86bb78368/libpysal/weights/raster.py#L229-L233
But
rioxarray
does not populate that general object, instead logs missing data underpop2.rio.nodata
:I think we should support both formats, read through vanilla
xarray
and withrioxarray
loaded in the session too. The former is a more generic approach, the latter is a more robust one for rasters.Not sure what'd be the ideal way of supporting this. I'm cc'ing here @MgeeeeK since he worked on the original implementation and might have some ideas, and @snowman2 as the main driver behind
rioxarray
in case they have some suggestions in terms of best practices.