API

spikeinterface.core

spikeinterface.core.load_extractor(file_or_folder_or_dict, base_folder=None) BaseExtractor
Instantiate extractor from:
  • a dict

  • a json file

  • a pickle file

  • folder (after save)

  • a zarr folder (after save)

Parameters:
file_or_folder_or_dictdictionary or folder or file (json, pickle)

The file path, folder path, or dictionary to load the extractor from

base_folderstr | Path | bool (optional)

The base folder to make relative paths absolute. If True and file_or_folder_or_dict is a file, the parent folder of the file is used.

Returns:
extractor: Recording or Sorting

The loaded extractor object

class spikeinterface.core.BaseRecording(sampling_frequency: float, channel_ids: list, dtype)

Abstract class representing several a multichannel timeseries (or block of raw ephys traces). Internally handle list of RecordingSegment

add_recording_segment(recording_segment)

Adds a recording segment.

Parameters:
recording_segmentBaseRecordingSegment

The recording segment to add

binary_compatible_with(dtype=None, time_axis=None, file_paths_lenght=None, file_offset=None, file_suffix=None)

Check is the recording is binary compatible with some constrain on

  • dtype

  • tim_axis

  • len(file_paths)

  • file_offset

  • file_suffix

get_binary_description()

When rec.is_binary_compatible() is True this returns a dictionary describing the binary format.

get_duration(segment_index=None) float

Returns the duration in seconds.

Parameters:
segment_indexint or None, default: None

The sample index to retrieve the duration for. For multi-segment objects, it is required, default: None With single segment recording returns the duration of the single segment

Returns:
float

The duration in seconds

get_memory_size(segment_index=None) int

Returns the memory size of segment_index in bytes.

Parameters:
segment_indexint or None, default: None

The index of the segment for which the memory size should be calculated. For multi-segment objects, it is required, default: None With single segment recording returns the memory size of the single segment

Returns:
int

The memory size of the specified segment in bytes.

get_num_frames(segment_index=None) int

Returns the number of samples for a segment.

Parameters:
segment_indexint or None, default: None

The segment index to retrieve the number of samples for. For multi-segment objects, it is required, default: None With single segment recording returns the number of samples in the segment

Returns:
int

The number of samples

get_num_samples(segment_index=None) int

Returns the number of samples for a segment.

Parameters:
segment_indexint or None, default: None

The segment index to retrieve the number of samples for. For multi-segment objects, it is required, default: None With single segment recording returns the number of samples in the segment

Returns:
int

The number of samples

get_num_segments() int

Returns the number of segments.

Returns:
int

Number of segments in the recording

get_time_info(segment_index=None) dict

Retrieves the timing attributes for a given segment index. As with other recorders this method only needs a segment index in the case of multi-segment recordings.

Returns:
dict

A dictionary containing the following key-value pairs:

  • “sampling_frequency”: The sampling frequency of the RecordingSegment.

  • “t_start”: The start time of the RecordingSegment.

  • “time_vector”: The time vector of the RecordingSegment.

Notes

The keys are always present, but the values may be None.

get_times(segment_index=None)

Get time vector for a recording segment.

If the segment has a time_vector, then it is returned. Otherwise a time_vector is constructed on the fly with sampling frequency. If t_start is defined and the time vector is constructed on the fly, the first time will be t_start. Otherwise it will start from 0.

Parameters:
segment_indexint or None, default: None

The segment index (required for multi-segment)

Returns:
np.array

The 1d times array

get_total_duration() float

Returns the total duration in seconds

Returns:
float

The duration in seconds

get_total_memory_size() int

Returns the sum in bytes of all the memory sizes of the segments.

Returns:
int

The total memory size in bytes for all segments.

get_total_samples() int

Returns the sum of the number of samples in each segment.

Returns:
int

The total number of samples

get_traces(segment_index: int | None = None, start_frame: int | None = None, end_frame: int | None = None, channel_ids: list | np.array | tuple | None = None, order: 'C' | 'F' | None = None, return_scaled: bool = False, cast_unsigned: bool = False)

Returns traces from recording.

Parameters:
segment_indexint | None, default: None

The segment index to get traces from. If recording is multi-segment, it is required, default: None

start_frameint | None, default: None

The start frame. If None, 0 is used, default: None

end_frameint | None, default: None

The end frame. If None, the number of samples in the segment is used, default: None

channel_idslist | np.array | tuple | None, default: None

The channel ids. If None, all channels are used, default: None

order“C” | “F” | None, default: None

The order of the traces (“C” | “F”). If None, traces are returned as they are

return_scaledbool, default: False

If True and the recording has scaling (gain_to_uV and offset_to_uV properties), traces are scaled to uV

cast_unsignedbool, default: False

If True and the traces are unsigned, they are cast to integer and centered (an offset of (2**nbits) is subtracted)

Returns:
np.array

The traces (num_samples, num_channels)

Raises:
ValueError

If return_scaled is True, but recording does not have scaled traces

has_scaled_traces() bool

Checks if the recording has scaled traces

Returns:
bool

True if the recording has scaled traces, False otherwise

has_time_vector(segment_index=None)

Check if the segment of the recording has a time vector.

Parameters:
segment_indexint or None, default: None

The segment index (required for multi-segment)

Returns:
bool

True if the recording has time vectors, False otherwise

is_binary_compatible() bool

Checks if the recording is “binary” compatible. To be used before calling rec.get_binary_description()

Returns:
bool

True if the underlying recording is binary

rename_channels(new_channel_ids: list | np.array | tuple) BaseRecording

Returns a new recording object with renamed channel ids.

Note that this method does not modify the current recording and instead returns a new recording object.

Parameters:
new_channel_idslist or np.array or tuple

The new channel ids. They are mapped positionally to the old channel ids.

sample_index_to_time(sample_ind, segment_index=None)

Transform sample index into time in seconds

select_channels(channel_ids: list | np.array | tuple) BaseRecording

Returns a new recording object with a subset of channels.

Note that this method does not modify the current recording and instead returns a new recording object.

Parameters:
channel_idslist or np.array or tuple

The channel ids to select.

set_times(times, segment_index=None, with_warning=True)

Set times for a recording segment.

Parameters:
times1d np.array

The time vector

segment_indexint or None, default: None

The segment index (required for multi-segment)

with_warningbool, default: True

If True, a warning is printed

class spikeinterface.core.BaseSorting(sampling_frequency: float, unit_ids: List)

Abstract class representing several segment several units and relative spiketrains.

count_num_spikes_per_unit(outputs='dict')

For each unit : get number of spikes across segments.

Parameters:
outputs: “dict” | “array”, default: “dict”

Control the type of the returned object: a dict (keys are unit_ids) or an numpy array.

Returns:
dict or numpy.array

Dict : Dictionary with unit_ids as key and number of spikes as values Numpy array : array of size len(unit_ids) in the same order as unit_ids.

count_total_num_spikes() int

Get total number of spikes in the sorting.

This is the sum of all spikes in all segments across all units.

Returns:
total_num_spikes: int

The total number of spike

get_all_spike_trains(outputs='unit_id')

Return all spike trains concatenated. This is deprecated and will be removed in spikeinterface 0.102 use sorting.to_spike_vector() instead

get_num_samples(segment_index=None) int

Returns the number of samples of the associated recording for a segment.

Parameters:
segment_indexint or None, default: None

The segment index to retrieve the number of samples for. For multi-segment objects, it is required

Returns:
int

The number of samples

get_times(segment_index=None)

Get time vector for a registered recording segment.

If a recording is registered:
  • if the segment has a time_vector, then it is returned

  • if not, a time_vector is constructed on the fly with sampling frequency

If there is no registered recording it returns None

get_total_duration()

Returns the total duration in s of the associated recording.

Returns:
float

The duration in seconds

get_total_samples() int

Returns the total number of samples of the associated recording.

Returns:
int

The total number of samples

has_time_vector(segment_index=None)

Check if the segment of the registered recording has a time vector.

precompute_spike_trains(from_spike_vector=None)

Pre-computes and caches all spike trains for this sorting

Parameters:
from_spike_vector: None | bool, default: None

If None, then it is automatic depending on whether the spike vector is cached. If True, will compute it from the spike vector. If False, will call get_unit_spike_train for each segment for each unit.

register_recording(recording, check_spike_frames=True)

Register a recording to the sorting.

Parameters:
recordingBaseRecording

Recording with the same number of segments as current sorting. Assigned to self._recording.

check_spike_framesbool, default: True

If True, assert for each segment that all spikes are within the recording’s range.

remove_empty_units()

Returns a new sorting object which contains only units with at least one spike. For multi-segments, a unit is considered empty if it contains no spikes in all segments.

Returns:
BaseSorting

Sorting object with non-empty units

remove_units(remove_unit_ids) BaseSorting

Returns a new sorting object with contains only a selected subset of units.

Parameters:
remove_unit_idsnumpy.array or list

List of unit ids to remove

Returns:
BaseSorting

Sorting without the removed units

rename_units(new_unit_ids: ndarray | list) BaseSorting

Returns a new sorting object with renamed units.

Parameters:
new_unit_idsnumpy.array or list

List of new names for unit ids. They should map positionally to the existing unit ids.

Returns:
BaseSorting

Sorting object with renamed units

select_units(unit_ids, renamed_unit_ids=None) BaseSorting

Returns a new sorting object which contains only a selected subset of units.

Parameters:
unit_idsnumpy.array or list

List of unit ids to keep

renamed_unit_idsnumpy.array or list, default: None

If given, the kept unit ids are renamed

Returns:
BaseSorting

Sorting object with selected units

to_multiprocessing(n_jobs)

When necessary turn sorting object into: * NumpySorting when n_jobs=1 * SharedMemorySorting when n_jobs>1

If the sorting is already NumpySorting, SharedMemorySorting or NumpyFolderSorting then this return the sortign itself, no transformation so.

Parameters:
n_jobs: int

The number of jobs.

Returns
——-
sharable_sorting:

A sorting that can be used for multiprocessing.

to_numpy_sorting(propagate_cache=True)

Turn any sorting in a NumpySorting. useful to have it in memory with a unique vector representation.

Parameters:
propagate_cachebool

Propagate the cache of indivudual spike trains.

to_shared_memory_sorting()

Turn any sorting in a SharedMemorySorting. Usefull to have it in memory with a unique vector representation and sharable across processes.

to_spike_vector(concatenated=True, extremum_channel_inds=None, use_cache=True) ndarray | list[ndarray]

Construct a unique structured numpy vector concatenating all spikes with several fields: sample_index, unit_index, segment_index.

Parameters:
concatenated: bool, default: True

With concatenated=True the output is one numpy “spike vector” with spikes from all segments. With concatenated=False the output is a list “spike vector” by segment.

extremum_channel_inds: None or dict, default: None

If a dictionnary of unit_id to channel_ind is given then an extra field “channel_index”. This can be convinient for computing spikes postion after sorter. This dict can be computed with get_template_extremum_channel(we, outputs=”index”)

use_cache: bool, default: True

When True the spikes vector is cached as an attribute of the object (_cached_spike_vector). This caching only occurs when extremum_channel_inds=None.

Returns:
spikes: np.array

Structured numpy array (“sample_index”, “unit_index”, “segment_index”) with all spikes Or (“sample_index”, “unit_index”, “segment_index”, “channel_index”) if extremum_channel_inds is given

class spikeinterface.core.BaseSnippets(sampling_frequency: float, nbefore: int | None, snippet_len: int, channel_ids: list, dtype)

Abstract class representing several multichannel snippets.

class spikeinterface.core.BaseEvent(channel_ids, structured_dtype)

Abstract class representing events.

Parameters:
channel_idslist or np.array

The channel ids

structured_dtypedtype or dict

The dtype of the events. If dict, each key is the channel_id and values must be the dtype of the channel (also structured). If dtype, each channel is assigned the same dtype. In case of structured dtypes, the “time” or “timestamp” field name must be present.

get_event_times(channel_id: int | str | None = None, segment_index: int | None = None, start_time: float | None = None, end_time: float | None = None)

Return events timestamps of a channel in seconds.

Parameters:
channel_idint | str | None, default: None

The event channel id

segment_indexint | None, default: None

The segment index, required for multi-segment objects

start_timefloat | None, default: None

The start time in seconds

end_timefloat | None, default: None

The end time in seconds

Returns:
np.array

1d array of timestamps for the event channel

get_events(channel_id: int | str | None = None, segment_index: int | None = None, start_time: float | None = None, end_time: float | None = None)

Return events of a channel in its native structured type.

Parameters:
channel_idint | str | None, default: None

The event channel id

segment_indexint | None, default: None

The segment index, required for multi-segment objects

start_timefloat | None, default: None

The start time in seconds

end_timefloat | None, default: None

The end time in seconds

Returns:
np.array

Structured np.array of dtype get_dtype(channel_id)

class spikeinterface.core.SortingAnalyzer(sorting=None, recording=None, rec_attributes=None, format=None, sparsity=None, return_scaled=True)

Class to make a pair of Recording-Sorting which will be used used for all post postprocessing, visualization and quality metric computation.

This internally maintains a list of computed ResultExtention (waveform, pca, unit position, spike position, …).

This can live in memory and/or can be be persistent to disk in 2 internal formats (folder/json/npz or zarr). A SortingAnalyzer can be transfer to another format using save_as()

This handle unit sparsity that can be propagated to ResultExtention.

This handle spike sampling that can be propagated to ResultExtention : works on only a subset of spikes.

This internally saves a copy of the Sorting and extracts main recording attributes (without traces) so the SortingAnalyzer object can be reloaded even if references to the original sorting and/or to the original recording are lost.

SortingAnalyzer() should not never be used directly for creating: use instead create_sorting_analyzer(sorting, resording, …) or eventually SortingAnalyzer.create(…)

compute(input, save=True, extension_params=None, verbose=False, **kwargs)

Compute one extension or several extensiosn. Internally calls compute_one_extension() or compute_several_extensions() depending on the input type.

Parameters:
input: str or dict or list

The extensions to compute, which can be passed as:

  • a string: compute one extension. Additional parameters can be passed as key word arguments.

  • a dict: compute several extensions. The keys are the extension names and the values are dictiopnaries with the extension parameters.

  • a list: compute several extensions. The list contains the extension names. Additional parameters can be passed with the extension_params argument.

save: bool, default: True

If True the extension is saved to disk (only if sorting analyzer format is not “memory”)

extension_params: dict or None, default: None

If input is a list, this parameter can be used to specify parameters for each extension. The extension_params keys must be included in the input list.

**kwargs:

All other kwargs are transmitted to extension.set_params() (if input is a string) or job_kwargs

Returns:
extension: SortingAnalyzerExtension | None

The extension instance if input is a string, None otherwise.

Examples

This function accepts the following possible signatures for flexibility:

Compute one extension, with parameters: >>> analyzer.compute(“waveforms”, ms_before=1.5, ms_after=2.5)

Compute two extensions with a list as input and with default parameters: >>> analyzer.compute([“random_spikes”, “waveforms”])

Compute two extensions with dict as input, one dict per extension >>> analyzer.compute({“random_spikes”:{}, “waveforms”:{“ms_before”:1.5, “ms_after”, “2.5”}})

Compute two extensions with an input list specifying custom parameters for one (the other will use default parameters): >>> analyzer.compute(

[“random_spikes”, “waveforms”], extension_params={“waveforms”:{“ms_before”:1.5, “ms_after”, “2.5”}}

)

compute_one_extension(extension_name, save=True, verbose=False, **kwargs)

Compute one extension.

Important note: when computing again an extension, all extensions that depend on it will be automatically and silently deleted to keep a coherent data.

Parameters:
extension_name: str

The name of the extension. For instance “waveforms”, “templates”, …

save: bool, default: True

It the extension can be saved then it is saved. If not then the extension will only live in memory as long as the object is deleted. save=False is convenient to try some parameters without changing an already saved extension.

**kwargs:

All other kwargs are transmitted to extension.set_params() or job_kwargs

Returns:
result_extension: AnalyzerExtension

Return the extension instance

Examples

>>> Note that the return is the instance extension.
>>> extension = sorting_analyzer.compute("waveforms", **some_params)
>>> extension = sorting_analyzer.compute_one_extension("waveforms", **some_params)
>>> wfs = extension.data["waveforms"]
>>> # Note this can be be done in the old way style BUT the return is not the same it return directly data
>>> wfs = compute_waveforms(sorting_analyzer, **some_params)
compute_several_extensions(extensions, save=True, verbose=False, **job_kwargs)

Compute several extensions

Important note: when computing again an extension, all extensions that depend on it will be automatically and silently deleted to keep a coherent data.

Parameters:
extensions: dict

Keys are extension_names and values are params.

save: bool, default: True

It the extension can be saved then it is saved. If not then the extension will only live in memory as long as the object is deleted. save=False is convenient to try some parameters without changing an already saved extension.

Returns:
No return

Examples

>>> sorting_analyzer.compute({"waveforms": {"ms_before": 1.2}, "templates" : {"operators": ["average", "std", ]} })
>>> sorting_analyzer.compute_several_extensions({"waveforms": {"ms_before": 1.2}, "templates" : {"operators": ["average", "std"]}})
copy()

Create a a copy of SortingAnalyzer with format “memory”.

delete_extension(extension_name) None

Delete the extension from the dict and also in the persistent zarr or folder.

get_computable_extensions()

Get all extensions that can be computed by the analyzer.

get_default_extension_params(extension_name: str)

Get the default params for an extension.

Parameters:
extension_name: str

The extension name

Returns:
default_params: dict

The default parameters for the extension

get_extension(extension_name: str)

Get a AnalyzerExtension. If not loaded then load is automatic.

Return None if the extension is not computed yet (this avoids the use of has_extension() and then get it)

get_loaded_extension_names()

Return the loaded or already computed extensions names.

get_saved_extension_names()

Get extension names saved in folder or zarr that can be loaded. This do not load data, this only explores the directory.

get_sorting_provenance()

Get the original sorting if possible otherwise return None

has_extension(extension_name: str) bool

Check if the extension exists in memory (dict) or in the folder or in zarr.

classmethod load(folder, recording=None, load_extensions=True, format='auto')

Load folder or zarr. The recording can be given if the recording location has changed. Otherwise the recording is loaded when possible.

load_all_saved_extension()

Load all saved extensions in memory.

load_extension(extension_name: str)

Load an extension from a folder or zarr into the ResultSorting.extensions dict.

Parameters:
extension_name: str

The extension name.

Returns:
ext_instanace:

The loaded instance of the extension

save_as(format='memory', folder=None) SortingAnalyzer

Save SortingAnalyzer object into another format. Uselful for memory to zarr or memory to binary.

Note that the recording provenance or sorting provenance can be lost.

Mainly propagates the copied sorting and recording properties.

Parameters:
folderstr or Path

The output waveform folder

format“binary_folder” | “zarr”, default: “binary_folder”

The backend to use for saving the waveforms

select_units(unit_ids, format='memory', folder=None) SortingAnalyzer

This method is equivalent to `save_as()`but with a subset of units. Filters units by creating a new sorting analyzer object in a new folder.

Extensions are also updated to filter the selected unit ids.

Parameters:
unit_idslist or array

The unit ids to keep in the new SortingAnalyzer object

folderPath or None

The new folder where selected waveforms are copied

format:
a
Returns
——-
weSortingAnalyzer

The newly create sorting_analyzer with the selected units

spikeinterface.core.create_sorting_analyzer(sorting, recording, format='memory', folder=None, sparse=True, sparsity=None, return_scaled=True, overwrite=False, **sparsity_kwargs)

Create a SortingAnalyzer by pairing a Sorting and the corresponding Recording.

This object will handle a list of AnalyzerExtension for all the post processing steps like: waveforms, templates, unit locations, spike locations, quality metrics …

This object will be also use used for plotting purpose.

Parameters:
sorting: Sorting

The sorting object

recording: Recording

The recording object

folder: str or Path or None, default: None

The folder where waveforms are cached

format: “memory | “binary_folder” | “zarr”, default: “memory”

The mode to store waveforms. If “folder”, waveforms are stored on disk in the specified folder. The “folder” argument must be specified in case of mode “folder”. If “memory” is used, the waveforms are stored in RAM. Use this option carefully!

sparse: bool, default: True

If True, then a sparsity mask is computed using the estimate_sparsity() function using a few spikes to get an estimate of dense templates to create a ChannelSparsity object. Then, the sparsity will be propagated to all ResultExtention that handle sparsity (like wavforms, pca, …) You can control estimate_sparsity() : all extra arguments are propagated to it (included job_kwargs)

sparsity: ChannelSparsity or None, default: None

The sparsity used to compute waveforms. If this is given, sparse is ignored.

return_scaled: bool, default: True

All extensions that play with traces will use this global return_scaled: “waveforms”, “noise_levels”, “templates”. This prevent return_scaled being differents from different extensions and having wrong snr for instance.

Returns:
sorting_analyzer: SortingAnalyzer

The SortingAnalyzer object

Notes

By default creating a SortingAnalyzer can be slow because the sparsity is estimated by default. In some situation, sparsity is not needed, so to make it fast creation, you need to turn sparsity off (or give external sparsity) like this.

Examples

>>> import spikeinterface as si
>>> # Extract dense waveforms and save to disk with binary_folder format.
>>> sorting_analyzer = si.create_sorting_analyzer(sorting, recording, format="binary_folder", folder="/path/to_my/result")
>>> # Can be reload
>>> sorting_analyzer = si.load_sorting_analyzer(folder="/path/to_my/result")
>>> # Can run extension
>>> sorting_analyzer = si.compute("unit_locations", ...)
>>> # Can be copy to another format (extensions are propagated)
>>> sorting_analyzer2 = sorting_analyzer.save_as(format="memory")
>>> sorting_analyzer3 = sorting_analyzer.save_as(format="zarr", folder="/path/to_my/result.zarr")
>>> # Can make a copy with a subset of units (extensions are propagated for the unit subset)
>>> sorting_analyzer4 = sorting_analyzer.select_units(unit_ids=sorting.units_ids[:5], format="memory")
>>> sorting_analyzer5 = sorting_analyzer.select_units(unit_ids=sorting.units_ids[:5], format="binary_folder", folder="/result_5units")
spikeinterface.core.load_sorting_analyzer(folder, load_extensions=True, format='auto')

Load a SortingAnalyzer object from disk.

Parameters:
folderstr or Path

The folder / zarr folder where the waveform extractor is stored

load_extensionsbool, default: True

Load all extensions or not.

format: “auto” | “binary_folder” | “zarr”

The format of the folder.

Returns:
sorting_analyzer: SortingAnalyzer

The loaded SortingAnalyzer

spikeinterface.core.compute_sparsity(templates_or_sorting_analyzer, noise_levels=None, method='radius', peak_sign='neg', num_channels=5, radius_um=100.0, threshold=5, by_property=None)

Get channel sparsity (subset of channels) for each template with several methods.

Parameters:
templates_or_sorting_analyzer: Templates | SortingAnalyzer

A Templates or a SortingAnalyzer object. Some methods accept both objects (“best_channels”, “radius”, ) Other methods require only SortingAnalyzer because internally the recording is needed.

method: str
  • “best_channels”: N best channels with the largest amplitude. Use the “num_channels” argument to specify the

    number of channels.

  • “radius”: radius around the best channel. Use the “radius_um” argument to specify the radius in um

  • “snr”: threshold based on template signal-to-noise ratio. Use the “threshold” argument

    to specify the SNR threshold (in units of noise levels)

  • “ptp”: threshold based on the peak-to-peak values on every channels. Use the “threshold” argument

    to specify the ptp threshold (in units of noise levels)

  • “energy”: threshold based on the expected energy that should be present on the channels,

    given their noise levels. Use the “threshold” argument to specify the SNR threshold (in units of noise levels)

  • “by_property”: sparsity is given by a property of the recording and sorting(e.g. “group”).

    Use the “by_property” argument to specify the property name.

peak_sign: str

Sign of the template to compute best channels (“neg”, “pos”, “both”)

num_channels: int

Number of channels for “best_channels” method

radius_um: float

Radius in um for “radius” method

threshold: float

Threshold in SNR “threshold” method

by_property: object

Property name for “by_property” method

Returns:
sparsity: ChannelSparsity

The estimated sparsity

spikeinterface.core.estimate_sparsity(recording: BaseRecording, sorting: BaseSorting, num_spikes_for_sparsity: int = 100, ms_before: float = 1.0, ms_after: float = 2.5, method: radius' | 'best_channels = 'radius', peak_sign: str = 'neg', radius_um: float = 100.0, num_channels: int = 5, **job_kwargs)

Estimate the sparsity without needing a SortingAnalyzer or Templates object This is faster than spikeinterface.waveforms_extractor.precompute_sparsity() and it traverses the recording to compute the average templates for each unit.

Contrary to the previous implementation:
  • all units are computed in one read of recording

  • it doesn’t require a folder

  • it doesn’t consume too much memory

  • it uses internally the estimate_templates_with_accumulator() which is fast and parallel

Parameters:
recording: BaseRecording

The recording

sorting: BaseSorting

The sorting

num_spikes_for_sparsity: int, default: 100

How many spikes per units to compute the sparsity

ms_before: float, default: 1.0

Cut out in ms before spike time

ms_after: float, default: 2.5

Cut out in ms after spike time

method: “radius” | “best_channels”, default: “radius”

Sparsity method propagated to the compute_sparsity() function. Only “radius” or “best_channels” are implemented

peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of the template to compute best channels

radius_um: float, default: 100.0

Used for “radius” method

num_channels: int, default: 5

Used for “best_channels” method

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

Returns:
sparsity: ChannelSparsity

The estimated sparsity

class spikeinterface.core.ChannelSparsity(mask, unit_ids, channel_ids)

Handle channel sparsity for a set of units. That is, for every unit, it indicates which channels are used to represent the waveform and the rest of the non-represented channels are assumed to be zero.

Internally, sparsity is stored as a boolean mask.

The ChannelSparsity object can also provide other sparsity representations:

  • ChannelSparsity.unit_id_to_channel_ids : unit_id to channel_ids

  • ChannelSparsity.unit_id_to_channel_indices : unit_id channel_inds

By default it is constructed with a boolean array:

>>> sparsity = ChannelSparsity(mask, unit_ids, channel_ids)

But can be also constructed from a dictionary:

>>> sparsity = ChannelSparsity.from_unit_id_to_channel_ids(unit_id_to_channel_ids, unit_ids, channel_ids)
Parameters:
mask: np.array of bool

The sparsity mask (num_units, num_channels)

unit_ids: list or array

Unit ids vector or list

channel_ids: list or array

