Skip to content

Commit

Permalink
Do not lose or mix variables when cfVarName or shortName are not uniq…
Browse files Browse the repository at this point in the history
…ue. Fixes #54.

(cherry picked from commit a8fc409)
  • Loading branch information
alexamici committed Feb 24, 2019
1 parent 321eda6 commit 6df2540
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
47 changes: 47 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ Data variables:
orog (y, x) float32 ...
tp (y, x) float32 ...
acpcp (y, x) float32 ...
csnow (y, x) float32 ...
cicep (y, x) float32 ...
cfrzr (y, x) float32 ...
crain (y, x) float32 ...
cape (y, x) float32 ...
cin (y, x) float32 ...
hpbl (y, x) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: kwbc
Expand Down Expand Up @@ -504,6 +511,46 @@ Attributes:
Conventions: CF-1.7
institution: US National Weather Service - NCEP...
history: ..., <xarray.Dataset>
Dimensions: (heightAboveGroundLayer: 2, x: 93, y: 65)
Coordinates:
time datetime64[ns] ...
step timedelta64[ns] ...
* heightAboveGroundLayer (heightAboveGroundLayer) int64 1000 3000
latitude (y, x) float64 ...
longitude (y, x) float64 ...
valid_time datetime64[ns] ...
Dimensions without coordinates: x, y
Data variables:
hlcy (heightAboveGroundLayer, y, x) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: kwbc
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP...
history: ..., <xarray.Dataset>
Dimensions: (x: 93, y: 65)
Coordinates:
time datetime64[ns] ...
step timedelta64[ns] ...
tropopause int64 ...
latitude (y, x) float64 ...
longitude (y, x) float64 ...
valid_time datetime64[ns] ...
Dimensions without coordinates: x, y
Data variables:
pres (y, x) float32 ...
t (y, x) float32 ...
u (y, x) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: kwbc
GRIB_centreDescription: US National Weather Service - NCEP...
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP...
history: ..., <xarray.Dataset>
Dimensions: (x: 93, y: 65)
Coordinates:
time datetime64[ns] ...
Expand Down
6 changes: 4 additions & 2 deletions cfgrib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,13 @@ def build_dataset_components(
):
filter_by_keys = dict(filter_by_keys)
index = stream.index(ALL_KEYS, indexpath=indexpath).subindex(filter_by_keys)
param_ids = index['paramId']
dimensions = collections.OrderedDict()
variables = collections.OrderedDict()
for param_id, short_name, var_name in zip(param_ids, index['shortName'], index['cfVarName']):
for param_id in index['paramId']:
var_index = index.subindex(paramId=param_id)
first = var_index.first()
short_name = first['shortName']
var_name = first['cfVarName']
try:
dims, data_var, coord_vars = build_variable_components(
var_index, encode_cf, filter_by_keys,
Expand Down

0 comments on commit 6df2540

Please sign in to comment.