.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ex_06_import_export_to_file.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_06_import_export_to_file.py: Import/export functions ----------------------- `probeinterface` has its own format based on JSON. The format can handle several probes in one file. It has a 'probes' key that can contain a list of probes. Each probe field in the json format contains the `Probe` class attributes. It also supports reading (and sometimes writing) from these formats: * PRB (.prb) : used by klusta/spyking-circus/tridesclous * CSV (.csv): 2 or 3 columns locations in text file * mearec (.h5) : mearec handles the geometry * spikeglx (.meta) : spikeglx also handles the geometry .. GENERATED FROM PYTHON SOURCE LINES 21-22 Import .. GENERATED FROM PYTHON SOURCE LINES 22-32 .. 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_dummy_probe from probeinterface import write_probeinterface, read_probeinterface from probeinterface import write_prb, read_prb .. GENERATED FROM PYTHON SOURCE LINES 33-35 Let's first generate 2 dummy probes and combine them into a ProbeGroup .. GENERATED FROM PYTHON SOURCE LINES 35-44 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 45-47 With the `write_probeinterface` and `read_probeinterface` functions we can write to and read from the json-based probeinterface format: .. GENERATED FROM PYTHON SOURCE LINES 47-53 .. code-block:: Python write_probeinterface('my_two_probe_setup.json', probegroup) probegroup2 = read_probeinterface('my_two_probe_setup.json') plot_probegroup(probegroup2) .. image-sg:: /examples/images/sphx_glr_ex_06_import_export_to_file_001.png :alt: ex 06 import export to file :srcset: /examples/images/sphx_glr_ex_06_import_export_to_file_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 54-55 The format looks like this: .. GENERATED FROM PYTHON SOURCE LINES 55-61 .. code-block:: Python with open('my_two_probe_setup.json', mode='r') as f: txt = f.read() print(txt[:600], '...') .. rst-class:: sphx-glr-script-out .. code-block:: none { "specification": "probeinterface", "version": "0.3.2", "probes": [ { "ndim": 2, "si_units": "um", "annotations": { "manufacturer": "me" }, "contact_annotations": { "quality": [ 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, ... .. GENERATED FROM PYTHON SOURCE LINES 62-72 PRB is an historical format introduced by the Klusta team and it is also used by SpikeInterface, Spyking-circus, and Tridesclous. The format is in fact a python script that describes a dictionary. This format handles: * multiple groups (multi-shank or multi-probe) * contact_positions with 'geometry' * device_channel_indices with 'channels' Here is an example of a .prb file with 2 channel groups of 4 channels each. It can be easily loaded and plotted with `probeinterface` .. GENERATED FROM PYTHON SOURCE LINES 72-104 .. code-block:: Python prb_two_tetrodes = """ channel_groups = { 0: { 'channels' : [0,1,2,3], 'geometry': { 0: [0, 50], 1: [50, 0], 2: [0, -50], 3: [-50, 0], } }, 1: { 'channels' : [4,5,6,7], 'geometry': { 4: [0, 50], 5: [50, 0], 6: [0, -50], 7: [-50, 0], } } } """ with open('two_tetrodes.prb', 'w') as f: f.write(prb_two_tetrodes) two_tetrode = read_prb('two_tetrodes.prb') plot_probegroup(two_tetrode, same_axes=False, with_contact_id=True) plt.show() .. image-sg:: /examples/images/sphx_glr_ex_06_import_export_to_file_002.png :alt: ex 06 import export to file :srcset: /examples/images/sphx_glr_ex_06_import_export_to_file_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.151 seconds) .. _sphx_glr_download_examples_ex_06_import_export_to_file.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex_06_import_export_to_file.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_06_import_export_to_file.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex_06_import_export_to_file.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_