Skip to content

Commit

Permalink
Merge pull request #99 from gfireman/main
Browse files Browse the repository at this point in the history
  • Loading branch information
ddasilva committed Oct 12, 2023
2 parents 8b9619f + 275c244 commit 21c1dfc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ccsdspy/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
13 changes: 10 additions & 3 deletions ccsdspy/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import division
from collections import namedtuple
import math
import warnings

import numpy as np

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ccsdspy/packet_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/converters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 21c1dfc

Please sign in to comment.