Skip to content

Commit

Permalink
Merge branch 'upstream-dev' into mag_l1a_compression
Browse files Browse the repository at this point in the history
  • Loading branch information
maxinelasp committed Sep 16, 2024
2 parents 306769a + 69911cc commit e6b0cd3
Show file tree
Hide file tree
Showing 101 changed files with 13,720 additions and 7,463 deletions.
9 changes: 0 additions & 9 deletions docs/source/code-documentation/swe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ SWE
This is the SWE (Solar Wind Electrons) Instrument module, which contains the code for processing
data from the SWE instrument.

The L0 code to decommutate the CCSDS packet data can be found below.

.. autosummary::
:toctree: generated/
:template: autosummary.rst
:recursive:

l0.decom_swe

The L1A code to unpack electron counts can be found below.

.. autosummary::
Expand Down
30 changes: 30 additions & 0 deletions docs/source/code-documentation/tools/xtce-generator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ the conversion details.
- ANALOG
- Apply an analog conversion
-
* - MY_INSTRUMENT_HK
- VARIABLE_ENUMERATED
- 1
- UINT
- STATE
- Apply an enumeration state
-
* - MY_INSTRUMENT_HK
- VARIABLE_LENGTH_BINARY_SCIENCE
- 100
Expand Down Expand Up @@ -164,3 +171,26 @@ coefficients defined from ``c0`` to ``c7`` to define the order of the polynomial
-
-
-

States tab (optional)
~~~~~~~~~~~~~~~~~~~~~

Packet parsing can also apply enumeration/state conversions to the data being read in.
For example, to change from a raw unsigned integer value to a "VALID" / "INVALID" string.
The ``States`` tab is used to define these enumerations.

.. list-table:: States
:header-rows: 1

* - packetName
- mnemonic
- value
- state
* - MY_INSTRUMENT_HK
- VARIABLE_ENUMERATED
- 0
- INVALID
* - MY_INSTRUMENT_HK
- VARIABLE_ENUMERATED
- 1
- VALID
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
(r"py:.*", r".*numpy.int.*"),
(r"py:.*", r".*np.ndarray.*"),
(r"py:.*", r".*numpy._typing._array_like._ScalarType_co.*"),
(r"py:.*", r".*idex.l1.TRIGGER_DESCRIPTION.*"),
]

# Ignore the inherited members from the <instrument>APID IntEnum class
Expand Down
33 changes: 32 additions & 1 deletion imap_processing/ccsds/excel_to_xtce.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def _add_parameter(self, row: pd.Series, total_packet_bits: int) -> None:
# Combine the packet name and mnemonic to create a unique parameter name
name = f"{row['packetName']}.{row['mnemonic']}"
parameter.attrib["name"] = name
# UINT8, ...
parameter.attrib["parameterTypeRef"] = name

# Add descriptions if they exist
Expand Down Expand Up @@ -329,6 +328,10 @@ def _add_parameter(self, row: pd.Series, total_packet_bits: int) -> None:
# Go look up the conversion in the AnalogConversions tab
# and add it to the encoding
self._add_analog_conversion(row, encoding)
elif row["convertAs"] == "STATE":
# Go look up the states in the States tab
# and add them to the parameter type
self._add_state_conversion(row, parameter_type)

def _add_analog_conversion(self, row: pd.Series, encoding: Et.Element) -> None:
"""
Expand Down Expand Up @@ -363,6 +366,34 @@ def _add_analog_conversion(self, row: pd.Series, encoding: Et.Element) -> None:
term.attrib["coefficient"] = str(conversion[col])
term.attrib["exponent"] = str(i)

def _add_state_conversion(self, row: pd.Series, parameter_type: Et.Element) -> None:
"""
Add a state conversion to the parameter type.
Changing from an IntegerParameterType to an EnumeratedParameterType. Adding
the list of state mappings to the parameter type.
Parameters
----------
row : pandas.Row
Row to be added to the XTCE file, containing mnemonic, packetName.
parameter_type : Element
The parameter type element to add the conversion to.
"""
# It is an EnumeratedParameterType rather than an IntegerParameterType
parameter_type.tag = "xtce:EnumeratedParameterType"
enumeration_list = Et.SubElement(parameter_type, "xtce:EnumerationList")
# Lookup the enumeration states for this parameter from the States sheet
state_sheet = self.sheets["States"]
state_sheet = state_sheet.loc[
(state_sheet["packetName"] == row["packetName"])
& (state_sheet["mnemonic"] == row["mnemonic"])
]
for _, state_row in state_sheet.iterrows():
enumeration = Et.SubElement(enumeration_list, "xtce:Enumeration")
enumeration.attrib["value"] = str(state_row["value"])
enumeration.attrib["label"] = str(state_row["state"])

def to_xml(self, output_xml_path: Path) -> None:
"""
Create and output an XTCE file from the Element Tree representation.
Expand Down
Loading

0 comments on commit e6b0cd3

Please sign in to comment.