From 20c655924143be0e0d730290edf4896d7cf9f108 Mon Sep 17 00:00:00 2001 From: RoryPTB <47696929+RoryPTB@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:54:32 +0100 Subject: [PATCH] Updated handling of env vars + removed bufr centre/subcentre from original mappings --- synop2bufr/__init__.py | 31 ++++++++++--------- .../resources/synop-mappings-307080.json | 2 -- .../resources/synop-mappings-307096.json | 2 -- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/synop2bufr/__init__.py b/synop2bufr/__init__.py index 5691918..bb50e9f 100644 --- a/synop2bufr/__init__.py +++ b/synop2bufr/__init__.py @@ -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 diff --git a/synop2bufr/resources/synop-mappings-307080.json b/synop2bufr/resources/synop-mappings-307080.json index 066c361..aa7e984 100644 --- a/synop2bufr/resources/synop-mappings-307080.json +++ b/synop2bufr/resources/synop-mappings-307080.json @@ -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"}, diff --git a/synop2bufr/resources/synop-mappings-307096.json b/synop2bufr/resources/synop-mappings-307096.json index 716c36e..aa83af5 100644 --- a/synop2bufr/resources/synop-mappings-307096.json +++ b/synop2bufr/resources/synop-mappings-307096.json @@ -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"},