neurocarto.probe_npx.desp

class neurocarto.probe_npx.desp.NpxProbeDesp

A Neuropixels probe interface.

CATE_FULL: ClassVar = 11

electrode full-density category.

CATE_HALF: ClassVar = 12

electrode half-density category

CATE_QUARTER: ClassVar = 13

electrode quarter-density category.

property supported_type: dict[str, int]

All supported probe type.

Used in CartoApp. install_right_panel_views() for dynamic generating options.

Returns:

dict of {description: code}, where code is used in new_channelmap(code)

property possible_states: dict[str, int]

Export electrode states.

Those states are used in CartoApp. install_right_panel_views() for generating buttons dynamically, which means only manual states need to be exported. The state such as STATE_DISABLED is programming update for remaining electrodes that users cannot change electrode as this state.

Returns:

dict of {description: state}

See:

all_possible_states()

property possible_categories: dict[str, int]

All possible exported electrode categories.

Those categories are used in CartoApp. install_right_panel_views() for generating buttons dynamically.

Returns:

dict of {description: category}

See:

all_possible_categories()

property channelmap_file_suffix: list[str]

The filename extension for supported channelmap.

The first suffix in returned list is considered the primary format.

Returns:

list of file extensions, like [“.imro”] for the Neuropixel probe.

load_from_file(file)

Load a channelmap file.

Parameters:

file (Path) – channelmap filepath

Returns:

channelmap instance

Raises:
  • IOError – If file is not supported.

  • FileNotFoundError – If file is not existed.

  • RuntimeError – errors when parsing the file.

Return type:

ChannelMap

save_to_file(chmap, file)

Save a channelmap into a file.

Parameters:
  • chmap (ChannelMap) – channelmap instance

  • file (Path) – channelmap filepath

Raises:
  • IOError – If file suffix is not supported.

  • IOError – If target directory is not existed.

  • RuntimeError – errors when serializing the channelmap.

channelmap_code(chmap)

Identify a given channelmap, and return the corresponding code.

Parameters:

chmap (Any | None) – Any instance. It could be a channelmap instance.

Returns:

a code from supported_type. None if chmap is unknown or is not supported.

Return type:

int | None

new_channelmap(probe_type=24)

Create a new, empty channelmap instance.

If you want to copy a channelmap instance, use copy_channelmap() instead.

Parameters:
Returns:

a channelmap instance

Return type:

ChannelMap

copy_channelmap(chmap)

Copy a channelmap instance, including properties of electrodes.

Parameters:

chmap (ChannelMap) – channelmap instance as reference.

Returns:

a channelmap instance

Return type:

ChannelMap

channelmap_desp(chmap)

A description for displaying the status of a channelmap instance.

Parameters:

chmap (ChannelMap | None) – a channelmap instance, or None when no probe (an initial description)

Returns:

description.

Return type:

str

all_electrodes(chmap)

Get all possible electrode set for the given channelmap code.

Implement Node:

make sure the result is consistent in its ordering.

Parameters:

chmap (int | ProbeType | ChannelMap) – a channelmap instance or a code from supported_type.

Returns:

a list of ElectrodeDesp

Return type:

list[NpxElectrodeDesp]

all_channels(chmap, electrodes=None)

Get a list of a selected electrodes in the given channelmap.

Parameters:
  • chmap (ChannelMap) – a channelmap instance

  • electrodes (Iterable[NpxElectrodeDesp] | None) – restrict electrode set that the return set is its subset.

Returns:

a list of ElectrodeDesp, keep in ordering by its channel identify (skip None electrodes).

Return type:

list[NpxElectrodeDesp]

is_valid(chmap)

Is it a valid and completed channelmap?

A valid and completed channelmap means:

  • This channelmap is able to save into a file

  • no electrode pair will break the probe restriction (probe_rule()).

  • The saved file can be read by other software or machines without any error or any mis-located electrode.

Parameters:

chmap (ChannelMap) – a channelmap instance

Returns:

Return type:

bool

get_electrode(electrodes, e)

Get an electrode from a set with a given identify e.

Parameters:
  • electrodes (Iterable[NpxElectrodeDesp]) – an electrode set

  • e (tuple[int, int, int] | NpxElectrodeDesp) – electrode identify, as same as ElectrodeDesp.:attr:~neurocarto.probe.ElectrodeDesp.electrode.

Returns:

found electrode in s. None if not found.

Return type:

NpxElectrodeDesp | None

add_electrode(chmap, e, *, overwrite=False)

