Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"regrid" drops dataset attributes #116

Closed
brews opened this issue Sep 14, 2021 · 8 comments · Fixed by #121
Closed

"regrid" drops dataset attributes #116

brews opened this issue Sep 14, 2021 · 8 comments · Fixed by #121
Labels
bug Something isn't working

Comments

@brews
Copy link
Member

brews commented Sep 14, 2021

Anytime we call dodola.core.xesmf_regrid, the output data is missing attributes from the input data. It would be great if we could keep — or merge — attrs from input data.

@brews
Copy link
Member Author

brews commented Sep 14, 2021

Using something like xr.set_options(keep_attrs=True) might get the behavior we need from xesmf. I'm not sure though. I'm not up to date on attrs behavior in xarray.

@dgergel
Copy link
Member

dgergel commented Sep 14, 2021

It looks like what we need is keep_attrs=True in the call to the xesmf regridder. The default is false for some reason.

e.g.

return regridder(x).astype(astype)
would be

if astype:
        return regridder(x, keep_attrs=True).astype(astype)
    return regridder(x)

@brews
Copy link
Member Author

brews commented Sep 15, 2021

@dgergel I think that's for the old xesmf from a few years back and not the pangeo-supported fork...?

Edit: My rough fix for getting attrs merged from ds to out_ds has been

out_ds.attrs |= ds.attrs
for k, v in ds.variables.items():
    if k in out_ds:
        out_ds[k].attrs |= v.attrs

@dgergel
Copy link
Member

dgergel commented Sep 15, 2021

@brews I took a look at the source code for the pangeo-supported fork of xesmf and it still has that keep_attrs=True option in applying the regridder (and the default is false), see here: https://github.com/pangeo-data/xESMF/blob/fa07fa6a7d382c8298261170e4e9df894d8f7cb6/xesmf/frontend.py#L382

@brews
Copy link
Member Author

brews commented Sep 15, 2021

@dgergel Huh! You're right! I'll see if that arg does the trick. Thanks.

@dgergel
Copy link
Member

dgergel commented Oct 20, 2021

@brews we fixed this, correct? So we can go ahead and close?

@brews
Copy link
Member Author

brews commented Oct 20, 2021

@dgergel good question. It's a bit of a stale issue but I say we should keep this open. Right now we have a hackish workaround. It works but I'd like to try the solution you recommend before we close this.

@dgergel
Copy link
Member

dgergel commented Oct 20, 2021

Got it - let's keep it open for now then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants