Skip to content

Commit

Permalink
Work around a random-bug in Python 3.5. See the comment for details.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamici committed Nov 8, 2018
1 parent 66d5376 commit f164f0d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cfgrib/xarray_to_grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
'polar_stereographic', 'reduced_gg', 'reduced_ll', 'regular_gg', 'regular_ll', 'rotated_gg',
'rotated_ll', 'sh',
]
MESSAGE_DEFINITION_KEYS = [
# for the GRIB 2 sample we must set this before setting 'totalNumber'
'productDefinitionTemplateNumber',
# NO IDEA WHAT IS GOING ON HERE: saving regular_ll_msl.grib results in the wrong `paramId`
# unless `units` is set before some other unknown key, this happens at random and only in
# Python 3.5, so it must be linked to dict key stability.
'units',
]


def regular_ll_params(values, min_value=-180., max_value=360.):
Expand Down Expand Up @@ -172,6 +180,11 @@ def make_template_message(merged_grib_keys, template_path=None, sample_name=None
sample_name = detect_sample_name(merged_grib_keys)
template_message = cfgrib.CfMessage.from_sample_name(sample_name)

for key in MESSAGE_DEFINITION_KEYS:
if key in list(merged_grib_keys):
template_message[key] = merged_grib_keys[key]
merged_grib_keys.pop(key)

for key, value in merged_grib_keys.items():
try:
template_message[key] = value
Expand Down

0 comments on commit f164f0d

Please sign in to comment.