Skip to content

Scalar coordinate inheritence between dataset and dataarray #6340

Answered by dcherian
rcaneill asked this question in Q&A
Discussion options

You must be logged in to vote

As you've found, xarray does not support this. cf_xarray, on the other hand, does parse the coordinates attribute

import cf_xarray
import xarray as xr

ds = xr.Dataset()
temp = xr.DataArray([[0, 1, 2], [3, 4, 5]], dims=("lat", "lon"))
sigma1 = xr.DataArray(
    [25.0], dims=("depth"), coords={"pref": 1000}, attrs={"coordinates": "pref"}
)

ds["temp"] = temp
ds["sigma1"] = sigma1

print(ds.cf["temp"].coords)
print(ds.cf["sigma1"].coords)
Coordinates:
    *empty*
Coordinates:
    pref     int64 1000

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rcaneill
Comment options

Answer selected by rcaneill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants