Closed renskegelderloos closed 4 years ago
Thanks @renskegelderloos, for reporting this bug!
The easiest way for us to fix this if you provide a minimal example of your issue, i.e. a bit of code that shows this bug. If you want, you can also add e.g. a WeTransfer link to a location with a bit of data. Only if we have that can we recreate your bug and then hopefully quickly fix it!
Hi @renskegelderloos, sorry for the long delay in getting back on this. I think I have now fixed the problem you encountered, and made xarray integration much more robust, in a new Pull Request #716. Can you try running with that PR? Let me know if it works!
It looks like there may be a bug in how OceanParcels reads variables from an Xarray dataset. When reading a dataset that has a dimension time, no error shows up and I think it works well as long as 'time' is the first dimension in the Xarray dataset. However, when reading a dataset that has no time dimension (and presumable also if 'time' is not the first dimension), creating a FieldSet fails. The problem is a combination of how the variable 'data_filenames' is assigned in field.py:
data_filenames = variable
and that whether or not there is a time dimension is determined by the length of that variable:
if len(data_filenames) > 1 and 'time' not in dimensions and timestamps is None: raise RuntimeError('Multiple files given but no time dimension specified')
However, len(variable) just returns the size of the first dimension associated with the variable pulled from the Xarray dataset, which is unlikely to have length 1. A more straightforward way to check for a time dimension is just to see if 'time' is in ds['U'].dims