dispel.signal.core module#
Core functionality for signal processing tasks.
- dispel.signal.core.assert_time_series_has_frequency(data)[source]#
Check whether a time series contains frequency as index.
- Parameters:
data (Series) –
- Return type:
None
- dispel.signal.core.autocorr(data)[source]#
Compute auto-correlation of a signal.
Uses cross-correlation with the same signal as input twice.
- Parameters:
data (ndarray[Any, dtype[float64]]) – A signal passed as an iterable of floats.
- Returns:
A Tuple containing temporal delays and auto-correlation array.
- Return type:
Tuple[numpy.ndarray, numpy.ndarray]
- dispel.signal.core.autocov(data)[source]#
Compute auto-covariance of a signal.
Uses autocovariance from as autocorrelation of demeaned signal.
- Parameters:
data (ndarray[Any, dtype[float64]]) – A signal passed as an iterable of floats.
- Returns:
A Tuple containing temporal delays and auto-covariance array.
- Return type:
Tuple[numpy.ndarray, numpy.ndarray]
- dispel.signal.core.compute_rotation_matrix_2d(origin, point, angle)[source]#
Compute a 2 dimension matrix rotation.
- dispel.signal.core.compute_rotation_matrix_3d(a, b)[source]#
Compute a rotation matrix from unit vector
a
onto unit vectorb
.- Parameters:
- Returns:
The rotation matrix from unit vector
a
onto unit vectorb
.- Return type:
- dispel.signal.core.cross_corr(data_1, data_2)[source]#
Compute cross-correlation between two signals.
Uses cross-correlation with the same signal as input twice.
- Parameters:
- Returns:
A Tuple containing temporal delays and auto-correlation array.
- Return type:
Tuple[numpy.ndarray, numpy.ndarray]
- dispel.signal.core.derive_time_data_frame(data)[source]#
Derive a data frame based on its time-based index.
This method is preferably used for data frames for which one wants to derive for each column (instead of using
data.apply(derive_time_series)
).- Parameters:
data (DataFrame) – The pandas data frame for which to derive the values based on time. The data frame must have a time-based index. See
index_time_diff()
.- Returns:
The time derivative of the values of
data
.- Return type:
- dispel.signal.core.derive_time_series(data)[source]#
Derive a series based on its time-based index.
- Parameters:
data (Series) – The series for which to derive the values based on time. The series must have a time-based index. See
index_time_diff()
.- Returns:
The time derivative of the values of
data
.- Return type:
- dispel.signal.core.discretize_sampling_frequency(data, fs_expected, max_frequency_distance=5)[source]#
Discretize the sampling frequency from a time series.
First we extract the median sampling frequency of data, then return the closest expected frequency if the estimated sampling frequency is close enough (
np.abs(fs_expected, fs_estimate) < 5
) to one of the expected sampling frequencies.- Parameters:
data (Series) – Any pandas series with a time series as index.
fs_expected (List[int]) – An iterable of expected sampling frequency in Hz.
max_frequency_distance (int) – An optional integer specifying the maximum accepted distance between the expected frequency and the estimated frequency above which we raise an error.
- Returns:
Discretized sampling frequency.
- Return type:
- Raises:
ValueError – If estimated sampling frequency is too far (abs distance > max_frequency_distance) from all the expected sampling frequency in
fs_expected
.
- dispel.signal.core.energy(power_spectrum_, lowcut=None, highcut=None)[source]#
Compute the energy of a signal.
- Parameters:
- Returns:
The signal’s energy.
- Return type:
- dispel.signal.core.euclidean_distance(point1, point2)[source]#
Calculate the euclidean distance between two points.
This particular algorithm is chosen based on question 37794849 on StackOverflow.
- dispel.signal.core.euclidean_norm(data)[source]#
Calculate the euclidean norm of a pandas Data Frame.
- Parameters:
data (DataFrame) – A pandas data frame for which to compute the euclidean norm
- Returns:
The euclidean norm of
data
- Return type:
- dispel.signal.core.extract_sampling_frequency(data)[source]#
Extract the median sampling frequency in Hz of a time series.
- Parameters:
data (Series) – Any pandas series with a time series as index.
- Returns:
The sampling frequency
- Return type:
- Raises:
ValueError – if any difference in consecutive timestamps is null.
- dispel.signal.core.get_cartesian(lat, lon)[source]#
Transform latitude longitude to cartesian coordinates in meters.
- dispel.signal.core.get_sampling_rate_idx(data)[source]#
Get sampling rate from time series index.
- Parameters:
data (Series) – A pandas series containing the signal data for which sampling frequency is to be extracted.
- Returns:
The sampling frequency.
- Return type:
- Raises:
ValueError – Raises a value error if data has not been resampled to a constant sampling rate.
- dispel.signal.core.index_time_diff(data)[source]#
Get the time difference from the index in seconds.
- dispel.signal.core.integrate_time_series(data)[source]#
Compute the integral of a time series.
- dispel.signal.core.non_uniform_power_spectrum(data)[source]#
Compute the power spectrum for non uniformly sampled data.
The algorithm for default frequencies and converting them to angular frequencies is taken from https://jakevdp.github.io/blog/2015/06/13/lomb-scargle-in-python/. Notably, we have decided to use gatspy rather than scipy.
- Parameters:
data (Series) – An pandas series containing the signal data for which the power spectrum is to be computed, indexed by time
- Returns:
One Dataframe containing the signal’s periodogram indexed by frequencies.
- Return type:
- dispel.signal.core.scale_corr(corr, n_samples, phase_shift, method)[source]#
Scale auto-correlation.
- Parameters:
corr (ndarray) – An iterable of floats containing the correlations for each delay.
n_samples (int) – The number of samples of the input signal (denoted N in equation).
phase_shift (ndarray) – The phase shift in number of samples (denoted m in equation).
method (Literal['biased', 'unbiased']) – the method to be used (biased or unbiased)
- Returns:
An array containing the scaled auto-correlation values.
- Return type:
- dispel.signal.core.scaled_autocorr(data, method='unbiased', do_autocov=True)[source]#
Compute scaled auto-correlation function of a signal.
- Parameters:
- Returns:
A Tuple containing lags and auto-correlation output..
- Return type:
Tuple[numpy.ndarray, numpy.ndarray]
- dispel.signal.core.sparc(movement, sample_freq=60.0, pad_level=4, cut_off_freq=10.0, amp_th=0.05)[source]#
Compute the spectral arc length of a signal.
- Parameters:
- Returns:
new_sal (float) – The spectral arc length value.
(freq, mag_spec) (tuple) – A tuple containing both frequencies and the normalized magnitude spectrum of the movement.
(freq_sel, mag_spec_sel) (tuple) – A tuple containing both frequencies (after applying a cutoff) and the normalized magnitude spectrum (after applying a cutoff) of the movement.
- Return type:
- dispel.signal.core.uniform_power_spectrum(data)[source]#
Compute the power spectrum of a signal.
- Parameters:
data (Series) – An pandas series containing the signal data for which the power spectrum is to be computed.
- Returns:
Two arrays, one containing the signal’s frequency and the other the power spectrum.
- Return type: