Skip to content

Commit

Permalink
fix for issue-559 (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikelimper authored Nov 2, 2023
1 parent d1be368 commit 6c4be0d
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions wis2box-management/wis2box/data/bufr4.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
"masterTablesVersionNumber", "localTablesVersionNumber",
"typicalYear", "typicalMonth", "typicalDay", "typicalHour",
"typicalMinute", "typicalSecond",
"numberOfSubsets", "observedData", "compressedData",
"unexpandedDescriptors"]
"numberOfSubsets", "observedData", "compressedData"]


class ObservationDataBUFR(BaseAbstractData):
Expand Down Expand Up @@ -108,22 +107,27 @@ def transform_message(self, bufr_in: int) -> None:

# get descriptors present in the file
descriptors = codes_get_array(bufr_in, "expandedDescriptors").tolist()
# get the headers in hte file

# prepare the headers for the new messages
headers = {}
for header in HEADERS:
headers[header] = codes_get(bufr_in, header)

num_subsets = codes_get(bufr_in, 'numberOfSubsets')
LOGGER.debug(f'Found {num_subsets} subsets')

# original to be splitted by subset, so set the number of subsets to 1
headers['numberOfSubsets'] = 1
# set the master table version number
table_version = max(
28, codes_get(bufr_in, 'masterTablesVersionNumber')
)

outUE = codes_get_array(bufr_in, 'unexpandedDescriptors').tolist()
if 301150 not in outUE:
outUE.insert(0, 301150)

headers['masterTablesVersionNumber'] = table_version
# set the unexpanded descriptors
out_ue = codes_get_array(bufr_in, 'unexpandedDescriptors').tolist()
if 301150 not in out_ue:
out_ue.insert(0, 301150)
headers['unexpandedDescriptors'] = out_ue

# loop over the subsets, create a new message for each
num_subsets = codes_get(bufr_in, 'numberOfSubsets')
LOGGER.debug(f'Found {num_subsets} subsets')
for i in range(num_subsets):
idx = i + 1
LOGGER.debug(f'Processing subset {idx}')
Expand Down Expand Up @@ -154,9 +158,7 @@ def transform_message(self, bufr_in: int) -> None:

# we need to copy all the headers, not just the
# unexpandedDescriptors and MT number
headers['unexpandedDescriptors'] = outUE
headers['masterTablesVersionNumber'] = table_version
headers['numberOfSubsets'] = 1

for k, v in headers.items():
if isinstance(v, list):
codes_set_array(subset_out, k, v)
Expand Down

0 comments on commit 6c4be0d

Please sign in to comment.