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

Require nc-time-axis (?) #123

Closed
marc-white opened this issue Nov 27, 2024 · 2 comments · Fixed by #125
Closed

Require nc-time-axis (?) #123

marc-white opened this issue Nov 27, 2024 · 2 comments · Fixed by #125

Comments

@marc-white
Copy link

I'm trying to update the quickstart notebooks in the access-nri-intake-catalog documentation (here), and I'm hitting this problem:

colors = {
    "01deg_jra55v13_ryf9091": "C0",
    "025deg_jra55_iaf_omip2": "C1",
    "025deg_jra55_ryf9091_gadi": "C2",
    "1deg_jra55_iaf_omip2": "C3",
    "1deg_jra55_iaf_omip2spunup": "C4",
    "1deg_jra55_ryf9091_gadi": "C5",
}

for idx, name in enumerate(sorted(esm_datastore_dict2.keys())):
    label = name.split("_cycle")[0]
    data = esm_datastore_dict2[name].to_dask(
        progressbar=False, xarray_open_kwargs=dict(use_cftime=True),
    )
    data["temp_global_ave"].plot(color=colors[label], label=label)

plt.title("")
plt.grid()

# Remove duplicates in legend
handles, labels = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels, handles))
plt.legend(by_label.values(), by_label.keys())


{
	"name": "ImportError",
	"message": "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.",
	"stack": "---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[46], line 15
     11     label = name.split(\"_cycle\")[0]
     12     data = esm_datastore_dict2[name].to_dask(
     13         progressbar=False, xarray_open_kwargs=dict(use_cftime=True),
     14     )
---> 15     data[\"temp_global_ave\"].plot(color=colors[label], label=label)
     17 plt.title(\"\")
     18 plt.grid()

File /g/data/xp65/public/apps/med_conda/envs/access-med-0.9/lib/python3.10/site-packages/xarray/plot/accessor.py:48, in DataArrayPlotAccessor.__call__(self, **kwargs)
     46 @functools.wraps(dataarray_plot.plot, assigned=(\"__doc__\", \"__annotations__\"))
     47 def __call__(self, **kwargs) -> Any:
---> 48     return dataarray_plot.plot(self._da, **kwargs)

File /g/data/xp65/public/apps/med_conda/envs/access-med-0.9/lib/python3.10/site-packages/xarray/plot/dataarray_plot.py:309, in plot(darray, row, col, col_wrap, ax, hue, subplot_kws, **kwargs)
    305     plotfunc = hist
    307 kwargs[\"ax\"] = ax
--> 309 return plotfunc(darray, **kwargs)

File /g/data/xp65/public/apps/med_conda/envs/access-med-0.9/lib/python3.10/site-packages/xarray/plot/dataarray_plot.py:509, in line(darray, row, col, figsize, aspect, size, ax, hue, x, y, xincrease, yincrease, xscale, yscale, xticks, yticks, xlim, ylim, add_legend, _labels, *args, **kwargs)
    506 xlabel = label_from_attrs(xplt, extra=x_suffix)
    507 ylabel = label_from_attrs(yplt, extra=y_suffix)
--> 509 _ensure_plottable(xplt_val, yplt_val)
    511 primitive = ax.plot(xplt_val, yplt_val, *args, **kwargs)
    513 if _labels:

File /g/data/xp65/public/apps/med_conda/envs/access-med-0.9/lib/python3.10/site-packages/xarray/plot/utils.py:698, in _ensure_plottable(*args)
    696     import nc_time_axis  # noqa: F401
    697 else:
--> 698     raise ImportError(
    699         \"Plotting of arrays of cftime.datetime \"
    700         \"objects or arrays indexed by \"
    701         \"cftime.datetime objects requires the \"
    702         \"optional `nc-time-axis` (v1.2.0 or later) \"
    703         \"package.\"
    704     )

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."
}

I presume this means we now need to include nc-time-axis in the environment?

@marc-white
Copy link
Author

marc-white commented Nov 27, 2024

Should have mentioned, using access-med-0.9. It looks like the package is already included in the analysis3 environment.

@charles-turner-1
Copy link

I think this can be resolved by updating the xarray dependency to xarray[viz] or xarray[complete] (see xarray installation docs).

So we would just need to update this line in environments/access-med/environments.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants