You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like NaNs are not masked when using Raster.to_xarray(). The Raster object contains the nodata attribute which is set via Raster.to_rio_dataset(), so not sure what the issue is and if that if that is a common issue, or only happens in my case.
I solved this by manually masking NaN values slope_xr.where(slope_xr != slope_xr.rio.nodata).
%matplotlibinlineimportpdemtoolsimportxdemfromgeoutilsimportRasterfrompyprojimportCRSimportmatplotlib.pyplotasplt# download some ArcticDEM data bounds= (-2789094.0, 708249.0, -2789044.0, 708299.0)
dem=pdemtools.load.mosaic(
dataset='arcticdem',
resolution=2,
bounds=bounds,
version='v4.1'
)
# Xarray to Rastercrs=CRS.from_wkt(dem['spatial_ref'].attrs['crs_wkt'])
epsg=crs.to_epsg()
affine=dem.rio.transform()
raster=Raster.from_array(
data=dem.data,
crs=epsg,
transform=affine,
nodata=-9999.# set nodata value
)
# Raster to xDEM x_dem=xdem.DEM(raster)
print(type(x_dem))
print(x_dem.nodata)
# Compute terrain parameterslope=xdem.terrain.slope(x_dem)
# Convert back to Xarrayslope_xr=slope.to_xarray()
print(slope_xr.data[0,:3,:3])
This code outputs:
The text was updated successfully, but these errors were encountered:
Thanks @geograFie, I also noticed this behaviour yesterday when adding the from_xarray() function to solve #519. Both are now fixed in #521 with more tests, awaiting peer-review before merging and making a new release. 😉
It seems like NaNs are not masked when using
Raster.to_xarray()
. TheRaster
object contains thenodata
attribute which is set viaRaster.to_rio_dataset()
, so not sure what the issue is and if that if that is a common issue, or only happens in my case.I solved this by manually masking NaN values
slope_xr.where(slope_xr != slope_xr.rio.nodata)
.This code outputs:
The text was updated successfully, but these errors were encountered: