hydromt icon indicating copy to clipboard operation
hydromt copied to clipboard

Bug: open_raster with named variable

Open hboisgon opened this issue 2 years ago • 2 comments

With rioxarray open_dataset, default_name arg is only used in case the data to open does not have a variable name. If it does, the encoded varibable name is used. https://github.com/Deltares/hydromt/blob/3d83073e6232a8ce69e6a0918552ef9c2351faef/hydromt/io.py#L58

In hydromt we need to pass the default_name name in kwargs to rename the opened dataset before selection on data, else it will complain that "data" is not a variable in this dataset: https://github.com/Deltares/hydromt/blob/3d83073e6232a8ce69e6a0918552ef9c2351faef/hydromt/io.py#L63

hboisgon avatar Sep 29 '22 08:09 hboisgon

Can you provide a minimal example where this bug happens? When do raster files have variable names encoded?

We could use xr.open_dataarray instead of xr.open_dataset to get an array directly instead of the way it's scripted in L63?

DirkEilander avatar Sep 29 '22 12:09 DirkEilander

Yes I guess open_dataaaray would work as well but you would anyway in that case loose the name of the variable which you still may need for renaming later. My example is for a precipitation dataset which has one tif file per day and is extracted from a netcdf file so contains enough encoding to have a variable name for precipitation. I can send you an example if you want (not sure if I can share the data).

For the temperature files, I actually have the problem that the datarray has an extra dimension (height) so should return a dataset but seems this is something rioxarray cannot handle.

hboisgon avatar Oct 03 '22 05:10 hboisgon

@hboisgon could you check if the solution in #262 works for your data?

DirkEilander avatar Jan 21 '23 08:01 DirkEilander

Indeed it works now!

hboisgon avatar Jan 26 '23 05:01 hboisgon