.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ex_05_device_channel_indices.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_ex_05_device_channel_indices.py: Handle channel indices ---------------------- Probes can have a complex contacts indexing system due to the probe layout. When they are plugged into a recording device like an Open Ephys with an Intan headstage, the channel order can be mixed again. So the physical contact channel index is rarely the channel index on the device. This is why the `Probe` object can handle separate `device_channel_indices`. .. GENERATED FROM PYTHON SOURCE LINES 14-15 Import .. GENERATED FROM PYTHON SOURCE LINES 15-23 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from probeinterface import Probe, ProbeGroup from probeinterface.plotting import plot_probe, plot_probegroup from probeinterface import generate_multi_columns_probe .. GENERATED FROM PYTHON SOURCE LINES 24-26 Let's first generate a probe. By default, the wiring is not complicated: each column increments the contact index from the bottom to the top of the probe: .. GENERATED FROM PYTHON SOURCE LINES 26-34 .. code-block:: Python probe = generate_multi_columns_probe(num_columns=3, num_contact_per_column=[5, 6, 5], xpitch=75, ypitch=75, y_shift_per_column=[0, -37.5, 0], contact_shapes='circle', contact_shape_params={'radius': 12}) plot_probe(probe, with_contact_id=True) .. image-sg:: /examples/images/sphx_glr_ex_05_device_channel_indices_001.png :alt: Probe - 16ch :srcset: /examples/images/sphx_glr_ex_05_device_channel_indices_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (, ) .. GENERATED FROM PYTHON SOURCE LINES 35-36 The Probe is not connected to any device yet: .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python print(probe.device_channel_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none None .. GENERATED FROM PYTHON SOURCE LINES 40-42 Let's imagine we have a headstage with the following wiring: the first half of the channels have natural indices, but the order of the other half is reversed: .. GENERATED FROM PYTHON SOURCE LINES 42-48 .. code-block:: Python channel_indices = np.arange(16) channel_indices[8:16] = channel_indices[8:16][::-1] probe.set_device_channel_indices(channel_indices) print(probe.device_channel_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none [ 0 1 2 3 4 5 6 7 15 14 13 12 11 10 9 8] .. GENERATED FROM PYTHON SOURCE LINES 49-53 We can visualize the two sets of indices:   * the prbXX is the contact index ordered from 0 to N * the devXX is the channel index on the device (with the second half reversed) .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python plot_probe(probe, with_contact_id=True, with_device_index=True) .. image-sg:: /examples/images/sphx_glr_ex_05_device_channel_indices_002.png :alt: Probe - 16ch :srcset: /examples/images/sphx_glr_ex_05_device_channel_indices_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (, ) .. GENERATED FROM PYTHON SOURCE LINES 57-60 Very often we have several probes on the device and this can lead to even more complex channel indices. `ProbeGroup.get_global_device_channel_indices()` gives an overview of the device wiring. .. GENERATED FROM PYTHON SOURCE LINES 60-84 .. code-block:: Python probe0 = generate_multi_columns_probe(num_columns=3, num_contact_per_column=[5, 6, 5], xpitch=75, ypitch=75, y_shift_per_column=[0, -37.5, 0], contact_shapes='circle', contact_shape_params={'radius': 12}) probe1 = probe0.copy() probe1.move([350, 200]) probegroup = ProbeGroup() probegroup.add_probe(probe0) probegroup.add_probe(probe1) # wire probe0 0 to 31 and shuffle channel_indices0 = np.arange(16) np.random.shuffle(channel_indices0) probe0.set_device_channel_indices(channel_indices0) # wire probe0 32 to 63 and shuffle channel_indices1 = np.arange(16, 32) np.random.shuffle(channel_indices1) probe1.set_device_channel_indices(channel_indices1) print(probegroup.get_global_device_channel_indices()) .. rst-class:: sphx-glr-script-out .. code-block:: none [(0, 6) (0, 4) (0, 15) (0, 8) (0, 12) (0, 2) (0, 11) (0, 13) (0, 9) (0, 5) (0, 14) (0, 10) (0, 1) (0, 3) (0, 7) (0, 0) (1, 22) (1, 29) (1, 23) (1, 26) (1, 28) (1, 20) (1, 16) (1, 27) (1, 19) (1, 31) (1, 21) (1, 18) (1, 24) (1, 17) (1, 25) (1, 30)] .. GENERATED FROM PYTHON SOURCE LINES 85-86 The indices of the probe group can also be plotted: .. GENERATED FROM PYTHON SOURCE LINES 86-91 .. code-block:: Python fig, ax = plt.subplots() plot_probegroup(probegroup, with_contact_id=True, same_axes=True, ax=ax) plt.show() .. image-sg:: /examples/images/sphx_glr_ex_05_device_channel_indices_003.png :alt: ex 05 device channel indices :srcset: /examples/images/sphx_glr_ex_05_device_channel_indices_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.230 seconds) .. _sphx_glr_download_examples_ex_05_device_channel_indices.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex_05_device_channel_indices.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_05_device_channel_indices.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex_05_device_channel_indices.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_