swarmpal.toolboxes.tfa.processes
================================

.. py:module:: swarmpal.toolboxes.tfa.processes


Attributes
----------

.. autoapisummary::

   swarmpal.toolboxes.tfa.processes.FLAG_THRESHOLDS


Classes
-------

.. autoapisummary::

   swarmpal.toolboxes.tfa.processes.Preprocess
   swarmpal.toolboxes.tfa.processes.Clean
   swarmpal.toolboxes.tfa.processes.Filter
   swarmpal.toolboxes.tfa.processes.Wavelet
   swarmpal.toolboxes.tfa.processes.WaveDetection


Functions
---------

.. autoapisummary::

   swarmpal.toolboxes.tfa.processes._get_tfa_active_subtree
   swarmpal.toolboxes.tfa.processes._get_sampling_rate


Module Contents
---------------

.. py:data:: FLAG_THRESHOLDS

.. py:class:: Preprocess(config: dict | None = None, active_tree: str = '/', inplace: bool = True)

   Bases: :py:obj:`swarmpal.io.PalProcess`


   Prepare data for input to other TFA tools


   .. py:property:: process_name
      :type: str



   .. py:method:: 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

      Set the process configuration

      :param dataset: Selects this dataset from the datatree
      :type dataset: str
      :param timevar: Identifies the name of the time variable, usually "Timestamp" or "Time"
      :type timevar: str
      :param active_variable: Selects the variable to use from within the dataset
      :type active_variable: str
      :param active_component: Selects the component to use (if active_variable is a vector)
      :type active_component: int, optional
      :param sampling_rate: Identify the sampling rate of the data input (in Hz), by default 1
      :type sampling_rate: float, optional
      :param remove_model: Remove a magnetic model prediction or not, by default False
      :type remove_model: bool, optional
      :param model: The name of the model
      :type model: str, optional
      :param convert_to_mfa: Rotate B to mean-field aligned (MFA) coordinates, by default False
      :type convert_to_mfa: bool, optional
      :param use_magnitude: Use the magnitude of a vector instead, by default False
      :type use_magnitude: bool, optional
      :param clean_by_flags: Whether to apply additional flag cleaning or not, by default False
      :type clean_by_flags: bool, optional
      :param flagclean_varname: Name of the variable to clean
      :type flagclean_varname: str, optional
      :param flagclean_flagname: Name of the flag to use to clean by
      :type flagclean_flagname: str, optional
      :param flagclean_maxval: Maximum allowable flag value
      :type flagclean_maxval: int, optional
      :param output_dataset: Sets the name of the dataset in the data tree that TFA processes will write results to, by default "PAL_TFA"
      :type output_dataset: str

      .. rubric:: 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.



   .. py:property:: active_variable


   .. py:property:: active_component


   .. py:method:: _call(datatree: xarray.DataTree) -> xarray.DataTree


   .. py:method:: _validate_inputs(datatree)

      Some checks that the inputs and config are valid



   .. py:method:: _prep_magnetic_data(ds: xarray.Dataset) -> xarray.Dataset

      Subtract model and/or rotate to MFA



   .. py:method:: _prep_efi_expt_data(ds: xarray.Dataset) -> xarray.Dataset

      Assign the Eh_XYZ or Ev_XYZ vector data variable



   .. py:method:: _flag_cleaning(ds)

      Set values to NaN where flags exceed a threshold



   .. py:method:: _constant_cadence(da)

      Convert array to that of constant cadence



.. py:function:: _get_tfa_active_subtree(datatree, output_dataset)

   Returns the relevant subtree when Preprocess has been applied


.. py:function:: _get_sampling_rate(datatree, output_dataset)

   Get the sampling rate set by Preprocess


.. py:class:: Clean(config: dict | None = None, active_tree: str = '/', inplace: bool = True)

   Bases: :py:obj:`swarmpal.io.PalProcess`


   Clean TFA_Variable by removing outliers and interpolate gaps


   .. py:property:: process_name
      :type: str



   .. py:method:: set_config(window_size: int = 10, method: str = 'iqr', multiplier: float = 0.5, output_dataset: str = 'PAL_TFA') -> None

      Set the process configuration

      :param window_size: The size (number of points) of the rolling window, by default 10
      :type window_size: int, optional
      :param method: "normal" or "iqr", by default "iqr"
      :type method: str, optional
      :param multiplier: Indicates the spread of the zone of accepted values, by default 0.5
      :type multiplier: float, optional
      :param output_dataset: Sets the name of the dataset in the data tree that TFA processes will write results to, by default "PAL_TFA"
      :type output_dataset: str



   .. py:method:: _call(datatree) -> xarray.DataTree


   .. py:method:: _clean_variable(target_var) -> xarray.DataArray


.. py:class:: Filter(config: dict | None = None, active_tree: str = '/', inplace: bool = True)

   Bases: :py:obj:`swarmpal.io.PalProcess`


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


   .. py:property:: process_name
      :type: str



   .. py:method:: set_config(cutoff_frequency: float = 20 / 1000, output_dataset: str = 'PAL_TFA') -> None

      Set the process configuration

      :param cutoff_frequency: The cutoff frequency (in Hz), by default 20/1000
      :type cutoff_frequency: float, optional
      :param output_dataset: Sets the name of the dataset in the data tree that TFA processes will write results to, by default "PAL_TFA"
      :type output_dataset: str



   .. py:method:: _call(datatree) -> xarray.DataTree


   .. py:method:: _filter(target_var, sampling_rate) -> xarray.DataArray


.. py:class:: Wavelet(config: dict | None = None, active_tree: str = '/', inplace: bool = True)

   Bases: :py:obj:`swarmpal.io.PalProcess`


   Apply wavelet analysis


   .. py:property:: process_name
      :type: str



   .. py:method:: 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

      Set the process configuration

      :param min_frequency: _description_, by default None
      :type min_frequency: float | None, optional
      :param max_frequency: _description_, by default None
      :type max_frequency: float | None, optional
      :param min_scale: _description_, by default None
      :type min_scale: float | None, optional
      :param max_scale: _description_, by default None
      :type max_scale: float | None, optional
      :param dj: _description_, by default 0.1
      :type dj: float, optional
      :param output_dataset: Sets the name of the dataset in the data tree that TFA processes will write results to, by default "PAL_TFA"
      :type output_dataset: str



   .. py:method:: _call(datatree: xarray.DataTree) -> xarray.DataTree


   .. py:method:: _configure(datatree)


   .. py:method:: _wavelets(target_var: xarray.DataArray)


.. py:class:: WaveDetection(config: dict | None = None, active_tree: str = '/', inplace: bool = True)

   Bases: :py:obj:`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.


   .. py:property:: process_name
      :type: str



   .. py:method:: set_config()


   .. py:method:: _call(datatree)
      :abstractmethod:



   .. py:method:: _attach_ibi()


