API

Probe

class probeinterface.Probe(ndim: int = 2, si_units: str = 'um', name: str | None = None, serial_number: str | None = None, model_name: str | None = None, manufacturer: str | None = None)

Class to handle the geometry of one probe.

This class mainly handles contact positions, in 2D or 3D. Optionally, it can also handle the shape of the contacts and the shape of the probe.

annotate(**kwargs)

Annotates the probe object.

Parameter

**kwargs : list of kwyword arguments to add to the annotations

property contact_positions

The position of the center for each contact

copy()

Copy to another Probe instance.

Note: device_channel_indices is not copied and contact_ids is not copied

create_auto_shape(probe_type: str = 'tip', margin: float = 20.0)

Create planar contour automatically based on probe contact positions.

Parameters

probe_typestr, by default ‘tip’

The probe type (‘tip’ or ‘rect’)

marginfloat, by default 20.0

The margin to add to the contact positions

static from_dataframe(df: pandas.DataFrame)

Create Probe from a pandas.DataFrame see Probe.to_dataframe()

Parameters

dfpandas.DataFrame

The dataframe representation of the probe

Returns

probeProbe

The instantiated Probe object

static from_dict(d: dict) Probe

Instantiate a Probe from a dictionary

Parameters

ddict

The dictionary representation of the probe

Returns

probeProbe

The instantiated Probe object

static from_numpy(arr: ndarray)

Create Probe from a complex numpy array see Probe.to_numpy()

Parameters

arrnp.array

The structured np.array representation of the probe

Returns

probeProbe

The instantiated Probe object

get_contact_count() int

Return the number of contacts on the probe.

get_contact_vertices() list

Return a list of contact vertices.

get_shank_count() int

Return the number of shanks for this probe.

get_shanks()

Return the list of Shank objects for this Probe

get_slice(selection: ndarray[bool | int])

Get a copy of the Probe with a sub selection of contacts.

Selection can be boolean or by index

Parameters

selectionnp.array of bool or int (for index)

Either an np.array of bool for desired selection of contacts or the indices of the desired contacts

Returns

sliced_probe: Probe

The sliced probe

move(translation_vector: np.array | list)

Translate the probe in one direction.

Parameters

translation_vectorlist or array

The translation vector in shape 2D or 3D

rotate(theta: float, center=None, axis=None)

Rotate the probe around a specified axis.

Parameters

thetafloat

In degrees, anticlockwise.

centerarray

Center of rotation. If None, the center of probe is used

axisNone

Axis of rotation. It must be None for 2D probes and specified for 3D ones

rotate_contacts(thetas: float | np.array[float] | list[float])

Rotate each contact of the probe. Internally, it modifies the contact_plane_axes.

Parameters

thetasarray of float

Rotation angle in degrees. If scalar, then it is applied to all contacts.

set_contact_ids(contact_ids: np.array | list)

Set contact ids. Channel ids are converted to strings. Contact ids must be unique for the Probe and also for the ProbeGroup

Parameters

contact_idslist or array

Array with contact ids. If contact_ids are int or float they are converted to str

set_contacts(positions, shapes='circle', shape_params={'radius': 10}, plane_axes=None, contact_ids=None, shank_ids=None)

Sets contacts to a Probe.

This sets four attributes of the probe:

contact_positions, contact_shapes, contact_shape_params, _contact_plane_axes

Parameters

positionsarray (num_contacts, ndim)

Positions of contacts (2D or 2D depending on probe ‘ndim’).

shapesstr or array

Shape of each contact (‘circle’/’square’/’rect’).

shape_paramsdict or list of dict

Contains kwargs for shapes (“radius” for circle, “width” for square, “width/height” for rect)

plane_axesnp.array (num_contacts, 2, ndim)

Defines the two axes of the contact plane for each electrode. The third dimension corresponds to the probe ndim (2d or 3d).

contact_ids: None or array of str

Defines the contact ids for the contacts. If None, contact ids are not assigned.

shank_idsNone or array of str

Defines the shank ids for the contacts. If None, then these are assigned to a unique Shank.

set_device_channel_indices(channel_indices: np.array | list)

Manually set the device channel indices.

If some channels are not connected or not recorded then channel should be set to “-1”

Parameters

channel_indicesarray of int

