Skip to content

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

Closed
@mktippett

Description

@mktippett

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions