CCSDS Time Package

This module contains the CCSDS specific time code implementations.

class spacepackets.ccsds.time.CcsdsTimeCodeId(value)

Bases: IntEnum

An enumeration.

CCS = 5
CDS = 4
CUC_AGENCY_EPOCH = 2
CUC_CCSDS_EPOCH = 1
NONE = 0
class spacepackets.ccsds.time.CcsdsTimeProvider

Bases: ABC

abstract as_date_time() datetime

Retrieve a datetime.datetime with the datetime.timezone set to utc.

as_datetime() datetime

Deprecated since version 0.14.0rc0: use as_date_time instead

as_time_string() str
abstract as_unix_seconds() float
ccsds_time_code() int
len

Deprecated since version 0.14.0rc1: use len_packed instead

abstract property len_packed: int
abstract pack() bytes
abstract property pfield: bytes
abstract read_from_raw(timestamp: bytes | bytearray) CcsdsTimeProvider
class spacepackets.ccsds.time.CdsShortTimestamp(ccsds_days: int, ms_of_day: int, init_dt_unix_stamp: bool = True)

Bases: CcsdsTimeProvider

Unpacks the time datafield of the TM packet. Right now, CDS Short timeformat is used, and the size of the time stamp is expected to be seven bytes.

>>> from spacepackets.ccsds.time import CcsdsTimeCodeId
>>> cds_short_now = CdsShortTimestamp.now()
>>> cds_short_now.len_packed
7
>>> hex(cds_short_now.pfield[0])
'0x40'

Create a stamp from the contained values directly.

>>> zero_stamp = CdsShortTimestamp(ccsds_days=0, ms_of_day=0)
>>> zero_stamp.ccsds_days
0
>>> zero_stamp.ms_of_day
0
>>> unix_zero_as_ccsds = CdsShortTimestamp(ccsds_days=convert_ccsds_days_to_unix_days(0), ms_of_day=0) # noqa: E501
>>> unix_zero_as_ccsds.ccsds_days
-4383
>>> CdsShortTimestamp(0x0102, 0x03040506).pack().hex(sep=',')
'40,01,02,03,04,05,06'
CDS_SHORT_ID = 4
TIMESTAMP_SIZE = 7
as_date_time() datetime

Deprecated since version 0.24.0: use as_datetime instead

as_datetime() datetime

Deprecated since version 0.14.0rc0: use as_date_time instead

as_unix_seconds() float
property ccsds_days: int
classmethod empty(init_dt_unix_stamp: bool = True) CdsShortTimestamp

Empty instance containing only zero for all fields.

Returns:

classmethod from_current_time() CdsShortTimestamp

Deprecated since version 0.14.0rc1: use from_now instead

classmethod from_date_time(dt: datetime) CdsShortTimestamp

Deprecated since version 0.24.0: use from_datetime instead

classmethod from_datetime(dt: datetime) CdsShortTimestamp
classmethod from_now() CdsShortTimestamp

Returns a seven byte CDS short timestamp with the current time.

Deprecated since version 0.24.0: use now instead

classmethod from_unix_days(unix_days: int, ms_of_day: int) CdsShortTimestamp
property len_packed: int
property ms_of_day: int
static ms_of_today(seconds_since_epoch: float | None = None) int
classmethod now() CdsShortTimestamp

Returns a seven byte CDS short timestamp with the current time.

pack() bytes
property pfield: bytes
read_from_raw(data: bytes | bytearray) CdsShortTimestamp

Updates the instance from a given raw CDS short timestamp

Parameters:

data

Returns:

classmethod unpack(data: bytes | bytearray) CdsShortTimestamp
static unpack_from_raw(data: bytes | bytearray) tuple[int, int]

Common Time Submodule

class spacepackets.ccsds.time.common.CcsdsTimeCodeId(value)

Bases: IntEnum

An enumeration.

CCS = 5
CDS = 4
CUC_AGENCY_EPOCH = 2
CUC_CCSDS_EPOCH = 1
NONE = 0
class spacepackets.ccsds.time.common.CcsdsTimeProvider

Bases: ABC

abstract as_date_time() datetime

Retrieve a datetime.datetime with the datetime.timezone set to utc.

as_datetime() datetime

Deprecated since version 0.14.0rc0: use as_date_time instead

as_time_string() str
abstract as_unix_seconds() float
ccsds_time_code() int
len

Deprecated since version 0.14.0rc1: use len_packed instead

