hydromt
hydromt copied to clipboard
Bug: open_raster with named variable
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
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?
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 could you check if the solution in #262 works for your data?
Indeed it works now!