spike_detection_vickers97.linear_interpolate_spikes
- spike_detection_vickers97.linear_interpolate_spikes(data: ndarray, is_spike: ndarray, error_value: float) ndarray [source]
Replace detected spikes with linear interpolation.
This function replaces spike values in a time series with linearly interpolated values using valid neighboring points. It handles both isolated spikes and consecutive sequences of spikes, as well as error values in the data.
- Parameters:
data (
numpy.ndarray
) – Input data array containing the original time series with spikesis_spike (
numpy.ndarray
) – Boolean array of same length as data, True where spikes were detectederror_value (
float
) – Special value indicating invalid or missing data points These points are skipped when finding valid neighbors for interpolation
- Returns:
Copy of input data with spikes replaced by linear interpolation
- Return type:
Notes
The interpolation strategy is: 1. For each sequence of spikes, find valid (non-spike, non-error) points
before and after the sequence
If both points exist: perform linear interpolation
If only one exists: use that value (nearest neighbor)
If neither exists: spikes remain unchanged
This implementation follows the EddyPro software’s approach but is vectorized for better performance in Python.
See also
spike_detection_vickers97
Main spike detection algorithm
Examples
>>> import numpy as np >>> # Create sample data with spikes >>> data = np.array([1.0, 10.0, 1.1, np.nan, 1.2]) >>> spikes = np.array([False, True, False, False, False]) >>> cleaned = linear_interpolate_spikes(data, spikes, np.nan) >>> print(cleaned) # [1.0, 1.05, 1.1, nan, 1.2]