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]: xarray=2022.11.0 .plot() breaks with time coordinates represented by cftime #402

Closed
tomvothecoder opened this issue Jan 19, 2023 · 0 comments · Fixed by #408
Closed
Assignees
Labels
type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. type: devops Testing, CI/CD, systems configuration

Comments

@tomvothecoder
Copy link
Collaborator

tomvothecoder commented Jan 19, 2023

What happened?

xarray's .plot wrapper requires the nc-time-axis package to plot time coordinates represented by cftime objects.

If nc-time-axis does not exist, xarray throws the error:
ImportError: Plotting of arrays of cftime.datetime objects or arrays indexed by cftime.datetime objects requires the optional nc-time-axis (v1.2.0 or later) package.

UPDATE: It looks like installing nc-time-axis does not fix the problem. It produces this error now: TypeError: float() argument must be a string or a real number, not 'cftime._cftime.DatetimeProlepticGregorian'

I traced the error back to xarray=2022.11.0: pydata/xarray#7275. The nc_time_axis import in xarray was accidentally removed and has since been restored in subsequent versions.

What did you expect to happen?

Plotting should work fine like in previous versions of xarray.

Minimal Complete Verifiable Example

import xcdat as xc

filepath = "https://esgf-data1.llnl.gov/thredds/dodsC/css03_data/CMIP6/CMIP/CSIRO/ACCESS-ESM1-5/historical/r10i1p1f1/Amon/tas/gn/v20200605/tas_Amon_ACCESS-ESM1-5_historical_r10i1p1f1_gn_185001-201412.nc"

ds = xc.open_dataset(
    filepath,
    add_bounds=True,
    decode_times=True,
    center_times=True
)

# Unit adjustment from Kelvin to Celcius.
ds["tas"] = ds.tas - 273.15

ds_trop_avg = ds.spatial.average("tas", axis=["X","Y"], lat_bounds=(-25,25))

ds_trop_avg.tas.isel(time=slice(0, 100)).plot()

Relevant log output

No response

Anything else we need to know?

We need to update the xarray version in our conda environment yml files to the latest one.

Environment

xcdat=0.4.0

@tomvothecoder tomvothecoder added wontfix This will not be worked on type: bug Inconsistencies or issues which will cause an issue or problem for users or implementors. labels Jan 19, 2023
@tomvothecoder tomvothecoder changed the title [Bug]: Plotting time coordinates represented with cftime through xarray breaks without nc-time-axis. [Bug]: xarray=2022.11.0 .plot() breaks with time coordinates represented bycftime Jan 19, 2023
@tomvothecoder tomvothecoder changed the title [Bug]: xarray=2022.11.0 .plot() breaks with time coordinates represented bycftime [Bug]: xarray=2022.11.0 .plot() breaks with time coordinates represented by cftime Jan 19, 2023
@tomvothecoder tomvothecoder removed the wontfix This will not be worked on label Jan 19, 2023
@tomvothecoder tomvothecoder added the type: devops Testing, CI/CD, systems configuration label Jan 23, 2023
@tomvothecoder tomvothecoder self-assigned this Jan 23, 2023
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. type: devops Testing, CI/CD, systems configuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant