From 275c24494e6ecacda63e5e0d6347dc62ba5aa5bd Mon Sep 17 00:00:00 2001 From: Gwyn Fireman Date: Wed, 11 Oct 2023 10:46:41 -0400 Subject: [PATCH] packet_types.py: assign bit_offset for array fields decode.py: allow processing of partial file (+spelling) converters.py: fixed units documentation --- ccsdspy/converters.py | 4 ++-- ccsdspy/decode.py | 13 ++++++++++--- ccsdspy/packet_types.py | 1 + docs/user-guide/converters.rst | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ccsdspy/converters.py b/ccsdspy/converters.py index d5662e8..6d5598b 100644 --- a/ccsdspy/converters.py +++ b/ccsdspy/converters.py @@ -204,8 +204,8 @@ def __init__(self, since, units): it, so will the converted datetimes. units : str or tuple of str Units string of tuples of units strings for the offset of each - input field. Valid units are "days", "minutes", "milliseconds", - "microseconds", and "nanoseconds". + input field. Valid units are "days", "hours", "minutes", + "seconds", "milliseconds", "microseconds", and "nanoseconds". Raises ------ diff --git a/ccsdspy/decode.py b/ccsdspy/decode.py index 17fb2df..ec619e5 100644 --- a/ccsdspy/decode.py +++ b/ccsdspy/decode.py @@ -2,6 +2,7 @@ from __future__ import division from collections import namedtuple import math +import warnings import numpy as np @@ -283,10 +284,16 @@ def _decode_variable_length(file_bytes, fields): packet_starts.append(offset) offset += file_bytes[offset + 4] * 256 + file_bytes[offset + 5] + 7 - assert offset == len(file_bytes) + if offset != len(file_bytes): + missing_bytes = offset - len(file_bytes) + message = ( + f"File appears truncated - missing {missing_bytes} bytes (or maybe garbage at end)" + ) + warnings.warn(message) + npackets = len(packet_starts) - # Initialize output dicitonary of field arrays, their dtypes, and the offsets + # Initialize output dictionary of field arrays, their dtypes, and the offsets # that can be determined before parsing each packet. # ------------------------------------------------------------------------ field_arrays, numpy_dtypes, bit_offsets = _varlength_intialize_field_arrays(fields, npackets) @@ -415,7 +422,7 @@ def _decode_variable_length(file_bytes, fields): def _varlength_intialize_field_arrays(fields, npackets): """ - Initialize output dicitonary of field arrays, their dtypes, and the offsets + Initialize output dictionary of field arrays, their dtypes, and the offsets that can be determined before parsing each packet. Expanding fields will be an array of dtype=object (jagged array), which will be diff --git a/ccsdspy/packet_types.py b/ccsdspy/packet_types.py index 5382d93..5517417 100644 --- a/ccsdspy/packet_types.py +++ b/ccsdspy/packet_types.py @@ -565,6 +565,7 @@ def _get_fields_csv_file(csv_file): name=row["name"], data_type=data_type, bit_length=int(row["bit_length"]), + bit_offset=int(row["bit_offset"]), array_shape=array_shape, ) ) diff --git a/docs/user-guide/converters.rst b/docs/user-guide/converters.rst index c7f092b..90ec610 100644 --- a/docs/user-guide/converters.rst +++ b/docs/user-guide/converters.rst @@ -29,7 +29,7 @@ Post-processing transformations are done through the Converters API, exposed thr .. contents:: :depth: 2 -Using a Built-In Transformations +Using Built-In Transformations ================================ An example of using a built in transformation to parse time, apply a linear transformation to a first field, and apply a enumerated values transformation to a secondary field is below.