Skip to content

Commit 3ae56b0

Browse files
authored
Merge pull request #248 from lasp/release/6.1
Post 6.1.2 merge to main
2 parents 9a65ffb + e6dcf0c commit 3ae56b0

7 files changed

Lines changed: 55 additions & 21 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ jobs:
2222

2323
# Run unit and integration tests
2424
run-tests:
25-
# Don't run for label additions
26-
if: |
27-
github.event_name != 'pull_request' ||
28-
github.event.action == 'opened' ||
29-
github.event.action == 'synchronize' ||
30-
github.event.action == 'reopened'
3125
name: Test
3226
runs-on: ${{ matrix.os }}
3327
permissions:
@@ -68,12 +62,6 @@ jobs:
6862

6963
# Run the example scripts and ensure there are no errors
7064
run-examples:
71-
# Don't run for label additions
72-
if: |
73-
github.event_name != 'pull_request' ||
74-
github.event.action == 'opened' ||
75-
github.event.action == 'synchronize' ||
76-
github.event.action == 'reopened'
7765
name: Run Examples
7866
runs-on: ubuntu-latest
7967
permissions:

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cff-version: 1.2.0
22
title: 'space_packet_parser'
33
type: software
4-
version: '6.1.1'
4+
version: '6.1.2'
55
description: A CCSDS telemetry packet decoding library based on the XTCE packet format description standard.
66
license: BSD-3-Clause
77
abstract: The Space Packet Parser Python library is a generalized, configurable packet decoding library for CCSDS telemetry

docs/source/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ list and release milestones.
77

88
Release notes for the `space_packet_parser` library
99

10+
### v6.1.2
11+
12+
- BUGFIX: Prevent BinaryParameter truncation in `create_dataset`. [#246](https://github.com/lasp/space_packet_parser/issues/246)
13+
1014
### v6.1.1
1115

1216
- BUGFIX: Support lxml 5.2.1. [#236](https://github.com/lasp/space_packet_parser/issues/236)

meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package:
22
name: "space_packet_parser"
3-
version: "6.1.1"
3+
version: "6.1.2"
44

55
source:
66
path: .

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "space_packet_parser"
3-
version = "6.1.1"
3+
version = "6.1.2"
44
description = "A CCSDS telemetry packet decoding library based on the XTCE packet format description standard."
55
license = { text = "BSD-3-Clause" }
66
readme = "README.md"

space_packet_parser/xarr.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,17 @@ def _process_generator(generator):
255255
dataset_by_apid = {}
256256

257257
for apid, data in data_dict.items():
258-
ds = xr.Dataset(
259-
data_vars={
260-
key: (["packet"], np.asarray(list_of_values, dtype=datatype_mapping[apid][key]))
261-
for key, list_of_values in data.items()
262-
}
263-
)
258+
data_vars: dict[str, tuple[list[str], np.ndarray]] = {} # {var_name: ([dims, ...], data_array)}
259+
for key, list_of_values in data.items():
260+
dtype = np.dtype(datatype_mapping[apid][key])
261+
if dtype.kind == "S":
262+
# Special case for byte strings. np.asarray doesn't process BinaryParameter objects correctly to
263+
# byte strings, so we need to convert them to bytes first before creating the array.
264+
# See: https://github.com/lasp/space_packet_parser/issues/246
265+
list_of_values = [bytes(val) for val in list_of_values]
266+
data_vars[key] = (["packet"], np.asarray(list_of_values, dtype=dtype))
267+
268+
ds = xr.Dataset(data_vars=data_vars)
264269

265270
dataset_by_apid[apid] = ds
266271

tests/unit/test_xarr.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,43 @@ def test_create_dataset_with_custom_generator(tmp_path, fixed_length_packet_defi
178178
assert list(dataset["INT32_FIELD"].values) == [12345, 67890, -99999]
179179

180180

181+
def test_create_dataset_preserves_binary_parameter_width(tmp_path):
182+
"""Test that binary parameters keep their full byte width in the resulting dataset."""
183+
packet_definition = definitions.XtcePacketDefinition(
184+
container_set=[
185+
containers.SequenceContainer(
186+
"BINARY_CONTAINER",
187+
entry_list=[
188+
parameters.Parameter(
189+
"BIN_FIELD",
190+
parameter_type=parameter_types.BinaryParameterType(
191+
"BIN_TYPE", encoding=encodings.BinaryDataEncoding(fixed_size_in_bits=64)
192+
),
193+
)
194+
],
195+
)
196+
]
197+
)
198+
packet_data = b"ABCDEFGH"
199+
test_file = tmp_path / "binary_packets.bin"
200+
test_file.write_bytes(packet_data)
201+
202+
datasets = xarr.create_dataset(
203+
test_file,
204+
packet_definition,
205+
packet_bytes_generator=fixed_length_generator,
206+
generator_kwargs={"packet_length_bytes": 8},
207+
parse_bytes_kwargs={"root_container_name": "BINARY_CONTAINER"},
208+
)
209+
210+
dataset = list(datasets.values())[0]
211+
212+
assert dataset["BIN_FIELD"].values.dtype.kind == "S" # Should be a bytes/string type
213+
assert dataset["BIN_FIELD"].values.dtype.itemsize == 8
214+
assert dataset["BIN_FIELD"].values.dtype == "|S8"
215+
assert dataset["BIN_FIELD"].values.tolist() == [packet_data]
216+
217+
181218
def test_create_dataset_with_packet_filter(tmp_path, fixed_length_packet_definition, fixed_length_test_packets):
182219
"""Test filtering packets with packet_filter parameter using raw byte inspection"""
183220
_, _, _, binary_data = fixed_length_test_packets

0 commit comments

Comments
 (0)