abstract property len_packed: int
abstract pack() bytes
abstract property pfield: bytes
abstract read_from_raw(timestamp: bytes | bytearray) CcsdsTimeProvider
spacepackets.ccsds.time.common.DAYS_CCSDS_TO_UNIX = -4383

The day offset to convert from CCSDS days to UNIX days.

spacepackets.ccsds.time.common.MS_PER_DAY: int = 86400000

Milliseconds per day as integer

spacepackets.ccsds.time.common.SECONDS_PER_DAY: int = 86400

Seconds per days as integer

spacepackets.ccsds.time.common.convert_ccsds_days_to_unix_days(ccsds_days: int) int

Convert CCSDS days to Unix days.

CCSDS epoch: 1958-01-01 00:00:00. Unix epoch: 1970-01-01 00:00:00.

spacepackets.ccsds.time.common.convert_unix_days_to_ccsds_days(unix_days: int) int

Convert Unix days to CCSDS days.

CCSDS epoch: 1958-01-01 00:00:00. Unix epoch: 1970-01-01 00:00:00.

spacepackets.ccsds.time.common.read_p_field(p_field: int) CcsdsTimeCodeId

Read the p field and return the CCSDS Time Code ID.

Parameters:

p_field

Returns:

Raises:

IndexError – P field has invalid value

CDS Time Submodule

class spacepackets.ccsds.time.cds.CdsShortTimestamp(ccsds_days: int, ms_of_day: int, init_dt_unix_stamp: bool = True)

Bases: CcsdsTimeProvider

Unpacks the time datafield of the TM packet. Right now, CDS Short timeformat is used, and the size of the time stamp is expected to be seven bytes.

>>> from spacepackets.ccsds.time import CcsdsTimeCodeId
>>> cds_short_now = CdsShortTimestamp.now()
>>> cds_short_now.len_packed
7
>>> hex(cds_short_now.pfield[0])
'0x40'

Create a stamp from the contained values directly.

>>> zero_stamp = CdsShortTimestamp(ccsds_days=0, ms_of_day=0)
>>> zero_stamp.ccsds_days
0
>>> zero_stamp.ms_of_day
0
>>> unix_zero_as_ccsds = CdsShortTimestamp(ccsds_days=convert_ccsds_days_to_unix_days(0), ms_of_day=0) # noqa: E501
>>> unix_zero_as_ccsds.ccsds_days
-4383
>>> CdsShortTimestamp(0x0102, 0x03040506).pack().hex(sep=',')
'40,01,02,03,04,05,06'
CDS_SHORT_ID = 4
TIMESTAMP_SIZE = 7
as_date_time() datetime

Deprecated since version 0.24.0: use as_datetime instead

as_datetime() datetime

Deprecated since version 0.14.0rc0: use as_date_time instead

as_unix_seconds() float
property ccsds_days: int
classmethod empty(init_dt_unix_stamp: bool = True) CdsShortTimestamp

Empty instance containing only zero for all fields.

Returns:

classmethod from_current_time() CdsShortTimestamp

Deprecated since version 0.14.0rc1: use from_now instead

classmethod from_date_time(dt: datetime) CdsShortTimestamp

Deprecated since version 0.24.0: use from_datetime instead

classmethod from_datetime(dt: datetime) CdsShortTimestamp
classmethod from_now() CdsShortTimestamp

Returns a seven byte CDS short timestamp with the current time.

Deprecated since version 0.24.0: use now instead

classmethod from_unix_days(unix_days: int, ms_of_day: int) CdsShortTimestamp
property len_packed: int
property ms_of_day: int
static ms_of_today(seconds_since_epoch: float | None = None) int
classmethod now() CdsShortTimestamp

Returns a seven byte CDS short timestamp with the current time.

pack() bytes
property pfield: bytes
read_from_raw(data: bytes | bytearray) CdsShortTimestamp

Updates the instance from a given raw CDS short timestamp

Parameters:

data

Returns:

classmethod unpack(data: bytes | bytearray) CdsShortTimestamp
static unpack_from_raw(data: bytes | bytearray) tuple[int, int]
class spacepackets.ccsds.time.cds.LenOfDaysSegment(value)

Bases: IntEnum

An enumeration.

DAYS_16_BITS = 0
DAYS_24_BITS = 1
spacepackets.ccsds.time.cds.len_of_day_seg_from_pfield(pfield: int) LenOfDaysSegment

Extract length of day segment from the pfield