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]: xr.DataArray.from_cdms2() deprecated in newer versions of xarray #1004

Closed
acordonez opened this issue Dec 12, 2023 · 1 comment · Fixed by #1006
Closed

[Bug]: xr.DataArray.from_cdms2() deprecated in newer versions of xarray #1004

acordonez opened this issue Dec 12, 2023 · 1 comment · Fixed by #1006

Comments

@acordonez
Copy link
Collaborator

What happened?

Running the precipitation variability metrics with xarray version > 2023.06.0 leads to a failure with the following message:

AttributeError: type object 'DataArray' has no attribute 'to_cdms2'

This is due to the following calls to 'to_cdms2' and 'from_cdms2':
https://github.com/acordonez/pcmdi_metrics/blob/variability_fixes/pcmdi_metrics/precip_variability/lib/lib_variability_across_timescales.py#L393
https://github.com/acordonez/pcmdi_metrics/blob/variability_fixes/pcmdi_metrics/precip_variability/lib/lib_variability_across_timescales.py#L395C12-L395C41

What did you expect to happen? Are there are possible answers you came across?

The driver should not fail here. The calls to 'to_cdms' and 'from_cdms' need to be removed, and ideally the call to cdutil to generate the land sea mask should also be removed.

Minimal Complete Verifiable Example (MVCE)

No response

Relevant log output

/home/ordonez4/miniconda3/envs/pmp_var/lib/python3.10/site-packages/pcmdi_metrics/precip_variability/lib/lib_variability_across_timescales.py:202: RuntimeWarning: Mean of empty slice
  clim = np.nanmean(dseg, axis=0)
Traceback (most recent call last):
  File "/home/ordonez4/git/pcmdi_metrics/pcmdi_metrics/precip_variability/variability_across_timescales_PS_driver.py", line 68, in <module>
    precip_variability_across_timescale(
  File "/home/ordonez4/miniconda3/envs/pmp_var/lib/python3.10/site-packages/pcmdi_metrics/precip_variability/lib/lib_variability_across_timescales.py", line 74, in precip_variability_across_timescale
    psdmfm_forced = Avg_PS_DomFrq(ps, freqs, ntd, dat, mip, "forced", regions_specs)
  File "/home/ordonez4/miniconda3/envs/pmp_var/lib/python3.10/site-packages/pcmdi_metrics/precip_variability/lib/lib_variability_across_timescales.py", line 393, in Avg_PS_DomFrq
    d_cdms = xr.DataArray.to_cdms2(d[0])
AttributeError: type object 'DataArray' has no attribute 'to_cdms2'

Anything else we need to know?

No response

Environment

xarray 2023.11.0 pyhd8ed1ab_0 conda-forge

I am using a dev version of PCMDI Metrics I believe this error will occur in any recent version.

@lee1043
Copy link
Contributor

lee1043 commented Dec 12, 2023

It looks like the cdms component is still remaining here only for land sea mask generation in this line.

As a part of ENSO code conversion I have made a land sea mask generation function using xarray, which could be applied here. I will work on it, thank you for reporting it!

@lee1043 lee1043 linked a pull request Dec 16, 2023 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants