line_length#
- class spidet.spike_detection.line_length.LineLength(file_path: str, dataset_paths: List[str] | None = None, exclude: List[str] | None = None, bipolar_reference: bool = False, leads: List[str] | None = None, bad_times: ndarray | None = None)[source]#
This class provides all operations regarding the line-length transformation.
- Parameters:
- file_path: str
Path to the file containing the iEEG data.
- bad_times: numpy.ndarray[numpy.dtype[float]]
An optional N x 2 numpy array containing periods that must be excluded before applying the line-length transformation. Each of th N rows in the array represents a period to be excluded, defined by the start and end indices of the period in the original iEEG data. The defined periods will be set to zero with the transitions being smoothed by applying a hanning window to prevent spurious patterns.
- dataset_paths: List[str], mandatory when the file is in .h5 format
A list of paths to the traces to be included within an h5 file. This is only necessary in the case of h5 files.
- bipolar_reference: bool, optional, default = False
If True, the bipolar references of the included channels will be computed. If channels already are in bipolar form this needs to be False.
- exclude: List[str], optional
A list of channel names that need to be excluded. This only applies in the case of .edf and .fif files.
- leads: List[str]
A list of the leads included. Only necessary if bipolar_reference is True, otherwise can be None.
- apply_parallel_line_length_pipeline(notch_freq: int = 50, resampling_freq: int = 500, bandpass_cutoff_low: int = 0.1, bandpass_cutoff_high: int = 200, line_length_freq: int = 50, line_length_window: int = 40) Tuple[float, List[str], ndarray[dtype[float]]][source]#
This function launches the line length pipeline, which first carries out the necessary preprocessing steps and then performs the line-length transformation of the preprocessed EEG data. The individual steps include
reading the data from the provided file (supported file formats are .h5, .edf, .fif) using the
data_loadingmodule, which transforms the data into a list ofTraceobjects,performing the necessary preprocessing steps by means of the
preprocessingmodule,and applying the line-length transformation.
To optimize computation, the channels are split into subsets and processed in parallel.
- Parameters:
- notch_freq: int, optional, default = 50
The frequency of the notch filter; data will be notch-filtered at this frequency and at the corresponding harmonics, e.g. notch_freq = 50 Hz -> harmonics = [50, 100, 150, etc.]
- resampling_freq: int, optional, default = 500
The frequency to resample the data after filtering and rescaling
- bandpass_cutoff_low: int, optional, default = 0.1
Cut-off frequency at the lower end of the passband of the bandpass filter.
- bandpass_cutoff_high: int, optional, default = 200
Cut-off frequency at the higher end of the passband of the bandpass filter.
- line_length_freq: int, optional, default = 50
Sampling frequency of the line-length transformed data
- line_length_window: int, optional, default = 40
Window length used to for the line-length operation (in milliseconds).
- Returns:
- Tuple[float, List[str], numpy.ndarray[numpy.dtype[float]]]
Tuple containing, the start timestamp of the recording, a list of channel names corresponding to the channels in the line-length transformed data, the line-length transformed data
- compute_line_length(eeg_data: ndarray, sfreq: int)[source]#
Performs the line-length transformation on the input EEG data..
- Parameters:
- eeg_datanumpy.ndarray
Input EEG data.
- sfreqint
Sampling frequency of the input EEG data.
- Returns:
- numpy.ndarray[Any,
Line length representation of the input EEG data.
Notes
The line length operation involves slicing the input data into evenly spaced intervals along the time axis and processing each block separately. It computes the summed absolute difference of the data along consecutive time points over a predefined segment. [1]
References
[1]Koolen, N., Jansen, K., Vervisch, J., Matic, V., De Vos, M., Naulaers, G., & Van Huffel, S. (2014). Line length as a robust method to detect high-activity events: Automated burst detection in premature EEG recordings. Clinical Neurophysiology, 125(10), 1985–1994. https://doi.org/https://doi.org/10.1016/j.clinph.2014.02.015
- compute_unique_line_length(notch_freq: int = 50, resampling_freq: int = 500, bandpass_cutoff_low: int = 0.1, bandpass_cutoff_high: int = 200, n_processes: int = 5, line_length_freq: int = 50, line_length_window: int = 40) ActivationFunction[source]#
This function computes the standard deviation of the data after performing the line-length transformation using the
apply_parallel_line_length_pipeline()method and wraps it into a singleActivationFunctionobject. The defined parameters will be passed on to theapply_parallel_line_length_pipeline()method.- Parameters:
- notch_freq: int, optional, default = 50
The frequency of the notch filter; data will be notch-filtered at this frequency and at the corresponding harmonics, e.g. notch_freq = 50 Hz -> harmonics = [50, 100, 150, etc.]
- resampling_freq: int, optional, default = 500
The frequency to resample the data after filtering and rescaling
- bandpass_cutoff_low: int, optional, default = 0.1
Cut-off frequency at the lower end of the passband of the bandpass filter.
- bandpass_cutoff_high: int, optional, default = 200
Cut-off frequency at the higher end of the passband of the bandpass filter.
- n_processes: int, optional, default = 5
Number of parallel processes to use for the line-length pipeline
- line_length_freq: int, optional, default = 50
Sampling frequency of the line-length transformed data
- line_length_window: int, optional, default = 40
Window length used to for the line-length operation (in milliseconds).
- Returns:
ActivationFunctionActivationFunction containing the standard deviation of the line-length transformed data.
- dampen_bad_times(data: ndarray[dtype[float]], sfreq: int, orig_sfreq: int, window_length: int = 100) ndarray[source]#
Dampens bad times within preprocessed iEEG data by setting values of bad times intervals to zero and applying hann windows (https://en.wikipedia.org/wiki/Hann_function) around starting and ending points in order to get smoothed transitions
- Parameters:
- datanumpy.ndarray[np.dtype[float]]
The preprocessed iEEG data.
- sfreqint
The sampling frequency of the preprocessed iEEG data.
- orig_sfreqint
The sampling frequency of the original iEEG data.
- window_lengthint, optional, default = 100
The length of the smoothed transition periods in milliseconds
- Returns:
- smoothed_datanumpy.ndarray[np.dtype[float]]
The preprocessed iEEG data wih artifacts being zeroed and having smoothed transition periods.