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

[Bug]: Regrid does not preserve attributes #445

Closed
lee1043 opened this issue Apr 5, 2023 · 3 comments · Fixed by #468
Closed

[Bug]: Regrid does not preserve attributes #445

lee1043 opened this issue Apr 5, 2023 · 3 comments · Fixed by #468
Assignees
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@lee1043
Copy link
Collaborator

lee1043 commented Apr 5, 2023

What happened?

After ds.regridder.horizontal process, attributions (e.g., units) are not preserved.

What did you expect to happen?

To be preserved.

Minimal Complete Verifiable Example

>>> ds = xc.open_dataset('/work/lee1043/cdat/pmp/E3SM/E3SMv3_evaluation/mean_climate/clim/clim/cmip6.historical.E3SMv3.r1i1p1f1.mon.pr.198101-200512.AC.v20230404.nc')
>>> ds['pr'].units
'kg m-2 s-1'
>>> t_grid = xc.create_uniform_grid(-88.875, 88.625, 2.5, 0, 357.5, 2.5)
>>> varname = 'pr'
>>> ds_regridded = ds.regridder.horizontal(varname, t_grid, tool='regrid2')
>>> ds_regridded[varname].attrs
{}
>>> ds_regridded['pr'].units
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lee1043/.conda/envs/pcmdi_metrics_dev_20230201/lib/python3.9/site-packages/xarray/core/common.py", line 278, in __getattr__
    raise AttributeError(
AttributeError: 'DataArray' object has no attribute 'units'


### Relevant log output

_No response_

### Anything else we need to know?

_No response_

### Environment

xCDAT 0.5.0
@lee1043 lee1043 added the type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Apr 5, 2023
@jasonb5
Copy link
Collaborator

jasonb5 commented May 4, 2023

@lee1043 If possible could you provide a link to the source file?

@lee1043
Copy link
Collaborator Author

lee1043 commented May 4, 2023

@jasonb5 Thank you for taking this a look. I noticed the directory path slightly changed since then. Would you be able to access below file from the gates? Otherwise I will email or upload it.

/work/lee1043/cdat/pmp/E3SM/E3SMv3_evaluation/mean_climate/clim/cmip6.historical.E3SMv3.r1i1p1f1.mon.pr.198101-200512.AC.v20230404.nc

@jasonb5
Copy link
Collaborator

jasonb5 commented May 4, 2023

Found the issue, will have a PR soon. Regrid2 is creating the dataarray from scratch and not copying the attributes from the source dataarray, we do copy the dataset attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants