Problem: If a dimension is renamed in cmip6_rename, the current code drops the coordinate entirely, losing the coordinate values.
Expected behaviour: The coordinate and dimension are both renamed.
See attached example for IPSL-CM6A-LR where old dimensions nvertex, olevel and axis_nbounds are renamed to vertex, lev and bnds but crucially deleted as coordinates. So now the returned dataset has no depth information for example.
Current relevent code is in the function
def _maybe_rename_dims(da, rdict):
for di in da.dims:
for target, candidates in rdict.items():
if di in candidates:
da = da.swap_dims({di: target})
if di in da.coords:
da = da.drop_vars(di)
return da
Where the final drop_vars is responsible. Can anyone explain the reason for this?
I have edited to have da = da.rename({di: target}).set_xindex(target) instead which seems to produce the desired result. Happy to make a pull request if there isn't a reason I'm missing for the current behaviour...
Thanks for this @emmomp. PR would be very welcome for this! I do not believe there was a particular reason for this other than the fact that I quickly threw this together during a hackathon many years ago 😆.
Problem: If a dimension is renamed in cmip6_rename, the current code drops the coordinate entirely, losing the coordinate values. Expected behaviour: The coordinate and dimension are both renamed.
See attached example for IPSL-CM6A-LR where old dimensions nvertex, olevel and axis_nbounds are renamed to vertex, lev and bnds but crucially deleted as coordinates. So now the returned dataset has no depth information for example.
Current relevent code is in the function
Where the final
drop_vars
is responsible. Can anyone explain the reason for this?I have edited to have
da = da.rename({di: target}).set_xindex(target)
instead which seems to produce the desired result. Happy to make a pull request if there isn't a reason I'm missing for the current behaviour...