The device channel indices to set

set_planar_contour(contour_polygon: list)

Set the planar countour (the shape) of the probe.

Parameters

contour_polygonlist

List of contour points (2D or 3D depending on ndim)

set_shank_ids(shank_ids: np.array | list)

Set shank ids.

Parameters

shank_idslist or array

Array with shank ids, if int or float converted to strings

to_2d(axes: str = 'xy')

Transform 3d probe to 2d probe.

Note: device_channel_indices is not copied.

Parameters

planestr

The plane on which the 2D probe is defined. ‘xy’, ‘yz’ ‘, xz’

to_3d(axes: str = 'xz')

Transform 2d probe to 3d probe.

Note: device_channel_indices is not copied.

Parameters

axesstr, default “xz”

The axes that define the plane on which the 2D probe is defined. ‘xy’, ‘yz’ ‘, xz’

to_dataframe(complete: bool = False) pandas.DataFrame

Export the probe to a pandas dataframe

Parameters

completebool, default False

If True, export complete information about the probe, including the probe plane axis.

Returns

dfpandas.DataFrame

The dataframe representation of the probe

to_dict(array_as_list: bool = False) dict

Create a dictionary of all necessary attributes. Useful for dumping and saving to json.

Parameters

array_as_listbool, default False

If True, arrays are converted to lists

Returns

ddict

The dictionary representation of the probe

to_image(values: np.array | list, pixel_size: float = 0.5, num_pixel: int | None = None, method: str = 'linear', xlims: tuple | None = None, ylims: tuple | None = None) tuple[np.ndarray, tuple, tuple]

Generated a 2d (image) from a values vector with an interpolation into a grid mesh.

Parameters

values :

vector same size as contact number to be color plotted

pixel_size :

size of one pixel in micrometers

num_pixel :

alternative to pixel_size give pixel number of the image width

methodstr, default ‘linear’

One of the options: ‘linear’ or ‘nearest’ or ‘cubic’

xlimsOptional[tuple], default None

Force image xlims

ylimsOptional[tuple], default None

Force image ylims

Returns

image2d array

The generated image

xlimstuple

The x limits

ylimstuple

The y limits

to_numpy(complete: bool = False) array

Export to a numpy vector (structured array). This vector handles all contact attributes.

Equivalent to the ‘to_dataframe()’ pandas function, but without pandas dependency.

Very useful to export/slice/attach to a recording.

Parameters

completebool, default False

If True, export complete information about the probe, including contact_plane_axes/si_units/device_channel_indices

returns

arrnumpy.array

With complex dtype

wiring_to_device(pathway: str, channel_offset: int = 0)

Automatically set device_channel_indices based on a pathway.

See probeinterface.get_available_pathways()

Parameters

pathwaystr

The pathway. E.g. ‘H32>RHD’

channel_offset: int, default 0

An optional offset to add to the device_channel_indices

ProbeGroup

class probeinterface.ProbeGroup

Class to handle a group of Probe objects and the global wiring to a device.

Optionally, it can handle the location of different probes.

auto_generate_contact_ids(*args, **kwargs)

Annotate all contacts with unique contact_id values.

Parameters

*args: will be forwarded to probeinterface.utils.generate_unique_ids **kwargs: will be forwarded to

probeinterface.utils.generate_unique_ids

auto_generate_probe_ids(*args, **kwargs)

Annotate all probes with unique probe_id values.

Parameters

*args: will be forwarded to probeinterface.utils.generate_unique_ids **kwargs: will be forwarded to

probeinterface.utils.generate_unique_ids

static from_dict(d)

Instantiate a ProbeGroup from a dictionary

Parameters

ddict

The dictionary representation of the probegroup

Returns

probegroupProbeGroup

The instantiated ProbeGroup object

get_contact_count()

Total number of channels.

get_global_contact_ids()

get all contact ids concatenated across probes

get_global_device_channel_indices()

return a numpy array vector with 2 columns (probe_index, device_channel_indices)

Note:

channel -1 means not connected

set_global_device_channel_indices(channels)

Set global indices for all probes

to_dict(array_as_list=False)

Create a dictionary of all necessary attributes.

Parameters

array_as_listbool, optional

If True, arrays are converted to lists, by default False

Returns

ddict

The dictionary representation of the probegroup

to_numpy(complete=False)

Export all probes into a numpy array.

Import/export to formats

Read/write probe info using a variety of formats:
  • probeinterface (.json)

  • PRB (.prb)

  • CSV (.csv)

  • mearec (.h5)

  • spikeglx (.meta)

  • ironclust/jrclust (.mat)

  • Neurodata Without Borders (.nwb)

probeinterface.io.read_probeinterface(file: str | Path) ProbeGroup

Read probeinterface JSON-based format.

Parameters

file: Path or str

The file path

Returns

probegroup : ProbeGroup object

probeinterface.io.write_probeinterface(file: str | Path, probe_or_probegroup: Probe | ProbeGroup)

Write a probeinterface JSON file.

The format handles several probes in one file.

Parameters

filePath or str

The file path

probe_or_probegroupProbe or ProbeGroup object

If probe is given a probegroup is created anyway

probeinterface.io.read_prb(file: str | Path) ProbeGroup

Read a PRB file and return a ProbeGroup object.

Since PRB does not handle contact shapes, contacts are set to be circle of 5um radius. Same for the probe shape, where an auto shape is created.

PRB format does not contain any information about the channel of the probe Only the channel index on device is given.

Parameters

filePath or str

The file path

Returns

probegroup : ProbeGroup object

probeinterface.io.write_prb(file: str, probegroup: ProbeGroup, total_nb_channels: int | None = None, radius: float | None = None, group_mode: str = 'by_probe')

Write ProbeGroup into a prb file.

This format handles:
  • multi Probe with channel group index key

  • channel positions with “geometry”

  • device_channel_indices with “channels “key

Note: much information is lost in the PRB format:
  • contact shape

  • shape

  • channel index

Note:
  • “total_nb_channels” is needed by spyking-circus

  • “radius” is needed by spyking-circus

  • “graph” is not handled

Parameters

file: str

The name of the file to be written

probegroup: ProbeGroup

The Probegroup to be used for writing

total_nb_channels: Optional[int], default None

***to do

radius: Optional[float], default None

*** to do

group_mode: str

One of “by_probe” or “by_shank

probeinterface.io.read_csv(file: str | Path)

Return a 2 or 3 columns csv file with contact positions

probeinterface.io.write_csv(file, probe)

Write contact postions into a 2 or 3 columns csv file

probeinterface.io.read_spikeglx(file: str | Path) Probe

Read probe position for the meta file generated by SpikeGLX

See http://billkarsh.github.io/SpikeGLX/#metadata-guides for implementation. The x_pitch/y_pitch/width are set automatically depending the NP version.

The shape is auto generated as a shank.

Now reads:
  • NP0.0 (=phase3A)

  • NP1.0 (=phase3B2)

  • NP2.0 with 4 shank

  • NP1.0-NHP

Parameters

filePath or str

The .meta file path

Returns

probe : Probe object

probeinterface.io.read_mearec(file: str | Path) Probe

Read probe position, and contact shape from a MEArec file.

See https://mearec.readthedocs.io/en/latest/ and https://doi.org/10.1007/s12021-020-09467-7 for implementation.

Parameters

filePath or str

The file path

Returns

probe : Probe object

probeinterface.io.read_nwb(file)

Read probe position from an NWB file

Probe generators

This module contains useful helper functions for generating probes.

probeinterface.generator.generate_dummy_probe(elec_shapes: str = 'circle') Probe

Generate a dummy probe with 3 columns and 32 contacts. Mainly used for testing and examples.

Parameters

elec_shapesstr, , by default ‘circle’

Shape of the electrodes with possibilities of (‘circle’, ‘square’, ‘rect’)

Returns

probeProbe

The generated probe

probeinterface.generator.generate_dummy_probe_group() ProbeGroup

Generate a ProbeGroup with 2 probes. Mainly used for testing and examples.

Returns

probeProbe

The generated probe

probeinterface.generator.generate_tetrode(r: float = 10) Probe

Generate a tetrode Probe. Parameters ———- r: float

The distance multiplier for the positions

Returns

probeProbe

The generated probe

probeinterface.generator.generate_multi_columns_probe(num_columns: int = 3, num_contact_per_column: int = 10, xpitch: float = 20, ypitch: float = 20, y_shift_per_column: np.array | list | None = None, contact_shapes: str = 'circle', contact_shape_params: dict = {'radius': 6}) Probe

