Is "variable the same name as dimension is a coordinate" part of CF? #324
Replies: 6 comments 18 replies
-
It's recommended against, but not forbidden, so xarray is indeed making a bad assumption. Section 5, paragraph 4:
CF takes its definition of coordinate variables from the NetCDF Users Guide:
CF also says:
So under CF, if it corresponds to X, Y, Z, or T, a 1-D variable with the same name as a dimension must be a coordinate variable, and vice-versa. But that doesn't hold for other kinds of dimensions. If you have a string-valued dimension (such as "model") of type |
Beta Was this translation helpful? Give feedback.
-
I agree, great summary, Seth. Not impacting on the original question, I wondered about:
This comes from section 1.4, but I don't think that it's always true - one-dimensional spatial coordinate information for a discrete axis is represented by an auxiliary coordinate variable (e.g. as used by DSGs, UGRID, etc.). This text is as old as the hills, having been in CF since version 1.0, a long time before DSGs and the like. I'd be inclined just to delete that sentence, changing the short paragraph to the even shorter: There are two methods used to identify variables that contain coordinate data, they are either NUG-defined "coordinate variables", or else are identified by the coordinates attribute. There's probably a better way than this first thought, though! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the question and answer, @ChrisBarker-NOAA and @sethmcg. I agree that they would be useful to add to the FAQ. |
Beta Was this translation helpful? Give feedback.
-
Check the xarray docs about Coordinates: https://docs.xarray.dev/en/stable/user-guide/data-structures.html#coordinates and their note about differing terminology from CF. I don't think I've seen xarray deviate from what I would expect for most inputs, also note that xarray has its own internal data model that does not support everything a netCDF4 file can do. |
Beta Was this translation helpful? Give feedback.
-
@ChrisBarker-NOAA asked "My original question has been answered -- should I close the discussion? I'm not sure of the protocol for discussions, if this were an issue, I would close it ..." I asked the same in discussion 313! Any thoughts? I tend to feel we don't need to close discussions. |
Beta Was this translation helpful? Give feedback.
-
OK -- turns out I'm not done with the question :-) It turns out there's some complexity with coordinates and UGRID. For example, I'm looking right now at an output file from FVCOM, and it has (in part):
When I load this into xarray, I get these coordinates:
So time is correct -- it's a proper time coordinate. but So the question is -- is xarray making an incorrect assumption, or is this file non-compliant? |
Beta Was this translation helpful? Give feedback.
-
Question
In the xarray package, if a variable has the same name as a dimension, it is assumed to be a coordinate -- and xarray does a lot of special stuff with coordinates.
This works great for typical files: "time", "lat", "lon" and the like.
However, I'm finding a fair number of files in the wild where a variable with the same name as a dimension is not, in fact a coordinate. Or maybe it is, but a more complex one like a 2-D depth, or .....
(this comes up a lot in unstructured grids)
So: is xarray making an unreasonable assumption here? Or is that in fact a a part of CF, and I should complain to the providers about it?
Beta Was this translation helpful? Give feedback.
All reactions