swarmpal.toolboxes.tfa.processes#

Attributes#

Classes#

Preprocess

Prepare data for input to other TFA tools

Clean

Clean TFA_Variable by removing outliers and interpolate gaps

Filter

High-pass filter the TFA_Variable, using the SciPy Chebysev Type II filter

Wavelet

Apply wavelet analysis

WaveDetection

Screen out potential false waves

Functions#

_get_tfa_active_subtree(datatree, output_dataset)

Returns the relevant subtree when Preprocess has been applied

_get_sampling_rate(datatree, output_dataset)

Get the sampling rate set by Preprocess

Module Contents#

swarmpal.toolboxes.tfa.processes.FLAG_THRESHOLDS#
class swarmpal.toolboxes.tfa.processes.Preprocess(config: dict | None = None, active_tree: str = '/', inplace: bool = True)[source]#

Bases: swarmpal.io.PalProcess

Prepare data for input to other TFA tools

property process_name: str#
set_config(dataset: str = '', timevar: str = 'Timestamp', active_variable: str = '', active_component: int | None = None, sampling_rate: float = 1, remove_model: bool = False, model: str = '', convert_to_mfa: bool = False, use_magnitude: bool = False, clean_by_flags: bool = False, flagclean_varname: str = '', flagclean_flagname: str = '', flagclean_maxval: int | None = None, output_dataset: str = 'PAL_TFA') None[source]#

Set the process configuration

Parameters:
  • dataset (str) – Selects this dataset from the datatree

  • timevar (str) – Identifies the name of the time variable, usually “Timestamp” or “Time”

  • active_variable (str) – Selects the variable to use from within the dataset

  • active_component (int, optional) – Selects the component to use (if active_variable is a vector)

  • sampling_rate (float, optional) – Identify the sampling rate of the data input (in Hz), by default 1

  • remove_model (bool, optional) – Remove a magnetic model prediction or not, by default False

  • model (str, optional) – The name of the model

  • convert_to_mfa (bool, optional) – Rotate B to mean-field aligned (MFA) coordinates, by default False

  • use_magnitude (bool, optional) – Use the magnitude of a vector instead, by default False

  • clean_by_flags (bool, optional) – Whether to apply additional flag cleaning or not, by default False

  • flagclean_varname (str, optional) – Name of the variable to clean

  • flagclean_flagname (str, optional) – Name of the flag to use to clean by

  • flagclean_maxval (int, optional) – Maximum allowable flag value

  • output_dataset (str) – Sets the name of the dataset in the data tree that TFA processes will write results to, by default “PAL_TFA”

Notes

Some special active_variable names exist which are added to the dataset on-the-fly:

  • “B_NEC_res_Model”

    where a model prediction must be available in the data, like "B_NEC_<Model>", and remove_model has been set. The name of the model can be set with, for example, model="CHAOS".

  • “B_MFA”

    when convert_to_mfa has been set.

  • “Eh_XYZ” and “Ev_XYZ”

    when using the TCT datasets, with vectors defined in ("Ehx", "Ehy", "Ehz") and ("Evx", "Evy", "Evz") respectively.

property active_variable#
property active_component#
_call(datatree: xarray.DataTree) xarray.DataTree[source]#
_validate_inputs(datatree)[source]#

Some checks that the inputs and config are valid

_prep_magnetic_data(ds: xarray.Dataset) xarray.Dataset[source]#

Subtract model and/or rotate to MFA

_prep_efi_expt_data(ds: xarray.Dataset) xarray.Dataset[source]#

Assign the Eh_XYZ or Ev_XYZ vector data variable

_flag_cleaning(ds)[source]#

Set values to NaN where flags exceed a threshold

_constant_cadence(da)[source]#

Convert array to that of constant cadence

swarmpal.toolboxes.tfa.processes._get_tfa_active_subtree(datatree, output_dataset)[source]#

Returns the relevant subtree when Preprocess has been applied

swarmpal.toolboxes.tfa.processes._get_sampling_rate(datatree, output_dataset)[source]#

Get the sampling rate set by Preprocess

class swarmpal.toolboxes.tfa.processes.Clean(config: dict | None = None, active_tree: str = '/', inplace: bool = True)[source]#

Bases: swarmpal.io.PalProcess

Clean TFA_Variable by removing outliers and interpolate gaps

property process_name: str#
set_config(window_size: int = 10, method: str = 'iqr', multiplier: float = 0.5, output_dataset: str = 'PAL_TFA') None[source]#

Set the process configuration

Parameters:
  • window_size (int, optional) – The size (number of points) of the rolling window, by default 10

  • method (str, optional) – “normal” or “iqr”, by default “iqr”

  • multiplier (float, optional) – Indicates the spread of the zone of accepted values, by default 0.5

  • output_dataset (str) – Sets the name of the dataset in the data tree that TFA processes will write results to, by default “PAL_TFA”

_call(datatree) xarray.DataTree[source]#
_clean_variable(target_var) xarray.DataArray[source]#
class swarmpal.toolboxes.tfa.processes.Filter(config: dict | None = None, active_tree: str = '/', inplace: bool = True)[source]#

Bases: swarmpal.io.PalProcess

High-pass filter the TFA_Variable, using the SciPy Chebysev Type II filter

property process_name: str#
set_config(cutoff_frequency: float = 20 / 1000, output_dataset: str = 'PAL_TFA') None[source]#

Set the process configuration

Parameters:
  • cutoff_frequency (float, optional) – The cutoff frequency (in Hz), by default 20/1000

  • output_dataset (str) – Sets the name of the dataset in the data tree that TFA processes will write results to, by default “PAL_TFA”

_call(datatree) xarray.DataTree[source]#
_filter(target_var, sampling_rate) xarray.DataArray[source]#
class swarmpal.toolboxes.tfa.processes.Wavelet(config: dict | None = None, active_tree: str = '/', inplace: bool = True)[source]#

Bases: swarmpal.io.PalProcess

Apply wavelet analysis

property process_name: str#
set_config(min_frequency: float | None = None, max_frequency: float | None = None, min_scale: float | None = None, max_scale: float | None = None, dj: float = 0.1, output_dataset: str = 'PAL_TFA') None[source]#

Set the process configuration

Parameters:
  • min_frequency (float | None, optional) – _description_, by default None

  • max_frequency (float | None, optional) – _description_, by default None

  • min_scale (float | None, optional) – _description_, by default None

  • max_scale (float | None, optional) – _description_, by default None

  • dj (float, optional) – _description_, by default 0.1

  • output_dataset (str) – Sets the name of the dataset in the data tree that TFA processes will write results to, by default “PAL_TFA”

_call(datatree: xarray.DataTree) xarray.DataTree[source]#
_configure(datatree)[source]#
_wavelets(target_var: xarray.DataArray)[source]#
class swarmpal.toolboxes.tfa.processes.WaveDetection(config: dict | None = None, active_tree: str = '/', inplace: bool = True)[source]#

Bases: swarmpal.io.PalProcess

Screen out potential false waves

Removes part of the wavelet spectrum that might be due to spikes, data gaps, ESFs or trailing parts of wave activity from either above or below the range of frequencies that were used to perform the wavelet transform.

property process_name: str#
set_config()[source]#
abstractmethod _call(datatree)[source]#
_attach_ibi()[source]#