Generate a Probe with several columns.

Parameters

num_columnsint, by default 3

Number of columns

num_contact_per_columnint, by default 10

Number of contacts per column

xpitchfloat, by default 20

Pitch in x direction

ypitchfloat, by default 20

Pitch in y direction

y_shift_per_columnarray-like, optional

Shift in y direction per column. It needs to have the same length as num_columns, by default None

contact_shapesstr, by default ‘circle’

Shape of the contacts (‘circle’, ‘rect’, ‘square’)

contact_shape_paramsdict, default {‘radius’: 6}

Parameters for the shape. For circle: {“radius”: float} For square: {“width”: float} For rectangle: {“width”: float, “height”: float}

Returns

probeProbe

The generated probe

probeinterface.generator.generate_linear_probe(num_elec: int = 16, ypitch: float = 20, contact_shapes: str = 'circle', contact_shape_params: dict = {'radius': 6}) Probe

Generate a one-column linear probe.

Parameters

num_elecint

Number of electrodes, by default 16

ypitchfloat

Pitch in y direction, by default 20

contact_shapesstr, default ‘circle’

Shape of the contacts (‘circle’, ‘rect’, ‘square’)

contact_shape_paramsdict, default {‘radius’: 6}

Parameters for the shape. For circle: {“radius”: float} For square: {“width”: float} For rectangle: {“width”: float, “height”: float}

Returns

probeProbe

The generated probe

Plotting

A simple implementation for plotting a Probe or ProbeGroup using matplotlib.

Depending on Probe.ndim, the plotting is done in 2D or 3D

probeinterface.plotting.plot_probe(probe, ax=None, contacts_colors=None, with_contact_id=False, with_device_index=False, text_on_contact=None, contacts_values=None, cmap='viridis', title=True, contacts_kargs={}, probe_shape_kwargs={}, xlims=None, ylims=None, zlims=None, show_channel_on_click=False)

Plot a Probe object. Generates a 2D or 3D axis, depending on Probe.ndim

Parameters

probeProbe

The probe object

axmatplotlib.axis, optional

The axis to plot the probe on. If None, an axis is created, by default None

contacts_colorsmatplotlib color, optional

The color of the contacts, by default None

with_contact_idbool, optional

If True, channel ids are displayed on top of the channels, by default False

with_device_indexbool, optional

If True, device channel indices are displayed on top of the channels, by default False

text_on_contact: None or list or numpy.array

Addintional text to plot on each contact

contacts_valuesnp.array, optional

Values to color the contacts with, by default None

cmapstr, optional

[description], by default ‘viridis’

titlebool, optional

If True, the axis title is set to the probe name, by default True

contacts_kargsdict, optional

Dict with kwargs for contacts (e.g. alpha, edgecolor, lw), by default {}

probe_shape_kwargsdict, optional

Dict with kwargs for probe shape (e.g. alpha, edgecolor, lw), by default {}

xlimstuple, optional

Limits for x dimension, by default None

ylimstuple, optional

Limits for y dimension, by default None

zlimstuple, optional

Limits for z dimension, by default None

show_channel_on_clickbool, optional

If True, the channel information is shown upon click, by default False

Returns

polyPolyCollection

The polygon collection for contacts

poly_contourPolyCollection

The polygon collection for the probe shape

probeinterface.plotting.plot_probe_group(probegroup, same_axes=True, **kargs)

Plot all probes from a ProbeGroup Can be in an existing set of axes or separate axes.

Parameters

probegroupProbeGroup

The ProbeGroup to plot

same_axesbool, optional

If True, the probes are plotted on the same axis, by default True

Library

Provides functions to download and cache pre-existing probe files from some manufacturers.

The library is hosted here: https://gin.g-node.org/spikeinterface/probeinterface_library

The gin platform enables contributions from users.

probeinterface.library.get_probe(manufacturer: str, probe_name: str, name: str | None = None) Probe

Get probe from ProbeInterface library

Parameters

manufacturerstr

The probe manufacturer (e.g. ‘cambridgeneurotech’, ‘neuronexus’)

probe_namestr

The probe name

namestr or None

Optional name for the probe

Returns

probe : Probe object