cf-xarray icon indicating copy to clipboard operation
cf-xarray copied to clipboard

should guess_coord_axis optionally create a variable for unindexed coordinates

Open dcherian opened this issue 2 years ago • 1 comments

da = xr.DataArray(np.ones(2,3), dims=("x", "y"))

This kind of dataarray exists in CMIP datasets. x,y have absolutely no data (no values, no attrs) associated with them, and so guess_coord_axis does not do anything.

We could have .cf.guess_coord_axis(add_indexes=True) that effectively does

da["x"] = np.arange(da.sizes["x"])
da["y"] = np.arange(da.sizes["y"])

# now do the guessing

This will assign axis='X' and axis='Y' appropriately. I think this would be an OK opt-in feature, though we need a better name than add_indexes.

dcherian avatar Nov 18 '21 17:11 dcherian

I think such an option is a good idea to maximize the utility of cf-xarray for dealing with messy CMIP data. I suppose there needs to be a check of whether the index arrays exist already. Thanks for considering this!

sgyeager avatar Nov 18 '21 18:11 sgyeager