.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ex_01_generate_probe_from_sratch.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_01_generate_probe_from_sratch.py: Generate a Probe from scratch ----------------------------- This example generates a probe from scratch. .. GENERATED FROM PYTHON SOURCE LINES 9-16 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from probeinterface import Probe from probeinterface.plotting import plot_probe .. GENERATED FROM PYTHON SOURCE LINES 17-18 First, let's create dummy positions for a 24-contact probe .. GENERATED FROM PYTHON SOURCE LINES 18-28 .. code-block:: Python n = 24 positions = np.zeros((n, 2)) for i in range(n): x = i // 8 y = i % 8 positions[i] = x, y positions *= 20 positions[8:16, 1] -= 10 .. GENERATED FROM PYTHON SOURCE LINES 29-36 Now we can create a `Probe` object  and set the position and shape of each contact   The `ndim` argument indicates that the contact is 2d, so the positions have a (n_elec, 2) shape.  We can also define a 3d probe with `ndim=3` and positions will have a (n_elec, 3) shape.   Note: `shapes` and `shape_params` could be arrays as well, indicating the shape for each contact separately. .. GENERATED FROM PYTHON SOURCE LINES 36-40 .. code-block:: Python probe = Probe(ndim=2, si_units='um') probe.set_contacts(positions=positions, shapes='circle', shape_params={'radius': 5}) .. GENERATED FROM PYTHON SOURCE LINES 41-42 `Probe` objects have fancy prints! .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python print(probe) .. rst-class:: sphx-glr-script-out .. code-block:: none Probe - 24ch .. GENERATED FROM PYTHON SOURCE LINES 46-47 In addition to contacts, we can create the planar contour (polygon) of the probe .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: Python polygon = [(-20, -30), (20, -110), (60, -30), (60, 190), (-20, 190)] probe.set_planar_contour(polygon) .. GENERATED FROM PYTHON SOURCE LINES 52-53 If `pandas` is installed, the `Probe` object can be exported as a dataframe for a simpler view: .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python df = probe.to_dataframe() df .. raw:: html
x y contact_shapes radius contact_ids
0 0.0 0.0 circle 5.0
1 0.0 20.0 circle 5.0
2 0.0 40.0 circle 5.0
3 0.0 60.0 circle 5.0
4 0.0 80.0 circle 5.0
5 0.0 100.0 circle 5.0
6 0.0 120.0 circle 5.0
7 0.0 140.0 circle 5.0
8 20.0 -10.0 circle 5.0
9 20.0 10.0 circle 5.0
10 20.0 30.0 circle 5.0
11 20.0 50.0 circle 5.0
12 20.0 70.0 circle 5.0
13 20.0 90.0 circle 5.0
14 20.0 110.0 circle 5.0
15 20.0 130.0 circle 5.0
16 40.0 0.0 circle 5.0
17 40.0 20.0 circle 5.0
18 40.0 40.0 circle 5.0
19 40.0 60.0 circle 5.0
20 40.0 80.0 circle 5.0
21 40.0 100.0 circle 5.0
22 40.0 120.0 circle 5.0
23 40.0 140.0 circle 5.0


.. GENERATED FROM PYTHON SOURCE LINES 58-59 If `matplotlib` is installed, the `Probe` can also be easily plotted: .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: Python plot_probe(probe) .. image-sg:: /examples/images/sphx_glr_ex_01_generate_probe_from_sratch_001.png :alt: Probe - 24ch :srcset: /examples/images/sphx_glr_ex_01_generate_probe_from_sratch_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (, ) .. GENERATED FROM PYTHON SOURCE LINES 63-65 A 2d `Probe` can be transformed into a 3d `Probe` by indicating the `axes` on which contacts will lie (Here the 'y' coordinate will be 0 for all contacts): .. GENERATED FROM PYTHON SOURCE LINES 65-70 .. code-block:: Python probe_3d = probe.to_3d(axes='xz') plot_probe(probe_3d) plt.show() .. image-sg:: /examples/images/sphx_glr_ex_01_generate_probe_from_sratch_002.png :alt: Probe - 24ch :srcset: /examples/images/sphx_glr_ex_01_generate_probe_from_sratch_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.545 seconds) .. _sphx_glr_download_examples_ex_01_generate_probe_from_sratch.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex_01_generate_probe_from_sratch.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_01_generate_probe_from_sratch.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex_01_generate_probe_from_sratch.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_