Python API Reference

PixelMap can be used programmatically from Python scripts or Jupyter notebooks.

Channel Map Generation

pixelmap.utils.imro.generate_imro_channelmap(probe_type, layout_preset=None, reference_id='External', probe_subtype=None, custom_electrodes=None, wiring_file=None, ap_gain=500, lf_gain=250, hp_filter=1)[source]

Generate IMRO-formatted channelmap for Neuropixels probes.

Parameters:
  • probe_type – Type of probe (“1.0”, “2.0-1shank”, “2.0-4shanks”, “NXT”)

  • layout_preset – Preset layout configuration

  • reference_id – Reference electrode selection (‘External’, ‘Tip’, ‘Ground’)

  • probe_subtype – Specific SpikeGLX type number (optional)

  • custom_electrodes – list of custom (shank_id, electrode_id) pairs (overrides preset)

  • positions_file – Path to positions CSV file

  • wiring_file – Path to wiring CSV file

  • ap_gain – AP band gain (for 1.0 probes)

  • lf_gain – LF band gain (for 1.0 probes)

  • hp_filter – High-pass filter setting (for 1.0 probes)

Returns:

IMRO-formatted string for channelmap

pixelmap.utils.imro.save_to_imro_file(imro_list, filename='channelmap.imro')[source]

Save IMRO list to a text file in SpikeGLX format.

Parameters:
  • imro_list – List of tuples from generate_imro_channelmap

  • filename – Output filename (default: “channelmap.imro”)

pixelmap.utils.imro.read_imro_file(filepath)[source]

Read IMRO file and return imro_list format.

Parameters:

filepath – Path to .imro file

Returns:

List of tuples matching generate_imro_channelmap output

Return type:

imro_list

pixelmap.utils.imro.parse_imro_file(content)[source]

Parse IMRO file content and return imro_list format.

Parameters:

content – str, contents of .imro file

Returns:

List of tuples matching generate_imro_channelmap output

Return type:

imro_list

pixelmap.utils.imro.parse_imro_list(imro_list)[source]

Parse imro_list to extract electrode selection and parameters.

Parameters:

imro_list – List from read_imro_file or generate_imro_channelmap

Returns:

(selected_electrodes, probe_type, probe_subtype, reference_id, ap_gain, lf_gain, hp_filter)

selected_electrodes: numpy array of (shank_id, electrode_id) pairs probe_type: “1.0”, “2.0-1shank”, “2.0-4shanks”, or “NXT” Other parameters: as used in original generation

Return type:

tuple

Electrode Selection

pixelmap.backend.get_electrodes(probe_type, wiring_df, preset=None, custom_electrodes=None, probe_subtype=None)[source]

Get electrode selection based on preset, avoiding channel conflicts. - probe_type: Type of probe (e.g., “1.0”, “2.0-1shank”, “2.0-4shanks”) - wiring_df: Wiring DataFrame containing wiring information - preset: Preset layout configuration - custom_electrodes: Optional list of custom (shank_id, electrode_id) pairs - probe_subtype: Part number string (e.g. “NP2003”) for per-shank cap lookup

pixelmap.backend.find_forbidden_electrodes(selected_electrodes, wiring_df)[source]

Return list of forbidden electrodes [[shank_id, electrode_id], …] given selected electrodes and wiring diagram.

pixelmap.backend.make_wiring_maps(wiring_maps_dir)[source]

Precomputes electrode wiring conflict maps for each probe type.

pixelmap.backend.format_imro_string(electrodes, wiring_df, probe_type, probe_subtype, reference_id, ap_gain, lf_gain, hp_filter)[source]

Format IMRO string based on probe type. See https://billkarsh.github.io/SpikeGLX/help/imroTables/ for details.

probe_subtype may be:
  • a part-number string such as “NP2003” (new default, SpikeGLX >= 20260115)

  • a legacy integer such as 2003 (SpikeGLX < 20260115 compatibility mode)

Types

class pixelmap.types.Electrode(shank_id, electrode_id)[source]

Neuropixels electrode electrode_id on shank shank_id.

Parameters:
  • shank_id (int)

  • electrode_id (int)

Constants

The following constants are defined in pixelmap.constants:

PROBE_TYPE_MAP

Mapping from probe type names ("1.0", "2.0-1shank", "2.0-4shanks") to lists of SpikeGLX probe types.

PROBE_N

Number of physical electrodes (N), ADC channels (n), and channels per shank (n_per_shank) for each probe type.

SUPPORTED_1shank_PRESETS

Available preset names for single-shank probes. See the preset reference.

SUPPORTED_4shanks_PRESETS

Available preset names for four-shank probes. See the preset reference.

Usage Examples

Generate a channelmap from a preset

import pixelmap as cmg

imro_list = cmg.generate_imro_channelmap(
    probe_type="2.0-4shanks",
    layout_preset="tips_all",
    wiring_file="wiring_maps/2.0-4shanks_wiring.csv"
)

cmg.save_to_imro_file(imro_list, "my_channelmap.imro")

Generate a channelmap with custom electrodes

import numpy as np
import pixelmap as cmg

# Custom electrode selection: array of (shank_id, electrode_id) pairs
custom = np.array([[0, i] for i in range(384)])

imro_list = cmg.generate_imro_channelmap(
    probe_type="1.0",
    custom_electrodes=custom,
    wiring_file="wiring_maps/1.0_wiring.csv"
)

cmg.save_to_imro_file(imro_list, "custom_channelmap.imro")

Read and inspect an existing IMRO file

import pixelmap as cmg

imro_list = cmg.read_imro_file("my_channelmap.imro")
(
    selected_electrodes,
    probe_type,
    probe_subtype,
    reference_string,
    ap_gain,
    lf_gain,
    hp_filter,
) = cmg.parse_imro_list(imro_list)

print(f"Probe group: {probe_type} (part number {probe_subtype})")
print(f"Reference: {reference_string}")
print(f"Selected {len(selected_electrodes)} electrodes")