Hey folks,
I'm working through the basics of xarray at the moment. In the docs, there's an example like this:
import numpy
import pandas
import xarray
xx = xarray.DataArray(numpy.random.rand(4, 3), [
('time', pandas.date_range('2000-01-01', periods=4)),
('space', ['IA', 'IL', 'IN'])
]).to_dataset(name='foo')
And then the `xx` object is:
<xarray.Dataset>
Dimensions: (space: 3, time: 4)
Coordinates:
* time (time) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03 2000-01-04
* space (space) <U2 'IA' 'IL' 'IN'
Data variables:
foo (time, space) float64 0.3914 0.6567 0.8812 0.5413 0.7003 0.5879 ...
And I can select values based on the coordinates with:
xx.sel(time='2000-01-01', space=['IA', 'IN'])
And understandably get:
<xarray.Dataset>
Dimensions: (space: 2)
Coordinates:
time datetime64[ns] 2000-01-01
* space (space) <U2 'IA' 'IN'
Data variables:
foo (space) float64 0.3914 0.8812
Easy enough. So now I'm reading grib files (with a pynio engine) from
NOAA and trying to select from it (note the emphasized labels):
ds = xarray.open_dataset('data/p06m_2018052418f060.grb', engine='pynio')
<xarray.Dataset>
Dimensions: (g3_x_0: 138, g3_y_1: 180)
Coordinates:
g3_lat_0 (g3_x_0, g3_y_1) float32 ...
g3_lon_1 (g3_x_0, g3_y_1) float32 ...
Dimensions without coordinates: g3_x_0, g3_y_1
Data variables:
A_PCP_GDS3_SFC_acc6h (g3_x_0, g3_y_1) float32 ...
g3_rot_2 (g3_x_0, g3_y_1) float32 ...
And so trying to select the data in a similar fashion fails with a ValueError that I don't understand:
ds.sel(method='nearest', g3_lat_0=19.017)
~/miniconda3/envs/grb/lib/python3.6/site-packages/xarray/core/indexing.py in get_dim_indexers(data_obj, indexers)
203 if invalid:
204 raise ValueError("dimensions or multi-index levels %r do not exist"
--> 205 % invalid)
206
207 level_indexers = defaultdict(dict)
ValueError: dimensions or multi-index levels ['g3_lat_0'] do not exist
How can I access values in a dataset where the coordinate labels appear to be tuples?
Cheers,
-Paul