xcdat.get_dim_coords#
- xcdat.get_dim_coords(obj, axis, multidim=False)[source]#
Gets the dimension coordinates for an axis.
This function uses
cf_xarrayto attempt to map the axis to its dimension coordinates by interpreting the CF axis and coordinate names found in the coordinate attributes. Refer to [1] for a list of CF axis and coordinate names that can be interpreted bycf_xarray.If
objis anxr.Dataset,, this function can return a single dimension coordinate variable as anxr.DataArrayor multiple dimension coordinate variables in anxr Dataset. Ifobjis anxr.DataArray, this function should return a single dimension coordinate variable as anxr.DataArray.- Parameters:
obj (
xr.Dataset | xr.DataArray) – The Dataset or DataArray object.axis (
CFAxisKey) – The CF axis key (“X”, “Y”, “T”, “Z”).multidim (
bool) – If True, also consider non-index coordinates, including multidimensional coordinates. Scalar coordinates are excluded. Defaults to False.
- Returns:
xr.Dataset | xr.DataArray– A Dataset of dimension coordinate variables or a DataArray for the single dimension coordinate variable.- Raises:
ValueError – If the
objis anxr.DataArrayand more than one dimension is mapped to the same axis.KeyError – If no dimension coordinate variables were found for the
axis.
Notes
Coordinates are identified using CF metadata or recognized common names. Multidimensional coordinates are ignored unless
multidim=True. In multidimensional mode, CF coordinate mappings take precedence over axis-only mappings and common names (e.g., 2D latitude over a grid index). If no CF coordinate mapping exists for a horizontal axis, recognized latitude/longitude names take precedence over axis-only mappings.References