Channel ids vector or list

Examples

The class can also be used to construct/estimate the sparsity from a SortingAnalyzer or a Templates with several methods:

Using the N best channels (largest template amplitude):

>>> sparsity = ChannelSparsity.from_best_channels(sorting_analyzer, num_channels, peak_sign="neg")

Using a neighborhood by radius:

>>> sparsity = ChannelSparsity.from_radius(sorting_analyzer, radius_um, peak_sign="neg")

Using a SNR threshold: >>> sparsity = ChannelSparsity.from_snr(sorting_analyzer, threshold, peak_sign=”neg”)

Using a template energy threshold: >>> sparsity = ChannelSparsity.from_energy(sorting_analyzer, threshold)

Using a recording/sorting property (e.g. “group”):

>>> sparsity = ChannelSparsity.from_property(sorting_analyzer, by_property="group")
classmethod create_dense(sorting_analyzer)

Create a sparsity object with all selected channel for all units.

densify_waveforms(waveforms: ndarray, unit_id: str | int) ndarray

Densify sparse waveforms that were sparisified according to a unit’s channel sparsity.

Given a unit_id its sparsified waveform, this method places the waveform back into its original form within a dense array.

Parameters:
waveformsnp.array

The sparsified waveforms array of shape (num_waveforms, num_samples, num_active_channels) or a single sparse waveform (template) with shape (num_samples, num_active_channels).

unit_idstr

The unit_id that was used to sparsify the waveform.

Returns:
densified_waveformsnp.array

The densified waveforms array of shape (num_waveforms, num_samples, num_channels) or a single dense waveform (template) with shape (num_samples, num_channels).

classmethod from_best_channels(templates_or_sorting_analyzer, num_channels, peak_sign='neg')

Construct sparsity from N best channels with the largest amplitude. Use the “num_channels” argument to specify the number of channels.

classmethod from_energy(sorting_analyzer, threshold)

Construct sparsity from a threshold based on per channel energy ratio. Use the “threshold” argument to specify the SNR threshold.

classmethod from_property(sorting_analyzer, by_property)

Construct sparsity witha property of the recording and sorting(e.g. “group”). Use the “by_property” argument to specify the property name.

classmethod from_ptp(templates_or_sorting_analyzer, threshold, noise_levels=None)

Construct sparsity from a thresholds based on template peak-to-peak values. Use the “threshold” argument to specify the SNR threshold.

classmethod from_radius(templates_or_sorting_analyzer, radius_um, peak_sign='neg')

Construct sparsity from a radius around the best channel. Use the “radius_um” argument to specify the radius in um

classmethod from_snr(templates_or_sorting_analyzer, threshold, noise_levels=None, peak_sign='neg')

Construct sparsity from a thresholds based on template signal-to-noise ratio. Use the “threshold” argument to specify the SNR threshold.

classmethod from_unit_id_to_channel_ids(unit_id_to_channel_ids, unit_ids, channel_ids)

Create a sparsity object from dict unit_id to channel_ids.

sparsify_waveforms(waveforms: ndarray, unit_id: str | int) ndarray

Sparsify the waveforms according to a unit_id corresponding sparsity.

Given a unit_id, this method selects only the active channels for that unit and removes the rest.

Parameters:
waveformsnp.array

Dense waveforms with shape (num_waveforms, num_samples, num_channels) or a single dense waveform (template) with shape (num_samples, num_channels).

unit_idstr

The unit_id for which to sparsify the waveform.

Returns:
sparsified_waveformsnp.array

Sparse waveforms with shape (num_waveforms, num_samples, num_active_channels) or a single sparsified waveform (template) with shape (num_samples, num_active_channels).

to_dict()

Return a serializable dict.

class spikeinterface.core.BinaryRecordingExtractor(file_paths, sampling_frequency, dtype, num_channels=None, t_starts=None, channel_ids=None, time_axis=0, file_offset=0, gain_to_uV=None, offset_to_uV=None, is_filtered=None, num_chan=None)

RecordingExtractor for a binary format

Parameters:
file_paths: str or Path or list

Path to the binary file

sampling_frequency: float

The sampling frequency

num_channels: int

Number of channels

num_chan: int [deprecated, use num_channels instead, will be removed as early as v0.100.0]

Number of channels

dtype: str or dtype

The dtype of the binary file

time_axis: int, default: 0

The axis of the time dimension

t_starts: None or list of float, default: None

Times in seconds of the first sample for each segment

channel_ids: list, default: None

A list of channel ids

file_offset: int, default: 0

Number of bytes in the file to offset by during memmap instantiation.

gain_to_uV: float or array-like, default: None

The gain to apply to the traces

offset_to_uV: float or array-like, default: None

The offset to apply to the traces

is_filtered: bool or None, default: None

If True, the recording is assumed to be filtered. If None, is_filtered is not set.

Returns:
recording: BinaryRecordingExtractor

The recording Extractor

Notes

When both num_channels and num_chan are provided, num_channels is used and num_chan is ignored.

class spikeinterface.core.ZarrRecordingExtractor(folder_path: Path | str, storage_options: dict | None = None)

RecordingExtractor for a zarr format

Parameters:
folder_path: str or Path

Path to the zarr root folder

storage_options: dict or None

Storage options for zarr store. E.g., if “s3://” or “gcs://” they can provide authentication methods, etc.

Returns:
recording: ZarrRecordingExtractor

The recording Extractor

class spikeinterface.core.BinaryFolderRecording(folder_path)

BinaryFolderRecording is an internal format used in spikeinterface. It is a BinaryRecordingExtractor + metadata contained in a folder.

It is created with the function: recording.save(format=”binary”, folder=”/myfolder”)

Parameters:
folder_path: str or Path
Returns:
recording: BinaryFolderRecording

The recording

class spikeinterface.core.NpzFolderSorting(folder_path)

NpzFolderSorting is the old internal format used in spikeinterface (<=0.98.0)

This a folder that contains:

  • “sorting_cached.npz” file in the NpzSortingExtractor format

  • “npz.json” which the json description of NpzSortingExtractor

  • a metadata folder for units properties.

It is created with the function: sorting.save(folder=”/myfolder”, format=”npz_folder”)

Parameters:
folder_path: str or Path
Returns:
sorting: NpzFolderSorting

The sorting

class spikeinterface.core.NpyFolderSnippets(folder_path)

NpyFolderSnippets is an internal format used in spikeinterface. It is a NpySnippetsExtractor + metadata contained in a folder.

It is created with the function: snippets.save(format=”npy”, folder=”/myfolder”)

Parameters:
folder_path: str or Path

The path to the folder

Returns:
snippets: NpyFolderSnippets

The snippets

class spikeinterface.core.NumpyRecording(traces_list, sampling_frequency, t_starts=None, channel_ids=None)

In memory recording. Contrary to previous version this class does not handle npy files.

Parameters:
traces_list: list of array or array (if mono segment)

The traces to instantiate a mono or multisegment Recording

sampling_frequency: float

The sampling frequency in Hz

t_starts: None or list of float

Times in seconds of the first sample for each segment

channel_ids: list

An optional list of channel_ids. If None, linear channels are assumed

class spikeinterface.core.NumpySorting(spikes, sampling_frequency, unit_ids)

In memory sorting object. The internal representation is always done with a long “spike vector”.

But we have convenient class methods to instantiate from:
  • other sorting object: NumpySorting.from_sorting()

  • from time+labels: NumpySorting.from_times_labels()

  • from dict of list: NumpySorting.from_unit_dict()

  • from neo: NumpySorting.from_neo_spiketrain_list()

Parameters:
spikes: numpy.array

A numpy vector, the one given by Sorting.to_spike_vector().

sampling_frequency: float

The sampling frequency in Hz

channel_ids: list

A list of unit_ids.

class spikeinterface.core.NumpySnippets(snippets_list, spikesframes_list, sampling_frequency, nbefore=None, channel_ids=None)

In memory recording. Contrary to previous version this class does not handle npy files.

Parameters:
snippets_list: list of array or array (if mono segment)

The snippets to instantiate a mono or multisegment basesnippet

spikesframes_list: list of array or array (if mono segment)

Frame of each snippet

sampling_frequency: float

The sampling frequency in Hz

channel_ids: list

An optional list of channel_ids. If None, linear channels are assumed

class spikeinterface.core.AppendSegmentRecording(recording_list, sampling_frequency_max_diff=0)

Takes as input a list of parent recordings each with multiple segments and returns a single multi-segment recording that “appends” all segments from all parent recordings.

For instance, given one recording with 2 segments and one recording with 3 segments, this class will give one recording with 5 segments

Parameters:
recording_listlist of BaseRecording

A list of recordings

sampling_frequency_max_difffloat, default: 0

Maximum allowed difference of sampling frequencies across recordings

class spikeinterface.core.ConcatenateSegmentRecording(recording_list, ignore_times=True, sampling_frequency_max_diff=0)

Return a recording that “concatenates” all segments from all parent recordings into one recording with a single segment. The operation is lazy.

For instance, given one recording with 2 segments and one recording with 3 segments, this class will give one recording with one large segment made by concatenating the 5 segments.

Time information is lost upon concatenation. By default ignore_times is True. If it is False, you get an error unless:

  • all segments DO NOT have times, AND

  • all segment have t_start=None

Parameters:
recording_listlist of BaseRecording

A list of recordings

ignore_times: bool, default: True

If True, time information (t_start, time_vector) is ignored when concatenating recordings

sampling_frequency_max_difffloat, default: 0

Maximum allowed difference of sampling frequencies across recordings

class spikeinterface.core.SelectSegmentRecording(recording: BaseRecording, segment_indices: int | list[int])

Return a new recording with a subset of segments from a multi-segment recording.

Parameters:
recordingBaseRecording

The multi-segment recording

segment_indicesint | list[int]

The segment indices to select

class spikeinterface.core.AppendSegmentSorting(sorting_list, sampling_frequency_max_diff=0)

Return a sorting that “append” all segments from all sorting into one sorting multi segment.

Parameters:
sorting_listlist of BaseSorting

A list of sortings

sampling_frequency_max_difffloat, default: 0

Maximum allowed difference of sampling frequencies across sortings

class spikeinterface.core.SplitSegmentSorting(parent_sorting: BaseSorting, recording_or_recording_list=None)

Splits a sorting with a single segment to multiple segments based on the given list of recordings (must be in order)

Parameters:
parent_sortingBaseSorting

Sorting with a single segment (e.g. from sorting concatenated recording)

recording_or_recording_listlist of recordings, ConcatenateSegmentRecording, or None, default: None

If list of recordings, uses the lengths of those recordings to split the sorting into smaller segments If ConcatenateSegmentRecording, uses the associated list of recordings to split the sorting into smaller segments If None, looks for the recording associated with the sorting

class spikeinterface.core.SelectSegmentSorting(sorting: BaseSorting, segment_indices: int | list[int])

Return a new sorting with a single segment from a multi-segment sorting.

Parameters:
sortingBaseSorting

The multi-segment sorting

segment_indicesint | list[int]

The segment indices to select

spikeinterface.core.download_dataset(repo: str = 'https://gin.g-node.org/NeuralEnsemble/ephy_testing_data', remote_path: str = 'mearec/mearec_test_10s.h5', local_folder: Path | None = None, update_if_exists: bool = False, unlock: bool = False) Path

Function to download dataset from a remote repository using datalad.

Parameters:
repostr, default: “https://gin.g-node.org/NeuralEnsemble/ephy_testing_data

The repository to download the dataset from

remote_pathstr, default: “mearec/mearec_test_10s.h5”

A specific subdirectory in the repository to download (e.g. Mearec, SpikeGLX, etc)

local_folderstr, default: None

The destination folder / directory to download the dataset to. defaults to the path “get_global_dataset_folder()” / f{repo_name} (see spikeinterface.core.globals)

update_if_existsbool, default: False

Forces re-download of the dataset if it already exists, default: False

unlockbool, default: False

Use to enable the edition of the downloaded file content, default: False

Returns:
Path

The local path to the downloaded dataset

spikeinterface.core.write_binary_recording(recording: BaseRecording, file_paths: list[Path | str] | Path | str, dtype: np.ndtype = None, add_file_extension: bool = True, byte_offset: int = 0, auto_cast_uint: bool = True, verbose: bool = False, **job_kwargs)

Save the trace of a recording extractor in several binary .dat format.

Note :

