Skip to content

Commit f5322b1

Browse files
Bug fix, BUFR to BUFR (#534)
* bufr to bufr bug fix, headers now copied and set in the output BUFR files. * Correctly set the number of subsets in output of bufr to bufr. * Flake8, sigh. * Update tests-docker.yml --------- Co-authored-by: Maaike <maaike.limper@gmail.com>
1 parent 763f04e commit f5322b1

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

.github/workflows/tests-docker.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,17 @@ jobs:
109109
check-jsonschema --schemafile /tmp/wcmp2-bundled.json /tmp/$DISCOVERY_METADATA_ID
110110
- name: sync stations 🔄
111111
run: |
112-
sleep 15
112+
sleep 30
113113
python3 wis2box-ctl.py execute wis2box metadata station publish-collection
114114
- name: run integration tests ⚙️
115115
run: |
116-
sleep 15
116+
sleep 30
117117
pytest -s tests/integration
118118
- name: run flake8 ⚙️
119119
run: |
120120
find . -type f -name "*.py" | xargs flake8
121121
- name: failed tests 🚩
122122
if: ${{ failure() }}
123123
run: |
124-
docker logs wis2box-management
125-
docker logs wis2box-api
126-
docker logs wis2box-minio
124+
docker logs -n1000 wis2box-management
125+
docker logs -n1000 wis2box-api

wis2box-management/wis2box/data/bufr4.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@
5454
'typicalSecond'
5555
]
5656

57+
HEADERS = ["edition", "masterTableNumber", "bufrHeaderCentre",
58+
"bufrHeaderSubCentre", "updateSequenceNumber", "dataCategory",
59+
"internationalDataSubCategory", "dataSubCategory",
60+
"masterTablesVersionNumber", "localTablesVersionNumber",
61+
"typicalYear", "typicalMonth", "typicalDay", "typicalHour",
62+
"typicalMinute", "typicalSecond",
63+
"numberOfSubsets", "observedData", "compressedData",
64+
"unexpandedDescriptors"]
65+
5766

5867
class ObservationDataBUFR(BaseAbstractData):
59-
"""Oservation data"""
68+
"""Observation data"""
6069

6170
def transform(
6271
self, input_data: Union[Path, bytes], filename: str = ''
@@ -97,6 +106,13 @@ def transform_message(self, bufr_in: int) -> None:
97106
LOGGER.error(f'Error unpacking message: {err}')
98107
raise err
99108

109+
# get descriptors present in the file
110+
descriptors = codes_get_array(bufr_in, "expandedDescriptors").tolist()
111+
# get the headers in hte file
112+
headers = {}
113+
for header in HEADERS:
114+
headers[header] = codes_get(bufr_in, header)
115+
100116
num_subsets = codes_get(bufr_in, 'numberOfSubsets')
101117
LOGGER.debug(f'Found {num_subsets} subsets')
102118

@@ -112,15 +128,41 @@ def transform_message(self, bufr_in: int) -> None:
112128
idx = i + 1
113129
LOGGER.debug(f'Processing subset {idx}')
114130

115-
LOGGER.debug('Copying template BUFR')
116-
subset_out = codes_clone(TEMPLATE)
117-
codes_set(subset_out, 'masterTablesVersionNumber', table_version)
118-
codes_set_array(subset_out, 'unexpandedDescriptors', outUE)
119-
120131
LOGGER.debug('Extracting subset')
121132
codes_set(bufr_in, 'extractSubset', idx)
122133
codes_set(bufr_in, 'doExtractSubsets', 1)
123134

135+
# copy the replication factors
136+
if 31000 in descriptors:
137+
short_replication_factors = codes_get_array(bufr_in, "shortDelayedDescriptorReplicationFactor").tolist() # noqa
138+
if 31001 in descriptors:
139+
replication_factors = codes_get_array(bufr_in, "delayedDescriptorReplicationFactor").tolist() # noqa
140+
if 31002 in descriptors:
141+
extended_replication_factors = codes_get_array(bufr_in, "extendedDelayedDescriptorReplicationFactor").tolist() # noqa
142+
143+
LOGGER.debug('Copying template BUFR')
144+
subset_out = codes_clone(TEMPLATE)
145+
146+
# set the replication factors, this needs to be done before
147+
# setting the unexpanded descriptors
148+
if 31000 in descriptors:
149+
codes_set_array(subset_out, "inputShortDelayedDescriptorReplicationFactor", short_replication_factors) # noqa
150+
if 31001 in descriptors:
151+
codes_set_array(subset_out, "inputDelayedDescriptorReplicationFactor", replication_factors) # noqa
152+
if 31002 in descriptors:
153+
codes_set_array(subset_out, "inputExtendedDelayedDescriptorReplicationFactor", extended_replication_factors) # noqa
154+
155+
# we need to copy all the headers, not just the
156+
# unexpandedDescriptors and MT number
157+
headers['unexpandedDescriptors'] = outUE
158+
headers['masterTablesVersionNumber'] = table_version
159+
headers['numberOfSubsets'] = 1
160+
for k, v in headers.items():
161+
if isinstance(v, list):
162+
codes_set_array(subset_out, k, v)
163+
else:
164+
codes_set(subset_out, k, v)
165+
124166
LOGGER.debug('Cloning subset to new message')
125167
subset = codes_clone(bufr_in)
126168
self.transform_subset(subset, subset_out)

0 commit comments

Comments
 (0)