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 Aug 29, 2024
2 parents 23e6ab4 + 3e71692 commit 75240fd
Show file tree
Hide file tree
Showing 94 changed files with 11,067 additions and 12,020 deletions.
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,5 @@ repos:
rev: 'v1.10.0'
hooks:
- id: mypy
pass_filenames: false
args: [ ., --strict, --explicit-package-bases,
--disable-error-code, import-untyped,
--disable-error-code, import-not-found,
--disable-error-code, no-untyped-call,
--disable-error-code, type-arg ]
exclude: .*(tests|docs).*
additional_dependencies: [ numpy==1.26.4 ]
210 changes: 146 additions & 64 deletions docs/source/code-documentation/tools/xtce-generator.rst
Original file line number Diff line number Diff line change
@@ -1,84 +1,166 @@
.. _xtce_generator:

Generating Telemetry XML with Python Script
===========================================
XML Telemetric and Command Exchange (XTCE)
==========================================

Here is some info on `XTCE <https://public.ccsds.org/Pubs/660x2g2.pdf/>`_. This Green
Book introduces the main concepts of XML Telemetric and Command Exchange (XTCE), a
telemetry and telecommand database format for spacecraft monitoring
and control.
The `XTCE green book <https://public.ccsds.org/Pubs/660x2g2.pdf>`_.
introduces the main concepts and specifications of XTCE.
The XTCE format is a specification for spacecraft monitoring and control data transfer.
It can be used to define how packets can be sent and received from the spacecraft,
which we then unpack on the ground using the XTCE format.

General
-------

This document provides steps and information on how to use
`xtce_generator_template.py` script as a base for users to generate
telemetry XML files. The script is designed to simplify the process of creating
telemetry definitions for various packet types.

The script is located in the `tools/xtce_generation` directory. The script is called
`xtce_generator_template.py`. The script is a ``template`` that can be modified to
generate telemetry XML files for different packet types. Your new file should be
called `xtce_generator_yourinstrument.py`.
An example of how to use the script is `xtce_generator_codice.py` which is also
located in the `tools/xtce_generation` directory.

Before you Start
----------------

Generating XTCEs is only done whenever packet definitions get updated, and thus it
is not a part of the main processing package. To use it there are a few extra
dependencies like ``pandas`` that you can install with
is not regularly run as a part of processing. To use it there are a few extra
dependencies (like ``openpyxl`` for reading excel spreadsheets) that you
can install with the tools extra.

.. code::
# with poetry
poetry install --extras tools
# or with pip
pip install imap_processing[tools]
How to Use
----------

Define the instrument name in the `main()` function by setting the `instrument_name`
variable to the name of your instrument.

.. code::
instrument_name = "your_instrument_name"
In the code, file paths are being configured. Make sure to change the file paths to
match your instrument's file structure.

.. code::
current_directory = Path(__file__).parent
module_path = f"{current_directory}/../../imap_processing"
# This is the path of the output directory
packet_definition_path = f"{module_path}/{instrument_name}/packet_definitions"
# This is the path to the excel file that contains the telemetry definitions
path_to_excel_file = f"{current_directory}/your_packet.xlsx"
Define packet names and `Application Process Identifiers (APIDs)
<https://sanaregistry.org/r/space_packet_protocol_application_process_id/>`_.
The packet names are **case sensitive** meaning the the packet names need to be exactly
what the tabs of the spreadsheet are. APID's must match the names and apIds in the
packet definition file. You can use as many packet names and apIds as you want.
The APID should be an integer (not hexadecimal).
Follow the format below.

.. code::
packets = {
# Define packet names and associated Application IDs (apId)
"your_packet_A": ####,
"your_packet_B": ####,
# ... (other packet definitions)
}
Generating Telemetry XML Files
-------------------------------

