synapticonn.core.connections.SpikeManager

class synapticonn.core.connections.SpikeManager(spike_times: dict | None = None, time_unit: str = 'ms', srate: float | None = None, recording_length_t: float | None = None, spike_id_type: type = <class 'int'>)[source]

Bases: object

Base class for managing and processing spike time data.

This class provides methods for validating, organizing, and analyzing spike time data for neuroscience studies. It facilitates quality control metrics computation, spike unit filtering, and retrieval of relevant spike unit information.

Parameters:
  • spike_times (dict) – Dictionary containing spike times for each unit, indexed by unit ID.

  • time_unit (str) – Unit of time for the spike times. Default is ‘ms’. Options include ‘s’, ‘ms’.

  • srate (float) – Sampling rate of the recording in Hz.

  • recording_length_t (float) – Length of the recording in the specified time unit.

  • spike_id_type (type) – Data type of the spike unit ID. Default is int or str.

spike_times

Validated dictionary of spike times, indexed by unit ID.

Type:

dict

time_unit

The time unit used for spike times (‘ms’ or ‘s’).

Type:

str

recording_length_t

The duration of the recording in the specified time unit.

Type:

float

spike_id_type

Data type of spike unit identifiers.

Type:

type

srate

Sampling rate of the recording in Hz.

Type:

float

spike_unit_filtering

Tracks whether spike units have been filtered.

Type:

bool

Notes

The SpikeManager object is used to manage spike time data. This object is used to store and process spike times for each unit in the recording. The object provides methods for computing quality metrics, filtering spike units, and reporting spike unit information.

The SpikeManager object is initialized with the spike times, time unit, sampling rate, recording length, and spike ID type. The spike times are stored in a dictionary, indexed by the unit ID.

The SpikeManager object provides methods for computing quality metrics for each unit, filtering spike units based on quality metrics, and reporting spike unit information. These methods are used to analyze and process the spike time data.

__init__(spike_times: dict | None = None, time_unit: str = 'ms', srate: float | None = None, recording_length_t: float | None = None, spike_id_type: type = <class 'int'>)[source]

Initialize the spike manager.

Methods

__init__([spike_times, time_unit, srate, ...])

Initialize the spike manager.

add_spike_time_data([spike_times, ...])

Add spike time data to the SpikeManager object.

filter_spike_units(quality_metrics[, query, ...])

Filter spike units based on quality metrics.

get_spike_times_for_units([...])

Retrieve spike times for the selected units.

report_spike_units()

Report the spike units.

spike_unit_labels()

Retrieve the spike unit labels.

spike_unit_quality([isi_threshold_ms, ...])

Compute spike isolation quality metrics.

Attributes

spike_unit_filtering

add_spike_time_data(spike_times: dict | None = None, recording_length_t: float | None = None, time_unit: str = 'ms', srate: float | None = None, spike_id_type: type = <class 'int'>)[source]

Add spike time data to the SpikeManager object.

Parameters:
  • spike_times (dict) – Dictionary containing spike times for each unit. Indexed by unit ID.

  • recording_length_t (float) – Length of the recording in time units.

  • time_unit (str) – Unit of time for the spike times. Default is ‘ms’. Options include ‘s’, ‘ms’.

  • srate (float) – Sampling rate of the recording in Hz.

  • spike_id_type (type) – Type of the spike unit ID. Default is int or str.

filter_spike_units(quality_metrics: DataFrame, query: str | None = None, log: bool = False, overwrite: bool = False) DataFrame[source]

Filter spike units based on quality metrics.

Parameters:
  • quality_metrics (pd.DataFrame) – DataFrame containing the quality metrics for each spike unit. This is the dataframe outputted from the spike_unit_quality method and will be used to filter spike units.

  • query (str) – Query to filter spike units based on the quality metrics. This query should be a valid pandas query

  • log (bool) – Whether to log the filtered spike units. Default is False.

  • overwrite (bool) – Whether to overwrite the existing spike_times dictionary with the filtered units. Default is False.

Returns:

  • filtered_units_df (pd.DataFrame) – DataFrame containing the filtered spike units based on the query.

  • Log

  • If log is True, the method will log the removed spike units

  • based on the query. The log will contain the unit ID and the

  • query used to filter the units.

  • The log file will be saved in the ‘removed_spike_units’ folder

  • in the current working directory. The log file will be named

  • ’low_quality_units_removed.log’.

get_spike_times_for_units(spike_units_to_collect: list | None = None) dict[source]

Retrieve spike times for the selected units.

Parameters:

spike_units_to_collect (list) – List of spike units to collect.

Returns:

filtered_spike_times – Filtered dictionary containing spike times for the selected units.

Return type:

dict

Notes

By default, this method returns all spike times if no units are specified. If specific units are specified, then the method will return the spike times for those units only.

report_spike_units()[source]

Report the spike units.

Returns:

spk_unit_summary – Dictionary containing the spike unit summary. Includes the unit ID, number of spikes, and firing rate in Hz.

Return type:

dict

Notes

The spike unit summary is computed for each unit in the spike_times dictionary. Firing rates are calculated based on the total number of spikes and the recording length. If the time unit is in seconds, the firing rate is converted to Hz.

spike_unit_filtering = False
spike_unit_labels()[source]

Retrieve the spike unit labels.

spike_unit_quality(isi_threshold_ms=1.5, min_isi_ms=0, presence_ratio_bin_duration_sec=60, presence_ratio_mean_fr_ratio_thresh=0.0) DataFrame[source]

Compute spike isolation quality metrics.

Parameters:
  • isi_threshold_ms (float) – Threshold for the interspike interval (ISI) violations, in milliseconds.

  • min_isi_ms (float) – Minimum ISI value, in milliseconds.

  • presence_ratio_bin_duration_sec (float) – Duration of each bin for the presence ratio, in seconds.

  • presence_ratio_mean_fr_ratio_thresh (float) – Minimum mean firing rate ratio threshold for the presence ratio. This is the minimum mean firing rate that must be present in a bin for the unit to be considered “present” in that bin. By default, this is set to 0.0. This means that the unit must have at least one spike in each bin to be considered “present.”

  • time_unit (str) – Unit of time for the spike times. Default is ‘ms’. This is used to compute the features in the quality metrics.

Returns:

quality_metrics – DataFrame containing the quality metrics for each spike unit.

Return type:

pd.DataFrame

Notes

Quality metrics include: - isi_violations_ratio: Fraction of ISIs that violate the threshold. - isi_violations_count: Number of ISIs that violate the threshold. - isi_violations_of_total_spikes: Fraction of ISIs that violate the threshold out of total spikes. - presence_ratio: Fraction of time during a session in which a unit is spiking. - mean_firing_rate: Mean firing rate of the unit. - recording_length_sec: Length of the recording in seconds. - n_spikes: Number of spikes for the unit.

These are computed for each spike unit in the spike_times dictionary.

For further information on the quality metric calculations, see the respective functions in the quality_metrics module.