src.canns.analyzer.utils¶
Functions¶
|
Converts a low-resolution firing rate signal to a high-resolution binary spike train. |
|
Normalizes firing rates to a range of [0, 1] based on the maximum firing rate. |
|
Converts a high-resolution spike train to a low-resolution firing rate signal. |
Module Contents¶
- src.canns.analyzer.utils.firing_rate_to_spike_train(firing_rates, dt_rate, dt_spike)[source]¶
Converts a low-resolution firing rate signal to a high-resolution binary spike train.
This function generates spikes using a Bernoulli process in each high-resolution time bin. The probability of a spike in each bin is calculated as: P(spike in dt_spike) = rate (spikes/dt_rate) / dt_rate (sec) * dt_spike (sec)
Note
A Bernoulli process is used, not a Poisson process. This means that in each time bin, at most one spike can occur. For high firing rates, the computed spike probability may exceed 1 and will be clipped to 1. This can lead to deviations from the expected Poisson statistics at high rates.
- Parameters:
- Returns:
A 2D integer array of shape (timesteps_spike, num_neurons) with binary values (0 or 1) representing the high-resolution spike train.
- Return type:
np.ndarray
- src.canns.analyzer.utils.normalize_firing_rates(firing_rates, method='min_max')[source]¶
Normalizes firing rates to a range of [0, 1] based on the maximum firing rate.
- Parameters:
firing_rates (np.ndarray) – 2D array of shape (timesteps_rate, num_neurons) with firing rates in dt_rate.
method (str) – Normalization method, either ‘min_max’ or ‘z_score’. - ‘min_max’: Normalizes to the range [0, 1]. - ‘z_score’: Normalizes to have mean 0 and standard deviation 1.
- Returns:
A 2D array of shape (timesteps_rate, num_neurons) with normalized firing rates.
- Return type:
np.ndarray
- src.canns.analyzer.utils.spike_train_to_firing_rate(spike_train, dt_spike, dt_rate)[source]¶
Converts a high-resolution spike train to a low-resolution firing rate signal.
This function bins the spikes into larger time windows (dt_rate) and calculates the average firing rate for each bin.
- Parameters:
- Returns:
A 2D array of shape (timesteps_rate, num_neurons) with firing rates in Hz.
- Return type:
np.ndarray