lutraconsulting / MDAL

Mesh Data Abstraction Library
http://www.mdal.xyz/
MIT License
160 stars 50 forks source link

UGRID reader does not support time coordinates as integers #348

Open JoerivanEngelen opened 3 years ago

JoerivanEngelen commented 3 years ago

Hi,

We encountered an issue in the UGRID reader when the time coordinates are encoded as integers instead of doubles. It seems like the UGRID reader expects time to be encoded as doubles.

I have attached two small examples, one with time encoded as integers, one with doubles. For the version with integers, running mdalinfo throws a ERROR: Status 3: Driver: Ugrid: Could not read double array. MDAL then falls back to interpreting the file as a regular NetCDF. For the version with time as doubles, there are no problems.

mdal_time_dtype.zip

To my understanding, the UGRID conventions have no specifications for data types of time, so the CF conventions apply here. For which I can only find here

Data variables must be one of the following data types: string, char, byte, unsigned byte, short, unsigned short, int, unsigned int, int64, unsigned int64, float or real, and double

So I guess assuming the time coordinate is specified as doubles will result in issues for the naive user. For example, at our department, we use the python package xarray a lot, which encodes CF time coordinates by default as integers.

visr commented 2 years ago

The same ERROR: Status 3: Driver: Ugrid: Could not read double array also pops up in files without time coordinates. For instance, if I have a vector of type int with one element for every node.

The error disappears when converting the vector to floats. That suggests to me this is the same issue, and the problem isn't time specific.