Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to transform in-situ magnetic field vector components from one reference frame representation to another #7389

Open
Zoe-F opened this issue Jan 18, 2024 · 4 comments
Labels
coordinates Affects the coordinates submodule Effort Medium Requires a moderate time investment Feature Request New feature wanted! Package Intermediate Requires some knowledge of the internal structure of SunPy Priority Medium Non-urgent action required Solar Physics Knowledge This requires some basic understanding of solar physics

Comments

@Zoe-F
Copy link

Zoe-F commented Jan 18, 2024

Describe the feature

To compare timeseries from Solar Orbiter in-situ observations of magnetic field in the spacecraft's RTN reference frame to magnetic field observations in a different reference frame, you need to be able to convert the components of the magnetic field vector to a common reference frame.
The sunpy.coordinates.spice module has a method to transform position coordinates from one reference frame to another, but I can't find a method to transform the representation of a vector field in one coordinate frame to another.
For example, a vector $v = a_0 e_r + a_1 e_t + a_2 e_n$ in the basis $(e_r, e_t, e_n)$, can be equally represented by $v = b_0 e_x + b_1 e_y + b_2 e_z$ in the alternate basis $(e_x, e_y, e_z)$.
The feature I am requesting is a method to compute the change of basis matrix required to find the components $(b_0, b_1, b_2)$ given $(a_0, a_1, a_2)$ and the two frames defined in SPICE kernels.

Proposed solution

spiceypy's pxform method gives the change of basis matrix $M$ such that $b_j = M_{i,j} a_i$ from frames defined in loaded SPICE kernels. It would be good to integrate that functionality with the rest of the sunpy.coordinates.spice module, and frames defined therein.
What do people think? I'm happy to work on a way to implement this, if there is a wider need for it.

@hayesla
Copy link
Member

hayesla commented Jan 18, 2024

thanks for raising this issue @Zoe-F!

This would be great to have, as several people from the in-situ Solar Orbiter side have been asking to do this (e.g. transform the data from RTN to HEEQ to compare with other spacecraft etc).

I guess it would be something like

matrix = spiceypy.pxform("SOLO_SUN_RTN", "SOLO_HEEQ", spiceypy.str2et('2023-01-03'))
then just a matrix multiplication of the B RTN components?

Maybe @ayshih can comment.

Also I imaging it could be nice to envision something on timeseries (e.g. transform_to()) so that you could do such things for vector in situ data?

@nabobalis nabobalis added Feature Request New feature wanted! coordinates Affects the coordinates submodule Priority Medium Non-urgent action required Effort Medium Requires a moderate time investment Package Intermediate Requires some knowledge of the internal structure of SunPy Solar Physics Knowledge This requires some basic understanding of solar physics labels Jan 18, 2024
@aadya940
Copy link

Hello! I'm new to sunPy, I'm interested in implementing this function. From what I understand it should be something like:

import spiceypy as spice
import numpy as np

def get_basis_transformation(from_frame, to_frame, et):
    """
    Get the change of basis matrix from one frame to another at a specific time.

    Parameters
    ---------------
    from_frame : str
        Name of the frame to transform from.
    to_frame : str
        Name of the frame to transform to.
    et : float
        Ephemeris time at which to compute the transformation.

    Returns
    ----------
    ndarray
        The 3x3 change of basis matrix.
    """

    matrix, _ = spice.pxform(from_frame, to_frame, et)

    # Only Return the Rotation (Not Translation)
    return np.array(matrix[:3, :3])

The we use this matrix and apply a Linear Transformation which can be used in transform_to?

@ayshih
Copy link
Member

ayshih commented Feb 15, 2024

You may be new to SunPy, but hopefully you are not new to SPICE! Some terse comments:

  • For the from/to frames, the function should accept the SunPy version of the frames (either a string of the form spice_... or the actual frame class) rather than the SPICE string
  • For the transformation time, the function needs to be able to accept a "from" time and a "to" time, and if the "to" time is not provided, it can be assumed to be the same as the "from" time
  • For the transformation time, the function needs to accept any parse_time()-compatible specification of time rather than a float
  • The above also means supporting array time, which means that the SPICE function to call will be sxform() rather than pxform()

@aadya940
Copy link

Sounds Good! @ayshih . I'll keep these pointers in mind and submit a PR soon as a first step. Thanks though! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coordinates Affects the coordinates submodule Effort Medium Requires a moderate time investment Feature Request New feature wanted! Package Intermediate Requires some knowledge of the internal structure of SunPy Priority Medium Non-urgent action required Solar Physics Knowledge This requires some basic understanding of solar physics
Projects
None yet
Development

No branches or pull requests

5 participants