Skip to content

Commit

Permalink
Updated handling of env vars + removed bufr centre/subcentre from ori…
Browse files Browse the repository at this point in the history
…ginal mappings
  • Loading branch information
RoryPTB committed Mar 27, 2024
1 parent 8cfcdb2 commit 20c6559
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
31 changes: 16 additions & 15 deletions synop2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,25 +1544,26 @@ def truncate_to_twenty(name: str) -> str:
# and subcentre codes are present
missing_env_vars = []

ORIGINATING_CENTRE = os.environ.get("BUFR_ORIGINATING_CENTRE", 65535) # noqa
ORIGINATING_SUBCENTRE = os.environ.get("BUFR_ORIGINATING_SUBCENTRE", 65535) # noqa
ORIGINATING_CENTRE = os.environ.get("BUFR_ORIGINATING_CENTRE", None) # noqa
ORIGINATING_SUBCENTRE = os.environ.get("BUFR_ORIGINATING_SUBCENTRE", None) # noqa

if ORIGINATING_CENTRE == 65535:
if ORIGINATING_CENTRE is None:
missing_env_vars.append("BUFR_ORIGINATING_CENTRE")
else:
# Add the BUFR header centre and subcentre to mappings
mapping["header"].append({
"eccodes_key": "bufrHeaderCentre",
"value": f"const:{ORIGINATING_CENTRE}" # noqa
})
ORIGINATING_CENTRE = 65535

if ORIGINATING_SUBCENTRE == 65535:
if ORIGINATING_SUBCENTRE is None:
missing_env_vars.append("BUFR_ORIGINATING_SUBCENTRE")
else:
mapping["header"].append({
"eccodes_key": "bufrHeaderSubCentre",
"value": f"const:{ORIGINATING_SUBCENTRE}" # noqa
})
ORIGINATING_SUBCENTRE = 65535

# Add the BUFR header centre and subcentre to mappings
mapping["header"].append({
"eccodes_key": "bufrHeaderCentre",
"value": f"const:{ORIGINATING_CENTRE}" # noqa
})
mapping["header"].append({
"eccodes_key": "bufrHeaderSubCentre",
"value": f"const:{ORIGINATING_SUBCENTRE}" # noqa
})

# If either of these environment variables are not set,
# we will default to missing and inform the user once
Expand Down
2 changes: 0 additions & 2 deletions synop2bufr/resources/synop-mappings-307080.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"header":[
{"eccodes_key": "edition", "value": "const:4"},
{"eccodes_key": "masterTableNumber", "value": "const:0"},
{"eccodes_key": "bufrHeaderCentre", "value": "const:65535"},
{"eccodes_key": "bufrHeaderSubCentre", "value": "const:65535"},
{"eccodes_key": "updateSequenceNumber", "value": "const:0"},
{"eccodes_key": "dataCategory", "value": "const:0"},
{"eccodes_key": "internationalDataSubCategory", "value": "const:2"},
Expand Down
2 changes: 0 additions & 2 deletions synop2bufr/resources/synop-mappings-307096.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"header":[
{"eccodes_key": "edition", "value": "const:4"},
{"eccodes_key": "masterTableNumber", "value": "const:0"},
{"eccodes_key": "bufrHeaderCentre", "value": "const:65535"},
{"eccodes_key": "bufrHeaderSubCentre", "value": "const:65535"},
{"eccodes_key": "updateSequenceNumber", "value": "const:0"},
{"eccodes_key": "dataCategory", "value": "const:0"},
{"eccodes_key": "internationalDataSubCategory", "value": "const:2"},
Expand Down

0 comments on commit 20c6559

Please sign in to comment.