### Install probeinterface from source Source: https://github.com/spikeinterface/probeinterface/blob/main/README.md Installs the latest development version of probeinterface by cloning the repository and installing it in editable mode. ```bash git clone https://github.com/SpikeInterface/probeinterface.git cd probeinterface pip install -e . cd .. ``` -------------------------------- ### Install probeinterface using pip Source: https://github.com/spikeinterface/probeinterface/blob/main/README.md Installs the latest version of the probeinterface package from PyPI using pip. ```bash pip install probeinterface ``` -------------------------------- ### Full Probeinterface JSON Example Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/format_spec.rst This example demonstrates a complete JSON file representing a probe configuration, including all necessary and optional fields for describing probe geometry and wiring. ```json { "specification": "probeinterface", "version": "0.1.0", "probes": [ { "ndim": 2, "si_units": "um", "annotations": { "name": "2 shank tetrodes", "manufacturer": "homemade" }, "contact_positions": [ [0, 0], [0, 20], [20, 0], [20, 20] ], "contact_shapes": [ "circle", "circle", "circle", "circle" ], "contact_shape_params": [ {"radius": 5}, {"radius": 5}, {"radius": 5}, {"radius": 5} ], "shank_ids": [ 0, 0, 1, 1 ] } ] } ``` -------------------------------- ### Build Complete Neuropixels Probes Source: https://context7.com/spikeinterface/probeinterface/llms.txt Provides an example of how to construct a full Neuropixels probe object, including all electrodes, based on manufacturer specifications using the `build_neuropixels_probe` function. This is useful for creating complete probe definitions for simulation or analysis. ```python from probeinterface.neuropixels_tools import build_neuropixels_probe from probeinterface.plotting import plot_probe # Example usage would follow here, e.g.: # probe = build_neuropixels_probe() # plot_probe(probe) ``` -------------------------------- ### File I/O: PRB Format (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates saving and loading probe configurations in the PRB format, commonly used by tools like Klusta and SpyKING CIRCUS. The example creates a `ProbeGroup` with two tetrodes, saves it to a PRB file, prints its content, and then loads it back for plotting. ```python from probeinterface import write_prb, read_prb from probeinterface import generate_tetrode, ProbeGroup from probeinterface.plotting import plot_probegroup # Create a tetrode array (2 tetrodes) tetrode0 = generate_tetrode(r=15) tetrode0.set_device_channel_indices([0, 1, 2, 3]) tetrode1 = generate_tetrode(r=15) tetrode1.move([100, 0]) tetrode1.set_device_channel_indices([4, 5, 6, 7]) probegroup = ProbeGroup() probegroup.add_probe(tetrode0) probegroup.add_probe(tetrode1) # Write to PRB format write_prb('tetrode_array.prb', probegroup) # View the PRB content with open('tetrode_array.prb', 'r') as f: print(f.read()) # Read PRB file loaded = read_prb('tetrode_array.prb') plot_probegroup(loaded, same_axes=False, with_contact_id=True) ``` -------------------------------- ### Reading from Other Recording Formats (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Provides examples of reading probe configurations from various common recording system formats using dedicated functions within ProbeInterface. This includes Maxwell Biosystems (MaxOne/MaxTwo), 3Brain (BioCAM), mearec, and spikegadgets. ```python from probeinterface import read_maxwell, read_3brain, read_mearec, read_spikegadgets # Maxwell Biosystems (MaxOne/MaxTwo) # maxwell_probe = read_maxwell( # '/path/to/recording.raw.h5', # well_name='well000', # For MaxTwo # rec_name='rec0000' # ) # print(maxwell_probe) # Output: Probe - Maxwell Biosystems - 1024ch # 3Brain (BioCAM) # brain3_probe = read_3brain( # '/path/to/recording.brw', # mea_pitch=42, # Optional: override default pitch # electrode_width=21 # Optional: override default width # ) # print(brain3_probe) # Output: Probe - 3Brain - 4096ch # Placeholder for mearec and spikegadgets if examples were available # read_mearec('/path/to/recording. தரவு') # read_spikegadgets('/path/to/recording.rec') ``` -------------------------------- ### Load MEArec and SpikeGadgets Recordings Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates how to load probe data from MEArec (.h5) and SpikeGadgets (.rec) file formats. It shows how to access basic probe information and annotations. ```python from probeinterface import read_mearec, read_spikegadgets # MEArec simulated recordings mearec_probe = read_mearec('/path/to/recording.h5') print(mearec_probe) print(f"MEArec name: {mearec_probe.annotations.get('mearec_name')}") # SpikeGadgets (.rec files with Neuropixels) sg_probegroup = read_spikegadgets('/path/to/recording.rec') print(f"Number of probes: {len(sg_probegroup.probes)}") ``` -------------------------------- ### Build and Inspect Neuropixels Probes (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates building various Neuropixels probe configurations (NP1.0, NP2.0 single-shank, NP2.0 4-shank) using the `build_neuropixels_probe` function. It also shows how to print probe information, access descriptions, count contacts per shank, and retrieve probe annotations like ADC bit depth and sample rate. ```python from probeinterface import build_neuropixels_probe # Build a complete NP1.0 probe (960 electrodes) np1_full = build_neuropixels_probe('NP1010') print(np1_full) # Output: Probe - imec - NP1010 - 960ch print(f"Description: {np1_full.description}") # Build a NP2.0 single-shank probe (1280 electrodes) np2_single = build_neuropixels_probe('NP2000') print(np2_single) # Output: Probe - imec - NP2000 - 1280ch # Build a NP2.0 4-shank probe (5120 electrodes total) np2_4shank = build_neuropixels_probe('NP2013') print(np2_4shank) # Output: Probe - imec - NP2013 - 5120ch - 4shanks print(f"Contacts per shank: {np2_4shank.get_contact_count() // 4}") # Access probe specifications print(f"ADC bit depth: {np2_4shank.annotations.get('adc_bit_depth')}") print(f"AP sample rate: {np2_4shank.annotations.get('ap_sample_frequency_hz')}") print(f"Shank tips: {np2_4shank.annotations.get('shank_tips')}") # Slice to a subset of electrodes selected_indices = list(range(0, 384)) # First 384 electrodes sliced_probe = np1_full.get_slice(selected_indices) print(sliced_probe) # Output: Probe - imec - NP1010 - 384ch ``` -------------------------------- ### File I/O: ProbeInterface JSON Format (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Shows how to save and load probe configurations using the native ProbeInterface JSON format. This format can store multiple probes within a `ProbeGroup`. The code demonstrates creating dummy probes, adding them to a `ProbeGroup`, writing to a JSON file, and reading it back. ```python from probeinterface import ( write_probeinterface, read_probeinterface, generate_dummy_probe, ProbeGroup ) import json # Create a probe setup probe0 = generate_dummy_probe(elec_shapes='square') probe1 = generate_dummy_probe(elec_shapes='circle') probe1.move([250, -90]) probegroup = ProbeGroup() probegroup.add_probe(probe0) probegroup.add_probe(probe1) # Save to ProbeInterface JSON format write_probeinterface('my_setup.json', probegroup) # Load back loaded = read_probeinterface('my_setup.json') print(f"Loaded {len(loaded.probes)} probes") # Can also save a single probe (wrapped in ProbeGroup internally) write_probeinterface('single_probe.json', probe0) # View JSON structure with open('my_setup.json', 'r') as f: data = json.load(f) print(f"Format: {data['specification']}") print(f"Version: {data['version']}") print(f"Number of probes: {len(data['probes'])}') ``` -------------------------------- ### File I/O: BIDS Format (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Illustrates saving and loading probe configurations in the Brain Imaging Data Structure (BIDS) ephys extension format. This involves preparing probes with BIDS-specific metadata, writing them to a temporary directory, and then reading them back. ```python from probeinterface import write_BIDS_probe, read_BIDS_probe from probeinterface import generate_dummy_probe, ProbeGroup import tempfile import os # Prepare probes with required BIDS metadata probe = generate_dummy_probe() probe.annotate(probe_id='probe001', type='silicon_array') probe.set_contact_ids([f'e{i}' for i in range(probe.get_contact_count())]) probegroup = ProbeGroup() probegroup.add_probe(probe) # Write to BIDS format (creates probes.tsv, contacts.tsv, and JSON files) output_dir = tempfile.mkdtemp() write_BIDS_probe(output_dir, probegroup, prefix='sub-001_ses-01') # List created files print(os.listdir(output_dir)) # Read back from BIDS format loaded = read_BIDS_probe(output_dir, prefix='sub-001_ses-01') print(loaded.probes[0]) ``` -------------------------------- ### Configure Device Channel Wiring (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Explains how to map probe contacts to recording device channels. It covers manual assignment, using predefined pathways, and automatic wiring for known configurations. ```python from probeinterface import generate_linear_probe, get_available_pathways, get_probe from probeinterface.plotting import plot_probe import numpy as np # Create probe probe = generate_linear_probe(num_elec=32, ypitch=25) # Manual channel assignment # Map physical contacts to device channels channel_indices = np.array([31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) probe.set_device_channel_indices(channel_indices) # Or use -1 for unconnected contacts partial_wiring = np.arange(32) partial_wiring[::2] = -1 # Every other contact disconnected probe.set_device_channel_indices(partial_wiring) # View available wiring pathways pathways = get_available_pathways() print(pathways) # ['H32>RHD2132', 'ASSY-116>RHD2132', ...] # Use automatic wiring for known adapter configurations cnt_probe = get_probe('cambridgeneurotech', 'ASSY-156-P-1') cnt_probe.wiring_to_device('ASSY-156>RHD2164') print(f"Device channels: {cnt_probe.device_channel_indices[:10]}") # Plot with device indices shown plot_probe(probe, with_device_index=True) ``` -------------------------------- ### Download Probe Description using get_probe Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/library.rst Downloads and caches a probe description locally using the `get_probe` function. It requires the manufacturer and probe name as input. The downloaded probe is cached for future use. ```python from probeinterface import get_probe probe = get_probe( manufacturer='neuronexus', probe_name='A1x32-Poly3-10mm-50-177' ) ``` -------------------------------- ### Load Probes from ProbeInterface Library Source: https://context7.com/spikeinterface/probeinterface/llms.txt Shows how to access and load pre-defined probes from the ProbeInterface library. It covers listing available manufacturers and probes, and then loading a specific probe by its manufacturer and name. Probes are downloaded and cached locally. ```python from probeinterface import ( get_probe, list_manufacturers, list_probes_by_manufacturer, list_all_probes ) from probeinterface.plotting import plot_probe # List available manufacturers manufacturers = list_manufacturers() print(manufacturers) # ['cambridgeneurotech', 'imec', 'neuronexus', ...] # List probes from a specific manufacturer neuronexus_probes = list_probes_by_manufacturer('neuronexus') print(neuronexus_probes[:5]) # ['A1x16-Poly2-5mm-50s-177', 'A1x32-Edge-5mm-20-177', ...] # Load a specific probe probe = get_probe( manufacturer='neuronexus', probe_name='A1x32-Poly3-10mm-50-177' ) print(probe) # Output: Probe - neuronexus - A1x32-Poly3-10mm-50-177 - 32ch # Access manufacturer-specific annotations print(probe.annotations) # {'manufacturer': 'neuronexus', 'first_index': 1, ...} # Load Cambridge Neurotech probe cnt_probe = get_probe('cambridgeneurotech', 'ASSY-156-P-1') print(cnt_probe) # Plot with contact IDs displayed plot_probe(probe, with_contact_id=True) ``` -------------------------------- ### Generate Standard Probe Configurations - Python Source: https://context7.com/spikeinterface/probeinterface/llms.txt Provides functions to generate common probe configurations like linear, multi-column, tetrode, and multi-shank probes. These functions allow customization of parameters such as the number of electrodes, pitch, contact shapes, and staggering. The generated probes can be plotted for visualization. ```python from probeinterface import ( generate_linear_probe, generate_multi_columns_probe, generate_tetrode, generate_multi_shank, generate_dummy_probe ) from probeinterface.plotting import plot_probe import matplotlib.pyplot as plt # Generate a 32-channel linear probe linear_probe = generate_linear_probe( num_elec=32, ypitch=25, # 25um vertical spacing contact_shapes='square', contact_shape_params={'width': 12} ) print(linear_probe) # Output: Probe - 32ch # Generate a multi-column probe (e.g., Poly2 style) poly_probe = generate_multi_columns_probe( num_columns=2, num_contact_per_column=16, xpitch=25, # Horizontal spacing ypitch=25, # Vertical spacing y_shift_per_column=[0, -12.5], # Stagger columns contact_shapes='circle', contact_shape_params={'radius': 6} ) # Generate a tetrode tetrode = generate_tetrode(r=15) # 15um radius arrangement print(tetrode) # Output: Probe - 4ch # Generate a multi-shank probe with 2 shanks multi_shank = generate_multi_shank( num_shank=2, shank_pitch=[200, 0], # 200um between shanks num_columns=2, num_contact_per_column=16 ) print(multi_shank) # Output: Probe - 64ch - 2shanks # Plot all probes fig, axes = plt.subplots(1, 4, figsize=(16, 6)) for ax, probe, title in zip(axes, [linear_probe, poly_probe, tetrode, multi_shank], ['Linear', 'Multi-column', 'Tetrode', 'Multi-shank']): plot_probe(probe, ax=ax, title=False) ax.set_title(title) plt.tight_layout() ``` -------------------------------- ### Apply Probe Geometric Transformations (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Illustrates how to apply geometric transformations such as translation, rotation, and dimension conversion to probes using ProbeInterface. This is useful for aligning probes or preparing them for analysis. ```python from probeinterface import generate_linear_probe from probeinterface.plotting import plot_probe import matplotlib.pyplot as plt import numpy as np # Create a probe probe = generate_linear_probe(num_elec=16, ypitch=25) # Move the probe probe.move([100, 200]) # Translate by (100, 200) um print(f"New center: {probe.contact_positions.mean(axis=0)}") # Rotate the probe probe_rotated = generate_linear_probe(num_elec=16, ypitch=25) probe_rotated.rotate(theta=45) # 45 degrees counterclockwise probe_rotated.move([300, 0]) # Rotate contacts individually (changes contact plane axes) probe_contact_rot = generate_linear_probe(num_elec=16, ypitch=25) probe_contact_rot.rotate_contacts(thetas=30) # All contacts rotated 30 deg probe_contact_rot.move([500, 0]) # Convert 2D to 3D probe_3d = probe.to_3d(axes='xz') # Place in x-z plane (y=0) print(f"3D positions shape: {probe_3d.contact_positions.shape}") # (16, 3) # Convert 3D back to 2D probe_2d = probe_3d.to_2d(axes='xz') # Plot transformations fig, axes = plt.subplots(1, 3, figsize=(12, 4)) for ax, p, title in zip(axes, [probe, probe_rotated, probe_contact_rot], ['Translated', 'Rotated 45deg', 'Contact rotation 30deg']): plot_probe(p, ax=ax, title=False) ax.set_title(title) plt.tight_layout() ``` -------------------------------- ### Visualize Probes and Probe Groups (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates various plotting functionalities for probes and probe groups using matplotlib. This includes displaying contact IDs, device indices, custom labels, and coloring contacts by values. ```python from probeinterface import generate_dummy_probe, ProbeGroup from probeinterface.plotting import plot_probe, plot_probegroup import matplotlib.pyplot as plt import numpy as np probe = generate_dummy_probe() # Basic plot fig, ax = plt.subplots(figsize=(4, 8)) plot_probe(probe, ax=ax) # Plot with contact IDs plot_probe(probe, with_contact_id=True) # Plot with device channel indices probe.set_device_channel_indices(np.arange(32)) plot_probe(probe, with_device_index=True) # Plot with custom text on contacts custom_labels = [f'ch{i}' for i in range(32)] plot_probe(probe, text_on_contact=custom_labels) # Color contacts by values (e.g., signal amplitude) values = np.random.randn(32) poly, poly_contour = plot_probe( probe, contacts_values=values, cmap='viridis' ) plt.colorbar(poly) # Custom styling plot_probe( probe, contacts_colors='red', contacts_kargs={'alpha': 0.8, 'edgecolor': 'black', 'lw': 1}, probe_shape_kwargs={'facecolor': 'lightblue', 'alpha': 0.5} ) # Plot ProbeGroup - all probes on same axes probegroup = ProbeGroup() probegroup.add_probe(generate_dummy_probe()) probe2 = generate_dummy_probe() probe2.move([200, 0]) probegroup.add_probe(probe2) plot_probegroup(probegroup, same_axes=True) # Or separate axes for each probe plot_probegroup(probegroup, same_axes=False) plt.show() ``` -------------------------------- ### Create a Custom Probe with Contacts and Contour - Python Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates how to create a custom 2D probe using the `Probe` class. It involves defining contact positions, shapes (circles with specified radius), and a planar contour outlining the probe shape. Metadata can also be added, and the probe can be exported to a pandas DataFrame for inspection. ```python import numpy as np from probeinterface import Probe from probeinterface.plotting import plot_probe # Create a 24-contact probe with 3 columns n = 24 positions = np.zeros((n, 2)) for i in range(n): x = i // 8 y = i % 8 positions[i] = x, y positions *= 20 # Scale to micrometers positions[8:16, 1] -= 10 # Offset middle column # Create probe with circular contacts probe = Probe(ndim=2, si_units='um') probe.set_contacts( positions=positions, shapes='circle', shape_params={'radius': 5} ) # Define the probe outline polygon polygon = [(-20, -30), (20, -110), (60, -30), (60, 190), (-20, 190)] probe.set_planar_contour(polygon) # Add metadata annotations probe.annotate(manufacturer='custom', brain_area='CA1') print(probe) # Output: Probe - custom - 24ch # Export to pandas DataFrame for inspection df = probe.to_dataframe() print(df[['x', 'y', 'contact_shapes', 'radius']].head()) # x y contact_shapes radius # 0 0.0 0.0 circle 5.0 # 1 0.0 20.0 circle 5.0 # 2 0.0 40.0 circle 5.0 # Plot the probe plot_probe(probe) ``` -------------------------------- ### Explore Probe Library Functions Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/library.rst Provides helper functions to explore the probeinterface library. These functions allow listing all manufacturers, listing probes by a specific manufacturer, and listing all probes in the library. An option to cache the full library is also available. ```python from probeinterface.library import ( list_manufacturers, list_probes_by_manufacturer, list_all_probes, cache_full_library ) # List all manufacturers manufacturers = list_manufacturers() # List all probes for a given manufacturer probes = list_probes_by_manufacturer('neuronexus') # List all probes in the library all_probes = list_all_probes() # Cache all probes locally cache_full_library() ``` -------------------------------- ### Read Neuropixels Probes from SpikeGLX Metadata Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates how to reconstruct probe configurations from SpikeGLX .meta files. This allows for accurate mapping of recorded data to the physical probe layout. It also shows how to access per-contact acquisition settings and parse raw metadata. ```python from probeinterface import read_spikeglx, parse_spikeglx_meta from probeinterface.plotting import plot_probe from pathlib import Path # Read probe from SpikeGLX .meta file meta_file = Path('/path/to/recording.ap.meta') probe = read_spikeglx(meta_file) print(probe) # Output: Probe - imec - NP1010 - 384ch print(f"Serial number: {probe.annotations.get('serial_number')}") print(f"Part number: {probe.annotations.get('part_number')}") # Access per-contact acquisition settings print(f"AP gains: {probe.contact_annotations.get('ap_gains')[:5]}") # [500, 500, 500, 500, 500] print(f"Banks: {probe.contact_annotations.get('banks')[:5]}") # [0, 0, 0, 0, 0] # Parse raw metadata dictionary meta = parse_spikeglx_meta(meta_file) print(f"Sample rate: {meta.get('imSampRate')} Hz") print(f"Saved channels: {meta.get('snsSaveChanSubset')}") # For Neuropixels 2.0 4-shank probes np2_probe = read_spikeglx('/path/to/np2_4shank.ap.meta') print(np2_probe) # Output: Probe - imec - NP2013 - 384ch - 4shanks print(f"Shank IDs: {np2_probe.shank_ids[:10]}") # Plot the probe configuration plot_probe(probe, with_device_index=True) ``` -------------------------------- ### Read and Write IMRO Files for Neuropixels Probes Source: https://context7.com/spikeinterface/probeinterface/llms.txt Details how to read and write IMRO (IMEC ReadOut) files, which define electrode selection and configuration for Neuropixels probes. It shows how to access IMRO-specific annotations like probe type, reference settings, and AP gains, and how to export probe data back to the IMRO format. ```python from probeinterface import read_imro, write_imro from probeinterface.plotting import plot_probe # Read an IMRO file probe = read_imro('/path/to/channel_map.imro') print(probe) # Output: Probe - imec - NP1010 - 384ch # Access IMRO-specific annotations print(f"Probe type: {probe.annotations.get('probe_type')}") print(f"Reference settings: {probe.contact_annotations.get('references')[:5]}") print(f"AP gains: {probe.contact_annotations.get('ap_gains')[:5]}") # Export probe back to IMRO format write_imro('/path/to/output.imro', probe) # View the IMRO content with open('/path/to/output.imro', 'r') as f: print(f.read()[:200]) # (0,384)(0 0 0 500 250 1)(1 0 0 500 250 1)... plot_probe(probe) ``` -------------------------------- ### Convert Probe Contact Values to 2D Interpolated Images Source: https://context7.com/spikeinterface/probeinterface/llms.txt Illustrates how to generate a 2D image by interpolating per-contact values across the probe's spatial layout. This is useful for visualizing spatial patterns of recorded signals or other contact-specific data. ```python from probeinterface import generate_multi_columns_probe import numpy as np import matplotlib.pyplot as plt from probeinterface.plotting import plot_probe # Create a dense probe probe = generate_multi_columns_probe( num_columns=4, num_contact_per_column=32, xpitch=25, ypitch=25 ) # Generate per-contact values (e.g., signal power) n = probe.get_contact_count() values = np.random.randn(n) # Add spatial structure y_pos = probe.contact_positions[:, 1] values += np.sin(y_pos / 100) * 2 # Convert to 2D image via interpolation image, xlims, ylims = probe.to_image( values, pixel_size=5, # 5um per pixel method='linear' # 'linear', 'nearest', or 'cubic' ) # Plot the image fig, axes = plt.subplots(1, 2, figsize=(10, 6)) # Original contact values plot_probe(probe, ax=axes[0], contacts_values=values, cmap='RdBu_r') axes[0].set_title('Contact Values') # Interpolated image im = axes[1].imshow( image, extent=[xlims[0], xlims[1], ylims[0], ylims[1]], origin='lower', cmap='RdBu_r', aspect='equal' ) axes[1].set_title('Interpolated Image') plt.colorbar(im, ax=axes[1]) plt.tight_layout() plt.show() ``` -------------------------------- ### Probeinterface Library Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/api.rst Functions for accessing predefined probe configurations from the library. ```APIDOC ## Probeinterface Library ### Description Accesses a collection of predefined probe configurations. ### Functions #### `get_probe(probe_name)` Retrieves a probe configuration by its name from the library. ``` -------------------------------- ### Probeinterface Plotting Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/api.rst Functions for visualizing probe configurations. ```APIDOC ## Probeinterface Plotting ### Description Utilities for plotting probe geometries and probe groups. ### Functions #### `plot_probe(probe, ...)` Plots a single probe. #### `plot_probe_group(probe_group, ...)` Plots a group of probes. ``` -------------------------------- ### Read Neuropixels Probes from Open Ephys Settings Source: https://context7.com/spikeinterface/probeinterface/llms.txt Explains how to load Neuropixels probe configurations from Open Ephys .xml settings files. It covers reading single and multi-probe recordings, and selecting probes by stream name, probe name, or serial number. Probe metadata like name, serial, slot, and port can be accessed. ```python from probeinterface import read_openephys from probeinterface.plotting import plot_probe # Single probe recording probe = read_openephys('/path/to/settings.xml') print(probe) # Output: Probe - imec - 384ch # Multi-probe recording - select by stream name probe_a = read_openephys( '/path/to/settings.xml', stream_name='ProbeA-AP' ) probe_b = read_openephys( '/path/to/settings.xml', stream_name='ProbeB-AP' ) # Or select by probe name directly probe = read_openephys( '/path/to/settings.xml', probe_name='ProbeC' ) # Or by serial number probe = read_openephys( '/path/to/settings.xml', serial_number='18194815751' ) # Access probe metadata print(f"Name: {probe.name}") print(f"Serial: {probe.serial_number}") print(f"Slot: {probe.annotations.get('slot')}") print(f"Port: {probe.annotations.get('port')}") plot_probe(probe) ``` -------------------------------- ### Extract Probe Subsets (Python) Source: https://context7.com/spikeinterface/probeinterface/llms.txt Shows how to extract subsets of contacts from a probe based on various selection criteria. This is useful for analyzing specific channels or regions of a probe. ```python from probeinterface import generate_dummy_probe from probeinterface.plotting import plot_probe import numpy as np probe = generate_dummy_probe() print(f"Original: {probe.get_contact_count()} contacts") ``` -------------------------------- ### Export Probe Group to DataFrame and Plot Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates how to convert a ProbeGroup object into a pandas DataFrame for analysis and how to plot all probes within the group on the same axes. This is useful for visualizing probe layouts and their spatial relationships. ```python df = probegroup.to_dataframe() print(df.groupby('probe_index').size()) # probe_index # 0 32 # 1 32 plot_probegroup(probegroup, same_axes=True) ``` -------------------------------- ### Manage Multiple Probes with ProbeGroup - Python Source: https://context7.com/spikeinterface/probeinterface/llms.txt Illustrates the use of the `ProbeGroup` class to manage multiple probes as a single entity. This includes adding individual probes, setting global channel indices, auto-generating probe IDs, and exporting the combined probe information to a numpy structured array. This is useful for multi-probe recordings. ```python from probeinterface import Probe, ProbeGroup, generate_dummy_probe from probeinterface.plotting import plot_probegroup import numpy as np # Create two probes probe0 = generate_dummy_probe(elec_shapes='circle') probe1 = generate_dummy_probe(elec_shapes='square') probe1.move([250, -50]) # Offset second probe # Combine into a ProbeGroup probegroup = ProbeGroup() probegroup.add_probe(probe0) probegroup.add_probe(probe1) print(f"Total contacts: {probegroup.get_contact_count()}") # Output: 64 # Set global device channel indices # Probe 0: channels 0-31, Probe 1: channels 32-63 all_channels = np.arange(probegroup.get_contact_count()) probegroup.set_global_device_channel_indices(all_channels) # Auto-generate unique probe IDs probegroup.auto_generate_probe_ids() # Export to numpy structured array arr = probegroup.to_numpy(complete=True) print(arr.dtype.names) # ('probe_index', 'x', 'y', 'contact_shapes', 'radius', 'width', ...) ``` -------------------------------- ### Serialize Probe Data to NumPy, DataFrame, and Dictionary Source: https://context7.com/spikeinterface/probeinterface/llms.txt Shows how to export probe geometry and metadata into structured NumPy arrays, pandas DataFrames, and Python dictionaries. It also demonstrates reconstructing Probe objects from these serialized formats, facilitating data exchange and integration with other libraries. ```python from probeinterface import generate_dummy_probe, Probe import numpy as np probe = generate_dummy_probe() probe.set_device_channel_indices(np.arange(32)) # Export to structured NumPy array arr = probe.to_numpy(complete=True) print(f"Fields: {arr.dtype.names}") # ('x', 'y', 'contact_shapes', 'radius', 'shank_ids', 'contact_ids', # 'device_channel_indices', 'si_units', 'plane_axis_x_0', ...) print(f"X positions: {arr['x'][:5]}") print(f"Device channels: {arr['device_channel_indices'][:5]}") # Reconstruct probe from NumPy array probe_from_arr = Probe.from_numpy(arr) print(probe_from_arr) # Export to pandas DataFrame df = probe.to_dataframe(complete=True) print(df.columns.tolist()) print(df[['x', 'y', 'contact_shapes', 'device_channel_indices']].head()) # Reconstruct from DataFrame probe_from_df = Probe.from_dataframe(df) # Export to dictionary (useful for JSON serialization) d = probe.to_dict(array_as_list=True) print(d.keys()) # dict_keys(['ndim', 'si_units', 'annotations', 'contact_positions', ...]) # Reconstruct from dictionary probe_from_dict = Probe.from_dict(d) # Export to Zarr (requires zarr package) # probe.to_zarr('/path/to/probe.zarr') # loaded_probe = Probe.from_zarr('/path/to/probe.zarr') ``` -------------------------------- ### Slice Probe by Boolean Mask or Index Array Source: https://context7.com/spikeinterface/probeinterface/llms.txt Demonstrates how to slice a probe object using a boolean mask to select contacts based on a condition (e.g., y-coordinate) or by providing an array of contact indices. This is useful for isolating specific subsets of contacts. ```python from probeinterface import generate_multi_shank import numpy as np # Assume 'probe' is an existing Probe object # Example: probe = generate_dummy_probe() # Slice by boolean mask mask = probe.contact_positions[:, 1] > 100 # Contacts above y=100 sliced_probe = probe.get_slice(mask) print(f"Sliced (y>100): {sliced_probe.get_contact_count()} contacts") # Slice by index array indices = np.array([0, 5, 10, 15, 20, 25, 30]) subset = probe.get_slice(indices) print(f"Subset by index: {subset.get_contact_count()} contacts") # Slice multi-shank probe by shank multi = generate_multi_shank(num_shank=4, num_columns=2, num_contact_per_column=8) print(f"Multi-shank probe: {multi.get_contact_count()} contacts, {multi.get_shank_count()} shanks") # Get contacts from shank 0 only shank0_mask = multi.shank_ids == '0' shank0_probe = multi.get_slice(shank0_mask) print(f"Shank 0 only: {shank0_probe.get_contact_count()} contacts") ``` -------------------------------- ### Probeinterface IO Operations Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/api.rst Functions for reading and writing probe data in various formats. ```APIDOC ## Probeinterface IO Operations ### Description Provides functions to read and write probe interface data from and to different file formats. ### Functions #### `read_probeinterface(filepath)` Reads probe data from a Probeinterface file. #### `write_probeinterface(probe, filepath)` Writes probe data to a Probeinterface file. #### `read_prb(filepath)` Reads probe data from a PRB file. #### `write_prb(probe, filepath)` Writes probe data to a PRB file. #### `read_csv(filepath)` Reads probe data from a CSV file. #### `write_csv(probe, filepath)` Writes probe data to a CSV file. #### `read_spikeglx(filepath)` Reads probe data from a SpikeGLX file. #### `read_mearec(filepath)` Reads probe data from a MEArec file. #### `read_nwb(filepath)` Reads probe data from a NWB file. ``` -------------------------------- ### Probeinterface Generators Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/api.rst Functions for generating various types of neural probes. ```APIDOC ## Probeinterface Generators ### Description Functions to programmatically generate different probe configurations. ### Functions #### `generate_dummy_probe()` Generates a dummy probe for testing purposes. #### `generate_dummy_probe_group()` Generates a dummy probe group for testing purposes. #### `generate_tetrode()` Generates a tetrode probe configuration. #### `generate_multi_columns_probe(num_columns, num_contact_per_column, ...)` Generates a probe with multiple columns of contacts. #### `generate_linear_probe(num_elec, pitch, ...)` Generates a linear probe with a specified number of electrodes and pitch. ``` -------------------------------- ### Probe Dictionary Fields in JSON Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/format_spec.rst Each probe within the 'probes' list is described by a dictionary. Key fields include dimensionality, units, annotations, and contact definitions (positions, shapes, shape parameters). Optional fields allow for more detailed descriptions. ```json { "ndim": 2, "si_units": "um", "annotations": { "name": "2 shank tetrodes", "manufacturer": "homemade" }, "contact_positions": [ ... ], "contact_shapes": [ ... ], "contact_shape_params": [ ... ] } ``` -------------------------------- ### Probeinterface JSON Structure Source: https://github.com/spikeinterface/probeinterface/blob/main/doc/format_spec.rst The top-level JSON structure for probeinterface configurations includes metadata like specification version and a list of probes. Each probe is a sub-dictionary containing its geometric and wiring information. ```json { "specification": "probeinterface", "version": "0.1.0", "probes": [ { ... } ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.