time_axis is always 0 (contrary to previous version. to get time_axis=1 (which is a bad idea) use write_binary_recording_file_handle()

Parameters:
recording: RecordingExtractor

The recording extractor object to be saved in .dat format

file_path: str or list[str]

The path to the file.

dtype: dtype or None, default: None

Type of the saved data

add_file_extension, bool, default: True

If True, and the file path does not end in “raw”, “bin”, or “dat” then “raw” is added as an extension.

byte_offset: int, default: 0

Offset in bytes for the binary file (e.g. to write a header). This is useful in case you want to append data to an existing file where you wrote a header or other data before.

auto_cast_uint: bool, default: True

If True, unsigned integers are automatically cast to int if the specified dtype is signed .. deprecated:: 0.103, use the unsigned_to_signed function instead.

verbose: bool

This is the verbosity of the ChunkRecordingExecutor

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

spikeinterface.core.set_global_tmp_folder(folder)

Set the global path temporary folder.

spikeinterface.core.set_global_dataset_folder(folder)

Set the global dataset folder.

spikeinterface.core.set_global_job_kwargs(**job_kwargs)

Set the global job kwargs.

Parameters:
**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

spikeinterface.core.get_random_data_chunks(recording, return_scaled=False, num_chunks_per_segment=20, chunk_size=10000, concatenated=True, seed=0, margin_frames=0)

Extract random chunks across segments

This is used for instance in get_noise_levels() to estimate noise on traces.

Parameters:
recording: BaseRecording

The recording to get random chunks from

return_scaled: bool, default: False

If True, returned chunks are scaled to uV

num_chunks_per_segment: int, default: 20

Number of chunks per segment

chunk_size: int, default: 10000

Size of a chunk in number of frames

concatenated: bool, default: True

If True chunk are concatenated along time axis

seed: int, default: 0

Random seed

margin_frames: int, default: 0

Margin in number of frames to avoid edge effects

Returns:
chunk_list: np.array

Array of concatenate chunks per segment

spikeinterface.core.get_channel_distances(recording)

Distance between channel pairs

spikeinterface.core.get_closest_channels(recording, channel_ids=None, num_channels=None)

Get closest channels + distances

Parameters:
recording: RecordingExtractor

The recording extractor to get closest channels

channel_ids: list

List of channels ids to compute there near neighborhood

num_channels: int, default: None

Maximum number of neighborhood channels to return

Returns:
closest_channels_indsarray (2d)

Closest channel indices in ascending order for each channel id given in input

dists: array (2d)

Distance in ascending order for each channel id given in input

spikeinterface.core.get_noise_levels(recording: BaseRecording, return_scaled: bool = True, method: Literal['mad', 'std'] = 'mad', force_recompute: bool = False, **random_chunk_kwargs)

Estimate noise for each channel using MAD methods. You can use standard deviation with method=”std”

Internally it samples some chunk across segment. And then, it use MAD estimator (more robust than STD)

Parameters:
recording: BaseRecording

The recording extractor to get noise levels

return_scaled: bool

If True, returned noise levels are scaled to uV

method: “mad” | “std”, default: “mad”

The method to use to estimate noise levels

force_recompute: bool

If True, noise levels are recomputed even if they are already stored in the recording extractor

random_chunk_kwargs: dict

Kwargs for get_random_data_chunks

Returns:
noise_levels: array

Noise levels for each channel

spikeinterface.core.get_chunk_with_margin(rec_segment, start_frame, end_frame, channel_indices, margin, add_zeros=False, add_reflect_padding=False, window_on_margin=False, dtype=None)

Helper to get chunk with margin

The margin is extracted from the recording when possible. If at the edge of the recording, no margin is used unless one of add_zeros or add_reflect_padding is True. In the first case zero padding is used, in the second case np.pad is called with mod=”reflect”.

spikeinterface.core.order_channels_by_depth(recording, channel_ids=None, dimensions=('x', 'y'), flip=False)

Order channels by depth, by first ordering the x-axis, and then the y-axis.

Parameters:
recordingBaseRecording

The input recording

channel_idslist/array or None

If given, a subset of channels to order locations for

dimensionsstr, tuple, or list, default: (‘x’, ‘y’)

If str, it needs to be ‘x’, ‘y’, ‘z’. If tuple or list, it sorts the locations in two dimensions using lexsort. This approach is recommended since there is less ambiguity

flip: bool, default: False

If flip is False then the order is bottom first (starting from tip of the probe). If flip is True then the order is upper first.

Returns:
order_fnp.array

Array with sorted indices

order_rnp.array

Array with indices to revert sorting

spikeinterface.core.get_template_amplitudes(templates_or_sorting_analyzer, peak_sign: neg' | 'pos' | 'both = 'neg', mode: extremum' | 'at_index' | 'peak_to_peak = 'extremum', return_scaled: bool = True, abs_value: bool = True)

Get amplitude per channel for each unit.

Parameters:
templates_or_sorting_analyzer: Templates | SortingAnalyzer

A Templates or a SortingAnalyzer object

peak_sign: “neg” | “pos” | “both”

Sign of the template to find extremum channels

mode: “extremum” | “at_index” | “peak_to_peak”, default: “at_index”

Where the amplitude is computed * “extremum”: take the peak value (max or min depending on peak_sign) * “at_index”: take value at nbefore index * “peak_to_peak”: take the peak-to-peak amplitude

return_scaled: bool, default True

The amplitude is scaled or not.

abs_value: bool = True

Whether the extremum amplitude should be returned as an absolute value or not

Returns:
peak_values: dict

Dictionary with unit ids as keys and template amplitudes as values

spikeinterface.core.get_template_extremum_channel(templates_or_sorting_analyzer, peak_sign: neg' | 'pos' | 'both = 'neg', mode: extremum' | 'at_index' | 'peak_to_peak = 'extremum', outputs: id' | 'index = 'id')

Compute the channel with the extremum peak for each unit.

Parameters:
templates_or_sorting_analyzer: Templates | SortingAnalyzer

A Templates or a SortingAnalyzer object

peak_sign: “neg” | “pos” | “both”

Sign of the template to find extremum channels

mode: “extremum” | “at_index” | “peak_to_peak”, default: “at_index”

Where the amplitude is computed * “extremum”: take the peak value (max or min depending on peak_sign) * “at_index”: take value at nbefore index * “peak_to_peak”: take the peak-to-peak amplitude

outputs: “id” | “index”, default: “id”
  • “id”: channel id

  • “index”: channel index

Returns:
extremum_channels: dict

Dictionary with unit ids as keys and extremum channels (id or index based on “outputs”) as values

spikeinterface.core.get_template_extremum_channel_peak_shift(templates_or_sorting_analyzer, peak_sign: neg' | 'pos' | 'both = 'neg')

In some situations spike sorters could return a spike index with a small shift related to the waveform peak. This function estimates and return these alignment shifts for the mean template. This function is internally used by compute_spike_amplitudes() to accurately retrieve the spike amplitudes.

Parameters:
templates_or_sorting_analyzer: Templates | SortingAnalyzer

A Templates or a SortingAnalyzer object

peak_sign: “neg” | “pos” | “both”

Sign of the template to find extremum channels

Returns:
shifts: dict

Dictionary with unit ids as keys and shifts as values

spikeinterface.core.get_template_extremum_amplitude(templates_or_sorting_analyzer, peak_sign: neg' | 'pos' | 'both = 'neg', mode: extremum' | 'at_index' | 'peak_to_peak = 'at_index', abs_value: bool = True)

Computes amplitudes on the best channel.

Parameters:
templates_or_sorting_analyzer: Templates | SortingAnalyzer

A Templates or a SortingAnalyzer object

peak_sign: “neg” | “pos” | “both”

Sign of the template to find extremum channels

mode: “extremum” | “at_index” | “peak_to_peak”, default: “at_index”

Where the amplitude is computed * “extremum”: take the peak value (max or min depending on peak_sign) * “at_index”: take value at nbefore index * “peak_to_peak”: take the peak-to-peak amplitude

abs_value: bool = True

Whether the extremum amplitude should be returned as an absolute value or not

Returns:
amplitudes: dict

Dictionary with unit ids as keys and amplitudes as values

spikeinterface.core.append_recordings(recording_list, sampling_frequency_max_diff=0)

Takes as input a list of parent recordings each with multiple segments and returns a single multi-segment recording that “appends” all segments from all parent recordings.

For instance, given one recording with 2 segments and one recording with 3 segments, this class will give one recording with 5 segments

Parameters:
recording_listlist of BaseRecording

A list of recordings

sampling_frequency_max_difffloat, default: 0

Maximum allowed difference of sampling frequencies across recordings

spikeinterface.core.concatenate_recordings(recording_list, ignore_times=True, sampling_frequency_max_diff=0)

Return a recording that “concatenates” all segments from all parent recordings into one recording with a single segment. The operation is lazy.

For instance, given one recording with 2 segments and one recording with 3 segments, this class will give one recording with one large segment made by concatenating the 5 segments.

Time information is lost upon concatenation. By default ignore_times is True. If it is False, you get an error unless:

  • all segments DO NOT have times, AND

  • all segment have t_start=None

Parameters:
recording_listlist of BaseRecording

A list of recordings

ignore_times: bool, default: True

If True, time information (t_start, time_vector) is ignored when concatenating recordings

sampling_frequency_max_difffloat, default: 0

Maximum allowed difference of sampling frequencies across recordings

spikeinterface.core.split_recording(recording: BaseRecording)

Return a list of mono-segment recordings from a multi-segment recording.

Parameters:
recordingBaseRecording

The multi-segment recording

Returns:
recording_list

A list of mono-segment recordings

spikeinterface.core.select_segment_recording(recording: BaseRecording, segment_indices: int | list[int])

Return a new recording with a subset of segments from a multi-segment recording.

Parameters:
recordingBaseRecording

The multi-segment recording

segment_indicesint | list[int]

The segment indices to select

spikeinterface.core.append_sortings(sorting_list, sampling_frequency_max_diff=0)

Return a sorting that “append” all segments from all sorting into one sorting multi segment.

Parameters:
sorting_listlist of BaseSorting

A list of sortings

sampling_frequency_max_difffloat, default: 0

Maximum allowed difference of sampling frequencies across sortings

spikeinterface.core.split_sorting(parent_sorting: BaseSorting, recording_or_recording_list=None)

Splits a sorting with a single segment to multiple segments based on the given list of recordings (must be in order)

Parameters:
parent_sortingBaseSorting

Sorting with a single segment (e.g. from sorting concatenated recording)

recording_or_recording_listlist of recordings, ConcatenateSegmentRecording, or None, default: None

If list of recordings, uses the lengths of those recordings to split the sorting into smaller segments If ConcatenateSegmentRecording, uses the associated list of recordings to split the sorting into smaller segments If None, looks for the recording associated with the sorting

spikeinterface.core.select_segment_sorting(sorting: BaseSorting, segment_indices: int | list[int])

Return a new sorting with a single segment from a multi-segment sorting.

Parameters:
sortingBaseSorting

The multi-segment sorting

segment_indicesint | list[int]

The segment indices to select

spikeinterface.core.read_binary(file_paths, sampling_frequency, dtype, num_channels=None, t_starts=None, channel_ids=None, time_axis=0, file_offset=0, gain_to_uV=None, offset_to_uV=None, is_filtered=None, num_chan=None)

RecordingExtractor for a binary format

Parameters:
file_paths: str or Path or list

Path to the binary file

sampling_frequency: float

The sampling frequency

num_channels: int

Number of channels

num_chan: int [deprecated, use num_channels instead, will be removed as early as v0.100.0]

Number of channels

dtype: str or dtype

The dtype of the binary file

time_axis: int, default: 0

The axis of the time dimension

t_starts: None or list of float, default: None

Times in seconds of the first sample for each segment

channel_ids: list, default: None

A list of channel ids

file_offset: int, default: 0

Number of bytes in the file to offset by during memmap instantiation.

gain_to_uV: float or array-like, default: None

The gain to apply to the traces

offset_to_uV: float or array-like, default: None

The offset to apply to the traces

is_filtered: bool or None, default: None

If True, the recording is assumed to be filtered. If None, is_filtered is not set.

Returns:
recording: BinaryRecordingExtractor

The recording Extractor

Notes

When both num_channels and num_chan are provided, num_channels is used and num_chan is ignored.

spikeinterface.core.read_zarr(folder_path: str | Path, storage_options: dict | None = None) ZarrRecordingExtractor | ZarrSortingExtractor

Read recording or sorting from a zarr format

Parameters:
folder_path: str or Path

Path to the zarr root file

storage_options: dict or None

Storage options for zarr store. E.g., if “s3://” or “gcs://” they can provide authentication methods, etc.

Returns:
extractor: ZarrExtractor

The loaded extractor

Low-level

class spikeinterface.core.ChunkRecordingExecutor(recording, func, init_func, init_args, verbose=False, progress_bar=False, handle_returns=False, gather_func=None, n_jobs=1, total_memory=None, chunk_size=None, chunk_memory=None, chunk_duration=None, mp_context=None, job_name='', max_threads_per_process=1)

Core class for parallel processing to run a “function” over chunks on a recording.

It supports running a function:
  • in loop with chunk processing (low RAM usage)

  • at once if chunk_size is None (high RAM usage)

  • in parallel with ProcessPoolExecutor (higher speed)

The initializer (“init_func”) allows to set a global context to avoid heavy serialization (for examples, see implementation in core.waveform_tools).

Parameters:
recording: RecordingExtractor

The recording to be processed

func: function

Function that runs on each chunk

init_func: function

Initializer function to set the global context (accessible by “func”)

init_args: tuple

Arguments for init_func

verbose: bool

If True, output is verbose

job_name: str, default: “”

Job name

handle_returns: bool, default: False

If True, the function can return values

gather_func: None or callable, default: None

Optional function that is called in the main thread and retrieves the results of each worker. This function can be used instead of handle_returns to implement custom storage on-the-fly.

n_jobs: int, default: 1

Number of jobs to be used. Use -1 to use as many jobs as number of cores

total_memory: str, default: None

Total memory (RAM) to use (e.g. “1G”, “500M”)

chunk_memory: str, default: None

Memory per chunk (RAM) to use (e.g. “1G”, “500M”)

chunk_size: int or None, default: None

Size of each chunk in number of samples. If “total_memory” or “chunk_memory” are used, it is ignored.

chunk_durationstr or float or None

Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

mp_context“fork” | “spawn” | None, default: None

“fork” or “spawn”. If None, the context is taken by the recording.get_preferred_mp_context(). “fork” is only safely available on LINUX systems.

max_threads_per_process: int or None, default: None

Limit the number of thread per process using threadpoolctl modules. This used only when n_jobs>1 If None, no limits.

progress_bar: bool, default: False

If True, a progress bar is printed to monitor the progress of the process

Returns:
res: list

If “handle_returns” is True, the results for each chunk process

spikeinterface.extractors

NEO-based

spikeinterface.extractors.read_alphaomega(folder_path, lsx_files=None, stream_id='RAW', stream_name=None, all_annotations=False)

Class for reading from AlphaRS and AlphaLab SnR boards.

Based on neo.rawio.AlphaOmegaRawIO

Parameters:
folder_path: str or Path-like

The folder path to the AlphaOmega recordings.

lsx_files: list of strings or None, default: None

A list of listings files that refers to mpx files to load.

stream_id: {“RAW”, “LFP”, “SPK”, “ACC”, “AI”, “UD”}, default: “RAW”

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_alphaomega_event(folder_path)

Class for reading events from AlphaOmega MPX file format

spikeinterface.extractors.read_axona(file_path, all_annotations=False)

Class for reading Axona RAW format.

Based on neo.rawio.AxonaRawIO

Parameters:
file_path: str

The file path to load the recordings from.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_biocam(file_path, mea_pitch=None, electrode_width=None, stream_id=None, stream_name=None, block_index=None, all_annotations=False)

Class for reading data from a Biocam file from 3Brain.

Based on neo.rawio.BiocamRawIO

Parameters:
file_path: str

The file path to load the recordings from.

mea_pitch: float, default: None

The inter-electrode distance (pitch) between electrodes.

electrode_width: float, default: None

Width of the electrodes in um.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_binary(file_paths, sampling_frequency, dtype, num_channels=None, t_starts=None, channel_ids=None, time_axis=0, file_offset=0, gain_to_uV=None, offset_to_uV=None, is_filtered=None, num_chan=None)

RecordingExtractor for a binary format

Parameters:
file_paths: str or Path or list

Path to the binary file

sampling_frequency: float

The sampling frequency

num_channels: int

Number of channels

num_chan: int [deprecated, use num_channels instead, will be removed as early as v0.100.0]

Number of channels

dtype: str or dtype

The dtype of the binary file

time_axis: int, default: 0

The axis of the time dimension

t_starts: None or list of float, default: None

Times in seconds of the first sample for each segment

channel_ids: list, default: None

A list of channel ids

file_offset: int, default: 0

Number of bytes in the file to offset by during memmap instantiation.

gain_to_uV: float or array-like, default: None

The gain to apply to the traces

offset_to_uV: float or array-like, default: None

The offset to apply to the traces

is_filtered: bool or None, default: None

If True, the recording is assumed to be filtered. If None, is_filtered is not set.

Returns:
recording: BinaryRecordingExtractor

The recording Extractor

Notes

When both num_channels and num_chan are provided, num_channels is used and num_chan is ignored.

spikeinterface.extractors.read_blackrock(file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False, use_names_as_ids=False)

Class for reading BlackRock data.

Based on neo.rawio.BlackrockRawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_ced(file_path, stream_id=None, stream_name=None, all_annotations=False)

Class for reading smr/smrw CED file.

Based on neo.rawio.CedRawIO / sonpy

Alternative to read_spike2 which does not handle smrx

Parameters:
file_path: str

The file path to the smr or smrx file.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

block_index: int, default: None

If there are several blocks, specify the block index you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_intan(file_path, stream_id=None, stream_name=None, all_annotations=False, use_names_as_ids=False)

Class for reading data from a intan board. Supports rhd and rhs format.

Based on neo.rawio.IntanRawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_maxwell(file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False, rec_name=None, install_maxwell_plugin=False)

Class for reading data from Maxwell device. It handles MaxOne (old and new format) and MaxTwo.

Based on neo.rawio.MaxwellRawIO

Parameters:
file_path: str

The file path to the maxwell h5 file.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load. For MaxTwo when there are several wells at the same time you need to specify stream_id=’well000’ or ‘well0001’, etc.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

rec_name: str, default: None

When the file contains several recordings you need to specify the one you want to extract. (rec_name=’rec0000’).

install_maxwell_plugin: bool, default: False

If True, install the maxwell plugin for neo.

spikeinterface.extractors.read_mearec(file_path)

Read a MEArec file.

Parameters:
file_path: str or Path

Path to MEArec h5 file

Returns:
recording: MEArecRecordingExtractor

The recording extractor object

sorting: MEArecSortingExtractor

The sorting extractor object

spikeinterface.extractors.read_mcsraw(file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False)

Class for reading data from “Raw” Multi Channel System (MCS) format. This format is NOT the native MCS format (.mcd). This format is a raw format with an internal binary header exported by the “MC_DataTool binary conversion” with the option header selected.

Based on neo.rawio.RawMCSRawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

block_index: int, default: None

If there are several blocks, specify the block index you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_neuralynx(folder_path, stream_id=None, stream_name=None, all_annotations=False, exclude_filename=None, strict_gap_mode=False)

Class for reading neuralynx folder

Based on neo.rawio.NeuralynxRawIO

Parameters:
folder_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

exlude_filename: list[str], default: None

List of filename to exclude from the loading. For example, use exclude_filename=[“events.nev”] to skip loading the event file.

strict_gap_mode: bool, default: False

See neo documentation. Detect gaps using strict mode or not.

  • strict_gap_mode = True then a gap is consider when timstamp difference between two consecutive data packets is more than one sample interval.

  • strict_gap_mode = False then a gap has an increased tolerance. Some new systems with different clocks need this option otherwise, too many gaps are detected

Note that here the default is False contrary to neo.

spikeinterface.extractors.read_neuralynx_sorting(folder_path: str, sampling_frequency: float | None = None, stream_id: str | None = None, stream_name: str | None = None)

Class for reading spike data from a folder with neuralynx spiking data (i.e .nse and .ntt formats).

Based on neo.rawio.NeuralynxRawIO

Parameters:
folder_path: str

The file path to load the recordings from.

sampling_frequency: float

The sampling frequency for the spiking channels. When the signal data is available (.ncs) those files will be used to extract the frequency. Otherwise, the sampling frequency needs to be specified for this extractor.

stream_id: str, default: None

Used to extract information about the sampling frequency and t_start from the analog signal if provided.

stream_name: str, default: None

Used to extract information about the sampling frequency and t_start from the analog signal if provided.

spikeinterface.extractors.read_neuroexplorer(file_path, stream_id=None, stream_name=None, all_annotations=False)

Class for reading NEX (NeuroExplorer data format) files.

Based on neo.rawio.NeuroExplorerRawIO

Importantly, at the moment, this recorder only extracts one channel of the recording. This is because the NeuroExplorerRawIO class does not support multi-channel recordings as in the NeuroExplorer format they might have different sampling rates.

Consider extracting all the channels and then concatenating them with the aggregate_channels function.

>>> from spikeinterface.extractors.neoextractors.neuroexplorer import NeuroExplorerRecordingExtractor
>>> from spikeinterface.core import aggregate_channels
>>>
>>> file_path="/the/path/to/your/nex/file.nex"
>>>
>>> streams = NeuroExplorerRecordingExtractor.get_streams(file_path=file_path)
>>> stream_names = streams[0]
>>>
>>> your_signal_stream_names = "Here goes the logic to filter from stream names the ones that you know have the same sampling rate and you want to aggregate"
>>>
>>> recording_list = [NeuroExplorerRecordingExtractor(file_path=file_path, stream_name=stream_name) for stream_name in your_signal_stream_names]
>>> recording = aggregate_channels(recording_list)
Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load. For this neo reader streams are defined by their sampling frequency.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_neuroscope(file_path, stream_id=None, keep_mua_units=False, exclude_shanks=None, load_recording=True, load_sorting=False)

Read neuroscope recording and sorting. This function assumses that all .res and .clu files are in the same folder as the .xml file.

Parameters:
file_path: str

The xml file.

stream_id: str or None

The stream id to load. If None, the first stream is loaded

keep_mua_units: bool, default: False

Optional. Whether or not to return sorted spikes from multi-unit activity

exclude_shanks: list

Optional. List of indices to ignore. The set of all possible indices is chosen by default, extracted as the final integer of all the .res. % i and .clu. % i pairs.

load_recording: bool, default: True

If True, the recording is loaded

load_sorting: bool, default: False

If True, the sorting is loaded

spikeinterface.extractors.read_nix(file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False)

Class for reading Nix file

Based on neo.rawio.NIXRawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

block_index: int, default: None

If there are several blocks, specify the block index you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_openephys(folder_path, **kwargs)

Read “legacy” or “binary” Open Ephys formats

Parameters:
folder_path: str or Path

Path to openephys folder

stream_id: str, default: None

If there are several streams, specify the stream id you want to load

stream_name: str, default: None

If there are several streams, specify the stream name you want to load

block_index: int, default: None

If there are several blocks (experiments), specify the block index you want to load

all_annotations: bool, default: False

Load exhaustively all annotation from neo

load_sync_channelbool, default: False

If False (default) and a SYNC channel is present (e.g. Neuropixels), this is not loaded. If True, the SYNC channel is loaded and can be accessed in the analog signals. For open ephsy binary format only

load_sync_timestampsbool, default: False

If True, the synchronized_timestamps are loaded and set as times to the recording. If False (default), only the t_start and sampling rate are set, and timestamps are assumed to be uniform and linearly increasing. For open ephsy binary format only

experiment_names: str, list, or None, default: None

If multiple experiments are available, this argument allows users to select one or more experiments. If None, all experiements are loaded as blocks. E.g. experiment_names=”experiment2”, experiment_names=[“experiment1”, “experiment2”] For open ephsy binary format only

ignore_timestamps_errors: bool, default: False

Ignore the discontinuous timestamps errors in neo For open ephsy legacy format only

Returns:
recording: OpenEphysLegacyRecordingExtractor or OpenEphysBinaryExtractor
spikeinterface.extractors.read_openephys_event(folder_path, block_index=None)

Read Open Ephys events from “binary” format.

Parameters:
folder_path: str or Path

Path to openephys folder

block_index: int, default: None

If there are several blocks (experiments), specify the block index you want to load.

Returns:
event: OpenEphysBinaryEventExtractor
spikeinterface.extractors.read_plexon(file_path, stream_id=None, stream_name=None, all_annotations=False)

Class for reading plexon plx files.

Based on neo.rawio.PlexonRawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_plexon_sorting(file_path)

Class for reading plexon spiking data (.plx files).

Based on neo.rawio.PlexonRawIO

Parameters:
file_path: str

The file path to load the recordings from.

spikeinterface.extractors.read_plexon2(file_path, stream_id=None, stream_name=None, all_annotations=False)

Class for reading plexon pl2 files.

Based on neo.rawio.Plexon2RawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_plexon2_sorting(file_path, sampling_frequency=None)

Class for reading plexon spiking data from .pl2 files.

Based on neo.rawio.Plexon2RawIO

Parameters:
file_path: str

The file path to load the recordings from.

sampling_frequency: float, default: None

The sampling frequency of the sorting (required for multiple streams with different sampling frequencies).

spikeinterface.extractors.read_spike2(file_path, stream_id=None, stream_name=None, all_annotations=False)

Class for reading spike2 smr files. smrx are not supported with this, prefer CedRecordingExtractor instead.

Based on neo.rawio.Spike2RawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_spikegadgets(file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False)

Class for reading rec files from spikegadgets.

Based on neo.rawio.SpikeGadgetsRawIO

Parameters:
file_path: str

The file path to load the recordings from.

stream_id: str or None, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str or None, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_spikeglx(folder_path, load_sync_channel=False, stream_id=None, stream_name=None, all_annotations=False)

Class for reading data saved by SpikeGLX software. See https://billkarsh.github.io/SpikeGLX/

Based on neo.rawio.SpikeGLXRawIO

Contrary to older verions, this reader is folder-based. If the folder contains several streams (e.g., “imec0.ap”, “nidq” ,”imec0.lf”), then the stream has to be specified with “stream_id” or “stream_name”.

Parameters:
folder_path: str

The folder path to load the recordings from.

load_sync_channel: bool default: False

Whether or not to load the last channel in the stream, which is typically used for synchronization. If True, then the probe is not loaded.

stream_id: str or None, default: None

If there are several streams, specify the stream id you want to load. For example, “imec0.ap”, “nidq”, or “imec0.lf”.

stream_name: str or None, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_tdt(folder_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False)

Class for reading TDT folder.

Based on neo.rawio.TdTRawIO

Parameters:
folder_path: str

The folder path to the tdt folder.

stream_id: str or None, default: None

If there are several streams, specify the stream id you want to load.

stream_name: str or None, default: None

If there are several streams, specify the stream name you want to load.

all_annotations: bool, default: False

Load exhaustively all annotations from neo.

spikeinterface.extractors.read_zarr(folder_path: str | Path, storage_options: dict | None = None) ZarrRecordingExtractor | ZarrSortingExtractor

Read recording or sorting from a zarr format

Parameters:
folder_path: str or Path

Path to the zarr root file

storage_options: dict or None

Storage options for zarr store. E.g., if “s3://” or “gcs://” they can provide authentication methods, etc.

Returns:
extractor: ZarrExtractor

The loaded extractor

Non-NEO-based

spikeinterface.extractors.read_alf_sorting(folder_path, sampling_frequency=30000)

Load ALF format data as a sorting extractor.

Parameters:
folder_pathstr or Path

Path to the ALF folder.

sampling_frequencyint, default: 30000

The sampling frequency.

Returns:
extractorALFSortingExtractor

The loaded data.

spikeinterface.extractors.read_bids(folder_path)

Load a BIDS folder of data into extractor objects.

The following files are considered:

  • _channels.tsv

  • _contacts.tsv

  • _ephys.nwb

  • _probes.tsv

Parameters:
folder_pathstr or Path

Path to the BIDS folder.

Returns:
extractorslist of extractors

The loaded data, with attached Probes.

spikeinterface.extractors.read_cbin_ibl(folder_path=None, load_sync_channel=False, stream_name='ap', cbin_file=None)

Load IBL data as an extractor object.

IBL have a custom format - compressed binary with spikeglx meta.

The format is like spikeglx (have a meta file) but contains:

  • “cbin” file (instead of “bin”)

  • “ch” file used by mtscomp for compression info

Parameters:
folder_path: str or Path

Path to ibl folder.

load_sync_channel: bool, default: False

Load or not the last channel (sync). If not then the probe is loaded.

stream_name: str, default: “ap”.

Whether to load AP or LFP band, one of “ap” or “lp”.

Returns:
recordingCompressedBinaryIblExtractor

The loaded data.

spikeinterface.extractors.read_combinato(folder_path, sampling_frequency=None, user='simple', det_sign='both', keep_good_only=True)

Load Combinato format data as a sorting extractor.

Parameters:
folder_pathstr or Path

Path to the Combinato folder.

sampling_frequencyint, default: 30000

The sampling frequency.

userstr, default: “simple”

The username that ran the sorting

det_sign“both”, “pos”, “neg”, default: “both”

Which sign was used for detection.

keep_good_onlybool, default: True

Whether to only keep good units.

Returns:
extractorCombinatoSortingExtractor

The loaded data.

spikeinterface.extractors.read_hdsort(file_path, keep_good_only=True)

Load HDSort format data as a sorting extractor.

Parameters:
file_pathstr or Path

Path to HDSort mat file.

keep_good_onlybool, default: True

Whether to only keep good units.

Returns:
extractorHDSortSortingExtractor

The loaded data.

spikeinterface.extractors.read_herdingspikes(file_path, load_unit_info=True)

Load HerdingSpikes format data as a sorting extractor.

Parameters:
folder_pathstr or Path

Path to the ALF folder.

load_unit_infobool, default: True

Whether to load the unit info from the file.

Returns:
extractorHerdingSpikesSortingExtractor

The loaded data.

spikeinterface.extractors.read_kilosort(folder_path: Path | str, keep_good_only: bool = False, remove_empty_units: bool = True)

Load Kilosort format data as a sorting extractor.

Parameters:
folder_path: str or Path

Path to the output Phy folder (containing the params.py).

keep_good_onlybool, default: True

Whether to only keep good units. If True, only Kilosort-labeled ‘good’ units are returned.

remove_empty_unitsbool, default: True

If True, empty units are removed from the sorting extractor.

Returns:
extractorKiloSortSortingExtractor

The loaded Sorting object.

spikeinterface.extractors.read_klusta(file_or_folder_path, exclude_cluster_groups=None)

Load Klusta format data as a sorting extractor.

Parameters:
file_or_folder_pathstr or Path

Path to the ALF folder.

exclude_cluster_groups: list or str, default: None

Cluster groups to exclude (e.g. “noise” or [“noise”, “mua”]).

Returns:
extractorKlustaSortingExtractor

The loaded data.

spikeinterface.extractors.read_mcsh5(file_path, stream_id=0)

Load a MCS H5 file as a recording extractor.

Parameters:
file_pathstr or Path

The path to the MCS h5 file.

stream_idint, default: 0

The stream ID to load.

Returns:
recordingMCSH5RecordingExtractor

The loaded data.

spikeinterface.extractors.read_mda_recording(folder_path, raw_fname='raw.mda', params_fname='params.json', geom_fname='geom.csv')

Load MDA format data as a recording extractor.

Parameters:
folder_pathstr or Path

Path to the MDA folder.

raw_fname: str, default: “raw.mda”

File name of raw file

params_fname: str, default: “params.json”

File name of params file

geom_fname: str, default: “geom.csv”

File name of geom file

Returns:
extractorMdaRecordingExtractor

The loaded data.

spikeinterface.extractors.read_mda_sorting(file_path, sampling_frequency)

Load MDA format data as a sorting extractor.

Parameters:
file_pathstr or Path

Path to the MDA file.

sampling_frequencyint

The sampling frequency.

Returns:
extractorMdaRecordingExtractor

The loaded data.

spikeinterface.extractors.read_nwb(file_path, load_recording=True, load_sorting=False, electrical_series_path=None)

Reads NWB file into SpikeInterface extractors.

Parameters:
file_path: str or Path

Path to NWB file.

load_recordingbool, default: True

If True, the recording object is loaded.

load_sortingbool, default: False

If True, the recording object is loaded.

electrical_series_path: str or None, default: None

The name of the ElectricalSeries (if multiple ElectricalSeries are present)

Returns:
extractors: extractor or tuple

Single RecordingExtractor/SortingExtractor or tuple with both (depending on “load_recording”/”load_sorting”) arguments.

spikeinterface.extractors.read_phy(folder_path: Path | str, exclude_cluster_groups: list[str] | str | None = None, load_all_cluster_properties: bool = True)

Load Phy format data as a sorting extractor.

Parameters:
folder_path: str or Path

Path to the output Phy folder (containing the params.py).

exclude_cluster_groups: list or str, default: None

Cluster groups to exclude (e.g. “noise” or [“noise”, “mua”]).

load_all_cluster_propertiesbool, default: True

If True, all cluster properties are loaded from the tsv/csv files.

Returns:
extractorPhySortingExtractor

The loaded Sorting object.

spikeinterface.extractors.read_shybrid_recording(file_path)

Load SHYBRID format data as a recording extractor.

Parameters:
file_pathstr or Path

Path to the SHYBRID file.

Returns:
extractorSHYBRIDRecordingExtractor

Loaded data.

spikeinterface.extractors.read_shybrid_sorting(file_path, sampling_frequency, delimiter=',')

Load SHYBRID format data as a sorting extractor.

Parameters:
file_pathstr or Path

Path to the SHYBRID file.

sampling_frequencyint

The sampling frequency.

delimiterstr

The delimiter to use for loading the file.

Returns:
extractorSHYBRIDSortingExtractor

Loaded data.

spikeinterface.extractors.read_spykingcircus(folder_path)

Load SpykingCircus format data as a recording extractor.

Parameters:
folder_pathstr or Path

Path to the SpykingCircus folder.

Returns:
extractorSpykingCircusSortingExtractor

Loaded data.

spikeinterface.extractors.toy_example(duration=10, num_channels=4, num_units=10, sampling_frequency=30000.0, num_segments=2, average_peak_amplitude=-100, upsample_factor=None, contact_spacing_um=40.0, num_columns=1, spike_times=None, spike_labels=None, firing_rate=3.0, seed=None)

Returns a generated dataset with “toy” units and spikes on top on white noise. This is useful to test api, algos, postprocessing and visualization without any downloading.

This a rewrite (with the lazy approach) of the old spikeinterface.extractor.toy_example() which itself was also a rewrite from the very old spikeextractor.toy_example() (from Jeremy Magland). In this new version, the recording is totally lazy and so it does not use disk space or memory. It internally uses NoiseGeneratorRecording + generate_templates + InjectTemplatesRecording.

For better control, you should use the generate_ground_truth_recording(), but provides better control over the parameters.

Parameters:
duration: float or list[float], default: 10

Duration in seconds. If a list is provided, it will be the duration of each segment.

num_channels: int, default: 4

Number of channels

num_units: int, default: 10

Number of units

sampling_frequency: float, default: 30000

Sampling frequency

num_segments: int, default: 2

Number of segments.

spike_times: np.array or list[nparray] or None, default: None

Spike time in the recording

spike_labels: np.array or list[nparray] or None, default: None

Cluster label for each spike time (needs to specified both together).

# score_detection: int (between 0 and 1)
# Generate the sorting based on a subset of spikes compare with the trace generation
firing_rate: float, default: 3.0

The firing rate for the units (in Hz)

seed: int or None, default: None

Seed for random initialization.

Returns:
recording: RecordingExtractor

The output recording extractor.

sorting: SortingExtractor

The output sorting extractor.

spikeinterface.extractors.read_tridesclous(folder_path, chan_grp=None)

Load Tridesclous format data as a sorting extractor.

Parameters:
folder_pathstr or Path

Path to the Tridesclous folder.

chan_grplist or None, default: None

The channel group(s) to load.

Returns:
extractorTridesclousSortingExtractor

Loaded data.

spikeinterface.extractors.read_waveclus(file_path, keep_good_only=True)

Load WaveClus format data as a sorting extractor.

Parameters:
file_pathstr or Path

Path to the WaveClus file.

keep_good_onlybool, default: True

Whether to only keep good units.

Returns:
extractorWaveClusSortingExtractor

Loaded data.

spikeinterface.extractors.read_yass(folder_path)

Load YASS format data as a sorting extractor.

Parameters:
folder_pathstr or Path

Path to the ALF folder.

Returns:
extractorYassSortingExtractor

Loaded data.

spikeinterface.preprocessing

spikeinterface.preprocessing.astype(recording, dtype=None, round: bool | None = None)

The spikeinterface analog of numpy.astype

Converts a recording to another dtype on the fly.

For recording with an unsigned dtype, please use the unsigned_to_signed preprocessing function.

If round is True, will round the values to the nearest integer. If round is None, will round in the case of float to integer conversion.

spikeinterface.preprocessing.average_across_direction(parent_recording: BaseRecording, direction: str = 'y', dtype='float32')

Abstract class representing several a multichannel timeseries (or block of raw ephys traces). Internally handle list of RecordingSegment

spikeinterface.preprocessing.bandpass_filter(recording, freq_min=300.0, freq_max=6000.0, margin_ms=5.0, dtype=None, **filter_kwargs)

Bandpass filter of a recording

Parameters:
recording: Recording

The recording extractor to be re-referenced

freq_min: float

The highpass cutoff frequency in Hz

freq_max: float

The lowpass cutoff frequency in Hz

margin_ms: float

Margin in ms on border to avoid border effect

dtype: dtype or None

The dtype of the returned traces. If None, the dtype of the parent recording is used

{}
Returns
——-
filter_recording: BandpassFilterRecording

The bandpass-filtered recording extractor object

spikeinterface.preprocessing.blank_staturation(recording, abs_threshold=None, quantile_threshold=None, direction='upper', fill_value=None, num_chunks_per_segment=50, chunk_size=500, seed=0)

Find and remove parts of the signal with extereme values. Some arrays may produce these when amplifiers enter saturation, typically for short periods of time. To remove these artefacts, values below or above a threshold are set to the median signal value. The threshold is either be estimated automatically, using the lower and upper 0.1 signal percentile with the largest deviation from the median, or specificed. Use this function with caution, as it may clip uncontaminated signals. A warning is printed if the data range suggests no artefacts.

Parameters:
recording: RecordingExtractor

The recording extractor to be transformed Minimum value. If None, clipping is not performed on lower interval edge.

abs_threshold: float or None, default: None

The absolute value for considering that the signal is saturating

quantile_threshold: float or None, default: None

Tha value in [0, 1] used if abs_threshold is None to automatically set the abs_threshold given the data. Must be provided if abs_threshold is None

direction: “upper” | “lower” | “both”, default: “upper”

Only values higher than the detection threshold are set to fill_value (“higher”), or only values lower than the detection threshold (“lower”), or both (“both”)

fill_value: float or None, default: None

The value to write instead of the saturating signal. If None, then the value is automatically computed as the median signal value

num_chunks_per_segment: int, default: 50

The number of chunks per segments to consider to estimate the threshold/fill_values

chunk_size: int, default: 500

The chunk size to estimate the threshold/fill_values

seed: int, default: 0

The seed to select the random chunks

Returns:
rescaled_traces: BlankSaturationRecording

The filtered traces recording extractor object

spikeinterface.preprocessing.center(recording, mode='median', dtype='float32', **random_chunk_kwargs)

Centers traces from the given recording extractor by removing the median/mean of each channel.

Parameters:
recording: RecordingExtractor

The recording extractor to be centered

mode: “median” | “mean”, default: “median”

The method used to center the traces

dtype: str or np.dtype, default: “float32”

The dtype of the output traces

**random_chunk_kwargs: Keyword arguments for `spikeinterface.core.get_random_data_chunk()` function
Returns:
centered_traces: ScaleRecording

The centered traces recording extractor object

spikeinterface.preprocessing.clip(recording, a_min=None, a_max=None)

Limit the values of the data between a_min and a_max. Values exceeding the range will be set to the minimum or maximum, respectively.

Parameters:
recording: RecordingExtractor

The recording extractor to be transformed

a_min: float or None, default: None

Minimum value. If None, clipping is not performed on lower interval edge.

a_max: float or None, default: None

Maximum value. If None, clipping is not performed on upper interval edge.

Returns:
rescaled_traces: ClipTracesRecording

The clipped traces recording extractor object

spikeinterface.preprocessing.common_reference(recording: BaseRecording, reference: Literal['global', 'single', 'local'] = 'global', operator: Literal['median', 'average'] = 'median', groups=None, ref_channel_ids=None, local_radius=(30, 55), dtype=None)

Re-references the recording extractor traces. That is, the value of the traces are shifted so the there is a new zero (reference).

The new reference can be estimated either by using a common median reference (CMR) or a common average reference (CAR).

The new reference can be set three ways:
  • “global”: the median/average of all channels is set as the new reference.

    In this case, the ‘global’ median/average is subtracted from all channels.

  • “single”: In the simplest case, a single channel from the recording is set as the new reference.

    This channel is subtracted from all other channels. To use this option, the ref_channel_ids argument is used with a single channel id. Note that this option will zero out the reference channel. A collection of channels can also be used as the new reference. In this case, the median/average of the selected channels is subtracted from all other channels. To use this option, pass the group of channels as a list in ref_channel_ids.

  • “local”: the median/average within an annulus is set as the new reference.

    The parameters of the annulus are specified using the local_radius argument. With this option, both channels which are too close and channels which are too far are excluded from the median/average. Note that setting the local_radius to (0, exclude_radius) will yield a simple circular local region.

Parameters:
recording: RecordingExtractor

The recording extractor to be re-referenced

reference: “global” | “single” | “local”, default: “global”

If “global” the reference is the average or median across all the channels. If “single”, the reference is a single channel or a list of channels that need to be set with the ref_channel_ids. If “local”, the reference is the set of channels within an annulus that must be set with the local_radius parameter.

operator: “median” | “average”, default: “median”
If “median”, a common median reference (CMR) is implemented (the median of

the selected channels is removed for each timestamp).

If “average”, common average reference (CAR) is implemented (the mean of the selected channels is removed

for each timestamp).

groups: list or None, default: None

List of lists containing the channel ids for splitting the reference. The CMR, CAR, or referencing with respect to single channels are applied group-wise. However, this is not applied for the local CAR. It is useful when dealing with different channel groups, e.g. multiple tetrodes.

ref_channel_ids: list or str or int, default: None

If no “groups” are specified, all channels are referenced to “ref_channel_ids”. If “groups” is provided, then a list of channels to be applied to each group is expected. If “single” reference, a list of one channel or an int is expected.

local_radius: tuple(int, int), default: (30, 55)

Use in the local CAR implementation as the selecting annulus with the following format:

(exclude radius, include radius)

Where the exlude radius is the inner radius of the annulus and the include radius is the outer radius of the annulus. The exclude radius is used to exclude channels that are too close to the reference channel and the include radius delineates the outer boundary of the annulus whose role is to exclude channels that are too far away.

dtype: None or dtype, default: None

If None the parent dtype is kept.

Returns:
referenced_recording: CommonReferenceRecording

The re-referenced recording extractor object

spikeinterface.preprocessing.correct_lsb(recording, num_chunks_per_segment=20, chunk_size=10000, seed=None, verbose=False)

Estimates the LSB of the recording and divide traces by LSB to ensure LSB = 1. Medians are also subtracted to avoid rounding errors.

Parameters:
recordingRecordingExtractor

The recording extractor to be LSB-corrected.

num_chunks_per_segment: int, default: 20

Number of chunks per segment for random chunk

chunk_sizeint, default: 10000

Size of a chunk in number for random chunk

seedint or None, default: None

Random seed for random chunk

verbosebool, default: False

If True, estimate LSB value is printed

Returns:
correct_lsb_recording: ScaleRecording

The recording extractor with corrected LSB

spikeinterface.preprocessing.correct_motion(recording, preset='nonrigid_accurate', folder=None, output_motion_info=False, detect_kwargs={}, select_kwargs={}, localize_peaks_kwargs={}, estimate_motion_kwargs={}, interpolate_motion_kwargs={}, **job_kwargs)

High-level function that estimates the motion and interpolates the recording.

This function has some intermediate steps that can be controlled one by one with parameters:
  • detect peaks

  • (optional) sub-sample peaks to speed up the localization

  • localize peaks

  • estimate the motion

  • create and return a InterpolateMotionRecording recording object

Even if this function is convinient, we recommend to run all step separately for fine tuning.

Optionally, this function can create a folder with files and figures ready to check.

This function depends on several modular components of spikeinterface.sortingcomponents.

If select_kwargs is None then all peak are used for localized.

The recording must be preprocessed (filter and denoised at least), and we recommend to not use whithening before motion estimation.

Parameters for each step are handled as separate dictionaries. For more information please check the documentation of the following functions:

Possible presets:
  • nonrigid_accurate: method by Paninski lab (monopolar_triangulation + decentralized)

  • nonrigid_fast_and_accurate: mixed methods by KS & Paninski lab (grid_convolution + decentralized)

  • rigid_fast: Rigid and not super accurate but fast. Use center of mass.

  • kilosort_like: Mimic the drift correction of kilosort (grid_convolution + iterative_template)

Parameters:
recording: RecordingExtractor

The recording extractor to be transformed

preset: str, default: “nonrigid_accurate”

The preset name

folder: Path str or None, default: None

If not None then intermediate motion info are saved into a folder

output_motion_info: bool, default: False

If True, then the function returns a motion_info dictionary that contains variables to check intermediate steps (motion_histogram, non_rigid_windows, pairwise_displacement) This dictionary is the same when reloaded from the folder

detect_kwargs: dict

Optional parameters to overwrite the ones in the preset for “detect” step.

select_kwargs: dict

If not None, optional parameters to overwrite the ones in the preset for “select” step. If None, the “select” step is skipped.

localize_peaks_kwargs: dict

Optional parameters to overwrite the ones in the preset for “localize” step.

estimate_motion_kwargs: dict

Optional parameters to overwrite the ones in the preset for “estimate_motion” step.

interpolate_motion_kwargs: dict

Optional parameters to overwrite the ones in the preset for “detect” step.

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

Returns:
recording_corrected: Recording

The motion corrected recording

motion_info: dict

Optional output if output_motion_info=True

spikeinterface.preprocessing.depth_order(parent_recording, channel_ids=None, dimensions=('x', 'y'), flip=False)

Re-orders the recording (channel IDs, channel locations, and traces)

Sorts channels lexicographically according to the dimensions in dimensions. See the documentation for order_channels_by_depth.

Parameters:
recordingBaseRecording

The recording to re-order.

channel_idslist/array or None

If given, a subset of channels to order locations for

dimensionsstr or tuple, list, default: (“x”, “y”)

If str, it needs to be “x”, “y”, “z”. If tuple or list, it sorts the locations in two dimensions using lexsort. This approach is recommended since there is less ambiguity

flip: bool, default: False

If flip is False then the order is bottom first (starting from tip of the probe). If flip is True then the order is upper first.

spikeinterface.preprocessing.detect_bad_channels(recording: BaseRecording, method: str = 'coherence+psd', std_mad_threshold: float = 5, psd_hf_threshold: float = 0.02, dead_channel_threshold: float = -0.5, noisy_channel_threshold: float = 1.0, outside_channel_threshold: float = -0.75, outside_channels_location: Literal['top', 'bottom', 'both'] = 'top', n_neighbors: int = 11, nyquist_threshold: float = 0.8, direction: Literal['x', 'y', 'z'] = 'y', chunk_duration_s: float = 0.3, num_random_chunks: int = 100, welch_window_ms: float = 10.0, highpass_filter_cutoff: float = 300, neighborhood_r2_threshold: float = 0.9, neighborhood_r2_radius_um: float = 30.0, seed: int | None = None)

Perform bad channel detection. The recording is assumed to be filtered. If not, a highpass filter is applied on the fly.

Different methods are implemented:

  • stdthrehshold on channel standard deviations

    If the standard deviation of a channel is greater than std_mad_threshold times the median of all channels standard deviations, the channel is flagged as noisy

  • mad : same as std, but using median absolute deviations instead

  • coeherence+psdmethod developed by the International Brain Laboratory that detects bad channels of three types:
    • Dead channels are those with low similarity to the surrounding channels (n=`n_neighbors` median)

    • Noise channels are those with power at >80% Nyquist above the psd_hf_threshold (default 0.02 uV^2 / Hz) and a high coherence with “far away” channels”

    • Out of brain channels are contigious regions of channels dissimilar to the median of all channels at the top end of the probe (i.e. large channel number)

  • neighborhood_r2

    A method tuned for LFP use-cases, where channels should be highly correlated with their spatial neighbors. This method estimates the correlation of each channel with the median of its spatial neighbors, and considers channels bad when this correlation is too small.

Parameters:
recordingBaseRecording

The recording for which bad channels are detected

method“coeherence+psd” | “std” | “mad” | “neighborhood_r2”, default: “coeherence+psd”

The method to be used for bad channel detection

std_mad_thresholdfloat, default: 5

The standard deviation/mad multiplier threshold

psd_hf_threshold (coeherence+psd)float, default: 0.02

An absolute threshold (uV^2/Hz) used as a cutoff for noise channels. Channels with average power at >80% Nyquist larger than this threshold will be labeled as noise

dead_channel_threshold (coeherence+psd)float, default: -0.5

Threshold for channel coherence below which channels are labeled as dead

noisy_channel_threshold (coeherence+psd)float, default: 1

Threshold for channel coherence above which channels are labeled as noisy (together with psd condition)

outside_channel_threshold (coeherence+psd)float, default: -0.75

Threshold for channel coherence above which channels at the edge of the recording are marked as outside of the brain

outside_channels_location (coeherence+psd)“top” | “bottom” | “both”, default: “top”

Location of the outside channels. If “top”, only the channels at the top of the probe can be marked as outside channels. If “bottom”, only the channels at the bottom of the probe can be marked as outside channels. If “both”, both the channels at the top and bottom of the probe can be marked as outside channels

n_neighbors (coeherence+psd)int, default: 11

Number of channel neighbors to compute median filter (needs to be odd)

nyquist_threshold (coeherence+psd)float, default: 0.8

Frequency with respect to Nyquist (Fn=1) above which the mean of the PSD is calculated and compared with psd_hf_threshold

direction (coeherence+psd): “x” | “y” | “z”, default: “y”

The depth dimension

highpass_filter_cutofffloat, default: 300

If the recording is not filtered, the cutoff frequency of the highpass filter

chunk_duration_sfloat, default: 0.5

Duration of each chunk

num_random_chunksint, default: 100

Number of random chunks Having many chunks is important for reproducibility.

welch_window_msfloat, default: 10

Window size for the scipy.signal.welch that will be converted to nperseg

neighborhood_r2_thresholdfloat, default: 0.95

R^2 threshold for the neighborhood_r2 method.

neighborhood_r2_radius_umfloat, default: 30

Spatial radius below which two channels are considered neighbors in the neighborhood_r2 method.

seedint or None, default: None

The random seed to extract chunks

Returns:
bad_channel_idsnp.array

The identified bad channel ids

channel_labelsnp.array of str
Channels labels depending on the method:
  • (coeherence+psd) good/dead/noise/out

  • (std, mad) good/noise

Notes

For details refer to: International Brain Laboratory et al. (2022). Spike sorting pipeline for the International Brain Laboratory. https://www.internationalbrainlab.com/repro-ephys

Examples

>>> import spikeinterface.preprocessing as spre
>>> bad_channel_ids, channel_labels = spre.detect_bad_channels(recording, method="coherence+psd")
>>> # remove bad channels
>>> recording_clean = recording.remove_channels(bad_channel_ids)
spikeinterface.preprocessing.directional_derivative(recording: BaseRecording, direction: str = 'y', order: int = 1, edge_order: int = 1, dtype='float32')

Abstract class representing several a multichannel timeseries (or block of raw ephys traces). Internally handle list of RecordingSegment

spikeinterface.preprocessing.filter(recording, band=[300.0, 6000.0], btype='bandpass', filter_order=5, ftype='butter', filter_mode='sos', margin_ms=5.0, add_reflect_padding=False, coeff=None, dtype=None)

Generic filter class based on:

  • scipy.signal.iirfilter

  • scipy.signal.filtfilt or scipy.signal.sosfilt

BandpassFilterRecording is built on top of it.

Parameters:
recording: Recording

The recording extractor to be re-referenced

band: float or list, default: [300.0, 6000.0]

If float, cutoff frequency in Hz for “highpass” filter type If list. band (low, high) in Hz for “bandpass” filter type

btype: “bandpass” | “highpass”, default: “bandpass”

Type of the filter

margin_ms: float, default: 5.0

Margin in ms on border to avoid border effect

filter_mode: “sos” | “ba”, default: “sos”

Filter form of the filter coefficients: - second-order sections (“sos”) - numerator/denominator: (“ba”)

coef: array or None, default: None

Filter coefficients in the filter_mode form.

dtype: dtype or None, default: None

The dtype of the returned traces. If None, the dtype of the parent recording is used

{}
Returns:
filter_recording: FilterRecording

The filtered recording extractor object

spikeinterface.preprocessing.gaussian_filter(recording: BaseRecording, freq_min: float = 300.0, freq_max: float = 5000.0, margin_sd: float = 5.0)

Class for performing a gaussian filtering/smoothing on a recording.

This is done by a convolution with a Gaussian kernel, which acts as a lowpass-filter. A highpass-filter can be computed by subtracting the result of the convolution to the original signal. A bandpass-filter is obtained by substracting the signal smoothed with a narrow gaussian to the signal smoothed with a wider gaussian.

Here, convolution is performed in the Fourier domain to accelerate the computation.

Parameters:
recording: BaseRecording

The recording extractor to be filtered.

freq_min: float or None

The lower frequency cutoff for the bandpass filter. If None, the resulting object is a lowpass filter.

freq_max: float or None

The higher frequency cutoff for the bandpass filter. If None, the resulting object is a highpass filter.

margin_sd: float, default: 5.0

The number of standard deviation to take for margins.

Returns:
gaussian_filtered_recording: GaussianFilterRecording

The filtered recording extractor object.

spikeinterface.preprocessing.highpass_filter(recording, freq_min=300.0, margin_ms=5.0, dtype=None, **filter_kwargs)

Highpass filter of a recording

Parameters:
recording: Recording

The recording extractor to be re-referenced

freq_min: float

The highpass cutoff frequency in Hz

margin_ms: float

Margin in ms on border to avoid border effect

dtype: dtype or None

The dtype of the returned traces. If None, the dtype of the parent recording is used

{}
Returns
——-
filter_recording: HighpassFilterRecording

The highpass-filtered recording extractor object

spikeinterface.preprocessing.highpass_spatial_filter(recording, n_channel_pad=60, n_channel_taper=0, direction='y', apply_agc=True, agc_window_length_s=0.1, highpass_butter_order=3, highpass_butter_wn=0.01, dtype=None)

Perform destriping with high-pass spatial filtering. Uses the kfilt() function of the International Brain Laboratory.

Median average filtering, by removing the median of signal across channels, assumes noise is constant across all channels. However, noise have exhibit low-frequency changes across nearby channels.

Alternative to median filtering across channels, in which the cut-band is extended from 0 to the 0.01 Nyquist corner frequency using butterworth filter. This allows removal of contaminating stripes that are not constant across channels.

Performs filtering on the 0 axis (across channels), with optional padding (mirrored) and tapering (cosine taper) prior to filtering. Applies a butterworth filter on the 0-axis with tapering / padding.

Parameters:
recordingBaseRecording

The parent recording

n_channel_padint, default: 60

Number of channels to pad prior to filtering. Channels are padded with mirroring. If None, no padding is applied

n_channel_taperint, default: 0

Number of channels to perform cosine tapering on prior to filtering. If None and n_channel_pad is set, n_channel_taper will be set to the number of padded channels. Otherwise, the passed value will be used

direction“x” | “y” | “z”, default: “y”

The direction in which the spatial filter is applied

apply_agcbool, default: True

It True, Automatic Gain Control is applied

agc_window_length_sfloat, default: 0.1

Window in seconds to compute Hanning window for AGC

highpass_butter_orderint, default: 3

Order of spatial butterworth filter

highpass_butter_wnfloat, default: 0.01

Critical frequency (with respect to Nyquist) of spatial butterworth filter

dtypedtype, default: None

The dtype of the output traces. If None, the dtype is the same as the input traces

Returns:
highpass_recordingHighpassSpatialFilterRecording

The recording with highpass spatial filtered traces

References

Details of the high-pass spatial filter function (written by Olivier Winter) used in the IBL pipeline can be found at: International Brain Laboratory et al. (2022). Spike sorting pipeline for the International Brain Laboratory. https://www.internationalbrainlab.com/repro-ephys

spikeinterface.preprocessing.interpolate_bad_channels(recording, bad_channel_ids, sigma_um=None, p=1.3, weights=None)

Interpolate the channel labeled as bad channels using linear interpolation. This is based on the distance (Gaussian kernel) from the bad channel, as determined from x,y channel coordinates.

Details of the interpolation function (written by Olivier Winter) used in the IBL pipeline can be found at:

International Brain Laboratory et al. (2022). Spike sorting pipeline for the International Brain Laboratory. https://www.internationalbrainlab.com/repro-ephys

Parameters:
recording: BaseRecording

The parent recording

bad_channel_idslist or 1d np.array

Channel ids of the bad channels to interpolate.

sigma_umfloat or None, default: None

Distance between sequential channels in um. If None, will use the most common distance between y-axis channels

pfloat, default: 1.3

Exponent of the Gaussian kernel. Determines rate of decay for distance weightings

weightsnp.array or None, default: None

The weights to give to bad_channel_ids at interpolation. If None, weights are automatically computed

Returns:
interpolated_recording: InterpolateBadChannelsRecording

The recording object with interpolated bad channels

spikeinterface.preprocessing.normalize_by_quantile(recording, scale=1.0, median=0.0, q1=0.01, q2=0.99, mode='by_channel', dtype='float32', **random_chunk_kwargs)

Rescale the traces from the given recording extractor with a scalar and offset. First, the median and quantiles of the distribution are estimated. Then the distribution is rescaled and offset so that the scale is given by the distance between the quantiles (1st and 99th by default) is set to scale, and the median is set to the given median.

Parameters:
recording: RecordingExtractor

The recording extractor to be transformed

scale: float, default: 1.0

Scale for the output distribution

median: float, default: 0.0

Median for the output distribution

q1: float, default: 0.01

Lower quantile used for measuring the scale

q1: float, default: 0.99

Upper quantile used for measuring the

mode: “by_channel” | “pool_channel”, default: “by_channel”

If “by_channel” each channel is rescaled independently.

dtype: str or np.dtype, default: “float32”

The dtype of the output traces

**random_chunk_kwargs: Keyword arguments for `spikeinterface.core.get_random_data_chunk()` function
Returns:
rescaled_traces: NormalizeByQuantileRecording

The rescaled traces recording extractor object

spikeinterface.preprocessing.notch_filter(recording, freq=3000, q=30, margin_ms=5.0, dtype=None)
Parameters:
recording: RecordingExtractor

The recording extractor to be notch-filtered

freq: int or float

The target frequency in Hz of the notch filter

q: int

The quality factor of the notch filter

{}
Returns
——-
filter_recording: NotchFilterRecording

The notch-filtered recording extractor object

spikeinterface.preprocessing.phase_shift(recording, margin_ms=40.0, inter_sample_shift=None, dtype=None)

This apply a phase shift to a recording to cancel the small sampling delay across for some recording system.

This is particularly relevant for neuropixel recording.

This code is inspired from from IBL lib. https://github.com/int-brain-lab/ibllib/blob/master/ibllib/dsp/fourier.py and also the one from spikeglx https://billkarsh.github.io/SpikeGLX/help/dmx_vs_gbl/dmx_vs_gbl/

Parameters:
recording: Recording

The recording. It need to have “inter_sample_shift” in properties.

margin_ms: float, default: 40.0

Margin in ms for computation. 40ms ensure a very small error when doing chunk processing

inter_sample_shift: None or numpy array, default: None

If “inter_sample_shift” is not in recording properties, we can externally provide one.

Returns:
filter_recording: PhaseShiftRecording

The phase shifted recording object

spikeinterface.preprocessing.rectify(recording)

Abstract class representing several a multichannel timeseries (or block of raw ephys traces). Internally handle list of RecordingSegment

spikeinterface.preprocessing.remove_artifacts(recording, list_triggers, ms_before=0.5, ms_after=3.0, mode='zeros', fit_sample_spacing=1.0, list_labels=None, artifacts=None, sparsity=None, scale_amplitude=False, time_jitter=0, waveforms_kwargs=None)

Removes stimulation artifacts from recording extractor traces. By default, artifact periods are zeroed-out (mode = “zeros”). This is only recommended for traces that are centered around zero (e.g. through a prior highpass filter); if this is not the case, linear and cubic interpolation modes are also available, controlled by the “mode” input argument. Note that several artifacts can be removed at once (potentially with distinct duration each), if labels are specified

Parameters:
recording: RecordingExtractor

The recording extractor to remove artifacts from

list_triggers: list of lists/arrays

One list per segment of int with the stimulation trigger frames

ms_before: float or None, default: 0.5

Time interval in ms to remove before the trigger events. If None, then also ms_after must be None and a single sample is removed

ms_after: float or None, default: 3.0

Time interval in ms to remove after the trigger events. If None, then also ms_before must be None and a single sample is removed

list_labels: list of lists/arrays or None

One list per segment of labels with the stimulation labels for the given artifacts. labels should be strings, for JSON serialization. Required for “median” and “average” modes.

mode: “zeros”, “linear”, “cubic”, “average”, “median”, default: “zeros”

Determines what artifacts are replaced by. Can be one of the following:

  • “zeros”: Artifacts are replaced by zeros.

  • “median”: The median over all artifacts is computed and subtracted for

    each occurence of an artifact

  • “average”: The mean over all artifacts is computed and subtracted for each

    occurence of an artifact

  • “linear”: Replacement are obtained through Linear interpolation between

    the trace before and after the artifact. If the trace starts or ends with an artifact period, the gap is filled with the closest available value before or after the artifact.

  • “cubic”: Cubic spline interpolation between the trace before and after

    the artifact, referenced to evenly spaced fit points before and after the artifact. This is an option thatcan be helpful if there are significant LFP effects around the time of the artifact, but visual inspection of fit behaviour with your chosen settings is recommended. The spacing of fit points is controlled by “fit_sample_spacing”, with greater spacing between points leading to a fit that is less sensitive to high frequency fluctuations but at the cost of a less smooth continuation of the trace. If the trace starts or ends with an artifact, the gap is filled with the closest available value before or after the artifact.

fit_sample_spacing: float, default: 1.0

Determines the spacing (in ms) of reference points for the cubic spline fit if mode = “cubic”. Note: The actual fit samples are the median of the 5 data points around the time of each sample point to avoid excessive influence from hyper-local fluctuations.

artifacts: dict or None, default: None

If provided (when mode is “median” or “average”) then it must be a dict with keys that are the labels of the artifacts, and values the artifacts themselves, on all channels (and thus bypassing ms_before and ms_after)

sparsity: dict or None, default: None

If provided (when mode is “median” or “average”) then it must be a dict with keys that are the labels of the artifacts, and values that are boolean mask of the channels where the artifacts should be considered (for subtraction/scaling)

scale_amplitude: False, default: False

If true, then for mode “median” or “average” the amplitude of the template will be scaled in amplitude at each time occurence to minimize residuals

time_jitter: float, default: 0

If non 0, then for mode “median” or “average”, a time jitter in ms can be allowed to minimize the residuals

waveforms_kwargs: None

Deprecated and ignored

Returns:
removed_recording: RemoveArtifactsRecording

The recording extractor after artifact removal

spikeinterface.preprocessing.resample(recording, resample_rate, margin_ms=100.0, dtype=None, skip_checks=False)

Resample the recording extractor traces.

If the original sampling rate is multiple of the resample_rate, it will use the signal.decimate method from scipy. In other cases, it uses signal.resample. In the later case, the resulting signal can have issues on the edges, mainly on the rightmost.

Parameters:
recordingRecording

The recording extractor to be re-referenced

resample_rateint

The resampling frequency

marginfloat, default: 100.0

Margin in ms for computations, will be used to decrease edge effects.

dtypedtype or None, default: None

The dtype of the returned traces. If None, the dtype of the parent recording is used.

skip_checksbool, default: False

If True, checks on sampling frequencies and cutoff filter frequencies are skipped

Returns:
resample_recording: ResampleRecording

The resampled recording extractor object.

spikeinterface.preprocessing.scale(recording, gain=1.0, offset=0.0, dtype='float32')

Scale traces from the given recording extractor with a scalar and offset. New traces = traces*scalar + offset.

Parameters:
recording: RecordingExtractor

The recording extractor to be transformed

gain: float or array

Scalar for the traces of the recording extractor or array with scalars for each channel

offset: float or array

Offset for the traces of the recording extractor or array with offsets for each channel

dtype: str or np.dtype, default: “float32”

The dtype of the output traces

Returns:
transform_traces: ScaleRecording

The transformed traces recording extractor object

spikeinterface.preprocessing.silence_periods(recording, list_periods, mode='zeros', noise_levels=None, seed=None, **random_chunk_kwargs)

Silence user-defined periods from recording extractor traces. By default, periods are zeroed-out (mode = “zeros”). You can also fill the periods with noise. Note that both methods assume that traces that are centered around zero. If this is not the case, make sure you apply a filter or center function prior to silencing periods.

Parameters:
recording: RecordingExtractor

The recording extractor to silance periods

list_periods: list of lists/arrays

One list per segment of tuples (start_frame, end_frame) to silence

noise_levels: array

Noise levels if already computed

mode: “zeros” | “noise, default: “zeros”

Determines what periods are replaced by. Can be one of the following:

  • “zeros”: Artifacts are replaced by zeros.

  • “noise”: The periods are filled with a gaussion noise that has the

    same variance that the one in the recordings, on a per channel basis

**random_chunk_kwargs: Keyword arguments for `spikeinterface.core.get_random_data_chunk()` function
Returns:
silence_recording: SilencedPeriodsRecording

The recording extractor after silencing some periods

spikeinterface.preprocessing.unsigned_to_signed(recording, bit_depth=None)

Converts a recording with unsigned traces to a signed one.

Parameters:
recording: Recording

The recording to be signed.

bit_depth: int or None, default: None

In case the bit depth of the ADC does not match that of the data type, it specifies the bit depth of the ADC to estimate the offset. For example, a bit_depth of 12 will correct for an offset of 2**11

spikeinterface.preprocessing.whiten(recording, dtype=None, apply_mean=False, mode='global', radius_um=100.0, int_scale=None, eps=None, W=None, M=None, **random_chunk_kwargs)

Whitens the recording extractor traces.

Parameters:
recording: RecordingExtractor

The recording extractor to be whitened.

dtype: None or dtype, default: None

If None the the parent dtype is kept. For integer dtype a int_scale must be also given.

mode: “global” | “local”, default: “global”

“global” use the entire covariance matrix to compute the W matrix “local” use local covariance (by radius) to compute the W matrix

radius_um: None or float, default: None

Used for mode = “local” to get the neighborhood

apply_mean: bool, default: False

Substract or not the mean matrix M before the dot product with W.

int_scaleNone or float, default: None

Apply a scaling factor to fit the integer range. This is used when the dtype is an integer, so that the output is scaled. For example, a value of int_scale=200 will scale the traces value to a standard deviation of 200.

epsfloat or None, default: None

Small epsilon to regularize SVD. If None, eps is defaulted to 1e-8. If the data is float type and scaled down to very small values, then the eps is automatically set to a small fraction (1e-3) of the median of the squared data.

W2d np.array or None, default: None

Pre-computed whitening matrix

M1d np.array or None, default: None

Pre-computed means. M can be None when previously computed with apply_mean=False

**random_chunk_kwargsKeyword arguments for spikeinterface.core.get_random_data_chunk() function
Returns:
whitened_recording: WhitenRecording

The whitened recording extractor

spikeinterface.preprocessing.zero_channel_pad(parent_recording: BaseRecording, num_channels: int, channel_mapping: list | None = None)

Abstract class representing several a multichannel timeseries (or block of raw ephys traces). Internally handle list of RecordingSegment

spikeinterface.preprocessing.zscore(recording, mode='median+mad', gain=None, offset=None, int_scale=None, dtype='float32', **random_chunk_kwargs)

Centers traces from the given recording extractor by removing the median of each channel and dividing by the MAD.

Parameters:
recording: RecordingExtractor

The recording extractor to be centered

mode: “median+mad” | “mean+std”, default: “median+mad”

The mode to compute the zscore

dtype: None or dtype

If None the the parent dtype is kept. For integer dtype a int_scale must be also given.

gainNone or np.array

Pre-computed gain.

offsetNone or np.array

Pre-computed offset

int_scaleNone or float

Apply a scaling factor to fit the integer range. This is used when the dtype is an integer, so that the output is scaled. For example, a value of int_scale=200 will scale the zscore value to a standard deviation of 200.

**random_chunk_kwargs: Keyword arguments for `spikeinterface.core.get_random_data_chunk()` function
Returns:
centered_traces: ScaleRecording

The centered traces recording extractor object

spikeinterface.postprocessing

spikeinterface.postprocessing.compute_noise_levels(sorting_analyzer, load_if_exists=None, *args, **kwargs)

Computes the noise level associated with each recording channel.

This function will wraps the get_noise_levels(recording) to make the noise levels persistent on disk (folder or zarr) as a WaveformExtension. The noise levels do not depend on the unit list, only the recording, but it is a convenient way to retrieve the noise levels directly ine the WaveformExtractor.

Note that the noise levels can be scaled or not, depending on the return_scaled parameter of the SortingAnalyzer.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

**params: dict with additional parameters for the `spikeinterface.get_noise_levels()` function
Returns:
noise_levels: np.array

The noise level vector

spikeinterface.postprocessing.compute_template_metrics(sorting_analyzer, load_if_exists=None, *args, **kwargs)
Compute template metrics including:
  • peak_to_valley

  • peak_trough_ratio

  • halfwidth

  • repolarization_slope

  • recovery_slope

  • num_positive_peaks

  • num_negative_peaks

Optionally, the following multi-channel metrics can be computed (when include_multi_channel_metrics=True):
  • velocity_above

  • velocity_below

  • exp_decay

  • spread

Parameters:
sorting_analyzer: SortingAnalyzer

The SortingAnalyzer object

metric_nameslist or None, default: None

List of metrics to compute (see si.postprocessing.get_template_metric_names())

peak_sign{“neg”, “pos”}, default: “neg”

Whether to use the positive (“pos”) or negative (“neg”) peaks to estimate extremum channels.

upsampling_factorint, default: 10

The upsampling factor to upsample the templates

sparsity: ChannelSparsity or None, default: None

If None, template metrics are computed on the extremum channel only. If sparsity is given, template metrics are computed on all sparse channels of each unit. For more on generating a ChannelSparsity, see the ~spikeinterface.compute_sparsity() function.

include_multi_channel_metrics: bool, default: False

Whether to compute multi-channel metrics

metrics_kwargs: dict
Additional arguments to pass to the metric functions. Including:
  • recovery_window_ms: the window in ms after the peak to compute the recovery_slope, default: 0.7

  • peak_relative_threshold: the relative threshold to detect positive and negative peaks, default: 0.2

  • peak_width_ms: the width in samples to detect peaks, default: 0.2

  • depth_direction: the direction to compute velocity above and below, default: “y” (see notes)

  • min_channels_for_velocity: the minimum number of channels above or below to compute velocity, default: 5

  • min_r2_velocity: the minimum r2 to accept the velocity fit, default: 0.7

  • exp_peak_function: the function to use to compute the peak amplitude for the exp decay, default: “ptp”

  • min_r2_exp_decay: the minimum r2 to accept the exp decay fit, default: 0.5

  • spread_threshold: the threshold to compute the spread, default: 0.2

  • spread_smooth_um: the smoothing in um to compute the spread, default: 20

  • column_range: the range in um in the horizontal direction to consider channels for velocity, default: None
    • If None, all channels all channels are considered

    • If 0 or 1, only the “column” that includes the max channel is considered

    • If > 1, only channels within range (+/-) um from the max channel horizontal position are used

Returns:
template_metricspd.DataFrame

Dataframe with the computed template metrics. If “sparsity” is None, the index is the unit_id. If “sparsity” is given, the index is a multi-index (unit_id, channel_id)

Notes

If any multi-channel metric is in the metric_names or include_multi_channel_metrics is True, sparsity must be None, so that one metric value will be computed per unit. For multi-channel metrics, 3D channel locations are not supported. By default, the depth direction is “y”.

spikeinterface.postprocessing.compute_principal_components(sorting_analyzer, load_if_exists=None, *args, **kwargs)

Compute PC scores from waveform extractor. The PCA projections are pre-computed only on the sampled waveforms available from the extensions “waveforms”.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

n_components: int, default: 5

Number of components fo PCA

mode: “by_channel_local” | “by_channel_global” | “concatenated”, default: “by_channel_local”
The PCA mode:
  • “by_channel_local”: a local PCA is fitted for each channel (projection by channel)

  • “by_channel_global”: a global PCA is fitted for all channels (projection by channel)

  • “concatenated”: channels are concatenated and a global PCA is fitted

sparsity: ChannelSparsity or None, default: None

The sparsity to apply to waveforms. If sorting_analyzer is already sparse, the default sparsity will be used

whiten: bool, default: True

If True, waveforms are pre-whitened

dtype: dtype, default: “float32”

Dtype of the pc scores

Examples

>>> sorting_analyzer = create_sorting_analyzer(sorting, recording)
>>> sorting_analyzer.compute("principal_components", n_components=3, mode='by_channel_local')
>>> ext_pca = sorting_analyzer.get_extension("principal_components")
>>> # get pre-computed projections for unit_id=1
>>> unit_projections = ext_pca.get_projections_one_unit(unit_id=1, sparse=False)
>>> # get pre-computed projections for some units on some channels
>>> some_projections, spike_unit_indices = ext_pca.get_some_projections(channel_ids=None, unit_ids=None)
>>> # retrieve fitted pca model(s)
>>> pca_model = ext_pca.get_pca_model()
>>> # compute projections on new waveforms
>>> proj_new = ext_pca.project_new(new_waveforms)
>>> # run for all spikes in the SortingExtractor
>>> pc.run_for_all_spikes(file_path="all_pca_projections.npy")
spikeinterface.postprocessing.compute_spike_amplitudes(sorting_analyzer, load_if_exists=None, *args, **kwargs)

AnalyzerExtension Computes the spike amplitudes.

Needs “templates” to be computed first. Localize spikes in 2D or 3D with several methods given the template.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

ms_beforefloat, default: 0.5

The left window, before a peak, in milliseconds

ms_afterfloat, default: 0.5

The right window, after a peak, in milliseconds

spike_retriver_kwargs: dict

A dictionary to control the behavior for getting the maximum channel for each spike This dictionary contains:

  • channel_from_template: bool, default: True

    For each spike is the maximum channel computed from template or re estimated at every spikes channel_from_template = True is old behavior but less acurate channel_from_template = False is slower but more accurate

  • radius_um: float, default: 50

    In case channel_from_template=False, this is the radius to get the true peak

  • peak_sign, default: “neg”

    In case channel_from_template=False, this is the peak sign.

method“center_of_mass” | “monopolar_triangulation” | “grid_convolution”, default: “center_of_mass”

The localization method to use

method_kwargsdict, default: dict()

Other kwargs depending on the method.

outputs“concatenated” | “by_unit”, default: “concatenated”

The output format

Returns:
spike_locations: np.array

All locations for all spikes and all units are concatenated

spikeinterface.postprocessing.compute_unit_locations(sorting_analyzer, load_if_exists=None, *args, **kwargs)

Localize units in 2D or 3D with several methods given the template.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

method: “center_of_mass” | “monopolar_triangulation” | “grid_convolution”, default: “center_of_mass”

The method to use for localization

method_kwargs: dict, default: {}

Other kwargs depending on the method

Returns:
unit_locations: np.array

unit location with shape (num_unit, 2) or (num_unit, 3) or (num_unit, 3) (with alpha)

spikeinterface.postprocessing.compute_spike_locations(sorting_analyzer, load_if_exists=None, *args, **kwargs)

Localize spikes in 2D or 3D with several methods given the template.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

ms_beforefloat, default: 0.5

The left window, before a peak, in milliseconds

ms_afterfloat, default: 0.5

The right window, after a peak, in milliseconds

spike_retriver_kwargs: dict

A dictionary to control the behavior for getting the maximum channel for each spike This dictionary contains:

  • channel_from_template: bool, default: True

    For each spike is the maximum channel computed from template or re estimated at every spikes channel_from_template = True is old behavior but less acurate channel_from_template = False is slower but more accurate

  • radius_um: float, default: 50

    In case channel_from_template=False, this is the radius to get the true peak

  • peak_sign, default: “neg”

    In case channel_from_template=False, this is the peak sign.

method“center_of_mass” | “monopolar_triangulation” | “grid_convolution”, default: “center_of_mass”

The localization method to use

method_kwargsdict, default: dict()

Other kwargs depending on the method.

outputs“concatenated” | “by_unit”, default: “concatenated”

The output format

{}
Returns:
spike_locations: np.array

All locations for all spikes

spikeinterface.postprocessing.compute_template_similarity(sorting_analyzer, load_if_exists=None, *args, **kwargs)

Compute similarity between templates with several methods.

Parameters:
sorting_analyzer: SortingAnalyzer

The SortingAnalyzer object

method: str, default: “cosine_similarity”

The method to compute the similarity

Returns:
similarity: np.array

The similarity matrix

spikeinterface.postprocessing.compute_isi_histograms(sorting_analyzer, load_if_exists=None, *args, **kwargs)

Compute ISI histograms.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

window_msfloat, default: 50

The window in ms

bin_msfloat, default: 1

The bin size in ms

method“auto” | “numpy” | “numba”, default: “auto”

. If “auto” and numba is installed, numba is used, otherwise numpy is used

Returns:
isi_histogramsnp.array

IDI_histograms with shape (num_units, num_bins)

binsnp.array

The bin edges in ms

spikeinterface.postprocessing.get_template_metric_names()
spikeinterface.postprocessing.align_sorting(sorting, unit_peak_shifts)

Class to shift a unit (generally to align the template on the peak) given the shifts for each unit.

Parameters:
sorting: BaseSorting

The sorting to align.

unit_peak_shifts: dict

Dictionary mapping the unit_id to the unit’s shift (in number of samples). A positive shift means the spike train is shifted back in time, while a negative shift means the spike train is shifted forward.

Returns:
aligned_sorting: AlignSortingExtractor

The aligned sorting.

spikeinterface.qualitymetrics

spikeinterface.qualitymetrics.compute_quality_metrics(sorting_analyzer, load_if_exists=None, *args, **kwargs)

Compute quality metrics on sorting_.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

metric_nameslist or None

List of quality metrics to compute.

qm_paramsdict or None

Dictionary with parameters for quality metrics calculation. Default parameters can be obtained with: si.qualitymetrics.get_default_qm_params()

skip_pc_metricsbool

If True, PC metrics computation is skipped.

Returns:
metrics: pandas.DataFrame

Data frame with the computed metrics

Notes

principal_components are loaded automatically if already computed.

spikeinterface.qualitymetrics.get_quality_metric_list()

Get a list of the available quality metrics.

spikeinterface.qualitymetrics.get_quality_pca_metric_list()

Get a list of the available PCA-based quality metrics.

spikeinterface.qualitymetrics.get_default_qm_params()

Return default dictionary of quality metrics parameters.

Returns:
dict

Default qm parameters with metric name as key and parameter dictionary as values.

spikeinterface.sorters

spikeinterface.sorters.available_sorters()

Lists available sorters.

spikeinterface.sorters.installed_sorters()

Lists installed sorters.

spikeinterface.sorters.get_default_sorter_params(sorter_name_or_class)

Returns default parameters for the specified sorter.

Parameters:
sorter_name_or_class: str or SorterClass

The sorter to retrieve default parameters from.

Returns:
default_params: dict

Dictionary with default params for the specified sorter.

spikeinterface.sorters.get_sorter_params_description(sorter_name_or_class)

Returns a description of the parameters for the specified sorter.

Parameters:
sorter_name_or_class: str or SorterClass

The sorter to retrieve parameters description from.

Returns:
params_description: dict

Dictionary with parameter description

spikeinterface.sorters.print_sorter_versions()

“Prints the versions of the installed sorters.

spikeinterface.sorters.get_sorter_description(sorter_name_or_class)

Returns a brief description for the specified sorter.

Parameters:
sorter_name_or_class: str or SorterClass

The sorter to retrieve description from.

Returns:
params_description: dict

Dictionary with parameter description.

spikeinterface.sorters.run_sorter(sorter_name: str, recording: BaseRecording, output_folder: str | None = None, remove_existing_folder: bool = False, delete_output_folder: bool = False, verbose: bool = False, raise_error: bool = True, docker_image: bool | str | None = False, singularity_image: bool | str | None = False, delete_container_files: bool = True, with_output: bool = True, **sorter_params)

Generic function to run a sorter via function approach.

Parameters:
sorter_name: str

The sorter name

recording: RecordingExtractor

The recording extractor to be spike sorted

output_folder: str or Path

Path to output folder

remove_existing_folder: bool

If True and output_folder exists yet then delete.

delete_output_folder: bool, default: False

If True, output folder is deleted

verbose: bool, default: False

If True, output is verbose

raise_error: bool, default: True

If True, an error is raised if spike sorting fails If False, the process continues and the error is logged in the log file.

docker_image: bool or str, default: False

If True, pull the default docker container for the sorter and run the sorter in that container using docker. Use a str to specify a non-default container. If that container is not local it will be pulled from docker hub. If False, the sorter is run locally

singularity_image: bool or str, default: False

If True, pull the default docker container for the sorter and run the sorter in that container using singularity. Use a str to specify a non-default container. If that container is not local it will be pulled from Docker Hub. If False, the sorter is run locally

with_output: bool, default: True

If True, the output Sorting is returned as a Sorting

delete_container_files: bool, default: True

If True, the container temporary files are deleted after the sorting is done

extra_requirements: list, default: None

List of extra requirements to install in the container

installation_mode: “auto” | “pypi” | “github” | “folder” | “dev” | “no-install”, default: “auto”
How spikeinterface is installed in the container:
  • “auto”: if host installation is a pip release then use “github” with tag

    if host installation is DEV_MODE=True then use “dev”

  • “pypi”: use pypi with pip install spikeinterface

  • “github”: use github with pip install git+https

  • “folder”: mount a folder in container and install from this one.

    So the version in the container is a different spikeinterface version from host, useful for cross checks

  • “dev”: same as “folder”, but the folder is the spikeinterface.__file__ to ensure same version as host

  • “no-install”: do not install spikeinterface in the container because it is already installed

spikeinterface_version: str, default: None

The spikeinterface version to install in the container. If None, the current version is used

spikeinterface_folder_source: Path or None, default: None

In case of installation_mode=”folder”, the spikeinterface folder source to use to install in the container

**sorter_params: keyword args

Spike sorter specific arguments (they can be retrieved with get_default_sorter_params(sorter_name_or_class))

Returns:
BaseSorting | None

The spike sorted data (it with_output is True) or None (if with_output is False)

Examples

>>> sorting = run_sorter("tridesclous", recording)
spikeinterface.sorters.run_sorter_jobs(job_list, engine='loop', engine_kwargs={}, return_output=False)

Run several run_sorter() sequentially or in parallel given a list of jobs.

For engine=”loop” this is equivalent to:

..code:

for job in job_list:
    run_sorter(**job)
The following engines block the I/O:
  • “loop”

  • “joblib”

  • “multiprocessing”

  • “dask”

The following engines are asynchronous:
  • “slurm”

Where blocking means that this function is blocking until the results are returned. This is in opposition to asynchronous, where the function returns None almost immediately (aka non-blocking), but the results must be retrieved by hand when jobs are finished. No mechanisim is provided here to be know when jobs are finish. In this asynchronous case, the read_sorter_folder() helps to retrieve individual results.

Parameters:
job_list: list of dict

A list a dict that are propagated to run_sorter(…)

engine: str “loop”, “joblib”, “dask”, “slurm”

The engine to run the list. * “loop”: a simple loop. This engine is

engine_kwargs: dict
return_output: bool, dfault False

Return a sortings or None. This also overwrite kwargs in in run_sorter(with_sorting=True/False)

Returns:
sortings: None or list of sorting

With engine=”loop” or “joblib” you can optional get directly the list of sorting result if return_output=True.

spikeinterface.sorters.run_sorter_by_property(sorter_name, recording, grouping_property, working_folder, mode_if_folder_exists=None, engine='loop', engine_kwargs={}, verbose=False, docker_image=None, singularity_image=None, **sorter_params)

Generic function to run a sorter on a recording after splitting by a “grouping_property” (e.g. “group”).

Internally, the function works as follows:
  • the recording is split based on the provided “grouping_property” (using the “split_by” function)

  • the “run_sorters” function is run on the split recordings

  • sorting outputs are aggregated using the “aggregate_units” function

  • the “grouping_property” is added as a property to the SortingExtractor

Parameters:
sorter_name: str

The sorter name

recording: BaseRecording

The recording to be sorted

grouping_property: object

Property to split by before sorting

working_folder: str

The working directory.

mode_if_folder_exists: bool or None, default: None

Must be None. This is deprecated. If not None then a warning is raise. Will be removed in next release.

engine: “loop” | “joblib” | “dask”, default: “loop”

Which engine to use to run sorter.

engine_kwargs: dict
This contains kwargs specific to the launcher engine:
  • “loop” : no kwargs

  • “joblib” : {“n_jobs” : } number of processes

  • “dask” : {“client”:} the dask client for submitting task

verbose: bool, default: False

Controls sorter verboseness

docker_image: None or str, default: None

If str run the sorter inside a container (docker) using the docker package

**sorter_params: keyword args

Spike sorter specific arguments (they can be retrieved with get_default_sorter_params(sorter_name_or_class))

Returns:
sortingUnitsAggregationSorting

The aggregated SortingExtractor.

Examples

This example shows how to run spike sorting split by group using the “joblib” backend with 4 jobs for parallel processing.

>>> sorting = si.run_sorter_by_property("tridesclous", recording, grouping_property="group",
                                        working_folder="sort_by_group", engine="joblib",
                                        engine_kwargs={"n_jobs": 4})
spikeinterface.sorters.read_sorter_folder(output_folder, register_recording=True, sorting_info=True, raise_error=True)

Load a sorting object from a spike sorting output folder. The ‘output_folder’ must contain a valid ‘spikeinterface_log.json’ file

Parameters:
output_folder: Pth or str

The sorter folder

register_recording: bool, default: True

Attach recording (when json or pickle) to the sorting

sorting_info: bool, default: True

Attach sorting info to the sorting.

Low level

class spikeinterface.sorters.BaseSorter(recording=None, output_folder=None, verbose=False, remove_existing_folder=False, delete_output_folder=False)

Base Sorter object.

spikeinterface.comparison

spikeinterface.comparison.compare_two_sorters(sorting1, sorting2, sorting1_name=None, sorting2_name=None, delta_time=0.4, match_score=0.5, chance_score=0.1, n_jobs=-1, verbose=False)

Compares two spike sorter outputs.

  • Spike trains are matched based on their agreement scores

  • Individual spikes are labelled as true positives (TP), false negatives (FN), false positives 1 (FP from spike train 1), false positives 2 (FP from spike train 2), misclassifications (CL)

It also allows to get confusion matrix and agreement fraction, false positive fraction and false negative fraction.

Parameters:
sorting1: SortingExtractor

The first sorting for the comparison

sorting2: SortingExtractor

The second sorting for the comparison

sorting1_name: str, default: None

The name of sorter 1

sorting2_name:str, default: None

The name of sorter 2

delta_time: float, default: 0.4

Number of ms to consider coincident spikes

match_score: float, default: 0.5

Minimum agreement score to match units

chance_score: float, default: 0.1

Minimum agreement score to for a possible match

n_jobs: int, default: -1

Number of cores to use in parallel. Uses all available if -1

verbose: bool, default: False

If True, output is verbose

Returns:
sorting_comparison: SortingComparison

The SortingComparison object

spikeinterface.comparison.compare_multiple_sorters(sorting_list, name_list=None, delta_time=0.4, match_score=0.5, chance_score=0.1, n_jobs=-1, spiketrain_mode='union', verbose=False, do_matching=True)

Compares multiple spike sorting outputs based on spike trains.

  • Pair-wise comparisons are made

  • An agreement graph is built based on the agreement score

It allows to return a consensus-based sorting extractor with the get_agreement_sorting() method.

Parameters:
sorting_list: list

List of sorting extractor objects to be compared

name_list: list, default: None

List of spike sorter names. If not given, sorters are named as “sorter0”, “sorter1”, “sorter2”, etc.

delta_time: float, default: 0.4

Number of ms to consider coincident spikes

match_score: float, default: 0.5

Minimum agreement score to match units

chance_score: float, default: 0.1

Minimum agreement score to for a possible match

n_jobs: int, default: -1

Number of cores to use in parallel. Uses all available if -1

spiketrain_mode: “union” | “intersection”, default: “union”
Mode to extract agreement spike trains:
  • “union”: spike trains are the union between the spike trains of the best matching two sorters

  • “intersection”: spike trains are the intersection between the spike trains of the

    best matching two sorters

verbose: bool, default: False

if True, output is verbose

Returns:
multi_sorting_comparison: MultiSortingComparison

MultiSortingComparison object with the multiple sorter comparison

spikeinterface.comparison.compare_sorter_to_ground_truth(gt_sorting, tested_sorting, gt_name=None, tested_name=None, delta_time=0.4, sampling_frequency=None, match_score=0.5, well_detected_score=0.8, redundant_score=0.2, overmerged_score=0.2, chance_score=0.1, exhaustive_gt=False, n_jobs=-1, match_mode='hungarian', compute_labels=False, compute_misclassifications=False, verbose=False)

Compares a sorter to a ground truth.

This class can:
  • compute a “match between gt_sorting and tested_sorting

  • compute optionally the score label (TP, FN, CL, FP) for each spike

  • count by unit of GT the total of each (TP, FN, CL, FP) into a Dataframe GroundTruthComparison.count

  • compute the confusion matrix .get_confusion_matrix()

  • compute some performance metric with several strategy based on the count score by unit

  • count well detected units

  • count false positive detected units

  • count redundant units

  • count overmerged units

  • summary all this

Parameters:
gt_sorting: SortingExtractor

The first sorting for the comparison

tested_sorting: SortingExtractor

The second sorting for the comparison

gt_name: str, default: None

The name of sorter 1

tested_name:str, default: None

The name of sorter 2

delta_time: float, default: 0.4

Number of ms to consider coincident spikes

match_score: float, default: 0.5

Minimum agreement score to match units

chance_score: float, default: 0.1

Minimum agreement score to for a possible match

redundant_score: float, default: 0.2

Agreement score above which units are redundant

overmerged_score: float, default: 0.2

Agreement score above which units can be overmerged

well_detected_score: float, default: 0.8

Agreement score above which units are well detected

exhaustive_gt: bool, default: False

Tell if the ground true is “exhaustive” or not. In other world if the GT have all possible units. It allows more performance measurement. For instance, MEArec simulated dataset have exhaustive_gt=True

match_mode: “hungarian” | “best”, default: “hungarian”

The method to match units

n_jobs: int, default: -1

Number of cores to use in parallel. Uses all available if -1

compute_labels: bool, default: False

If True, labels are computed at instantiation

compute_misclassifications: bool, default: False

If True, misclassifications are computed at instantiation

verbose: bool, default: False

If True, output is verbose

Returns:
sorting_comparison: SortingComparison

The SortingComparison object

spikeinterface.comparison.compare_templates(sorting_analyzer_1, sorting_analyzer_2, name1=None, name2=None, unit_ids1=None, unit_ids2=None, match_score=0.7, chance_score=0.3, similarity_method='cosine_similarity', sparsity_dict=None, verbose=False)

Compares units from different sessions based on template similarity

Parameters:
sorting_analyzer_1SortingAnalyzer

The first SortingAnalyzer to get templates to compare

sorting_analyzer_2SortingAnalyzer

The second SortingAnalyzer to get templates to compare

unit_ids1list, default: None

List of units from sorting_analyzer_1 to compare

unit_ids2list, default: None

List of units from sorting_analyzer_2 to compare

similarity_methodstr, default: “cosine_similarity”

Method for the similaroty matrix

sparsity_dictdict, default: None

Dictionary for sparsity

verbosebool, default: False

If True, output is verbose

Returns:
comparisonTemplateComparison

The output TemplateComparison object

spikeinterface.comparison.compare_multiple_templates(waveform_list, name_list=None, match_score=0.8, chance_score=0.3, verbose=False, similarity_method='cosine_similarity', sparsity_dict=None, do_matching=True)

Compares multiple waveform extractors using template similarity.

  • Pair-wise comparisons are made

  • An agreement graph is built based on the agreement score

Parameters:
waveform_list: list

List of waveform extractor objects to be compared

name_list: list, default: None

List of session names. If not given, sorters are named as “sess0”, “sess1”, “sess2”, etc.

match_score: float, default: 0.8

Minimum agreement score to match units

chance_score: float, default: 0.3

Minimum agreement score to for a possible match

verbose: bool, default: False

if True, output is verbose

Returns:
multi_template_comparison: MultiTemplateComparison

MultiTemplateComparison object with the multiple template comparisons

spikeinterface.comparison.create_hybrid_units_recording(parent_recording: BaseRecording, templates: np.ndarray, injected_sorting: BaseSorting | None = None, nbefore: List[int] | int | None = None, firing_rate: float = 10, amplitude_factor: np.ndarray | None = None, amplitude_std: float = 0.0, refractory_period_ms: float = 2.0, injected_sorting_folder: str | Path | None = None, seed=None)

Class for creating a hybrid recording where additional units are added to an existing recording.

Parameters:
parent_recording: BaseRecording

Existing recording to add on top of.

templates: np.ndarray[n_units, n_samples, n_channels]

Array containing the templates to inject for all the units.

injected_sorting: BaseSorting | None:

The sorting for the injected units. If None, will be generated using the following parameters.

nbefore: list[int] | int | None

Where is the center of the template for each unit? If None, will default to the highest peak.

firing_rate: float

The firing rate of the injected units (in Hz).

amplitude_factor: np.ndarray | None:

The amplitude factor for each spike. If None, will be generated as a gaussian centered at 1.0 and with an std of amplitude_std.

amplitude_std: float

The standard deviation of the amplitude (centered at 1.0).

refractory_period_ms: float

The refractory period of the injected spike train (in ms).

injected_sorting_folder: str | Path | None

If given, the injected sorting is saved to this folder. It must be specified if injected_sorting is None or not serialisable to file.

Returns:
hybrid_units_recording: HybridUnitsRecording

The recording containing real and hybrid units.

spikeinterface.comparison.create_hybrid_spikes_recording(wvf_extractor, injected_sorting: BaseSorting | None = None, unit_ids: List[int] | None = None, max_injected_per_unit: int = 1000, injected_rate: float = 0.05, refractory_period_ms: float = 1.5, injected_sorting_folder: str | Path | None = None) None

Class for creating a hybrid recording where additional spikes are added to already existing units.

Parameters:
wvf_extractor: WaveformExtractor

The waveform extractor object of the existing recording.

injected_sorting: BaseSorting | None

Additional spikes to inject. If None, will generate it.

max_injected_per_unit: int

If injected_sorting=None, the max number of spikes per unit that is allowed to be injected.

unit_ids: list[int] | None

unit_ids to take in the wvf_extractor for spikes injection.

injected_rate: float

If injected_sorting=None, the max fraction of spikes per unit that is allowed to be injected.

refractory_period_ms: float

If injected_sorting=None, the injected spikes need to respect this refractory period.

injected_sorting_folder: str | Path | None

If given, the injected sorting is saved to this folder. It must be specified if injected_sorting is None or not serializable to file.

Returns:
hybrid_spikes_recording: HybridSpikesRecording:

The recording containing units with real and hybrid spikes.

class spikeinterface.comparison.GroundTruthComparison(gt_sorting, tested_sorting, gt_name=None, tested_name=None, delta_time=0.4, sampling_frequency=None, match_score=0.5, well_detected_score=0.8, redundant_score=0.2, overmerged_score=0.2, chance_score=0.1, exhaustive_gt=False, n_jobs=-1, match_mode='hungarian', compute_labels=False, compute_misclassifications=False, verbose=False)

Compares a sorter to a ground truth.

This class can:
  • compute a “match between gt_sorting and tested_sorting

  • compute optionally the score label (TP, FN, CL, FP) for each spike

  • count by unit of GT the total of each (TP, FN, CL, FP) into a Dataframe GroundTruthComparison.count

  • compute the confusion matrix .get_confusion_matrix()

  • compute some performance metric with several strategy based on the count score by unit

  • count well detected units

  • count false positive detected units

  • count redundant units

  • count overmerged units

  • summary all this

Parameters:
gt_sorting: SortingExtractor

The first sorting for the comparison

tested_sorting: SortingExtractor

The second sorting for the comparison

gt_name: str, default: None

The name of sorter 1

tested_name:str, default: None

The name of sorter 2

delta_time: float, default: 0.4

Number of ms to consider coincident spikes

match_score: float, default: 0.5

Minimum agreement score to match units

chance_score: float, default: 0.1

Minimum agreement score to for a possible match

redundant_score: float, default: 0.2

Agreement score above which units are redundant

overmerged_score: float, default: 0.2

Agreement score above which units can be overmerged

well_detected_score: float, default: 0.8

Agreement score above which units are well detected

exhaustive_gt: bool, default: False

Tell if the ground true is “exhaustive” or not. In other world if the GT have all possible units. It allows more performance measurement. For instance, MEArec simulated dataset have exhaustive_gt=True

match_mode: “hungarian” | “best”, default: “hungarian”

The method to match units

n_jobs: int, default: -1

Number of cores to use in parallel. Uses all available if -1

compute_labels: bool, default: False

If True, labels are computed at instantiation

compute_misclassifications: bool, default: False

If True, misclassifications are computed at instantiation

verbose: bool, default: False

If True, output is verbose

Returns:
sorting_comparison: SortingComparison

The SortingComparison object

count_bad_units()

See get_bad_units

count_false_positive_units(redundant_score=None)

See get_false_positive_units().

count_overmerged_units(overmerged_score=None)

See get_overmerged_units().

count_redundant_units(redundant_score=None)

See get_redundant_units().

count_well_detected_units(well_detected_score)

Count how many well detected units. kwargs are the same as get_well_detected_units.

get_bad_units()

Return units list of “bad units”.

“bad units” are defined as units in tested that are not in the best match list of GT units.

So it is the union of “false positive units” + “redundant units”.

Need exhaustive_gt=True

get_confusion_matrix()

Computes the confusion matrix.

Returns:
confusion_matrix: pandas.DataFrame

The confusion matrix

get_false_positive_units(redundant_score=None)

Return units list of “false positive units” from tested_sorting.

“false positive units” are defined as units in tested that are not matched at all in GT units.

Need exhaustive_gt=True

Parameters:
redundant_score: float, default: None

The agreement score below which tested units are counted as “false positive”” (and not “redundant”).

get_overmerged_units(overmerged_score=None)

Return “overmerged units”

“overmerged units” are defined as units in tested that match more than one GT unit with an agreement score larger than overmerged_score.

Parameters:
overmerged_score: float, default: None

Tested units with 2 or more agreement scores above “overmerged_score” are counted as “overmerged”.

get_performance(method='by_unit', output='pandas')
Get performance rate with several method:
  • “raw_count” : just render the raw count table

  • “by_unit” : render perf as rate unit by unit of the GT

  • “pooled_with_average” : compute rate unit by unit and average

Parameters:
method: “by_unit” | “pooled_with_average”, default: “by_unit”

The method to compute performance

output: “pandas” | “dict”, default: “pandas”

The output format

Returns:
perf: pandas dataframe/series (or dict)

dataframe/series (based on “output”) with performance entries

get_redundant_units(redundant_score=None)

Return “redundant units”

“redundant units” are defined as units in tested that match a GT units with a big agreement score but it is not the best match. In other world units in GT that detected twice or more.

Parameters:
redundant_score=None: float, default: None

The agreement score above which tested units are counted as “redundant” (and not “false positive” ).

get_well_detected_units(well_detected_score=None)

Return units list of “well detected units” from tested_sorting.

“well detected units” are defined as units in tested that are well matched to GT units.

Parameters:
well_detected_score: float, default: None

The agreement score above which tested units are counted as “well detected”.

print_performance(method='pooled_with_average')

Print performance with the selected method

print_summary(well_detected_score=None, redundant_score=None, overmerged_score=None)
Print a global performance summary that depend on the context:
  • exhaustive= True/False

  • how many gt units (one or several)

This summary mix several performance metrics.

class spikeinterface.comparison.SymmetricSortingComparison(sorting1, sorting2, sorting1_name=None, sorting2_name=None, delta_time=0.4, match_score=0.5, chance_score=0.1, n_jobs=-1, verbose=False)

Compares two spike sorter outputs.

  • Spike trains are matched based on their agreement scores

  • Individual spikes are labelled as true positives (TP), false negatives (FN), false positives 1 (FP from spike train 1), false positives 2 (FP from spike train 2), misclassifications (CL)

It also allows to get confusion matrix and agreement fraction, false positive fraction and false negative fraction.

Parameters:
sorting1: SortingExtractor

The first sorting for the comparison

sorting2: SortingExtractor

The second sorting for the comparison

sorting1_name: str, default: None

The name of sorter 1

sorting2_name:str, default: None

The name of sorter 2

delta_time: float, default: 0.4

Number of ms to consider coincident spikes

match_score: float, default: 0.5

Minimum agreement score to match units

chance_score: float, default: 0.1

Minimum agreement score to for a possible match

n_jobs: int, default: -1

Number of cores to use in parallel. Uses all available if -1

verbose: bool, default: False

If True, output is verbose

Returns:
sorting_comparison: SortingComparison

The SortingComparison object

get_agreement_fraction(unit1=None, unit2=None)
get_best_unit_match1(unit1)
get_best_unit_match2(unit2)
get_matching()
get_matching_event_count(unit1, unit2)
get_matching_unit_list1(unit1)
get_matching_unit_list2(unit2)
class spikeinterface.comparison.GroundTruthStudy(study_folder)

This class is an helper function to run any comparison on several “cases” for many ground-truth dataset.

“cases” refer to:
  • several sorters for comparisons

  • same sorter with differents parameters

  • any combination of these (and more)

For increased flexibility, cases keys can be a tuple so that we can vary complexity along several “levels” or “axis” (paremeters or sorters). In this case, the result dataframes will have MultiIndex to handle the different levels.

A ground-truth dataset is made of a Recording and a Sorting object. For example, it can be a simulated dataset with MEArec or internally generated (see generate_ground_truth_recording()).

This GroundTruthStudy have been refactor in version 0.100 to be more flexible than previous versions. Note that the underlying folder structure is not backward compatible!

compute_metrics(case_keys=None, metric_names=['snr', 'firing_rate'], force=False)
copy_sortings(case_keys=None, force=True)
classmethod create(study_folder, datasets={}, cases={}, levels=None)
create_sorting_analyzer_gt(case_keys=None, random_params={}, waveforms_params={}, **job_kwargs)
get_count_units(case_keys=None, well_detected_score=None, redundant_score=None, overmerged_score=None)
get_metrics(key)
get_performance_by_unit(case_keys=None)
get_run_times(case_keys=None)
get_sorting_analyzer(case_key=None, dataset_key=None)
get_units_snr(key)
key_to_str(key)
remove_sorting(key)
run_comparisons(case_keys=None, comparison_class=<class 'spikeinterface.comparison.paircomparisons.GroundTruthComparison'>, **kwargs)
run_sorters(case_keys=None, engine='loop', engine_kwargs={}, keep=True, verbose=False)
scan_folder()
class spikeinterface.comparison.MultiSortingComparison(sorting_list, name_list=None, delta_time=0.4, match_score=0.5, chance_score=0.1, n_jobs=-1, spiketrain_mode='union', verbose=False, do_matching=True)

Compares multiple spike sorting outputs based on spike trains.

  • Pair-wise comparisons are made

  • An agreement graph is built based on the agreement score

It allows to return a consensus-based sorting extractor with the get_agreement_sorting() method.

Parameters:
sorting_list: list

List of sorting extractor objects to be compared

name_list: list, default: None

List of spike sorter names. If not given, sorters are named as “sorter0”, “sorter1”, “sorter2”, etc.

delta_time: float, default: 0.4

Number of ms to consider coincident spikes

match_score: float, default: 0.5

Minimum agreement score to match units

chance_score: float, default: 0.1

Minimum agreement score to for a possible match

n_jobs: int, default: -1

Number of cores to use in parallel. Uses all available if -1

spiketrain_mode: “union” | “intersection”, default: “union”
Mode to extract agreement spike trains:
  • “union”: spike trains are the union between the spike trains of the best matching two sorters

  • “intersection”: spike trains are the intersection between the spike trains of the

    best matching two sorters

verbose: bool, default: False

if True, output is verbose

Returns:
multi_sorting_comparison: MultiSortingComparison

MultiSortingComparison object with the multiple sorter comparison

get_agreement_sorting(minimum_agreement_count=1, minimum_agreement_count_only=False)

Returns AgreementSortingExtractor with units with a “minimum_matching” agreement.

Parameters:
minimum_agreement_count: int

Minimum number of matches among sorters to include a unit.

minimum_agreement_count_only: bool

If True, only units with agreement == “minimum_matching” are included. If False, units with an agreement >= “minimum_matching” are included

Returns:
agreement_sorting: AgreementSortingExtractor

The output AgreementSortingExtractor

class spikeinterface.comparison.CollisionGTComparison(gt_sorting, tested_sorting, collision_lag=2.0, nbins=11, **kwargs)

This class is an extension of GroundTruthComparison by focusing to benchmark spike in collision.

This class needs maintenance and need a bit of refactoring.

collision_lag: float

Collision lag in ms.

class spikeinterface.comparison.CorrelogramGTComparison(gt_sorting, tested_sorting, window_ms=100.0, bin_ms=1.0, well_detected_score=0.8, **kwargs)

This class is an extension of GroundTruthComparison by focusing to benchmark correlation reconstruction.

This class needs maintenance and need a bit of refactoring.

class spikeinterface.comparison.CollisionGTStudy(study_folder)
class spikeinterface.comparison.CorrelogramGTStudy(study_folder)

spikeinterface.widgets

spikeinterface.widgets.set_default_plotter_backend(backend)
spikeinterface.widgets.get_default_plotter_backend()

Return the default backend for spikeinterface widgets. The default backend is “matplotlib” at init. It can be be globally set with set_default_plotter_backend(backend)

spikeinterface.widgets.plot_agreement_matrix(sorting_comparison, ordered=True, count_text=True, unit_ticks=True, backend=None, **backend_kwargs)

Plots sorting comparison agreement matrix.

Parameters:
sorting_comparison: GroundTruthComparison or SymmetricSortingComparison

The sorting comparison object. Can optionally be symmetric if given a SymmetricSortingComparison

ordered: bool, default: True

Order units with best agreement scores. If True, agreement scores can be seen along a diagonal

count_text: bool, default: True

If True counts are displayed as text

unit_ticks: bool, default: True

If True unit tick labels are displayed

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_all_amplitudes_distributions(sorting_analyzer: SortingAnalyzer, unit_ids=None, unit_colors=None, backend=None, **backend_kwargs)

Plots distributions of amplitudes as violin plot for all or some units.

Parameters:
sorting_analyzer: SortingAnalyzer

The SortingAnalyzer

unit_ids: list

List of unit ids, default None

unit_colors: None or dict

Dict of colors with key: unit, value: color, default None

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_amplitudes(sorting_analyzer: SortingAnalyzer, unit_ids=None, unit_colors=None, segment_index=None, max_spikes_per_unit=None, hide_unit_selector=False, plot_histograms=False, bins=None, plot_legend=True, backend=None, **backend_kwargs)

Plots spike amplitudes

Parameters:
sorting_analyzerSortingAnalyzer

The input waveform extractor

unit_idslist or None, default: None

List of unit ids

segment_indexint or None, default: None

The segment index (or None if mono-segment)

max_spikes_per_unitint or None, default: None

Number of max spikes per unit to display. Use None for all spikes

hide_unit_selectorbool, default: False

If True the unit selector is not displayed (sortingview backend)

plot_histogrambool, default: False

If True, an histogram of the amplitudes is plotted on the right axis (matplotlib backend)

binsint or None, default: None

If plot_histogram is True, the number of bins for the amplitude histogram. If None this is automatically adjusted

plot_legendbool, default: True

True includes legend in plot

backend: str

[‘matplotlib’, ‘sortingview’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_autocorrelograms(*args, **kargs)

Plots unit cross correlograms.

Parameters:
sorting_analyzer_or_sortingSortingAnalyzer or BaseSorting

The object to compute/get crosscorrelograms from

unit_ids list or None, default: None

List of unit ids

min_similarity_for_correlogramsfloat, default: 0.2

For sortingview backend. Threshold for computing pair-wise cross-correlograms. If template similarity between two units is below this threshold, the cross-correlogram is not displayed

window_msfloat, default: 100.0

Window for CCGs in ms. If correlograms are already computed (e.g. with SortingAnalyzer), this argument is ignored

bin_msfloat, default: 1.0

Bin size in ms. If correlograms are already computed (e.g. with SortingAnalyzer), this argument is ignored

hide_unit_selectorbool, default: False

For sortingview backend, if True the unit selector is not displayed

unit_colors: dict or None, default: None

If given, a dictionary with unit ids as keys and colors as values

backend: str

[‘matplotlib’, ‘sortingview’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_confusion_matrix(gt_comparison, count_text=True, unit_ticks=True, backend=None, **backend_kwargs)

Plots sorting comparison confusion matrix.

Parameters:
gt_comparison: GroundTruthComparison

The ground truth sorting comparison object

count_text: bool

If True counts are displayed as text

unit_ticks: bool

If True unit tick labels are displayed

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_comparison_collision_by_similarity(comp, templates, unit_ids=None, metric='cosine_similarity', figure=None, ax=None, mode='heatmap', similarity_bins=array([-4.00000000e-01, -2.00000000e-01, -5.55111512e-17, 2.00000000e-01, 4.00000000e-01, 6.00000000e-01, 8.00000000e-01, 1.00000000e+00]), cmap='winter', good_only=False, min_accuracy=0.9, show_legend=False, ylim=(0, 1), backend=None, **backend_kwargs)

Plots CollisionGTComparison pair by pair orderer by cosine_similarity

Parameters:
comp: CollisionGTComparison

The collision ground truth comparison object

templates: array

template of units

mode: “heatmap” or “lines”

to see collision curves for every pairs (“heatmap”) or as lines averaged over pairs.

similarity_bins: array

if mode is “lines”, the bins used to average the pairs

cmap: string

colormap used to show averages if mode is “lines”

metric: “cosine_similarity”

metric for ordering

good_only: True

keep only the pairs with a non zero accuracy (found templates)

min_accuracy: float

If good only, the minimum accuracy every cell should have, individually, to be considered in a putative pair

unit_ids: list

List of considered units

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_crosscorrelograms(sorting_analyzer_or_sorting: SortingAnalyzer | BaseSorting, unit_ids=None, min_similarity_for_correlograms=0.2, window_ms=100.0, bin_ms=1.0, hide_unit_selector=False, unit_colors=None, backend=None, **backend_kwargs)

Plots unit cross correlograms.

Parameters:
sorting_analyzer_or_sortingSortingAnalyzer or BaseSorting

The object to compute/get crosscorrelograms from

unit_ids list or None, default: None

List of unit ids

min_similarity_for_correlogramsfloat, default: 0.2

For sortingview backend. Threshold for computing pair-wise cross-correlograms. If template similarity between two units is below this threshold, the cross-correlogram is not displayed

window_msfloat, default: 100.0

Window for CCGs in ms. If correlograms are already computed (e.g. with SortingAnalyzer), this argument is ignored

bin_msfloat, default: 1.0

Bin size in ms. If correlograms are already computed (e.g. with SortingAnalyzer), this argument is ignored

hide_unit_selectorbool, default: False

For sortingview backend, if True the unit selector is not displayed

unit_colors: dict or None, default: None

If given, a dictionary with unit ids as keys and colors as values

backend: str

[‘matplotlib’, ‘sortingview’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_isi_distribution(sorting, unit_ids=None, window_ms=100.0, bin_ms=1.0, backend=None, **backend_kwargs)

Plots spike train ISI distribution.

Parameters:
sorting: SortingExtractor

The sorting extractor object

unit_ids: list

List of unit ids

bins_ms: int

Bin size in ms

window_ms: float

Window size in ms

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_motion(motion_info, recording=None, depth_lim=None, motion_lim=None, color_amplitude=False, scatter_decimate=None, amplitude_cmap='inferno', amplitude_clim=None, amplitude_alpha=1, backend=None, **backend_kwargs)

Plot unit depths

Parameters:
motion_info: dict

The motion info return by correct_motion() or load back with load_motion_info()

recordingRecordingExtractor, default: None

The recording extractor object (only used to get “real” times)

sampling_frequencyfloat, default: None

The sampling frequency (needed if recording is None)

depth_limtuple or None, default: None

The min and max depth to display, if None (min and max of the recording)

motion_limtuple or None, default: None

The min and max motion to display, if None (min and max of the motion)

color_amplitudebool, default: False

If True, the color of the scatter points is the amplitude of the peaks

scatter_decimateint, default: None

If > 1, the scatter points are decimated

amplitude_cmapstr, default: “inferno”

The colormap to use for the amplitude

amplitude_climtuple or None, default: None

The min and max amplitude to display, if None (min and max of the amplitudes)

amplitude_alphafloat, default: 1

The alpha of the scatter points

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_multicomparison_agreement(multi_comparison, plot_type='pie', cmap='YlOrRd', fontsize=9, show_legend=True, backend=None, **backend_kwargs)

Plots multi comparison agreement as pie or bar plot.

Parameters:
multi_comparison: BaseMultiComparison

The multi comparison object

plot_type: “pie” | “bar”, default: “pie”

The plot type

cmap: matplotlib colormap, default: “YlOrRd”

The colormap to be used for the nodes

fontsize: int, default: 9

The text fontsize

show_legend: bool, default: True

If True a legend is shown

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_multicomparison_agreement_by_sorter(multi_comparison, plot_type='pie', cmap='YlOrRd', fontsize=9, show_legend=True, backend=None, **backend_kwargs)

Plots multi comparison agreement as pie or bar plot.

Parameters:
multi_comparison: BaseMultiComparison

The multi comparison object

plot_type: “pie” | “bar”, default: “pie

The plot type

cmap: matplotlib colormap, default: “Reds”

The colormap to be used for the nodes

fontsize: int, default: 9

The text fontsize

show_legend: bool

Show the legend in the last axes

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_multicomparison_graph(multi_comparison, draw_labels=False, node_cmap='viridis', edge_cmap='hot', alpha_edges=0.5, colorbar=False, backend=None, **backend_kwargs)

Plots multi comparison graph.

Parameters:
multi_comparison: BaseMultiComparison

The multi comparison object

draw_labels: bool, default: False

If True unit labels are shown

node_cmap: matplotlib colormap, default: “viridis”

The colormap to be used for the nodes

edge_cmap: matplotlib colormap, default: “hot”

The colormap to be used for the edges

alpha_edges: float, default: 0.5

Alpha value for edges

colorbar: bool, default: False

If True a colorbar for the edges is plotted

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_peak_activity(recording, peaks, bin_duration_s=None, with_contact_color=True, with_interpolated_map=True, with_channel_ids=False, with_color_bar=True, backend=None, **backend_kwargs)

Plots spike rate (estimated with detect_peaks()) as 2D activity map.

Can be static (bin_duration_s=None) or animated (bin_duration_s=60.)

Parameters:
recording: RecordingExtractor

The recording extractor object.

peaks: None or numpy array

Optionally can give already detected peaks to avoid multiple computation.

detect_peaks_kwargs: None or dict, default: None

If peaks is None here the kwargs for detect_peak function.

bin_duration_s: None or float, default: None

If None then static image If not None then it is an animation per bin.

with_contact_color: bool, default: True

Plot rates with contact colors

with_interpolated_map: bool, default: True

Plot rates with interpolated map

with_channel_ids: bool, default: False

Add channel ids text on the probe

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_probe_map(recording, color_channels=None, with_channel_ids=False, backend=None, **backend_or_plot_probe_kwargs)

Plot the probe of a recording.

Parameters:
recording: RecordingExtractor

The recording extractor object

color_channels: list or matplotlib color

List of colors to be associated with each channel_id, if only one color is present all channels will take the specified color

with_channel_ids: bool False default

Add channel ids text on the probe

**plot_probe_kwargs: keyword arguments for probeinterface.plotting.plot_probe_group() function
backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_quality_metrics(sorting_analyzer: SortingAnalyzer, unit_ids=None, include_metrics=None, skip_metrics=None, unit_colors=None, hide_unit_selector=False, backend=None, **backend_kwargs)

Plots quality metrics distributions.

Parameters:
sorting_analyzerSortingAnalyzer

The object to get quality metrics from

unit_ids: list or None, default: None

List of unit ids

include_metrics: list or None, default: None

If given, a list of quality metrics to include

skip_metrics: list or None, default: None

If given, a list of quality metrics to skip

unit_colorsdict or None, default: None

If given, a dictionary with unit ids as keys and colors as values

hide_unit_selectorbool, default: False

For sortingview backend, if True the unit selector is not displayed

backend: str

[‘matplotlib’, ‘sortingview’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_rasters(sorting, segment_index=None, unit_ids=None, time_range=None, color='k', backend=None, **backend_kwargs)

Plots spike train rasters.

Parameters:
sorting: SortingExtractor

The sorting extractor object

segment_index: None or int

The segment index.

unit_ids: list

List of unit ids

time_range: list

List with start time and end time

color: matplotlib color

The color to be used

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_sorting_summary(sorting_analyzer: SortingAnalyzer, unit_ids=None, sparsity=None, max_amplitudes_per_unit=None, min_similarity_for_correlograms=0.2, curation=False, unit_table_properties=None, label_choices=None, backend=None, **backend_kwargs)

Plots spike sorting summary. This is the main viewer to visualize the final result with several sub view. This use sortingview (in a web browser) or spikeinterface-gui (with Qt).

Parameters:
sorting_analyzerSortingAnalyzer

The SortingAnalyzer object

unit_idslist or None, default: None

List of unit ids

sparsityChannelSparsity or None, default: None

Optional ChannelSparsity to apply If SortingAnalyzer is already sparse, the argument is ignored

max_amplitudes_per_unitint or None, default: None

Maximum number of spikes per unit for plotting amplitudes. If None, all spikes are plotted

min_similarity_for_correlogramsfloat, default: 0.2

Threshold for computing pair-wise cross-correlograms. If template similarity between two units is below this threshold, the cross-correlogram is not computed (sortingview backend)

curationbool, default: False

If True, manual curation is enabled (sortingview backend)

label_choiceslist or None, default: None

List of labels to be added to the curation table (sortingview backend)

unit_table_propertieslist or None, default: None

List of properties to be added to the unit table (sortingview backend)

backend: str

[‘sortingview’, ‘spikeinterface_gui’]

**backend_kwargs: kwargs

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_spike_locations(sorting_analyzer: SortingAnalyzer, unit_ids=None, segment_index=None, max_spikes_per_unit=500, with_channel_ids=False, unit_colors=None, hide_unit_selector=False, plot_all_units=True, plot_legend=False, hide_axis=False, backend=None, **backend_kwargs)

Plots spike locations.

Parameters:
sorting_analyzerSortingAnalyzer

The object to get spike locations from

unit_idslist or None, default: None

List of unit ids

segment_indexint or None, default: None

The segment index (or None if mono-segment)

max_spikes_per_unitint or None, default: 500

Number of max spikes per unit to display. Use None for all spikes.

with_channel_idsbool, default: False

Add channel ids text on the probe

unit_colorsdict or None, default: None

If given, a dictionary with unit ids as keys and colors as values

hide_unit_selectorbool, default: False

For sortingview backend, if True the unit selector is not displayed

plot_all_unitsbool, default: True

If True, all units are plotted. The unselected ones (not in unit_ids), are plotted in grey (matplotlib backend)

plot_legendbool, default: False

If True, the legend is plotted (matplotlib backend)

hide_axisbool, default: False

If True, the axis is set to off (matplotlib backend)

backend: str

[‘matplotlib’, ‘sortingview’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_spikes_on_traces(sorting_analyzer: SortingAnalyzer, segment_index=None, channel_ids=None, unit_ids=None, order_channel_by_depth=False, time_range=None, unit_colors=None, sparsity=None, mode='auto', return_scaled=False, cmap='RdBu', show_channel_ids=False, color_groups=False, color=None, clim=None, tile_size=512, seconds_per_row=0.2, scale=1, spike_width_ms=4, spike_height_um=20, with_colorbar=True, backend=None, **backend_kwargs)

Plots unit spikes/waveforms over traces.

Parameters:
sorting_analyzerSortingAnalyzer

The SortingAnalyzer

channel_idslist or None, default: None

The channel ids to display

unit_idslist or None, default: None

List of unit ids

order_channel_by_depthbool, default: False

If true orders channel by depth

time_range: list or None, default: None

List with start time and end time in seconds

sparsityChannelSparsity or None, default: None

Optional ChannelSparsity to apply If SortingAnalyzer is already sparse, the argument is ignored

unit_colorsdict or None, default: None

If given, a dictionary with unit ids as keys and colors as values If None, then the get_unit_colors() is internally used. (matplotlib backend)

mode“line” | “map” | “auto”, default: “auto”
  • “line”: classical for low channel count

  • “map”: for high channel count use color heat map

  • “auto”: auto switch depending on the channel count (“line” if less than 64 channels, “map” otherwise)

return_scaledbool, default: False

If True and the recording has scaled traces, it plots the scaled traces

cmapstr, default: “RdBu”

matplotlib colormap used in mode “map”

show_channel_idsbool, default: False

Set yticks with channel ids

color_groupsbool, default: False

If True groups are plotted with different colors

colorstr or None, default: None

The color used to draw the traces

climNone, tuple or dict, default: None

When mode is “map”, this argument controls color limits. If dict, keys should be the same as recording keys

scalefloat, default: 1

Scale factor for the traces

with_colorbarbool, default: True

When mode is “map”, a colorbar is added

tile_sizeint, default: 512

For sortingview backend, the size of each tile in the rendered image

seconds_per_rowfloat, default: 0.2

For “map” mode and sortingview backend, seconds to render in each row

backend: str

[‘matplotlib’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_template_metrics(sorting_analyzer: SortingAnalyzer, unit_ids=None, include_metrics=None, skip_metrics=None, unit_colors=None, hide_unit_selector=False, backend=None, **backend_kwargs)

Plots template metrics distributions.

Parameters:
sorting_analyzerSortingAnalyzer

The object to get quality metrics from

unit_idslist or None, default: None

List of unit ids

include_metricslist or None, default: None

If given list of quality metrics to include

skip_metricslist or None or None, default: None

If given, a list of quality metrics to skip

unit_colorsdict or None, default: None

If given, a dictionary with unit ids as keys and colors as values

hide_unit_selectorbool, default: False

For sortingview backend, if True the unit selector is not displayed

backend: str

[‘matplotlib’, ‘sortingview’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_template_similarity(sorting_analyzer: SortingAnalyzer, unit_ids=None, cmap='viridis', display_diagonal_values=False, show_unit_ticks=False, show_colorbar=True, backend=None, **backend_kwargs)

Plots unit template similarity.

Parameters:
sorting_analyzerSortingAnalyzer

The object to get template similarity from

unit_idslist or None, default: None

List of unit ids default: None

display_diagonal_valuesbool, default: False

If False, the diagonal is displayed as zeros. If True, the similarity values (all 1s) are displayed

cmapmatplotlib colormap, default: “viridis”

The matplotlib colormap

show_unit_ticksbool, default: False

If True, ticks display unit ids

show_colorbarbool, default: True

If True, color bar is displayed

backend: str

[‘matplotlib’, ‘sortingview’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_traces(recording, segment_index=None, channel_ids=None, order_channel_by_depth=False, time_range=None, mode='auto', return_scaled=False, cmap='RdBu_r', show_channel_ids=False, events=None, events_color='gray', events_alpha=0.5, color_groups=False, color=None, clim=None, tile_size=1500, seconds_per_row=0.2, scale=1, with_colorbar=True, add_legend=True, backend=None, **backend_kwargs)

Plots recording timeseries.

Parameters:
recording: RecordingExtractor, dict, or list

The recording extractor object. If dict (or list) then it is a multi-layer display to compare, for example, different processing steps

segment_index: None or int, default: None

The segment index (required for multi-segment recordings)

channel_ids: list or None, default: None

The channel ids to display

order_channel_by_depth: bool, default: False

Reorder channel by depth

time_range: list, tuple or None, default: None

List with start time and end time

mode: “line” | “map” | “auto”, default: “auto”

Three possible modes * “line”: classical for low channel count * “map”: for high channel count use color heat map * “auto”: auto switch depending on the channel count (“line” if less than 64 channels, “map” otherwise)

return_scaled: bool, default: False

If True and the recording has scaled traces, it plots the scaled traces

events: np.array | list[np.narray] or None, default: None

Events to display as vertical lines. The numpy arrays cen either be of dtype float, with event times in seconds, or a structured array with the “time” field, and optional “duration” and “label” fields. For multi-segment recordings, provide a list of numpy array events, one for each segment.

cmap: matplotlib colormap, default: “RdBu_r”

matplotlib colormap used in mode “map”

show_channel_ids: bool, default: False

Set yticks with channel ids

color_groups: bool, default: False

If True groups are plotted with different colors

color: str or None, default: None

The color used to draw the traces

clim: None, tuple or dict, default: None

When mode is “map”, this argument controls color limits. If dict, keys should be the same as recording keys

scale: float, default: 1

Scale factor for the traces

with_colorbar: bool, default: True

When mode is “map”, a colorbar is added

tile_size: int, default: 1500

For sortingview backend, the size of each tile in the rendered image

seconds_per_row: float, default: 0.2

For “map” mode and sortingview backend, seconds to render in each row

add_legendbool, default: True

If True adds legend to figures

backend: str

[‘matplotlib’, ‘sortingview’, ‘ipywidgets’, ‘ephyviewer’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_depths(sorting_analyzer, unit_colors=None, depth_axis=1, peak_sign='neg', backend=None, **backend_kwargs)

Plot unit depths

Parameters:
sorting_analyzerSortingAnalyzer

The SortingAnalyzer object

unit_colorsdict or None, default: None

If given, a dictionary with unit ids as keys and colors as values

depth_axisint, default: 1

The dimension of unit_locations that is depth

peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of peak for amplitudes

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_locations(sorting_analyzer: SortingAnalyzer, unit_ids=None, with_channel_ids=False, unit_colors=None, hide_unit_selector=False, plot_all_units=True, plot_legend=False, hide_axis=False, backend=None, **backend_kwargs)

Plots each unit’s location.

Parameters:
sorting_analyzerSortingAnalyzer

The SortingAnalyzer that must contains “unit_locations” extension

unit_idslist or None, default: None

List of unit ids

with_channel_idsbool, default: False

Add channel ids text on the probe

unit_colorsdict or None, default: None

If given, a dictionary with unit ids as keys and colors as values

hide_unit_selectorbool, default: False

If True, the unit selector is not displayed (sortingview backend)

plot_all_unitsbool, default: True

If True, all units are plotted. The unselected ones (not in unit_ids), are plotted in grey (matplotlib backend)

plot_legendbool, default: False

If True, the legend is plotted (matplotlib backend)

hide_axisbool, default: False

If True, the axis is set to off (matplotlib backend)

backend: str

[‘matplotlib’, ‘sortingview’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_presence(sorting, segment_index=None, time_range=None, bin_duration_s=0.05, smooth_sigma=4.5, backend=None, **backend_kwargs)

Estimates of the probability density function for each unit using Gaussian kernels,

Parameters:
sorting: SortingExtractor

The sorting extractor object

segment_index: None or int

The segment index.

time_range: list or None, default: None

List with start time and end time

bin_duration_s: float, default: 0.5

Bin size (in seconds) for the heat map time axis

smooth_sigma: float, default: 4.5

Sigma for the Gaussian kernel (in number of bins)

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_probe_map(sorting_analyzer, unit_ids=None, channel_ids=None, animated=None, with_channel_ids=False, colorbar=True, backend=None, **backend_kwargs)

Plots unit map. Amplitude is color coded on probe contact.

Can be static (animated=False) or animated (animated=True)

Parameters:
sorting_analyzer: SortingAnalyzer
unit_ids: list

List of unit ids.

channel_ids: list

The channel ids to display

animated: bool, default: False

Animation for amplitude on time

with_channel_ids: bool, default: False

add channel ids text on the probe

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_summary(sorting_analyzer, unit_id, unit_colors=None, sparsity=None, radius_um=100, backend=None, **backend_kwargs)

Plot a unit summary.

If amplitudes are alreday computed they are displayed.

Parameters:
sorting_analyzerSortingAnalyzer

The SortingAnalyzer object

unit_idint or str

The unit id to plot the summary of

unit_colorsdict or None, default: None

If given, a dictionary with unit ids as keys and colors as values,

sparsityChannelSparsity or None, default: None

Optional ChannelSparsity to apply. If SortingAnalyzer is already sparse, the argument is ignored

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_templates(*args, **kargs)

Plots unit waveforms.

Parameters:
sorting_analyzer_or_templatesSortingAnalyzer | Templates

The SortingAnalyzer or Templates object. If Templates is given, the “plot_waveforms” argument is set to False

channel_ids: list or None, default: None

The channel ids to display

unit_idslist or None, default: None

List of unit ids

plot_templatesbool, default: True

If True, templates are plotted over the waveforms

sparsityChannelSparsity or None, default: None

Optional ChannelSparsity to apply If SortingAnalyzer is already sparse, the argument is ignored

set_titlebool, default: True

Create a plot title with the unit number if True

plot_channelsbool, default: False

Plot channel locations below traces

unit_selected_waveformsNone or dict, default: None

A dict key is unit_id and value is the subset of waveforms indices that should be be displayed (matplotlib backend)

max_spikes_per_unitint or None, default: 50

If given and unit_selected_waveforms is None, only max_spikes_per_unit random units are displayed per waveform, (matplotlib backend)

scalefloat, default: 1

Scale factor for the waveforms/templates (matplotlib backend)

widen_narrow_scalefloat, default: 1

Scale factor for the x-axis of the waveforms/templates (matplotlib backend)

axis_equalbool, default: False

Equal aspect ratio for x and y axis, to visualize the array geometry to scale

lw_waveformsfloat, default: 1

Line width for the waveforms, (matplotlib backend)

lw_templatesfloat, default: 2

Line width for the templates, (matplotlib backend)

unit_colorsNone or dict, default: None

A dict key is unit_id and value is any color format handled by matplotlib. If None, then the get_unit_colors() is internally used. (matplotlib / ipywidgets backend)

alpha_waveformsfloat, default: 0.5

Alpha value for waveforms (matplotlib backend)

alpha_templatesfloat, default: 1

Alpha value for templates, (matplotlib backend)

shade_templatesbool, default: True

If True, templates are shaded, see templates_percentile_shading argument

templates_percentile_shadingfloat, tuple/list of floats, or None, default: (1, 25, 75, 99)

It controls the shading of the templates. If None, the shading is +/- the standard deviation of the templates. If float, it controls the percentile of the template values used to shade the templates. Note that it is one-sided: if 5 is given, the 5th and 95th percentiles are used to shade the templates. If list of floats, it needs to be have an even number of elements which control the lower and upper percentile used to shade the templates. The first half of the elements are used for the lower bounds, and the second half for the upper bounds. Inner elements produce darker shadings. For sortingview backend only 2 or 4 elements are supported.

scalebarbool, default: False

Display a scale bar on the waveforms plot (matplotlib backend)

hide_unit_selectorbool, default: False

For sortingview backend, if True the unit selector is not displayed

same_axisbool, default: False

If True, waveforms and templates are displayed on the same axis (matplotlib backend)

x_offset_unitsbool, default: False

In case same_axis is True, this parameter allow to x-offset the waveforms for different units (recommended for a few units) (matlotlib backend)

plot_legendbool, default: True

Display legend (matplotlib backend)

backend: str

[‘matplotlib’, ‘sortingview’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

sortingview:

  • generate_url: If True, the figurl URL is generated and printed, default: True

  • display: If True and in jupyter notebook/lab, the widget is displayed in the cell, default: True.

  • figlabel: The figurl figure label, default: None

  • height: The height of the sortingview View in jupyter, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_waveforms_density_map(sorting_analyzer, channel_ids=None, unit_ids=None, sparsity=None, same_axis=False, use_max_channel=False, peak_sign='neg', unit_colors=None, backend=None, **backend_kwargs)

Plots unit waveforms using heat map density.

Parameters:
sorting_analyzerSortingAnalyzer

The SortingAnalyzer for calculating waveforms

channel_idslist or None, default: None

The channel ids to display

unit_idslist or None, default: None

List of unit ids

sparsityChannelSparsity or None, default: None

Optional ChannelSparsity to apply If SortingAnalyzer is already sparse, the argument is ignored

use_max_channelbool, default: False

Use only the max channel

peak_sign“neg” | “pos” | “both”, default: “neg”

Used to detect max channel only when use_max_channel=True

unit_colorsNone or dict, default: None

A dict key is unit_id and value is any color format handled by matplotlib. If None, then the get_unit_colors() is internally used

same_axisbool, default: False

If True then all density are plot on the same axis and then channels is the union all channel per units

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_unit_waveforms(sorting_analyzer_or_templates: SortingAnalyzer | Templates, channel_ids=None, unit_ids=None, plot_waveforms=True, plot_templates=True, plot_channels=False, unit_colors=None, sparsity=None, ncols=5, scale=1, widen_narrow_scale=1, lw_waveforms=1, lw_templates=2, axis_equal=False, unit_selected_waveforms=None, max_spikes_per_unit=50, set_title=True, same_axis=False, shade_templates=True, templates_percentile_shading=(1, 25, 75, 99), scalebar=False, x_offset_units=False, alpha_waveforms=0.5, alpha_templates=1, hide_unit_selector=False, plot_legend=True, backend=None, **backend_kwargs)

Plots unit waveforms.

Parameters:
sorting_analyzer_or_templatesSortingAnalyzer | Templates

The SortingAnalyzer or Templates object. If Templates is given, the “plot_waveforms” argument is set to False

channel_ids: list or None, default: None

The channel ids to display

unit_idslist or None, default: None

List of unit ids

plot_templatesbool, default: True

If True, templates are plotted over the waveforms

sparsityChannelSparsity or None, default: None

Optional ChannelSparsity to apply If SortingAnalyzer is already sparse, the argument is ignored

set_titlebool, default: True

Create a plot title with the unit number if True

plot_channelsbool, default: False

Plot channel locations below traces

unit_selected_waveformsNone or dict, default: None

A dict key is unit_id and value is the subset of waveforms indices that should be be displayed (matplotlib backend)

max_spikes_per_unitint or None, default: 50

If given and unit_selected_waveforms is None, only max_spikes_per_unit random units are displayed per waveform, (matplotlib backend)

scalefloat, default: 1

Scale factor for the waveforms/templates (matplotlib backend)

widen_narrow_scalefloat, default: 1

Scale factor for the x-axis of the waveforms/templates (matplotlib backend)

axis_equalbool, default: False

Equal aspect ratio for x and y axis, to visualize the array geometry to scale

lw_waveformsfloat, default: 1

Line width for the waveforms, (matplotlib backend)

lw_templatesfloat, default: 2

Line width for the templates, (matplotlib backend)

unit_colorsNone or dict, default: None

A dict key is unit_id and value is any color format handled by matplotlib. If None, then the get_unit_colors() is internally used. (matplotlib / ipywidgets backend)

alpha_waveformsfloat, default: 0.5

Alpha value for waveforms (matplotlib backend)

alpha_templatesfloat, default: 1

Alpha value for templates, (matplotlib backend)

shade_templatesbool, default: True

If True, templates are shaded, see templates_percentile_shading argument

templates_percentile_shadingfloat, tuple/list of floats, or None, default: (1, 25, 75, 99)

It controls the shading of the templates. If None, the shading is +/- the standard deviation of the templates. If float, it controls the percentile of the template values used to shade the templates. Note that it is one-sided: if 5 is given, the 5th and 95th percentiles are used to shade the templates. If list of floats, it needs to be have an even number of elements which control the lower and upper percentile used to shade the templates. The first half of the elements are used for the lower bounds, and the second half for the upper bounds. Inner elements produce darker shadings. For sortingview backend only 2 or 4 elements are supported.

scalebarbool, default: False

Display a scale bar on the waveforms plot (matplotlib backend)

hide_unit_selectorbool, default: False

For sortingview backend, if True the unit selector is not displayed

same_axisbool, default: False

If True, waveforms and templates are displayed on the same axis (matplotlib backend)

x_offset_unitsbool, default: False

In case same_axis is True, this parameter allow to x-offset the waveforms for different units (recommended for a few units) (matlotlib backend)

plot_legendbool, default: True

Display legend (matplotlib backend)

backend: str

[‘matplotlib’, ‘ipywidgets’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

ipywidgets:

  • width_cm: Width of the figure in cm, default: 10

  • height_cm: Height of the figure in cm, default 6

  • display: If True, widgets are immediately displayed, default: True

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_study_run_times(study, case_keys=None, backend=None, **backend_kwargs)

Plot sorter run times for a GroundTruthStudy

Parameters:
study: GroundTruthStudy

A study object.

case_keys: list or None

A selection of cases to plot, if None, then all.

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_study_unit_counts(study, case_keys=None, backend=None, **backend_kwargs)

Plot unit counts for a study: “num_well_detected”, “num_false_positive”, “num_redundant”, “num_overmerged”

Parameters:
study: GroundTruthStudy

A study object.

case_keys: list or None

A selection of cases to plot, if None, then all.

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_study_performances(study, mode='ordered', performance_names=('accuracy', 'precision', 'recall'), case_keys=None, backend=None, **backend_kwargs)

Plot performances over case for a study.

Parameters:
study: GroundTruthStudy

A study object.

mode: “ordered” | “snr” | “swarm”, default: “ordered”

Which plot mode to use:

  • “ordered”: plot performance metrics vs unit indices ordered by decreasing accuracy

  • “snr”: plot performance metrics vs snr

  • “swarm”: plot performance metrics as a swarm plot (see seaborn.swarmplot for details)

performance_names: list or tuple, default: (“accuracy”, “precision”, “recall”)

Which performances to plot (“accuracy”, “precision”, “recall”)

case_keys: list or None

A selection of cases to plot, if None, then all.

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_study_agreement_matrix(study, ordered=True, case_keys=None, backend=None, **backend_kwargs)

Plot agreement matrix.

Parameters:
study: GroundTruthStudy

A study object.

case_keys: list or None

A selection of cases to plot, if None, then all.

ordered: bool

Order units with best agreement scores. This enable to see agreement on a diagonal.

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_study_summary(study, case_keys=None, backend=None, **backend_kwargs)

Plot a summary of a ground truth study. Internally this plotting function runs:

  • plot_study_run_times

  • plot_study_unit_counts

  • plot_study_performances

  • plot_study_agreement_matrix

Parameters:
study: GroundTruthStudy

A study object.

case_keys: list or None, default: None

A selection of cases to plot, if None, then all.

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.widgets.plot_study_comparison_collision_by_similarity(study, case_keys=None, metric='cosine_similarity', similarity_bins=array([-4.00000000e-01, -2.00000000e-01, -5.55111512e-17, 2.00000000e-01, 4.00000000e-01, 6.00000000e-01, 8.00000000e-01, 1.00000000e+00]), show_legend=False, ylim=(0.5, 1), good_only=False, min_accuracy=0.9, cmap='winter', backend=None, **backend_kwargs)

Plots CollisionGTComparison pair by pair orderer by cosine_similarity for all cases in a study.

Parameters:
study: CollisionGTStudy

The collision study object.

case_keys: list or None

A selection of cases to plot, if None, then all.

metric: “cosine_similarity”

metric for ordering

similarity_bins: array

if mode is “lines”, the bins used to average the pairs

cmap: string

colormap used to show averages if mode is “lines”

good_only: False

keep only the pairs with a non zero accuracy (found templates)

min_accuracy: float

If good only, the minimum accuracy every cell should have, individually, to be considered in a putative pair

backend: str

[‘matplotlib’]

**backend_kwargs: kwargs

matplotlib:

  • figure: Matplotlib figure. When None, it is created, default: None

  • ax: Single matplotlib axis. When None, it is created, default: None

  • axes: Multiple matplotlib axes. When None, they is created, default: None

  • ncols: Number of columns to create in subplots, default: 5

  • figsize: Size of matplotlib figure, default: None

  • figtitle: The figure title, default: None

Returns:
wBaseWidget

The output widget object.

spikeinterface.exporters

spikeinterface.exporters.export_to_phy(sorting_analyzer: SortingAnalyzer, output_folder: str | Path, compute_pc_features: bool = True, compute_amplitudes: bool = True, sparsity: ChannelSparsity | None = None, copy_binary: bool = True, remove_if_exists: bool = False, peak_sign: Literal['both', 'neg', 'pos'] = 'neg', template_mode: str = 'average', dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any] = None, verbose: bool = True, use_relative_path: bool = False, **job_kwargs)

Exports a waveform extractor to the phy template-gui format.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

output_folder: str | Path

The output folder where the phy template-gui files are saved

compute_pc_features: bool, default: True

If True, pc features are computed

compute_amplitudes: bool, default: True

If True, waveforms amplitudes are computed

sparsity: ChannelSparsity or None, default: None

The sparsity object

copy_binary: bool, default: True

If True, the recording is copied and saved in the phy “output_folder”

remove_if_exists: bool, default: False

If True and “output_folder” exists, it is removed and overwritten

peak_sign: “neg” | “pos” | “both”, default: “neg”

Used by compute_spike_amplitudes

template_mode: str, default: “average”

Parameter “mode” to be given to SortingAnalyzer.get_template()

dtype: dtype or None, default: None

Dtype to save binary data

verbose: bool, default: True

If True, output is verbose

use_relative_pathbool, default: False

If True and copy_binary=True saves the binary file dat_path in the params.py relative to output_folder (ie dat_path=r”recording.dat”). If copy_binary=False, then uses a path relative to the output_folder If False, uses an absolute path in the params.py (ie dat_path=r”path/to/the/recording.dat”)

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

spikeinterface.exporters.export_report(sorting_analyzer, output_folder, remove_if_exists=False, format='png', show_figures=False, peak_sign='neg', force_computation=False, **job_kwargs)

Exports a SI spike sorting report. The report includes summary figures of the spike sorting output (e.g. amplitude distributions, unit localization and depth VS amplitude) as well as unit-specific reports, that include waveforms, templates, template maps, ISI distributions, and more.

Parameters:
sorting_analyzer: SortingAnalyzer

A SortingAnalyzer object

output_folder: str

The output folder where the report files are saved

remove_if_exists: bool, default: False

If True and the output folder exists, it is removed

format: str, default: “png”

The output figure format (any format handled by matplotlib)

peak_sign: “neg” or “pos”, default: “neg”

used to compute amplitudes and metrics

show_figures: bool, default: False

If True, figures are shown. If False, figures are closed after saving

force_computation: bool, default: False

Force or not some heavy computaion before exporting

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

spikeinterface.curation

class spikeinterface.curation.CurationSorting(parent_sorting, make_graph=False, properties_policy='keep')

Class that handles curation of a Sorting object.

Parameters:
parent_sorting: Recording

The recording object

properties_policy: “keep” | “remove”, default: “keep”

Policy used to propagate properties after split and merge operation. If “keep” the properties will be passed to the new units (if the original units have the same value). If “remove” the new units will have an empty value for all the properties

make_graph: bool

True to keep a Networkx graph instance with the curation history

Returns
——-
sorting: Sorting

Sorting object with the selected units merged

class spikeinterface.curation.MergeUnitsSorting(parent_sorting, units_to_merge, new_unit_ids=None, properties_policy='keep', delta_time_ms=0.4)

Class that handles several merges of units from a Sorting object based on a list of lists of unit_ids.

Parameters:
parent_sorting: Recording

The sorting object

units_to_merge: list/tuple of lists/tuples

A list of lists for every merge group. Each element needs to have at least two elements (two units to merge), but it can also have more (merge multiple units at once).

new_unit_ids: None or list

A new unit_ids for merged units. If given, it needs to have the same length as units_to_merge

properties_policy: “keep” | “remove”, default: “keep”
Policy used to propagate properties. If “keep” the properties will be passed to the new units

(if the units_to_merge have the same value). If “remove” the new units will have an empty value for all the properties of the new unit.

delta_time_ms: float or None

Number of ms to consider for duplicated spikes. None won’t check for duplications

Returns:
sorting: Sorting

Sorting object with the selected units merged

class spikeinterface.curation.SplitUnitSorting(parent_sorting, split_unit_id, indices_list, new_unit_ids=None, properties_policy='keep')

Class that handles spliting of a unit. It creates a new Sorting object linked to parent_sorting.

Parameters:
parent_sorting: Recording

The recording object

parent_unit_id: int

Unit id of the unit to split

indices_list: list or np.array

A list of index arrays selecting the spikes to split in each segment. Each array can contain more than 2 indices (e.g. for splitting in 3 or more units) and it should be the same length as the spike train (for each segment). If the sorting has only one segment, indices_list can be a single array

new_unit_ids: int

Unit ids of the new units to be created

properties_policy: “keep” | “remove”, default: “keep”
Policy used to propagate properties. If “keep” the properties will be passed to the new units

(if the units_to_merge have the same value). If “remove” the new units will have an empty value for all the properties of the new unit

Returns
——-
sorting: Sorting

Sorting object with the selected units split

spikeinterface.curation.get_potential_auto_merge(sorting_analyzer, minimum_spikes=1000, maximum_distance_um=150.0, peak_sign='neg', bin_ms=0.25, window_ms=100.0, corr_diff_thresh=0.16, template_diff_thresh=0.25, censored_period_ms=0.3, refractory_period_ms=1.0, sigma_smooth_ms=0.6, contamination_threshold=0.2, adaptative_window_threshold=0.5, censor_correlograms_ms: float = 0.15, num_channels=5, num_shift=5, firing_contamination_balance=1.5, extra_outputs=False, steps=None, template_metric='l1')

Algorithm to find and check potential merges between units.

This is taken from lussac version 1 done by Aurelien Wyngaard and Victor Llobet. https://github.com/BarbourLab/lussac/blob/v1.0.0/postprocessing/merge_units.py

The merges are proposed when the following criteria are met:

  • STEP 1: enough spikes are found in each units for computing the correlogram (minimum_spikes)

  • STEP 2: each unit is not contaminated (by checking auto-correlogram - contamination_threshold)

  • STEP 3: estimated unit locations are close enough (maximum_distance_um)

  • STEP 4: the cross-correlograms of the two units are similar to each auto-corrleogram (corr_diff_thresh)

  • STEP 5: the templates of the two units are similar (template_diff_thresh)

  • STEP 6: the unit “quality score” is increased after the merge.

The “quality score” factors in the increase in firing rate (f) due to the merge and a possible increase in contamination (C), wheighted by a factor k (firing_contamination_balance).

\[Q = f(1 - (k + 1)C)\]
Parameters:
sorting_analyzer: SortingAnalyzer

The SortingAnalyzer

minimum_spikes: int, default: 1000

Minimum number of spikes for each unit to consider a potential merge. Enough spikes are needed to estimate the correlogram

maximum_distance_um: float, default: 150

Maximum distance between units for considering a merge

peak_sign: “neg” | “pos” | “both”, default: “neg”

Peak sign used to estimate the maximum channel of a template

bin_ms: float, default: 0.25

Bin size in ms used for computing the correlogram

window_ms: float, default: 100

Window size in ms used for computing the correlogram

corr_diff_thresh: float, default: 0.16

The threshold on the “correlogram distance metric” for considering a merge. It needs to be between 0 and 1

template_diff_thresh: float, default: 0.25

The threshold on the “template distance metric” for considering a merge. It needs to be between 0 and 1

template_metric: ‘l1’

The metric to be used when comparing templates. Default is l1 norm

censored_period_ms: float, default: 0.3

Used to compute the refractory period violations aka “contamination”

refractory_period_ms: float, default: 1

Used to compute the refractory period violations aka “contamination”

sigma_smooth_ms: float, default: 0.6

Parameters to smooth the correlogram estimation

contamination_threshold: float, default: 0.2

Threshold for not taking in account a unit when it is too contaminated

adaptative_window_threshold:: float, default: 0.5

Parameter to detect the window size in correlogram estimation

censor_correlograms_ms: float, default: 0.15

The period to censor on the auto and cross-correlograms

num_channels: int, default: 5

Number of channel to use for template similarity computation

num_shift: int, default: 5

Number of shifts in samles to be explored for template similarity computation

firing_contamination_balance: float, default: 1.5

Parameter to control the balance between firing rate and contamination in computing unit “quality score”

extra_outputs: bool, default: False

If True, an additional dictionary (outs) with processed data is returned

steps: None or list of str, default: None

which steps to run (gives flexibility to running just some steps) If None all steps are done. Pontential steps: “min_spikes”, “remove_contaminated”, “unit_positions”, “correlogram”, “template_similarity”, “check_increase_score”. Please check steps explanations above!

template_metric: ‘l1’, ‘l2’ or ‘cosine’

The metric to consider when measuring the distances between templates. Default is l1

Returns:
potential_merges:

A list of tuples of 2 elements. List of pairs that could be merged.

outs:

Returned only when extra_outputs=True A dictionary that contains data for debugging and plotting.

spikeinterface.curation.find_redundant_units(sorting, delta_time: float = 0.4, agreement_threshold=0.2, duplicate_threshold=0.8)

Finds redundant or duplicate units by comparing the sorting output with itself.

Parameters:
sortingBaseSorting

The input sorting object

delta_timefloat, default: 0.4

The time in ms to consider matching spikes

agreement_thresholdfloat, default: 0.2

Threshold on the agreement scores to flag possible redundant/duplicate units

duplicate_thresholdfloat, default: 0.8

Final threshold on the portion of coincident events over the number of spikes above which the unit is flagged as duplicate/redundant

Returns:
list

The list of duplicate units

list of 2-element lists

The list of duplicate pairs

spikeinterface.curation.remove_redundant_units(sorting_or_sorting_analyzer, align=True, unit_peak_shifts=None, delta_time=0.4, agreement_threshold=0.2, duplicate_threshold=0.8, remove_strategy='minimum_shift', peak_sign='neg', extra_outputs=False)

Removes redundant or duplicate units by comparing the sorting output with itself.

When a redundant pair is found, there are several strategies to choose which unit is the best:

  • “minimum_shift”

  • “highest_amplitude”

  • “max_spikes”

Parameters:
sorting_or_sorting_analyzerBaseSorting or SortingAnalyzer

If SortingAnalyzer, the spike trains can be optionally realigned using the peak shift in the template to improve the matching procedure. If BaseSorting, the spike trains are not aligned.

alignbool, default: False

If True, spike trains are aligned (if a SortingAnalyzer is used)

delta_timefloat, default: 0.4

The time in ms to consider matching spikes

agreement_thresholdfloat, default: 0.2

Threshold on the agreement scores to flag possible redundant/duplicate units

duplicate_thresholdfloat, default: 0.8

Final threshold on the portion of coincident events over the number of spikes above which the unit is removed

remove_strategy: “minimum_shift” | “highest_amplitude” | “max_spikes”, default: “minimum_shift”

Which strategy to remove one of the two duplicated units:

  • “minimum_shift”: keep the unit with best peak alignment (minimum shift)

    If shifts are equal then the “highest_amplitude” is used

  • “highest_amplitude”: keep the unit with the best amplitude on unshifted max.

  • “max_spikes”: keep the unit with more spikes

peak_sign: “neg” | “pos” | “both”, default: “neg”

Used when remove_strategy=”highest_amplitude”

extra_outputs: bool, default: False

If True, will return the redundant pairs.

Returns:
BaseSorting

Sorting object without redundant units

spikeinterface.curation.remove_duplicated_spikes(sorting: BaseSorting, censored_period_ms: float = 0.3, method: str = 'keep_first') None

Class to remove duplicated spikes from the spike trains. Spikes are considered duplicated if they are less than x ms apart where x is the censored period.

Parameters:
sorting: BaseSorting

The parent sorting.

censored_period_ms: float

The censored period to consider 2 spikes to be duplicated (in ms).

method: “keep_first” | “keep_last” | “keep_first_iterative” | “keep_last_iterative” | “random”, default: “keep_first”

Method used to remove the duplicated spikes. If method = “random”, will randomly choose to remove the first or last spike. If method = “keep_first”, for each ISI violation, will remove the second spike. If method = “keep_last”, for each ISI violation, will remove the first spike. If method = “keep_first_iterative”, will iteratively keep the first spike and remove the following violations. If method = “keep_last_iterative”, does the same as “keep_first_iterative” but starting from the end. In the iterative methods, if there is a triplet A, B, C where (A, B) and (B, C) are in the censored period (but not (A, C)), then only B is removed. In the non iterative methods however, only one spike remains.

Returns:
sorting_without_duplicated_spikes: Remove_DuplicatedSpikesSorting

The sorting without any duplicated spikes.

spikeinterface.curation.remove_excess_spikes(sorting, recording)

Remove excess spikes from the spike trains. Excess spikes are the ones exceeding a recording number of samples, for each segment.

Parameters:
sorting: BaseSorting

The parent sorting.

recording: BaseRecording

The recording to use to get the number of samples.

Returns:
sorting_without_excess_spikes: Sorting

The sorting without any excess spikes.

spikeinterface.curation.apply_sortingview_curation(sorting, uri_or_json, exclude_labels=None, include_labels=None, skip_merge=False, verbose=False)

Apply curation from SortingView manual curation. First, merges (if present) are applied. Then labels are loaded and units are optionally filtered based on exclude_labels and include_labels.

Parameters:
sortingBaseSorting

The sorting object to be curated

uri_or_jsonstr or Path

The URI curation link from SortingView or the path to the curation json file

exclude_labelslist, default: None

Optional list of labels to exclude (e.g. [“reject”, “noise”]). Mutually exclusive with include_labels

include_labelslist, default: None

Optional list of labels to include (e.g. [“accept”]). Mutually exclusive with exclude_labels, by default None

skip_mergebool, default: False

If True, merges are not applied (only labels)

verbosebool, default: False

If True, output is verbose

Returns:
sorting_curatedBaseSorting

The curated sorting

spikeinterface.generation

spikeinterface.generation.make_linear_displacement(start, stop, num_step=10)

Generates 2D linear displacements between start and stop positions (included in returned displacements).

Parameters:
start: np.array of 2 elements

The start position.

stop: np.array of 2 elements

The stop position.

num_step: int, default: 10

The number of steps between start and stop.

Returns:
displacements: np.array

The displacements with shape (num_step, 2)

spikeinterface.generation.move_dense_templates(templates_array, displacements, source_probe, dest_probe=None, interpolation_method='cubic')

Move all templates_array given some displacements using spatial interpolation (cubic or linear). Optionally, the displaced templates can be remapped to another probe with a different geometry.

This function operates on dense templates only.

Note: in this function no checks are done to see if templates_array can be interpolatable after displacements. To check if the given displacements are interpolatable use the higher-level function move_templates().

Parameters:
templates_array: np.array

A numpy array with dense templates_array. shape = (num_templates, num_samples, num_channels)

displacements: np.array

Displacement vector shape: (num_displacement, 2)

source_probe: Probe

The Probe object on which templates_array are defined

dest_probe: Probe | None, default: None

The destination Probe. Can be different geometry than the original. If None then the same probe is used.

interpolation_method: “cubic” | “linear”, default: “cubic”

The interpolation method.

Returns:
new_templates_array: np.array

shape = (num_displacement, num_templates, num_samples, num_channels)

spikeinterface.generation.interpolate_templates(templates_array, source_locations, dest_locations, interpolation_method='cubic')

Interpolate templates_array to new positions. Useful to create motion or to remap templates_array form probeA to probeB.

Note that multiple interpolations can be performed by broadcasting when dest_locations have more than one dimension.

Parameters:
templates_array: np.array

A numpy array with dense templates_array. shape = (num_templates, num_samples, num_channels)

source_locations: np.array

The channel source location corresponding to templates_array. shape = (num_channels, 2)

dest_locations: np.array

The new channel position, if ndim == 3, then the interpolation is broadcated with last dim. shape = (num_channels, 2) or (num_motions, num_channels, 2)

interpolation_method: str, default “cubic”

The interpolation method.

Returns:
new_templates_array: np.array

shape = (num_templates, num_samples, num_channels) or = (num_motions, num_templates, num_samples, num_channel)

class spikeinterface.generation.DriftingTemplates(**kwargs)

Templates with drift. This is useful to generate drifting recording.

This class supports 2 different strategies:
  • move every templates on-the-fly, this lead to one interpolation per spike

  • precompute some displacements for all templates and use a discreate interpolation, for instance by step of 1um This is the same strategy used by MEArec.

class spikeinterface.generation.InjectDriftingTemplatesRecording(sorting: BaseSorting, drifting_templates: DriftingTemplates, displacement_vectors: list[ndarray], displacement_sampling_frequency: float, displacement_unit_factor: ndarray | None = None, parent_recording: BaseRecording | None = None, num_samples: list[int] | None = None, amplitude_factor: list[ndarray] | ndarray | float | None = None, mode='precompute')

Class for injecting drifting templates into a recording. This is similar to InjectTemplatesRecording but with drifts.

Parameters:
sorting: BaseSorting

Sorting object containing all the units and their spike train

drifting_templates: DriftingTemplates

The drifting template object

displacement_vectors: list of numpy array

The lenght of the list is the number of segment. Per segment, the drift vector is a numpy array with shape (num_times, 2, num_motions) num_motions is generally = 1 but can be > 1 in case of combining several drift vectors

displacement_sampling_frequency: float

The sampling frequency of drift vector

displacement_unit_factor: numpy array or None, default: None

A array containing the factor per unit of the drift. This is used to create non rigid with a factor gradient of depending on units position. shape (num_units, num_motions) If None then all unit have the same factor (1) and the drift is rigid.

parent_recording: BaseRecording or None, default: None

The recording over which to add the templates. If None, will default to traces containing all 0.

num_samples: list[int] or int or None, default: None

The number of samples in the recording per segment. You can use int for mono-segment objects.

amplitude_factor: list of numpy array or numpy array or float or None, default: None

Controls the amplitude scaling for each spike for each unit. If None, no amplitude scaling is applied. If scalar all spikes have the same factor (certainly useless). If vector, it must have the same size as the spike vector.

Returns:
injected_recording: InjectDriftingTemplatesRecording

The recording with the templates injected.

spikeinterface.sortingcomponents

Peak Localization

Sorting components: peak localization.

spikeinterface.sortingcomponents.peak_localization.localize_peaks(recording, peaks, method='center_of_mass', ms_before=0.5, ms_after=0.5, **kwargs)

Localize peak (spike) in 2D or 3D depending the method.

When a probe is 2D then:
  • X is axis 0 of the probe

  • Y is axis 1 of the probe

  • Z is orthogonal to the plane of the probe

Parameters:
recording: RecordingExtractor

The recording extractor object.

peaks: array

Peaks array, as returned by detect_peaks() in “compact_numpy” way.

method: ‘center_of_mass’, ‘monopolar_triangulation’, ‘grid_convolution’

Method to use.

arguments for method=’center_of_mass’
radius_um: float

Radius in um for channel sparsity.

feature: “ptp” | “mean” | “energy” | “peak_voltage”, default: “ptp”

Feature to consider for computation

arguments for method=’monopolar_triangulation’
radius_um: float

For channel sparsity.

max_distance_um: float, default: 1000

Boundary for distance estimation.

enforce_decreasebool, default: True

Enforce spatial decreasingness for PTP vectors

feature: “ptp”, “energy”, “peak_voltage”, default: “ptp”

The available features to consider for estimating the position via monopolar triangulation are peak-to-peak amplitudes (ptp, default), energy (“energy”, as L2 norm) or voltages at the center of the waveform (peak_voltage)

arguments for method=’grid_convolution’
radius_um: float, default: 40.0

Radius in um for channel sparsity.

upsampling_um: float, default: 5.0

Upsampling resolution for the grid of templates

sigma_ms: float

The temporal decay of the fake templates

margin_um: float, default: 50.0

The margin for the grid of fake templates

peak_sign: “neg” | “pos”, default: “neg”

Sign of the peak if no prototype are provided for the waveforms

prototype: np.array

Fake waveforms for the templates. If None, generated as Gaussian

percentile: float, default: 5.0

The percentage in [0, 100] of the best scalar products kept to estimate the position

weight_method: dict

Parameter that should be provided to the get_convolution_weights() function in order to know how to estimate the positions. One argument is mode that could be either gaussian_2d (KS like) or exponential_3d (default)

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

Returns:
peak_locations: ndarray

Array with estimated location for each spike. The dtype depends on the method. (“x”, “y”) or (“x”, “y”, “z”, “alpha”).

Peak Detection

Sorting components: peak detection.

spikeinterface.sortingcomponents.peak_detection.detect_peaks(recording, method='by_channel', pipeline_nodes=None, gather_mode='memory', folder=None, names=None, **kwargs)

Peak detection based on threshold crossing in term of k x MAD.

In “by_channel” : peak are detected in each channel independently In “locally_exclusive” : a single best peak is taken from a set of neighboring channels

Parameters:
recording: RecordingExtractor

The recording extractor object.

pipeline_nodes: None or list[PipelineNode]

Optional additional PipelineNode need to computed just after detection time. This avoid reading the recording multiple times.

gather_mode: str

How to gather the results: * “memory”: results are returned as in-memory numpy arrays * “npy”: results are stored to .npy files in folder

folder: str or Path

If gather_mode is “npy”, the folder where the files are created.

names: list

List of strings with file stems associated with returns.

method: ‘by_channel’, ‘locally_exclusive’, ‘locally_exclusive_cl’, ‘by_channel_torch’, ‘locally_exclusive_torch’, ‘matched_filtering’

Method to use.

arguments for method=’by_channel’
peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of the peak

detect_threshold: float, default: 5

Threshold, in median absolute deviations (MAD), to use to detect peaks

exclude_sweep_ms: float, default: 0.1

Time, in ms, during which the peak is isolated. Exclusive param with exclude_sweep_size For example, if exclude_sweep_ms is 0.1, a peak is detected if a sample crosses the threshold, and no larger peaks are located during the 0.1ms preceding and following the peak

noise_levels: array or None, default: None

Estimated noise levels to use, if already computed If not provide then it is estimated from a random snippet of the data

random_chunk_kwargs: dict, default: dict()

A dict that contain option to randomize chunk for get_noise_levels(). Only used if noise_levels is None

arguments for method=’locally_exclusive’
peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of the peak

detect_threshold: float, default: 5

Threshold, in median absolute deviations (MAD), to use to detect peaks

exclude_sweep_ms: float, default: 0.1

Time, in ms, during which the peak is isolated. Exclusive param with exclude_sweep_size For example, if exclude_sweep_ms is 0.1, a peak is detected if a sample crosses the threshold, and no larger peaks are located during the 0.1ms preceding and following the peak

noise_levels: array or None, default: None

Estimated noise levels to use, if already computed If not provide then it is estimated from a random snippet of the data

random_chunk_kwargs: dict, default: dict()

A dict that contain option to randomize chunk for get_noise_levels(). Only used if noise_levels is None

radius_um: float

The radius to use to select neighbour channels for locally exclusive detection.

arguments for method=’locally_exclusive_cl’
peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of the peak

detect_threshold: float, default: 5

Threshold, in median absolute deviations (MAD), to use to detect peaks

exclude_sweep_ms: float, default: 0.1

Time, in ms, during which the peak is isolated. Exclusive param with exclude_sweep_size For example, if exclude_sweep_ms is 0.1, a peak is detected if a sample crosses the threshold, and no larger peaks are located during the 0.1ms preceding and following the peak

noise_levels: array or None, default: None

Estimated noise levels to use, if already computed If not provide then it is estimated from a random snippet of the data

random_chunk_kwargs: dict, default: dict()

A dict that contain option to randomize chunk for get_noise_levels(). Only used if noise_levels is None

radius_um: float

The radius to use to select neighbour channels for locally exclusive detection.

opencl_context_kwargs: None or dict

kwargs to create the opencl context

arguments for method=’by_channel_torch’
peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of the peak

detect_threshold: float, default: 5

Threshold, in median absolute deviations (MAD), to use to detect peaks

exclude_sweep_ms: float, default: 0.1

Time, in ms, during which the peak is isolated. Exclusive param with exclude_sweep_size For example, if exclude_sweep_ms is 0.1, a peak is detected if a sample crosses the threshold, and no larger peaks are located during the 0.1ms preceding and following the peak

noise_levels: array or None, default: None

Estimated noise levels to use, if already computed. If not provide then it is estimated from a random snippet of the data

devicestr or None, default: None

“cpu”, “cuda”, or None. If None and cuda is available, “cuda” is selected

return_tensorbool, default: False

If True, the output is returned as a tensor, otherwise as a numpy array

random_chunk_kwargs: dict, default: dict()

A dict that contain option to randomize chunk for get_noise_levels(). Only used if noise_levels is None.

arguments for method=’locally_exclusive_torch’
peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of the peak

detect_threshold: float, default: 5

Threshold, in median absolute deviations (MAD), to use to detect peaks

exclude_sweep_ms: float, default: 0.1

Time, in ms, during which the peak is isolated. Exclusive param with exclude_sweep_size For example, if exclude_sweep_ms is 0.1, a peak is detected if a sample crosses the threshold, and no larger peaks are located during the 0.1ms preceding and following the peak

noise_levels: array or None, default: None

Estimated noise levels to use, if already computed If not provide then it is estimated from a random snippet of the data

random_chunk_kwargs: dict, default: dict()

A dict that contain option to randomize chunk for get_noise_levels(). Only used if noise_levels is None

radius_um: float

The radius to use to select neighbour channels for locally exclusive detection.

arguments for method=’matched_filtering’
peak_sign: “neg” | “pos” | “both”, default: “neg”

Sign of the peak

detect_threshold: float, default: 5

Threshold, in median absolute deviations (MAD), to use to detect peaks

exclude_sweep_ms: float, default: 0.1

Time, in ms, during which the peak is isolated. Exclusive param with exclude_sweep_size For example, if exclude_sweep_ms is 0.1, a peak is detected if a sample crosses the threshold, and no larger peaks are located during the 0.1ms preceding and following the peak

noise_levels: array or None, default: None

Estimated noise levels to use, if already computed If not provide then it is estimated from a random snippet of the data

random_chunk_kwargs: dict, default: dict()

A dict that contain option to randomize chunk for get_noise_levels(). Only used if noise_levels is None

radius_um: float

The radius to use to select neighbour channels for locally exclusive detection.

prototype: array

The canonical waveform of action potentials

rankint (default 1)

The rank for SVD convolution of spatiotemporal templates with the traces

weight_method: dict

Parameter that should be provided to the get_convolution_weights() function in order to know how to estimate the positions. One argument is mode that could be either gaussian_2d (KS like) or exponential_3d (default)

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

Returns:
peaks: array

Detected peaks.

Notes

This peak detection ported from tridesclous into spikeinterface.

Motion Correction

class spikeinterface.sortingcomponents.motion_interpolation.InterpolateMotionRecording(recording, motion, temporal_bins, spatial_bins, direction=1, border_mode='remove_channels', spatial_interpolation_method='kriging', sigma_um=20.0, p=1, num_closest=3)

Recording that corrects motion on-the-fly given a motion vector estimation (rigid or non-rigid). This internally applies a spatial interpolation on the original traces after reversing the motion. estimate_motion() must be called before this to estimate the motion vector.

Parameters:
recording: Recording

The parent recording.

motion: np.array 2D

The motion signal obtained with estimate_motion() motion.shape[0] must correspond to temporal_bins.shape[0] motion.shape[1] is 1 when “rigid” motion and spatial_bins.shape[0] when “non-rigid”

temporal_bins: np.array

Temporal bins in second.

spatial_bins: None or np.array

Bins for non-rigid motion. If None, rigid motion is used

direction: 0 | 1 | 2, default: 1

Dimension along which channel_locations are shifted (0 - x, 1 - y, 2 - z)

spatial_interpolation_method: “kriging” | “idw” | “nearest”, default: “kriging”

The spatial interpolation method used to interpolate the channel locations. See spikeinterface.preprocessing.get_spatial_interpolation_kernel() for more details. Choice of the method:

  • “kriging” : the same one used in kilosort

  • “idw” : inverse distance weighted

  • “nearest” : use neareast channel

sigma_um: float, default: 20.0

Used in the “kriging” formula

p: int, default: 1

Used in the “kriging” formula

num_closest: int, default: 3

Number of closest channels used by “idw” method for interpolation.

border_mode: “remove_channels” | “force_extrapolate” | “force_zeros”, default: “remove_channels”

Control how channels are handled on border:

  • “remove_channels”: remove channels on the border, the recording has less channels

  • “force_extrapolate”: keep all channel and force extrapolation (can lead to strange signal)

  • “force_zeros”: keep all channel but set zeros when outside (force_extrapolate=False)

Returns:
corrected_recording: InterpolateMotionRecording

Recording after motion correction

Clustering

spikeinterface.sortingcomponents.clustering.find_cluster_from_peaks(recording, peaks, method='stupid', method_kwargs={}, extra_outputs=False, **job_kwargs)

Find cluster from peaks.

Parameters:
recording: RecordingExtractor

The recording extractor object

peaks: numpy.array

The peak vector

method: str

Which method to use (“stupid” | “XXXX”)

method_kwargs: dict, default: dict()

Keyword arguments for the chosen method

extra_outputs: bool, default: False

If True then debug is also return

**job_kwargs: keyword arguments for parallel processing:
  • chunk_duration or chunk_size or chunk_memory or total_memory
    • chunk_size: int

      Number of samples per chunk

    • chunk_memory: str

      Memory usage for each job (e.g. “100M”, “1G”, “500MiB”, “2GiB”)

    • total_memory: str

      Total memory usage (e.g. “500M”, “2G”)

    • chunk_durationstr or float or None

      Chunk duration in s if float or with units if str (e.g. “1s”, “500ms”)

  • n_jobs: int | float

    Number of jobs to use. With -1 the number of jobs is the same as number of cores. Using a float between 0 and 1 will use that fraction of the total cores.

  • progress_bar: bool

    If True, a progress bar is printed

  • mp_context: “fork” | “spawn” | None, default: None

    Context for multiprocessing. It can be None, “fork” or “spawn”. Note that “fork” is only safely available on LINUX systems

Returns:
labels_set: ndarray of int

possible clusters list

peak_labels: array of int

peak_labels.shape[0] == peaks.shape[0]

Template Matching

spikeinterface.sortingcomponents.matching.find_spikes_from_templates(recording, method='naive', method_kwargs={}, extra_outputs=False, verbose=False, **job_kwargs)

Find spike from a recording from given templates.

Parameters:
recording: RecordingExtractor

The recording extractor object

method: “naive” | “tridesclous” | “circus” | “circus-omp” | “wobble”

Which method to use for template matching

method_kwargs: dict, optional

Keyword arguments for the chosen method

extra_outputs: bool

If True then method_kwargs is also returned

job_kwargs: dict

Parameters for ChunkRecordingExecutor

Returns:
spikes: ndarray

Spikes found from templates.

method_kwargs:

Optionaly returns for debug purpose.