Once you have your xtce processing file defined, you can run it with the
following command:
There is a command line utility ``imap_xtce`` that can be used to generate XTCE files
that is installed with the ``imap_processing`` package.
The utility takes in an excel file and generates XTCE files for each packet definition
in the excel file. If you don't provide an output file, it will generate the XTCE file
with the same name as the input Excel file but with the extension changed to ``.xml``.

.. code::
python xtce_generator_instrument_name.py
imap_xtce path/to/excel_packet_file.xlsx --output path/to/output_packet_definition.xml
Spreadsheet definitions
-----------------------

The XTCE generator uses an excel spreadsheet to define the packet structure.
This is a commonly used spreadsheet format at the Laboratory for Atmospheric and Space Physics (LASP).
The required tabs are ``Subsystem``, ``Packets``, and whatever packet names you have.

Subsystem tab
~~~~~~~~~~~~~

The ``Subsystem`` tab is used to define the instrument name and last updated date of the packet data.

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

* - infoField
- infoValue
* - subsystem
- MY_INSTRUMENT
* - sheetReleaseDate
- 01/01/2010
* - sheetReleaseRev
- 1.2.3

Packets tab
~~~~~~~~~~~

The packets tab contains the list of packets that you want to include within your XTCE
packet definition. You can remove rows from this to control which individual packet tabs
are read in later. The ``packetName`` column defines which other tabs to read in. So in
the following table, the generator will read in the ``MY_INSTRUMENT_HK`` and
``MY_INSTRUMENT_SCI`` tabs that contain the packet definitions.

.. note::
The generator will also work with tabs prefixed with ``P_``, so ``P_MY_INSTRUMENT_HK`` and
``P_MY_INSTRUMENT_SCI`` tab names would also work.

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

* - packetName
- apId
* - MY_INSTRUMENT_HK
- 123
* - MY_INSTRUMENT_SCI
- 124

Individual packet tabs
~~~~~~~~~~~~~~~~~~~~~~

Each packet tab contains the contents that will create the XTCE packet definition.
The required columns are ``packetName``, ``mnemonic``, ``lengthInBits``, ``dataType``,
``convertAs``, with optional ``shortDescription`` and ``longDescription`` columns.

Within the XTCE definition, the variable names will be ``packetName.mnemonic`` separated
with a period for easier distinguishing between packets and variables. For example,
the table below would have this XTCE parameter definition ``MY_INSTRUMENT_HK.VARIABLE1_UINT``
for the first variable. If an analog conversion is required, the ``convertAs`` column
should be set to ``ANALOG``, which will then look at the ``AnalogConversions`` tab for
the conversion details.

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

* - packetName
- mnemonic
- lengthInBits
- dataType
- convertAs
- shortDescription
- longDescription
* - MY_INSTRUMENT_HK
- VARIABLE1_UINT
- 3
- UINT
- NONE
- My short variable description
- My verbose variable description
* - MY_INSTRUMENT_HK
- VARIABLE2_CONVERTED
- 3
- UINT
- ANALOG
- Apply an analog conversion
-
* - MY_INSTRUMENT_HK
- VARIABLE_LENGTH_BINARY_SCIENCE
- 100
- BYTE
- NONE
-
- This variable size will be dynamic and based on the packet size

AnalogConversions tab (optional)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Packet parsing can also apply analog conversions to the data being read in.
For example, to change from a raw unsigned integer value to a temperature in Kelvin.
The ``AnalogConversions`` tab is used to define these conversions.
It currently only supports unsegmented polynomial conversions, and looks for the
coefficients defined from ``c0`` to ``c7`` to define the order of the polynomial.

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

* - packetName
- mnemonic
- c0
- c1
- c2
- c3
- c4
- c5
- c6
- c7
* - MY_INSTRUMENT_HK
- VARIABLE2_CONVERTED
- 123.456
- 0.234
-
-
-
-
-
-
3 changes: 3 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
(r"py:.*", r".*InitVar*"),
(r"py:.*", r".*.glows.utils.constants.TimeTuple.*"),
(r"py:.*", r".*glows.utils.constants.DirectEvent.*"),
(r"py:.*", r".*numpy.int.*"),
(r"py:.*", r".*np.ndarray.*"),
(r"py:.*", r".*numpy._typing._array_like._ScalarType_co.*"),
]

