Analysis of Swarm HR data (50 Hz sampling rate)#

Imports:

import datetime as dt
import swarmpal.toolboxes.tfa.tfa_processor as tfa

Provide values for the parameters of the analysis. The dataset can be chosen from one of the compatible magnetic data collections, and the var is a VirES-compatible variable string (see viresclient for more information). The “start” and “end” times must be given as a datetime object. If the data are required as they are, set the remove_chaos_model parameter to False. Otherwise, if the inputs are magnetic field data and the analysis requires subtraction of the model field, set the parameter to True. For the HR product, remember to set the sampling_time to 0.02 seconds, i.e. 50 Hz rate.

dataset = "SW_OPER_MAGB_HR_1B"
series_dt = "PT0.02S"
var = "B_NEC"
remove_chaos_model = True
time_start = dt.datetime(2015, 3, 14, 12, 5, 0)
time_end = dt.datetime(2015, 3, 14, 12, 30, 0)

Now run the TfaInput to retrieve the selected data.

inputs = tfa.TfaInput(
    collection=dataset,
    start_time=time_start,
    end_time=time_end,
    initialise=True,
    varname=var,
    sampling_time=series_dt,
    remove_chaos=remove_chaos_model,
)

We can now use the full arsenal of functions to perform pre-processing of the data. If the selected variable is in vector form, we can convert it to its magnitude using the calculate_magnitude() function. This will generate a new variable named simply B .

inputs.flag_cleaning()
inputs.subtract_chaos()
inputs.calculate_magnitude()

Now that the model field has been removed and the transformation has been performed, we can proceed to for Wavelet processing by initiating the TfaProcessor object and specifying the name of the variable.

processor = tfa.TfaProcessor(inputs, active_variable={"varname": "B"})
processor.plotX()
../../_images/430c79266c0bb39e96e87853a438d49d48cd7d74485077420383be32689720d6.png

To perform cleaning on the data, we initialize a Cleaning object with the parameters of our choice and then apply it on the data with the TfaProcessor apply() function. The active variable series can be plotted by means of the plotX() function.

c = tfa.Cleaning({"Window_Size": 300, "Method": "iqr", "Multiplier": 1})
processor.apply(c)
processor.plotX()
../../_images/7184e51c5c3275891f92f4421b01bb27e758435f60daa1dc9eb7f04c3c869edd.png

Similarly, the filtering can be performed by first initializing a Filtering object with the parameters of our choosing and the applying in on the data.

f = tfa.Filtering({"Cutoff_Frequency": 0.1})
processor.apply(f)
processor.plotX()
../../_images/3a7fec9ac739e3ce6e11d3ea73bd1b87f78073c7bd94d06ac9a72571d5f2adc4.png

In the same way, the wavelet transform is applied. The result of the wavelet can be visualized by means of the image() function

w = tfa.Wavelet(
    {
        "Min_Frequency": 1,
        "Max_Frequency": 25,
        "dj": 0.1,
    }
)
processor.apply(w)
processor.image(cbar_lims=[-6, -3])
../../_images/d559260477f570e18ef6d118468b969e41d96313004831e5d4f27e617a80b565.png