CCSDSPy / ccsdspy

I/O interface and utilities for CCSDS binary spacecraft data in Python. Library used in flight missions at NASA, NOAA, and SWRI
https://ccsdspy.org
BSD 3-Clause "New" or "Revised" License
75 stars 18 forks source link

Add post-processing steps to aide in calibration and time conversion #51

Closed ddasilva closed 1 year ago

ddasilva commented 1 year ago

It would be very useful fulfill to implement post-processing steps, including time conversation and things like converting digital values to analog using known calibration curves. For instance, sometimes temperature will be sent down from a spacecraft as a 0-255 digital value, and you have some linear function y=mx+b from pre-launch engineering that converts the digital value to degrees Celsius. Another common use case is replacing integer values with string values, such as replacing 0 with "DISABLED", 1 with "ENABLED", and 2 with "STANDBY".

Handling a 48-bit time field split between 32-bit coarse time and 16 bit fine time could be handled like this. The result in the dictionary returned by pkt.load() would be an array of datetimes.

     rtime42_conv = RTime42Converter(
         coarse_length=32,
         fine_length=16,
         reference_time=datetime(1970, 1, 1),
         coarse_units='s',
         fine_units='ms'
      )

     pkt = FixedLength([
         ....
         PacketField(name="packet_time", bit_length=48, data_type='uint', converter=rtime42_conv)
         ....
     ])

Calibration curves could be handled like this (having both PolyConverter and LinearConverterer is redundant, but reads better).

     pkt = FixedLength([
         ....
         PacketField(
              name="temperature", bit_length=8, data_type='uint',
              converter=LinearConverter(slope=1.2, intercept=-30)
         ),
         PacketField(
              name="current", bit_length=8, data_type='uint',
              converter=PolyConverter(coeffs=[0.1, 1.2, 0.3])
         ),
         ....
     ])