Add an electrode e into chmap.

An error raised when:

  • Either chmap or e is in incorrect state. For example, e is None.

  • chmap is complete, and it doesn’t allow to add any additional electrode.

  • chmap is incomplete, but it doesn’t allow to add e due to probe restriction.

It is better to raise an error instead of ignoring because an error can carry the message to frontend.

Parameters:
Raise:

any error means the action was failed.

del_electrode(chmap, e)

Remove an electrode e from the chmap.

Parameters:
Raise:

any error means the action was failed.

clear_electrode(chmap)

Remove all electrodes from the chmap.

Parameters:

chmap (ChannelMap) – a channelmap instance

probe_rule(chmap, e1, e2)

Does electrode e1 and e2 can be used in the same time?

This method’s implementation should follow the rules in most cases:

  • probe_rule(M, e, e) should return False

  • probe_rule(M, e1, e2) == probe_rule(M, e2, e1)

Parameters:
Returns:

True when e1 and e2 are compatible.

Return type:

bool

invalid_electrodes(chmap, e, electrodes)

Collect the invalid electrodes that an electrode from electrodes will break the probe_rule() with the electrode e (or any electrode from e).

Note that e may also be contained in the result if e in electrodes.

Parameters:
Returns:

an invalid electrode set from electrodes.

Return type:

list[NpxElectrodeDesp]

save_blueprint(blueprint)

Store blueprint, included all electrode information into a numpy array.

Parameters:

blueprint (list[NpxElectrodeDesp]) – blueprint.

Returns:

blueprint matrix.

Return type:

ndarray[tuple[int, …], dtype[int64]]

load_blueprint(a, chmap)

Restore blueprint, included all electrode information from a numpy array a.

If chmap is a list[E], it indicates only restore the information only for this electrode subset.

Parameters:
  • a (str | Path | ndarray[tuple[int, ...], dtype[int64]]) – saved category matrix, or a saved ‘.npy’ file path

  • chmap (int | ProbeType | ChannelMap | list[NpxElectrodeDesp]) – channelmap type, or an electrode set.

Returns:

blueprint

Return type:

list[NpxElectrodeDesp]

select_electrodes(chmap, blueprint, *, selector='default', **kwargs)

Selecting electrodes based on the electrode blueprint.

Parameters:
  • chmap (ChannelMap) – channelmap type. It is a reference.

  • blueprint (list[NpxElectrodeDesp]) – channelmap blueprint

  • kwargs – other parameters.

Returns:

generated channelmap

Return type:

ChannelMap

extra_controls(config)

Probe specific controls.

Parameters:

config (CartoConfig) – application configurations.

Returns:

list of type of the probe-specific views.

view_ext_electrode_density(chmap)

Calculate electrode density along the probe.

Parameters:

chmap (ChannelMap)

Returns:

Array[float, [S,], (v, y), Y] density array

See:

ProbeElectrodeDensityProtocol

Return type:

ndarray[tuple[int, …], dtype[float64]]

view_ext_statistics_info(bp)
Parameters:

bp (BlueprintFunctions)

Returns:

See:

ProbeElectrodeEfficiencyProtocol

Return type:

dict[str, str]

view_ext_plot_blueprint(callback, chmap)
Parameters:
See:

ProbePlotBlueprintProtocol

view_ext_blueprint_plot_categories(ax, chmap, blueprint, color=None, *, probe_color=None, shank_width_scale=0.5, label_axis=False, **kwargs)
Parameters:
  • ax (Axes)

  • chmap (ChannelMap)

  • blueprint (NDArray[np.int_])

  • color (dict[int, Any])

  • probe_color (str | None)

  • shank_width_scale

  • label_axis

  • kwargs

See:

ProbePlotElectrodeProtocol, plot_category_area(), plot_probe_shape()

view_ext_blueprint_plot_electrode(ax, chmap, data, *, probe_color=None, shank_width_scale=0.5, label_axis=False, **kwargs)
Parameters:
  • ax (Axes)

  • chmap (ChannelMap)

  • data (NDArray[np.float64]) – Array[float, E], where E means all electrodes

  • probe_color (str | None)

  • shank_width_scale

  • label_axis

  • kwargs

See:

ProbePlotElectrodeProtocol, plot_electrode_block(), plot_probe_shape()

class neurocarto.probe_npx.desp.NpxElectrodeDesp

A Neuropixels electrode interface.

electrode: tuple[int, int, int]

electrode identify. It is a 3-int tuple of (shank, column, row)

channel: int

channel identify.