Skip to content

Fold pitch angles and flux

el_paso.processing.fold_pitch_angles_and_flux

Classes

Functions:

el_paso.processing.fold_pitch_angles_and_flux.fold_pitch_angles_and_flux

fold_pitch_angles_and_flux

Folds pitch angles and corresponding flux values around 90 degrees.

This function modifies the input flux_var and pa_local_var in place by folding the pitch angle data and averaging the corresponding flux values around 90 degrees. It assumes that pitch angles are symmetric around 90 degrees.

Parameters:

Name Type Description Default
flux_var Variable

A Variable object containing the flux data. This object will be modified in place with the folded flux data. Expected to have a shape compatible with (time, energy_bins, pitch_angle_bins).

required
pa_local_var Variable

A Variable object containing the local pitch angle data. This object will be modified in place with the unique folded pitch angles in degrees. Expected to have a shape compatible with (time, pitch_angle_bins).

required
produce_statistic_plot bool

If True, a statistical plot related to the folding process will be produced. Defaults to False.

False

Raises:

Type Description
ValueError
  • If local pitch angles are found to change over time (they are assumed constant).
  • If the time dimensions of flux_var and pa_local_var do not match.
  • If the pitch angle dimension of flux_var does not match the second dimension of pa_local_var.
Source code in el_paso/processing/fold_pitch_angles_and_flux.py
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@timed_function()
def fold_pitch_angles_and_flux(
    flux_var: Variable, pa_local_var: Variable, *, produce_statistic_plot: bool = False
) -> None:
    """Folds pitch angles and corresponding flux values around 90 degrees.

    This function modifies the input `flux_var` and `pa_local_var` in place
    by folding the pitch angle data and averaging the corresponding flux values
    around 90 degrees. It assumes that pitch angles are symmetric around 90 degrees.

    Args:
        flux_var (Variable): A Variable object containing the flux data.
            This object will be modified in place with the folded flux data.
            Expected to have a shape compatible with (time, energy_bins, pitch_angle_bins).
        pa_local_var (Variable): A Variable object containing the local pitch angle data.
            This object will be modified in place with the unique folded pitch angles in degrees.
            Expected to have a shape compatible with (time, pitch_angle_bins).
        produce_statistic_plot (bool, optional): If True, a statistical plot
            related to the folding process will be produced. Defaults to False.

    Raises:
        ValueError:
            - If local pitch angles are found to change over time (they are assumed constant).
            - If the time dimensions of `flux_var` and `pa_local_var` do not match.
            - If the pitch angle dimension of `flux_var` does not match the
              second dimension of `pa_local_var`.
    """
    logger.info("Folding pitch angles and flux ...")

    flux = flux_var.get_data().astype(np.float64)
    pa_local = pa_local_var.get_data(u.deg).astype(np.float64)

    if np.all(np.repeat(pa_local[0, :][np.newaxis, :], pa_local.shape[0], axis=0) != pa_local):
        msg = "We assume that local pitch angles do not change in time!"
        raise ValueError(msg)

    if len(flux) != len(pa_local):
        msg = f"Size of time dimensions of flux ({len(flux)}) and local pitch angles ({len(pa_local)}) do not match!"
        raise ValueError(msg)

    if flux.shape[2] != pa_local.shape[1]:
        msg = f"Dimension mismatch: flux: {flux.shape}, pitch angle: {pa_local.shape}"
        raise ValueError(msg)

    folded_flux, unique_angles = _fold_pitch_angles_and_flux(
        pa_local, flux, produce_statistic_plot=produce_statistic_plot
    )

    flux_var.set_data(folded_flux, "same")
    flux_var.metadata.add_processing_note("Folded around 90 degrees local pitch angle")

    pa_local_var.set_data(unique_angles, u.deg)
    pa_local_var.metadata.add_processing_note("Folded around 90 degrees local pitch angle")