Skip to content

Create quality flag from magnetometer

el_paso.processing.create_quality_flag_from_magnetometer

Functions:

el_paso.processing.create_quality_flag_from_magnetometer.create_quality_flag_from_magnetometer

create_quality_flag_from_magnetometer

Compute a quality mask for magnetometer data using Bt.

The mask flags samples that are considered valid based on two criteria: 1. Magnetic field magnitude (Bt) must be positive. 2. Consecutive differences |ΔBt| must be below the spike threshold.

Parameters:

Name Type Description Default
bt_var Variable

Variable holding the total magnetic field.

required
threshold int

Spike detection threshold in nT. Defaults to 500.

500

Returns:

Type Description
Variable

ep.Variable: A boolean mask variable where True indicates valid data and

Variable

False indicates flagged samples.

Source code in el_paso/processing/create_quality_flag_from_magnetometer.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def create_quality_flag_from_magnetometer(bt_var: ep.Variable, threshold: int = 500) -> ep.Variable:
    """Compute a quality mask for magnetometer data using Bt.

    The mask flags samples that are considered valid based on two criteria:
    1. Magnetic field magnitude (Bt) must be positive.
    2. Consecutive differences |ΔBt| must be below the spike threshold.

    Args:
        bt_var (ep.Variable): Variable holding the total magnetic field.
        threshold (int, optional): Spike detection threshold in nT.
            Defaults to 500.

    Returns:
        ep.Variable: A boolean mask variable where ``True`` indicates valid data and
        ``False`` indicates flagged samples.
    """
    bt = bt_var.get_data(u.nT)

    mask_positive = bt > 0

    delta_b = np.diff(bt, prepend=bt[0])
    mask_spike = np.abs(delta_b) < threshold

    mask = ep.Variable(
        data=mask_positive & mask_spike,
        original_unit=u.dimensionless_unscaled,
    )

    return mask