ait.core.dtype module¶
-
class
ait.core.dtype.
ArrayType
(elem_type, nelems)¶ Bases:
object
-
__init__
(elem_type, nelems)¶ Creates a new ArrayType of nelems, each of type elem_type.
-
decode
(bytes[[, index], raw=False]) → value1, ..., valueN¶ Decodes the given sequence of bytes according to this Array’s element type.
If the optional index parameter is an integer or slice, then only the element(s) at the specified position(s) will be decoded and returned.
-
decode_elem
(bytes, index, raw=False)¶ Decodes a single element at array[index] from a sequence bytes that contain data for the entire array.
-
encode
(value1[, ...]) → bytes¶ Encodes the given values to a sequence of bytes according to this Array’s underlying element type
-
static
parse
(name) → [typename | None, nelems | None]¶ Parses an ArrayType name to return the element type name and number of elements, e.g.:
>>> ArrayType.parse('MSB_U16[32]') ['MSB_U16', 32]
If typename cannot be determined, None is returned. Similarly, if nelems is not an integer or less than one (1), None is returned.
-
name
¶ Name of this ArrayType.
-
nbits
¶ Number of bits required to represent this ArrayType.
-
nbytes
¶ Number of bytes required to represent this ArrayType.
-
nelems
¶ Number of elements in this ArrayType.
-
type
¶ Type of array elements.
-
-
class
ait.core.dtype.
CmdType
¶ Bases:
ait.core.dtype.PrimitiveType
This type is used to take a two byte opcode and return the corresponding Command Definition (
CmdDefn
).-
__init__
()¶ PrimitiveType(name) -> PrimitiveType
Creates a new PrimitiveType based on the given typename (e.g. ‘MSB_U16’ for a big endian, 16 bit short integer).
-
decode
(bytearray, raw=False) → value¶ Decodes the given bytearray and returns the corresponding Command Definition (
CmdDefn
) for the underlying ‘MSB_U16’ command opcode.If the optional parameter
raw
isTrue
, the command opcode itself will be returned instead of the Command Definition (CmdDefn
).
-
encode
(value) → bytearray¶ Encodes the given value to a bytearray according to this PrimitiveType definition.
-
BASEPDT
= 'MSB_U16'¶
-
cmddict
¶ PrimitiveType base for the ComplexType
-
pdt
¶ PrimitiveType base for the ComplexType
-
-
class
ait.core.dtype.
CustomTypes
¶ Bases:
object
Pseudo-ABC for users to inject custom types into AIT
CustomTypes is the vector through which users can inject custom types that they create into the toolkit. dtype.get is used throughout AIT to fetch the appropriate class for a given data type. Users that want to create a custom type should inherit from CustomTypes, implement get() so their types can be exposed, and configure AIT’s extensions to use their class.
Custom classes must inherit from PrimitiveType. For examples of “custom” types look at the implementation of the ComplexTypeMap classes. All of these build on top of PrimitiveType in some way.
-
get
(typename: str) → Optional[ait.core.dtype.PrimitiveType]¶ Retrieve an instance of a type’s class given its name
Maps a class name to an instance of its respective class. Should return None if no match is found.
-
-
class
ait.core.dtype.
EVRType
¶ Bases:
ait.core.dtype.PrimitiveType
This type is used to take a two byte Event Verification Record (EVR) code and return the corresponding EVR Definition (
EVRDefn
).-
__init__
()¶ PrimitiveType(name) -> PrimitiveType
Creates a new PrimitiveType based on the given typename (e.g. ‘MSB_U16’ for a big endian, 16 bit short integer).
-
decode
(bytearray, raw=False) → value¶ Decodes the given bytearray according the corresponding EVR Definition (
EVRDefn
) for the underlying ‘MSB_U16’ EVR code.If the optional parameter
raw
isTrue
, the EVR code itself will be returned instead of the EVR Definition (EVRDefn
).
-
encode
(value) → bytearray¶ Encodes the given value to a bytearray according to this Complex Type definition.
-
BASEPDT
= 'MSB_U16'¶
-
evrs
¶ Getter EVRs dictionary
-
pdt
¶ PrimitiveType base for the ComplexType
-
-
class
ait.core.dtype.
PrimitiveType
(name)¶ Bases:
object
A PrimitiveType contains a number of fields that provide information on the details of a primitive type, including: name (e.g. “MSB_U32”), format (Python C struct format code), endianness (“MSB” or “LSB”), float, signed, nbits, nbytes, min, and max.
PrimitiveTypes can validate() specific values and encode() and decode() binary representations.
-
__init__
(name)¶ PrimitiveType(name) -> PrimitiveType
Creates a new PrimitiveType based on the given typename (e.g. ‘MSB_U16’ for a big endian, 16 bit short integer).
-
decode
(bytearray, raw=False) → value¶ Decodes the given bytearray according to this PrimitiveType definition.
NOTE: The parameter
raw
is present to adhere to thedecode()
inteface, but has no effect for PrimitiveType definitions.
-
encode
(value) → bytearray¶ Encodes the given value to a bytearray according to this PrimitiveType definition.
-
toJSON
()¶
-
validate
(value[, messages[, prefix]]) → True | False¶ Validates the given value according to this PrimitiveType definition. Validation error messages are appended to an optional messages array, each with the optional message prefix.
-
endian
¶ Endianness of this PrimitiveType, either ‘MSB’ or ‘LSB’.
-
float
¶ Indicates whether or not this PrimitiveType is a float or double.
-
format
¶ Python C struct format code for this PrimitiveType.
-
max
¶ Maximum value for this PrimitiveType.
-
min
¶ Minimum value for this PrimitiveType.
-
name
¶ Name of this PrimitiveType (e.g. ‘I8’, ‘MSB_U16’, ‘LSB_F32’, etc.).
-
nbits
¶ Number of bits required to represent this PrimitiveType.
-
nbytes
¶ Number of bytes required to represent this PrimitiveType.
-
signed
¶ Indicates whether or not this PrimitiveType is signed or unsigned.
-
string
¶ Indicates whether or not this PrimitiveType is a string.
-
-
class
ait.core.dtype.
Time32Type
¶ Bases:
ait.core.dtype.PrimitiveType
This four byte time represents the elapsed time in seconds since the GPS epoch.
-
__init__
()¶ PrimitiveType(name) -> PrimitiveType
Creates a new PrimitiveType based on the given typename (e.g. ‘MSB_U16’ for a big endian, 16 bit short integer).
-
decode
(bytearray, raw=False) → value¶ Decodes the given bytearray containing the elapsed time in seconds since the GPS epoch and returns the corresponding Python
datetime
.If the optional parameter
raw
isTrue
, the integral number of seconds will be returned instead.
-
encode
(value) → bytearray¶ Encodes the given value to a bytearray according to this ComplexType definition.
-
pdt
¶ PrimitiveType base for the ComplexType
-
-
class
ait.core.dtype.
Time40Type
¶ Bases:
ait.core.dtype.PrimitiveType
This five byte time is made up of four bytes of seconds and one byte of (1 / 256) subseconds, representing the elapsed time since the GPS epoch.
-
__init__
()¶ PrimitiveType(name) -> PrimitiveType
Creates a new PrimitiveType based on the given typename (e.g. ‘MSB_U16’ for a big endian, 16 bit short integer).
-
decode
(bytearray, raw=False) → value¶ Decodes the given bytearray containing the elapsed time in seconds plus 1/256 subseconds since the GPS epoch returns the corresponding Python
datetime
.If the optional parameter
raw
isTrue
, the number of seconds and subseconds will be returned as a floating-point number instead.
-
encode
(value) → bytearray¶ Encodes the given value to a bytearray according to this ComplexType definition.
-
pdt
¶ PrimitiveType base for the ComplexType
-
-
class
ait.core.dtype.
Time64Type
¶ Bases:
ait.core.dtype.PrimitiveType
This eight byte time is made up of four bytes of seconds and four bytes of nanoseconds, representing the elapsed time since the GPS epoch.
-
__init__
()¶ PrimitiveType(name) -> PrimitiveType
Creates a new PrimitiveType based on the given typename (e.g. ‘MSB_U16’ for a big endian, 16 bit short integer).
-
decode
(bytearray, False) → value¶ Decodes the given bytearray containing the elapsed time in seconds plus nanoseconds since the GPS epoch and and returns the corresponding Python
datetime
. NOTE: The Pythondatetime
class has only microsecond resolution.If the optional parameter
raw
isTrue
, the number of seconds and nanoseconds will be returned as a floating-point number instead.
-
encode
(value) → bytearray¶ Encodes the given value to a bytearray according to this ComplexType definition.
-
pdt
¶ PrimitiveType base for the ComplexType
-
-
class
ait.core.dtype.
Time8Type
¶ Bases:
ait.core.dtype.PrimitiveType
This 8-bit time type represents the fine time in the CCSDS secondary header. This time is calculated where the LSB of the octet is equal to 1/256 seconds (or 2^-8), approximately 4 msec. See SSP 41175-02H for more details on the CCSDS headers.
-
__init__
()¶ PrimitiveType(name) -> PrimitiveType
Creates a new PrimitiveType based on the given typename (e.g. ‘MSB_U16’ for a big endian, 16 bit short integer).
-
decode
(bytearray, raw=False) → value¶ Decodes the given bytearray and returns the number of (fractional) seconds.
If the optional parameter
raw
isTrue
, the byte (U8) itself will be returned.
-
encode
(value) → bytearray¶ Encodes the given value to a bytearray according to this ComplexType definition.
-
pdt
¶ PrimitiveType base for the ComplexType
-
-
ait.core.dtype.
get
(typename)¶ Returns the type for typename or None.
get() checks primitive types, then complex types, and finally custom user defined types (via CustomTypes extension) for the typename.
-
ait.core.dtype.
get_cdt
(typename)¶ Returns the ComplexType for typename or None.
-
ait.core.dtype.
get_pdt
(typename)¶ Returns the PrimitiveType for typename or None.