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

Fixes preserving ds/da attributes in the regrid2 module #468

Merged
merged 2 commits into from
May 22, 2023

Conversation

jasonb5
Copy link
Collaborator

@jasonb5 jasonb5 commented May 5, 2023

Description

Fixes preserving the DataArray attributes when regridding using the regrid2 module.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

If applicable:

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass with my changes (locally and CI/CD build)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have noted that this is a breaking change for a major release (fix or feature that would cause existing functionality to not work as expected)

@codecov-commenter
Copy link

codecov-commenter commented May 5, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (d86a116) 100.00% compared to head (cb48817) 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #468   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           14        14           
  Lines         1424      1424           
=========================================
  Hits          1424      1424           
Impacted Files Coverage Δ
xcdat/regridder/regrid2.py 100.00% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lee1043
Copy link
Collaborator

lee1043 commented May 9, 2023

@jasonb5 thank you for the PR. I confirm this resolves #445.

>>> import xcdat as xc
>>> ds = xc.open_dataset('/work/lee1043/cdat/pmp/E3SM/E3SMv3_evaluation/mean_climate/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
{'standard_name': 'precipitation_flux', 'long_name': 'Precipitation', 'comment': 'includes both liquid and solid phases', 'units': 'kg m-2 s-1', 'cell_methods': 'area: time: mean', 'cell_measures': 'area: areacella', 'operation': 'temporal_avg', 'mode': 'climatology', 'freq': 'month', 'weighted': 'True'}
>>> ds_regridded['pr'].units
'kg m-2 s-1'

@tomvothecoder tomvothecoder added type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. Priority: High labels May 10, 2023
@tomvothecoder tomvothecoder self-requested a review May 10, 2023 16:46
Copy link
Collaborator

@tomvothecoder tomvothecoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lee1043
Copy link
Collaborator

lee1043 commented May 19, 2023

Can we merge this?

@jasonb5 jasonb5 merged commit 0ba0cbd into xCDAT:main May 22, 2023
@jasonb5 jasonb5 deleted the fix_regrid2_da_attrs branch May 22, 2023 16:04
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
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Regrid does not preserve attributes
4 participants