Exemplo n.º 1
0
 def get_probegroup(self):
     arr = self.get_property('contact_vector')
     if arr is None:
         positions = self.get_property('location')
         if positions is None:
             raise ValueError(
                 'There is not Probe attached to recording. use set_probe(...)'
             )
         else:
             warn(
                 'There is no Probe attached to this recording. Creating a dummy one with contact positions'
             )
             ndim = positions.shape[1]
             probe = Probe(ndim=ndim)
             probe.set_contacts(positions=positions,
                                shapes='circle',
                                shape_params={'radius': 5})
             probe.set_device_channel_indices(
                 np.arange(self.get_num_channels(), dtype='int64'))
             #  probe.create_auto_shape()
             probegroup = ProbeGroup()
             probegroup.add_probe(probe)
     else:
         probegroup = ProbeGroup.from_numpy(arr)
         for probe_index, probe in enumerate(probegroup.probes):
             contour = self.get_annotation(
                 f'probe_{probe_index}_planar_contour')
             if contour is not None:
                 probe.set_planar_contour(contour)
     return probegroup
#  
# Note: `shapes` and `shape_params` could be arrays as well, indicating the shape for each contact separately.

probe = Probe(ndim=2, si_units='um')
probe.set_contacts(positions=positions, shapes='circle', shape_params={'radius': 5})

##############################################################################
#  `Probe` objects have fancy prints!

print(probe)

##############################################################################
# In addition to contacts, we can crate the planar contour (polygon) of the probe

polygon = [(-20, -30), (20, -110), (60, -30), (60, 190), (-20, 190)]
probe.set_planar_contour(polygon)

##############################################################################
#  If `pandas` is installed, the `Probe` object can be exported as a dataframe for a simpler view:

df = probe.to_dataframe()
df

##############################################################################
# If `matplotlib` is installed, the `Probe` can also be easily plotted:

plot_probe(probe)

##############################################################################
# A 2d `Probe` can be transformed to a 3d `Probe` by indicating the `axes`
# on which contacts will lie (Here the 'y' coordinate will be 0 for all contacts):
Exemplo n.º 3
0
def test_probe():
    positions = _dummy_posistion()

    probe = Probe(ndim=2, si_units='um')
    probe.set_electrodes(positions=positions,
                         shapes='circle',
                         shape_params={'radius': 5})
    probe.set_electrodes(positions=positions,
                         shapes='square',
                         shape_params={'width': 5})
    probe.set_electrodes(positions=positions,
                         shapes='rect',
                         shape_params={
                             'width': 8,
                             'height': 5
                         })

    assert probe.get_electrode_count() == 24

    # shape of the probe
    vertices = [(-20, -30), (20, -110), (60, -30), (60, 190), (-20, 190)]
    probe.set_planar_contour(vertices)

    # auto shape
    probe.create_auto_shape()

    # device channel
    chans = np.arange(0, 24, dtype='int')
    np.random.shuffle(chans)
    probe.set_device_channel_indices(chans)

    # electrode_ids int or str
    elec_ids = np.arange(24)
    probe.set_electrode_ids(elec_ids)
    elec_ids = [f'elec #{e}' for e in range(24)]
    probe.set_electrode_ids(elec_ids)

    # copy
    probe2 = probe.copy()

    # move rotate
    probe.move([20, 50])
    probe.rotate(theta=40, center=[0, 0], axis=None)

    # make annimage
    values = np.random.randn(24)
    image, xlims, ylims = probe.to_image(values, method='cubic')

    image2, xlims, ylims = probe.to_image(values, method='cubic', num_pixel=16)

    #~ from probeinterface.plotting import plot_probe_group, plot_probe
    #~ import matplotlib.pyplot as plt
    #~ fig, ax = plt.subplots()
    #~ plot_probe(probe, ax=ax)
    #~ ax.imshow(image, extent=xlims+ylims, origin='lower')
    #~ ax.imshow(image2, extent=xlims+ylims, origin='lower')
    #~ plt.show()

    # 3d
    probe_3d = probe.to_3d()
    probe_3d.rotate(theta=60, center=[0, 0, 0], axis=[0, 1, 0])

    #~ from probeinterface.plotting import plot_probe_group, plot_probe
    #~ import matplotlib.pyplot as plt
    #~ plot_probe(probe_3d)
    #~ plt.show()

    # get shanks
    for shank in probe.get_shanks():
        print(shank)
        print(shank.electrode_positions)

    # get dict and df
    d = probe.to_dict()
    #~ print(d)
    df = probe.to_dataframe()
    print(df)