xarray-contrib/cf-xarray

On vertical vs Z

Closed this issue · 5 comments

Also I realize that the vertical Axes and Coords are not what I was expecting but my eyes glossed over them earlier.

image

Probably s_rho should be the Axes Z (and I am setting this in xroms for this to appear here). But then the associated coord should be z_rho, in analogy to the relationship between xi_rho and lon_rho. Is there an adjustment I can make so that z_rho will become linked as a coord to s_rho in DataArrays?

Originally posted by @kthyng in #82 (comment)

I would add z_rho to the coordinates attribute of ds.temp and others to make the link explicit.


But the fundamental issue here is that Z and vertical are synonyms. One way to solve this would be to

  1. Have vertical not match axis: Z.
  2. Delete the positive: up attribute from s_rho (i don't like this but don't see an alternative)
  3. then ds.cf["Z"] will give you s_rho and ds.cf["vertical"] will give you z_rho.

cc @jthielen; for this model s_rho is a non-dimensional 1D vertical coordinate and z_rho is a 4D parameterized vertical coordinate; and this issue is about making it easy for users to pull out one or the other based on attributes using either Z or vertical. This is messy because positive is set on s_rho (which makes sense but is inconvenient).

image

What are your thoughts making Z and vertical not synonyms (similar to X vs longitude)?

  • Z would match axis and maybe formula_terms and/or appropriate standard_name for parameterized vertical coordinates (looks like the standard names for meteorological variables are already in the criteria).
  • vertical would match positive and standard_names like height, depth etc.

From a quick look at http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#vertical-coordinate I don't see how else to distinguish between Z and vertical (it isn't obvious that the conventions distinguish between the two)

Maybe @rsignell-usgs also has thoughts here?

Thank you, you explained my issue clearly. In the meantime I'll try your suggestion to add coordinate attributes, I haven't used those.

EDIT: I added this ds['temp'].attrs['coordinates'] = 'lon_rho lat_rho z_rho ocean_time' and ds.temp.cf.describe() still does not recognize z_rho as coordinates.

ah yes. Now that it is in coordinates, cf_xarray will look at the z_rho variable but not find any attrs matching the criteria for vertical. I would set positive: up on z_rho.

cc @jthielen; for this model s_rho is a non-dimensional 1D vertical coordinate and z_rho is a 4D parameterized vertical coordinate; and this issue is about making it easy for users to pull out one or the other based on attributes using either Z or vertical. This is messy because positive is set on s_rho (which makes sense but is inconvenient).

...

What are your thoughts making Z and vertical not synonyms (similar to X vs longitude)?

* `Z` would match `axis` and maybe `formula_terms` and/or appropriate `standard_name` for parameterized vertical coordinates (looks like the standard names for meteorological variables are already in the criteria).

* `vertical` would match `positive` and `standard_name`s like `height`, `depth` etc.

Sounds like a good idea! Both s_rho and z_rho are vertical coordinates, with s_rho being the axis-like coordinate and z_rho being the full/physical coordinate, which, as you said, is analogous to a grid_x versus longitude situation (where grid_x is the axis-like coordinate and longitude is the full/physical coordinate). So, having the distinction between Z and vertical makes sense.

With that in mind, would this be a correct/useful perspective, perhaps worth adding to the docs?

  • Z, Y, and X identify axis-like coordinates (typically 1D dimension coordinates)
  • vertical, latitude, and longitude identify physical (fully-expanded) coordinates (typically non-dimension/auxiliary coordinates, unless on a particular grid type where they are 1D/dimension coordinates)

With that in mind, would this be a correct/useful perspective, perhaps worth adding to the docs?

@kthyng is advocating for this. I also think it makes sense.

My only concern is that this isn't explicitly the intent of the conventions AFAICT but we should do what's useful...