The timesignal
module
A module for time signal handling
Warning
This module is not considered finalized even though it is part of pylife-2.0. Breaking changes might occur in upcoming minor releases.
- class pylife.stress.timesignal.TimeSignalGenerator(sample_rate, sine_set, gauss_set, log_gauss_set)[source]
Generates mixed time signals
The generated time signal is a mixture of random sets of sinus signals
For each set the user supplys a dict describing the set:
sinus_set = { 'number': number of signals 'amplitude_median': 'amplitude_std_dev': 'frequency_median': 'frequency_std_dev': 'offset_median': 'offset_std_dev': }
The amplitudes (\(A\)), fequencies (\(\omega\)) and offsets (\(c\)) are then norm distributed. Each sinus signal looks like
\(s = A \sin(\omega t + \phi) + c\)
where \(phi\) is a random value between 0 and \(2\pi\).
So the whole sinus \(S\) set is given by the following expression:
\(S = \sum^n_i A_i \sin(\omega_i t + \phi_i) + c_i\).
- query(sample_num)[source]
Gets a sample chunk of the time signal
- Parameters:
sample_num (int) – number of the samples requested
- Returns:
samples – the requested samples
- Return type:
1D numpy.ndarray
You can query multiple times, the newly delivered samples will smoothly attach to the previously queried ones.
- pylife.stress.timesignal.butter_bandpass(df, lowcut, highcut, order=5)[source]
Use the functonality of scipy
- pylife.stress.timesignal.clean_timeseries(df, comparison_column, window_size=1000, overlap=800, feature='abs_energy', method='keep', n_gridpoints=3, percentage_max=0.05, order=3)[source]
Removes segments of the data in which the extracted feature value is lower as percentage_max and fills the gaps with polynomial regression
- Parameters:
df (input pandas DataFrame that shall be cleaned) –
comparison_column (str, column that is used for the feature) – comparison with percentage max
window_size (int, optional) – window size of the rolled segments - The default is 1000.
overlap (int, optional) – overlap between 2 adjecent windows -The default is 200.
feature (string, optional) – extracted feature - only supports one at a time - and only features form tsfresh that dont need extra parameters. The default is “maximum”.
method (string, optional) –
‘keep’: keeps the windows which are extracted,
’remove’: removes the windows which are extracted
n_gridpoints (TYPE, optional) – number of gridpoints. The default is 3.
percentage_max (float, optional) – min percentage of the maximum to keep the window. The default is 0.05.
order (int, optional) – order of polynom The default is 3.
- Returns:
df_poly – cleaned DataFrame
- Return type:
pandas DataFrame
- pylife.stress.timesignal.fs_calc(df)[source]
Calculates the sample frequency of a DataFrame time series