Skip to content

Commit

Permalink
Merge pull request #58 from ecmwf/issue54-filter
Browse files Browse the repository at this point in the history
Fix #54. Do not lose or mix variables when cfVarName or shortName are not unique
  • Loading branch information
alexamici authored Feb 24, 2019
2 parents 1855a10 + a8fc409 commit 5ec600a
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 @@ -386,6 +386,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 @@ -500,6 +507,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 @@ -436,11 +436,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, errors=errors,
Expand Down

0 comments on commit 5ec600a

Please sign in to comment.