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

forecast data with start (time) and lead (deltatime) dimensions does not plot #6930

Closed
4 tasks done
mktippett opened this issue Aug 18, 2022 · 3 comments
Closed
4 tasks done

Comments

@mktippett
Copy link

What happened?

Weather/climate data often uses two dimensions: Start time (when the initial time of the forecast integration) and Lead time (how long the forecast integration beyond the initial time). Also there is target time (the date being forecast) which is equal to start time + lead time.

It seems reasonable to use datetime for the S dimension and timedelta for the L dimension so that the target T is simply T = S + L. Using those types as dimensions seems to work until I try to plot.
image

What did you expect to happen?

A plot :-) which is what I get if I use the commented S & L in the MCVE
image

Minimal Complete Verifiable Example

import xarray as xr
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

L = pd.to_timedelta(np.array([1, 2]), unit='D')
S = pd.date_range(start='2022-01-01', periods=3, freq='D')
#L = np.array([1, 2])
#S = np.array([8, 9, 10])
coords = {'L': L, 'S': S}

data = xr.DataArray(np.random.randn(2, 3), dims=('L', 'S'), coords=coords)
T = data.S + data.L
data.coords['T'] = T

data.plot()

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 12:58:59)
[GCC Clang 10.0.0 ]
python-bits: 64
OS: Darwin
OS-release: 21.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.6.2

xarray: 0.18.0
pandas: 1.1.5
numpy: 1.19.2
scipy: 1.5.2
netCDF4: 1.5.1.2
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.11.1
cftime: 1.4.1
nc_time_axis: 1.2.0
PseudoNetCDF: None
rasterio: None
cfgrib: 0.9.8.5
iris: None
bottleneck: 1.3.2
dask: 2021.03.0
distributed: 2021.03.0
matplotlib: 3.3.4
cartopy: 0.18.0
seaborn: 0.11.1
numbagg: None
pint: None
setuptools: 52.0.0.post20210125
pip: 21.1.2
conda: None
pytest: 6.2.4
IPython: 7.16.1
sphinx: None

@mktippett mktippett added bug needs triage Issue that has not been reviewed by xarray team member labels Aug 18, 2022
@dcherian
Copy link
Contributor

Can you check whether matplotlib can plot these by default?

so does this work:

plt.pcolormesh(..., ..., ...)

@dcherian dcherian added topic-plotting and removed needs triage Issue that has not been reviewed by xarray team member labels Aug 18, 2022
@mktippett
Copy link
Author

Can you check whether matplotlib can plot these by default?

so does this work:

plt.pcolormesh(..., ..., ...)

Good point. Nope,

plt.pcolormesh(S, L, data.values)

fails .

@dcherian
Copy link
Contributor

Thanks closing as dupe of #2898.

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

No branches or pull requests

2 participants