# Ignore the inherited members from the <instrument>APID IntEnum class
Expand Down
18 changes: 16 additions & 2 deletions docs/source/data-access-api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ The SDC provides a REST API that allows users to upload and download files, as
well as query for file metadata. The following documentation describes the
various endpoints that are supported and how to use them.

The API can be accessed from the following URL: https://api.dev.imap-mission.com

*Note: Several sections and links begin with* [WIP]. *As development on the API is ongoing, this indicates
that the full implementation of the functionality is yet to be completed.*

The API can be accessed from the following URL [WIP]: https://api.dev.imap-mission.com

.. openapi:: openapi.yml
:group:
:include: /upload

When uploading files to the API, ensure these files are stored properly in a ``data`` directory. Then,
ensure your working directory is one level above the ``data`` directory in order to properly upload files.

[WIP] Certain ancillary files can also be uploaded to the API. For more specific information regarding these files, visit
`Ancillary Files <https://imap-processing.readthedocs.io/en/latest/data-access-api/calibration-files.html>`_

**Example Usage:**

.. code-block:: bash
Expand All @@ -45,6 +52,13 @@ The API can be accessed from the following URL: https://api.dev.imap-mission.com
:group:
:include: /download

It is important to note that your working directory will be established as the default directory. I.e, the ``data``
directory--which files are downloaded to--will automatically be placed in this file path. Choose your working directory
accordingly to suit your desires.

When downloading a file from the API, different folders within the ``data`` directory will be made to better
organize the files. See the example file path: ``data/imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_20240105_v00-01.pkts``

**Example Usage:**

.. code-block:: bash
Expand Down
4 changes: 3 additions & 1 deletion docs/source/data-access-api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ paths:
items:
type: string


'/download/{filepath}':
get:
tags:
Expand Down Expand Up @@ -143,7 +144,8 @@ paths:
type: string
- in: query
name: version
description: The version of data product in the format ``vXX-YY`` (e.g. ``v01-01``).
description: The version of data product in the format ``vNNN`` (e.g. ``v001``). You can also choose to
query ``--version latest`` in order to receive the most recent version of a file.
required: false
schema:
type: string
Expand Down
14 changes: 14 additions & 0 deletions imap_processing/cdf/config/imap_codice_global_cdf_attrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ imap_codice_l1a_hi_sectored:
Logical_source: imap_codice_l1a_hi-sectored
Logical_source_description: IMAP Mission CoDICE Hi Level-1A Sectored Data.

imap_codice_l1a_hi_pha:
<<: *instrument_base
Data_level: 1A
Data_type: L1A_hi-pha->Level-1A Hi Event Data
Logical_source: imap_codice_l1a_hi-pha
Logical_source_description: IMAP Mission CoDICE Hi Level-1A Event Data.

imap_codice_l1a_lo_counters_aggregated:
<<: *instrument_base
Data_level: 1A
Expand Down Expand Up @@ -105,6 +112,13 @@ imap_codice_l1a_lo_nsw_species:
Logical_source: imap_codice_l1a_lo-nsw-species
Logical_source_description: IMAP Mission CoDICE Lo Level-1A Non-Sunward Species Counts Data.

imap_codice_l1a_lo_pha:
<<: *instrument_base
Data_level: 1A
Data_type: L1A_lo-pha->Level-1A Lo Event Data
Logical_source: imap_codice_l1a_lo-pha
Logical_source_description: IMAP Mission CoDICE Lo Level-1A Event Data.

# L1b
imap_codice_l1b_hskp:
<<: *instrument_base
Expand Down
Loading

0 comments on commit 75240fd

Please sign in to comment.