Utils for the CCSDSPy package.
def ccsdspy.utils.count_packets |
( |
|
file, |
|
|
|
return_missing_bytes = False |
|
) |
| |
Count the number of packets in a file and check if there are any
missing bytes in the last packet.
This function works with mixed files containing multiple APIDs, which may
include both fixed length and variable length packets. When used with
multiple APIDs, it simply returns the total number of packets of any APID.
If end of last packet doesn't align with end of file, a warning is issued.
Parameters
----------
file : str, file-like
Path to file on the local file system, or file-like object
return_missing_bytes : bool, optional
Also return the number of missing bytes at the end of the file. This
is the number of bytes which would need to be added to the file to
complete the last packet expected (as set by the packet length in
the last packet's primary header).
Returns
-------
num_packets : int
Number of complete packets in the file
missing_bytes : int, optional
The number of bytes which would need to be added to the file to
complete the last packet expected (as set by the packet length in
the last packet's primary header).
Definition at line 185 of file utils.py.
def ccsdspy.utils.iter_packet_bytes |
( |
|
file, |
|
|
|
include_primary_header = True |
|
) |
| |
Iterate through packets as raw bytes objects, in the order they appear in a file.
This function works with mixed files containing multiple APIDs, which may
include both fixed length and variable length packets.
If end of last packet doesn't align with end of file, a warning is issued.
Parameters
----------
file : str, file-like
Path to file on the local file system, or file-like object
include_primary_header : bool
If set to False, excludes the primary header bytes (the first six)
Yields
------
packet_bytes : bytes
Bytes associated with each packet as it appears in the file. When
include_primary_header=False, the primary header bytes are excluded.
Definition at line 33 of file utils.py.
def ccsdspy.utils.read_primary_headers |
( |
|
file | ) |
|
Read primary header fields and return contents as a dictionary
of arrays.
This function works with mixed files containing multiple APIDs, which may
include both fixed length and variable length packets.
Parameters
----------
file : str, file-like
Path to file on the local file system, or file-like object
Returns
-------
header_arrays : dict, string to NumPy array
Dictionary mapping header names to NumPy arrays. The header names are:
`CCSDS_VERSION_NUMBER`, `CCSDS_PACKET_TYPE`, `CCSDS_SECONDARY_FLAG`,
`CCSDS_SEQUENCE_FLAG`, `CCSDS_APID`, `CCSDS_SEQUENCE_COUNT`,
`CCSDS_PACKET_LENGTH`
Definition at line 109 of file utils.py.
def ccsdspy.utils.split_by_apid |
( |
|
mixed_file, |
|
|
|
valid_apids = None |
|
) |
| |
Split a stream of mixed APIDs into separate streams by APID.
This works with a mix of both fixed length and variable length packets.
Parameters
----------
mixed_file: str, file-like
Path to file on the local file system, or file-like object
valid_apids: list of int, None
Optional list of valid APIDs. If specified, warning will be issued when
an APID is encountered outside this list.
Returns
-------
stream_by_apid : dict, int to :py:class:`~io.BytesIO`
Dictionary mapping integer apid number to BytesIO instance with the file
pointer at the beginning of the stream.
Definition at line 143 of file utils.py.
def ccsdspy.utils.split_packet_bytes |
( |
|
file, |
|
|
|
include_primary_header = True |
|
) |
| |
Retrieve a list of bytes objects corresponding to each packet in a file.
This function works with mixed files containing multiple APIDs, which may
include both fixed length and variable length packets.
If end of last packet doesn't align with end of file, a warning is issued.
Parameters
----------
file : str, file-like
Path to file on the local file system, or file-like object
include_primary_header : bool
If set to False, excludes the primary header bytes (the first six)
Returns
-------
packet_bytes : list of bytes
List of bytes objects associated with each packet as it appears in the
file. When include_primary_header=False, each byte object will have its
primary header bytes excluded.
Definition at line 84 of file utils.py.