Skip to content

SWAPI: add L3A alpha and proton velocity vectors in GSE, GSM, and HAE-J2000 coordinates - #165

Open
leowerneck wants to merge 7 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:lw/issue21
Open

SWAPI: add L3A alpha and proton velocity vectors in GSE, GSM, and HAE-J2000 coordinates#165
leowerneck wants to merge 7 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:lw/issue21

Conversation

@leowerneck

Copy link
Copy Markdown
Collaborator

Change Summary

Closes #21

Overview

Add SWAPI L3A proton and alpha velocity vectors, covariance matrices, and uncertainties in GSE, GSM, and HAE-J2000 coordinates.

File changes

  • Add generic RTN vector and covariance transformations using SPICE frames.
  • Generate all target-frame products for proton and alpha processing.
  • Add the corresponding CDF models, metadata, labels, and documentation.
  • Extend existing tests and add one focused transformation test.

Testing

  • 32 affected unit tests pass.
  • SPICE-backed integration tests were not run because usable Git LFS kernel files are unavailable locally.

@leowerneck
leowerneck requested a review from jtniehof August 18, 2026 15:06
@leowerneck leowerneck self-assigned this Aug 18, 2026
@leowerneck

leowerneck commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

@jtniehof @hafarooki — Could you please review if this is the intended approach? I followed @hafarooki's suggestion and rotated the alpha and proton velocity vectors from the RTN frame. For now, I focused on adding these only to SWAPI.

Comment thread imap_l3_processing/swapi/l3a/utils.py

@hafarooki hafarooki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some minor things: a comment would help in the code for the einsum. And the test cases should perhaps flip around signs and axes instead of added 300 to all components…

@hafarooki

Copy link
Copy Markdown
Contributor

@jtniehof requested for review of metadata aspects

@leowerneck

leowerneck commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

Looks good. Some minor things: a comment would help in the code for the einsum. And the test cases should perhaps flip around signs and axes instead of added 300 to all components…

@hafarooki That's a good point. I updated the tests to add rotations.

@leowerneck leowerneck added Data Release 2 Deadline: September 1, 2026 Ins: SWAPI Related to the SWAPI instrument enhancement New feature or request labels Aug 19, 2026
@leowerneck
leowerneck requested a balanced review from Copilot August 19, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds SWAPI L3A proton and alpha velocity products in GSE, GSM, and HAE-J2000 coordinates.

Changes:

  • Adds SPICE-based vector and covariance transformations.
  • Extends CDF models, metadata, labels, and documentation.
  • Updates processor and model tests for new products.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
imap_l3_processing/swapi/swapi_processor.py Generates target-frame products.
imap_l3_processing/swapi/l3a/utils.py Implements coordinate transformations.
imap_l3_processing/swapi/l3a/models.py Exposes new CDF variables and labels.
imap_l3_processing/cdf/config/imap_swapi_l3a_variable_attrs.yaml Defines variable metadata.
docs/swapi/proton-sw.md Documents proton outputs.
docs/swapi/alpha-sw.md Documents alpha outputs.
tests/test_utils.py Updates model fixtures.
tests/swapi/test_swapi_processor.py Tests processor integration.
tests/swapi/l3a/test_utils.py Tests transformation mathematics.
tests/swapi/l3a/test_models.py Tests new model variables.
tests/swapi/l3a/test_chunk_fits.py Isolates target-frame processing in existing tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread imap_l3_processing/swapi/swapi_processor.py Outdated
Comment thread docs/swapi/proton-sw.md
Comment thread docs/swapi/alpha-sw.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

imap_l3_processing/swapi/swapi_processor.py:68

  • Each call computes TT-to-ET and the same RTN-to-target rotation matrix, and this function repeats that work for the Sun-relative vector and covariance at every epoch and frame. That causes three SPICE frame lookups per output frame per record. Compute the rotation once per epoch/frame (or batch a frame and fall back per epoch only on a SPICE coverage error), then apply it to both vectors and the covariance.
    velocity = convert_velocity_rtn_to_frame(
        epoch_slice,
        result[f"{prefix}_rtn"][index : index + 1],
        target_frame,
    )[0]

Comment thread imap_l3_processing/swapi/swapi_processor.py Outdated
@leowerneck
leowerneck requested a balanced review from Copilot August 20, 2026 13:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Suppressed comments (1)

imap_l3_processing/swapi/swapi_processor.py:65

  • Each epoch/frame computes the same timestamp conversion and SPICE rotation three times: once for each velocity and once for the covariance. At the one-minute product cadence, this adds 9 SPICE rotations per record (12,960 per day/product) although only 3 unique rotations are needed. Compute one rotation matrix per epoch/frame and apply it to both vectors and the covariance, or pass that matrix into the conversion helpers.
    velocity = convert_velocity_rtn_to_frame(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Data Release 2 Deadline: September 1, 2026 enhancement New feature or request Ins: SWAPI Related to the SWAPI instrument

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SWAPI: All vectors / tensors in multiple frames (Phase D deferred)

3 participants