VariableLength¶
- class ccsdspy.VariableLength(fields, apid=None, name=None, description=None)[source]¶
Bases:
_BasePacketDefine a variable length packet to decode binary data.
Variable length packets are packets which have a different length each time. Variable length fields are defined as
PacketArrayfields wherearray_shape="expand"(causing the field to grow to fill the packet) orarray_shape="other_field"(causes the field namedother_fieldto set the number of elements in this array).Please note that while this class is able to parse fixed length packets, it is much slower. Use the
FixedLengthclass instead.- Rules for variable length packets:
Do only specify a
PacketArraywith thearray_shape="other_field"whenother_fieldprecedes it in the packet definitionDo not provide more than one expanding
PacketArraywitharray_shape="expand"Do not specify the primary header fields manually
Do not specify explicit bit_offsets (they will be computed automatically)
- Parameters:
- fieldslist of
PacketFieldorPacketArray Layout of packet fields contained in the definition. No more than one field should have array_shape=”expand”. The field must have no bit_offset’s. Do not include the primary header fields.
- apidint, optional
APID of the packet. Acts as a unique identifier for the packet type. Used as metadata.
- namestr, optional
Name of the packet. Used as metadata.
- descriptionstr, optional
Description of the packet. Used as metadata.
- fieldslist of
- Raises:
- ValueError
one or more of the arguments are invalid, or do not follow the specified rules.
Methods Summary
load(file[, include_primary_header, ...])Decode a file-like object containing a sequence of these packets.
Methods Documentation
- load(file, include_primary_header=False, reset_file_obj=False)[source]¶
Decode a file-like object containing a sequence of these packets.
- Parameters:
- filestr
Path to file on the local file system, or file-like object
- include_primary_headerbool
If True, provides the primary header in the output. The names of the fields are:
CCSDS_VERSION_NUMBER,CCSDS_PACKET_TYPE,CCSDS_SECONDARY_FLAG,CCSDS_SEQUENCE_FLAG,CCSDS_APID,CCSDS_SEQUENCE_COUNT, andCCSDS_PACKET_LENGTH- reset_file_objbool
If True, leave the file object, when it is file buffer, where it was before load is called. Otherwise, (default), leave the file stream pos after the read packets. Does not apply when file is a string.
- Returns:
- field_arraysdict, string to NumPy array
dictionary mapping field names to NumPy arrays, with key order matching the order of fields in the packet.
- Warns:
- UserWarning
If the ccsds sequence count is not in order
- UserWarning
If the ccsds sequence count is missing packets
- UserWarning
If there are more than one APID