pyrfu.mms.rotate_tensor module#

pyrfu.mms.rotate_tensor.rotate_tensor(inp: DataArray, rot_flag: str, vec: DataArray | ndarray[tuple[int, ...], dtype[float32 | float64]] | Dataset, perp: str | None = 'pp', verbose: bool | None = False) DataArray[source]#

Rotates pressure or temperature tensor into another coordinate system.

Parameters:
  • inp (DataArray) – Time series of the tensor to rotate. The tensor must be given in the form of a 3x3 matrix, where the first index is the time index and the last two indices are the tensor indices.

  • rot_flag (str) –

    Flag of the target coordinates system :
    • ”fac”Field-aligned coordinates, requires background

      magnetic field Bback, optional flag “pp” \(\\mathbf{P}_{\\perp 1} = \\mathbf{P}_{\\perp2}\) or “qq” \(\\mathbf{P}_{\\perp 1}\) and \(\\mathbf{P}_{\\perp 2}\) are most unequal, sets P_{23} to zero.

    • ”rot”Arbitrary coordinate system, requires new x-direction

      xnew, new y and z directions ynew, znew (if not included y and z directions are orthogonal to xnew and closest to the original y and z directions)

    • ”gse” : GSE coordinates, requires MMS spacecraft attitude DEFATT.

    • ”gsm” : GSM coordinates, requires MMS spacecraft attitude DEFATT.

  • vec (DataArray or numpy.ndarray or xarray.Dataset) – Vector or coordinates system to rotate the tensor. If vec is time series of a vector tensor is rotated in field aligned coordinates. If vec is a numpy.ndarray rotates to a time independent coordinates system.

  • perp (str, Optional) –

    Flag for perpendicular components of the tensor. Default is pp.
    • ”pp” : perpendicular diagonal components are equal

    • ”qq” : perpendicular diagonal components are most unequal

  • verbose (bool, Optional) – Set to True to print additional information.

Returns:

Time series of the pressure or temperature tensor in field-aligned, user-defined, or GSE coordinates. For “fac” Pe = [Ppar P12 P13; P12 Pperp1 P23; P13 P23 Pperp2]. For “rot” and “gse” Pe = [Pxx Pxy Pxz; Pxy Pyy Pyz; Pxz Pyz Pzz]

Return type:

DataArray

Raises:
  • TypeError

    • If inp is not a xarray.DataArray.

    • If vec is not a xarray.DataArray, numpy.ndarray or xarray.Dataset.

    • If rot_flag is not a string.

    • If perp is not a string.

  • NotImplementedError

    • If rot_flag is not ‘fac’, ‘rot’, ‘gse’, or ‘gsm’.

    • If rot_flag is ‘rot’ and vec is time dependent.

Examples

>>> from pyrfu import mms, pyrf
>>> # Time interval
>>> tint = ["2015-10-30T05:15:20.000", "2015-10-30T05:16:20.000"]
>>> # Spacecraft index
>>> mms_id = 1
>>> # Load magnetic field and ion temperature tensor
>>> b_xyz = mms.get_data("B_gse_fgm_srvy_l2", tint, mms_id)
>>> t_xyz_i = mms.get_data("Ti_gse_fpi_fast_l2", tint, mms_id)
>>> # Compute ion temperature in field aligned coordinates
>>> t_xyzfac_i = mms.rotate_tensor(t_xyz_i, "fac", b_xyz, "pp")