Converting in-situ solar wind data to Heliographic Carrington

Hi,

I’m trying to convert solar wind data (position, velocity, magnetic field) from satellites such as ACE and Parker Solar Probe to Heliographic Carrington Coordinates. I’m having trouble dealing with the velocity and magnetic field transforms.

For ACE, I’m using the AC_H2_SWE dataset and taking the GSE S/C position vectors and the V_GSE plasma velocity vectors. I retrieve the data using the cdaws library and store position and velocity in arrays p and v respectively. The code below runs and the radial velocity component ends up about the same as the radial component of the V_RTN data also in the dataset. Though I’m not entirely confident whether the observer should be “sun” or “self”.

vdiff = CartesianDifferential(v, xyz_axis=1)
coord = SkyCoord(
            CartesianRepresentation(p, xyz_axis=1, differentials=vdiff),
            obstime=self.raw["Epoch"].values,
            frame=frames.GeocentricSolarEcliptic
           )
        coord = coord.transform_to(frames.HeliographicCarrington(observer="sun"))

For the magnetic field, I use the AC_H2_MFI dataset which provides magnetic field vectors in GSM and GSE coordinates. I’m struggling to find a clean method in sunpy to rotate these vectors to the HGC frame. The skycoord method doesn’t seem to work since it’s meant for position vectors. Even still, I tried it by changing the B vector units to meters and the observer in the carrington frame to ‘self’ to try and avoid any translation. With the GSM data, the code raises an error:

ValueError                                Traceback (most recent call last)
Cell In[38], line 1
----> 1 coord = coord.transform_to(
      2     frames.HeliographicCarrington(observer='sun', obstime=data['Epoch'].values)
      3 )  # no origin shift for B vector

File ~/Documents/PyDaHelioPrep/.venv/lib/python3.10/site-packages/astropy/coordinates/sky_coordinate.py:722, in SkyCoord.transform_to(self, frame, merge_attributes)
    718 generic_frame = GenericFrame(frame_kwargs)
    720 # Do the transformation, returning a coordinate frame of the desired
    721 # final type (not generic).
--> 722 new_coord = trans(self.frame, generic_frame)
    724 # Finally make the new SkyCoord object from the `new_coord` and
    725 # remaining frame_kwargs that are not frame_attributes in `new_coord`.
    726 for attr in set(new_coord.frame_attributes) & set(frame_kwargs.keys()):

File ~/Documents/PyDaHelioPrep/.venv/lib/python3.10/site-packages/astropy/coordinates/transformations/composite.py:113, in CompositeTransform.__call__(self, fromcoord, toframe)
    110             frattrs[inter_frame_attr_nm] = attr
    112     curr_toframe = t.tosys(**frattrs)
--> 113     curr_coord = t(curr_coord, curr_toframe)
    115 # this is safe even in the case where self.transforms is empty, because
    116 # coordinate objects are immutable, so copying is not needed
    117 return curr_coord

File ~/Documents/.venv/lib/python3.10/site-packages/astropy/coordinates/transformations/function.py:175, in FunctionTransformWithFiniteDifference.__call__(self, fromcoord, toframe)
...
    815     raise ValueError
    817 if decimalyear <= years[-1]:
    818     # Use piecewise linear interpolation before the last year

With the GSE magnetic field data, the code runs, but produces Br values of order 10^{11} nT which doesn’t seem right. I saw an Issue on the sunpy github about converting magnetic field vectors with the provided solution using the spice module to generate a rotation matrix between frames. However, I have not able to find the heliographic Carrington frame in spice.

Apart from this, I also want to be able to use the PSP_COHO1HR_MERGED_MAG_PLASMA dataset from the Parker Solar Probe which provides [inertial] RTN data for velocities and magnetic fields. Based on this User Guide for SWEAP Data Products , it seems the inertial RTN velocity data will account for spacecraft motion.

From this, would it be correct to take velocities in the RTN frame to correspond to radial, tangential (along latitudes), and azimuthal (along longitudes) on a sun-centered non-rotating frame like HEEQ? To convert to HGC I would then have to factor in the angular velocity due to the rotation of the axes. For magnetic fields, I think I run into the same problem as before, since I’m having trouble rotating vectors between sunny frames.

Thanks