thresholding#
- class spidet.spike_detection.thresholding.ThresholdGenerator(activation_function_matrix: ndarray[dtype[float]], preprocessed_data: ndarray[dtype[float]] | None = None, sfreq: int = 50, z_threshold: int = 10)[source]#
This class is the primary entity for computing detected events on a given single activation function or set of activation functions.
- Parameters:
- activation_function_matrix: numpy.ndarray[numpy.dtype[float]]
A single or set of activation functions for which to compute events
- preprocessed_data: np.ndarray[numpy.dtype[float]]
The preprocessed iEEG data, produced by applying the preprocessing steps listed in the preprocessing section.
- sfreq: int
The sampling frequency of the data contained in the activation functions, defaults to 50 Hz.
- z_threshold: int
The z-threshold used for computing the channels involved in a particular event.
- find_events(threshold: float | None = None) Dict[int, Dict][source]#
Computes the events for the activation functions in the activation_function_matrix, which was passed to the ThresholdGenerator at initialization. If the threshold argument is None, the computation is based on the thresholds generated for each activation function by
generate_individual_thresholds()- Parameters:
- threshold: float
The threshold used to compute events for the activation_function_matrix. This can be useful e.g. if the activation_function_matrix contains a single activation function and events need to be computed based on a custom threshold.
- Returns:
- Dict[(int, Dict)]
A nested dictionary containing the events for each activation function. A given activation function in the dictionary can be accessed by its respective index in the
activation_function_matrix. The events for a given activation function are represented by a dictionary containing two index arrays corresponding to the onset, accessible by the “events_on”-key, and offset, accessible by the “events_off”-key, indices of the events, and one binary masking array indicating the indices of all detected events, accessible via the “event_mask”-key.
- generate_individual_thresholds() None[source]#
Computes the threshold for each individual activation function based on
generate_threshold()
- generate_threshold(data: ndarray[dtype[float]] | None = None) float[source]#
Computes the threshold for individual activation functions. The threshold is defined as the zero-crossing of the line that is fitted to the right of the histogram of a given activation function.
- Parameters:
- data: np.ndarray[np.dtype[float]]
This represents the data for which to compute the threshold. If None, the threshold is computed for the activation_function_matrix passed to the ThresholdGenerator at initialization.
- Returns:
- float
The threshold computed for either the data passed as a function argument or the activation function passed to the ThresholdGenerator at initialization.