Parametric Vertical Coordinates¶
See also
cf_xarray
supports decoding parametric vertical coordinates encoded in the formula_terms
attribute using Dataset.cf.decode_vertical_coords()
.
Decoding parametric coordinates¶
from cf_xarray.datasets import romsds
romsds
<xarray.Dataset> Size: 1kB Dimensions: (s_rho: 30, ocean_time: 2) Coordinates: * s_rho (s_rho) float64 240B -0.9833 -0.95 -0.9167 ... -0.05 -0.01667 hc float64 8B 20.0 h float64 8B 603.9 Vtransform float64 8B 2.0 Cs_r (s_rho) float64 240B -0.933 -0.8092 ... -0.0005206 -5.758e-05 z_rho_dummy (ocean_time, s_rho) float64 480B 0.3486 0.01682 ... 0.8693 Dimensions without coordinates: ocean_time Data variables: zeta (ocean_time) float64 16B -0.1554 -0.1274 temp (ocean_time, s_rho) float64 480B 20.0 20.34 ... 29.66 30.0
Now we decode the vertical coordinates in-place. Note the new z_rho
variable. cf_xarray
sees that s_rho
has a formula_terms
attribute, looks up the right formula using s_rho.attrs["standard_name"]
and computes a new vertical coordinate variable.
romsds.cf.decode_vertical_coords(outnames={'s_rho': 'z_rho'}) # adds new z_rho variable
romsds.z_rho
<xarray.DataArray 'z_rho' ()> Size: 8B OceanSG2(s=<xarray.DataArray 's_rho' (s_rho: 30)> Size: 240B -0.9833 -0.95 -0... Coordinates: hc float64 8B 20.0 h float64 8B 603.9 Vtransform float64 8B 2.0 z_rho object 8B OceanSG2(s=<xarray.DataArray 's_rho' (s_rho: 30)> S...
Formula terms¶
To see whether decoding is possible, use the Dataset.cf.formula_terms
attribute
romsds.cf.formula_terms
{'s_rho': {'s': 's_rho',
'C': 'Cs_r',
'eta': 'zeta',
'depth': 'h',
'depth_c': 'hc'}}