Skip to content

Commit

Permalink
An 1-bit increment of one should indicate missing compressed data
Browse files Browse the repository at this point in the history
Fix a bug where an 1-bit increment of one is treated as normal
increment.

According to WMO spec 94.1.6
   The convention for representing missing data for compressed data
   within the binary Data section shall be to set the corresponding
   increments to fields of all ones.

There it should be processed as missing data.

Resolves: #33
  • Loading branch information
ywangd committed Jan 26, 2024
1 parent f1cea08 commit be91cb6
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 370 deletions.
2 changes: 1 addition & 1 deletion pybufrkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
UnknownDescriptor,
PyBufrKitError)

__version__ = '0.2.21'
__version__ = '0.2.22'
__author__ = '[email protected]'

LOGGER = logging.getLogger('PyBufrKit')
Expand Down
6 changes: 6 additions & 0 deletions pybufrkit/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def process_numeric_compressed(self, state, bit_reader, descriptor, nbits_min_va
else:
for decoded_values in state.decoded_values_all_subsets:
diff = bit_reader.read_uint_or_none(nbits_diff)
# A one-bit increment of value one is considered as missing
if diff == 1 and nbits_diff == 1:
diff = None
if diff is None:
value = None
else:
Expand Down Expand Up @@ -332,6 +335,9 @@ def process_codeflag_compressed(self, state, bit_reader, descriptor, nbits_min_v
else:
for decoded_values in state.decoded_values_all_subsets:
diff = bit_reader.read_uint_or_none(nbits_diff)
# A one-bit increment of value one is considered as missing
if diff == 1 and nbits_diff == 1:
diff = None
if diff is None:
value = None
else:
Expand Down
36 changes: 18 additions & 18 deletions tests/data/ISMD01_OKPR.values.cmp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
16 -80.0
17 8
18 None
19 92510.0
20 750
19 None
20 None
21 2.0
22 271.85
23 271.75
Expand All @@ -156,7 +156,7 @@
40 7
41 120.0
42 1
43 12
43 None
44 None
45 None
46 None
Expand Down Expand Up @@ -248,8 +248,8 @@
16 -110.0
17 8
18 None
19 92510.0
20 750
19 None
20 None
21 2.0
22 273.05
23 271.15
Expand All @@ -272,7 +272,7 @@
40 7
41 240.0
42 1
43 12
43 None
44 None
45 None
46 None
Expand Down Expand Up @@ -364,8 +364,8 @@
16 -70.0
17 5
18 None
19 92510.0
20 750
19 None
20 None
21 1.98
22 273.65
23 271.95
Expand All @@ -388,7 +388,7 @@
40 7
41 240.0
42 1
43 12
43 None
44 None
45 None
46 None
Expand Down Expand Up @@ -480,8 +480,8 @@
16 -130.0
17 7
18 None
19 92510.0
20 750
19 None
20 None
21 2.01
22 271.85
23 270.85
Expand All @@ -504,7 +504,7 @@
40 7
41 120.0
42 1
43 12
43 None
44 None
45 None
46 None
Expand Down Expand Up @@ -596,8 +596,8 @@
16 -120.0
17 8
18 None
19 92510.0
20 750
19 None
20 None
21 2.0
22 275.05
23 272.45
Expand All @@ -620,7 +620,7 @@
40 7
41 450.0
42 1
43 12
43 None
44 None
45 None
46 None
Expand Down Expand Up @@ -712,8 +712,8 @@
16 -170.0
17 7
18 None
19 92510.0
20 750
19 None
20 None
21 2.0
22 278.65
23 273.05
Expand All @@ -736,7 +736,7 @@
40 0
41 6900.0
42 1
43 12
43 None
44 None
45 None
46 None
Expand Down
Loading

0 comments on commit be91cb6

Please sign in to comment.