예제 #1
0
def create_CN_figure(probe_name, probe):
    """
    Create custum figire for CN with custum colors + logo
    """
    fig, ax = plt.subplots()
    fig.set_size_inches(18.5, 10.5)

    n = probe.get_contact_count()
    plot_probe(
        probe,
        ax=ax,
        contacts_colors=['#5bc5f2'] * n,  # made change to default color
        probe_shape_kwargs=dict(facecolor='#6f6f6e',
                                edgecolor='k',
                                lw=0.5,
                                alpha=0.3),  # made change to default color
        with_channel_index=True)

    ax.set_xlabel(u'Width (\u03bcm)')  #modif to legend
    ax.set_ylabel(u'Height (\u03bcm)')  #modif to legend
    ax.spines['right'].set_visible(False)  #remove external axis
    ax.spines['top'].set_visible(False)  #remove external axis

    ax.set_title('\n' + 'CambridgeNeuroTech' + '\n' +
                 probe.annotations.get('name'),
                 fontsize=24)

    fig.tight_layout()  #modif tight layout

    im = plt.imread(work_dir / 'CN_logo-01.jpg')
    newax = fig.add_axes([0.8, 0.85, 0.2, 0.1], anchor='NW', zorder=0)
    newax.imshow(im)
    newax.axis('off')

    return fig
예제 #2
0
def test_wire_probe():
    
    manufacturer = 'neuronexus'
    probe_name = 'A1x32-Poly3-10mm-50-177'
    probe = get_probe(manufacturer, probe_name)
    
    probe.wiring_to_device('H32>RHD')
    
    plot_probe(probe, with_channel_index=True)
예제 #3
0
    def _plot_one_bin(self, rec, probe, peaks, duration):

        # TODO: @alessio weight_with_amplitudes is not implemented yet
        rates = np.zeros(rec.get_num_channels(), dtype='float64')
        for chan_ind, chan_id in enumerate(rec.channel_ids):
            mask = peaks['channel_ind'] == chan_ind
            num_spike = np.sum(mask)
            rates[chan_ind] = num_spike / duration

        artists = ()
        if self.with_contact_color:
            poly, poly_contour = plot_probe(probe,
                                            ax=self.ax,
                                            contacts_values=rates,
                                            probe_shape_kwargs={
                                                'facecolor': 'w',
                                                'alpha': .1
                                            },
                                            contacts_kargs={'alpha': 1.})
            artists = artists + (poly, poly_contour)

        if self.with_interpolated_map:
            image, xlims, ylims = probe.to_image(rates,
                                                 pixel_size=0.5,
                                                 num_pixel=None,
                                                 method='linear',
                                                 xlims=None,
                                                 ylims=None)
            im = self.ax.imshow(image,
                                extent=xlims + ylims,
                                origin='lower',
                                alpha=0.5)
            artists = artists + (im, )

        return artists
예제 #4
0
    def plot(self):
        we = self.waveform_extractor
        unit_localisation = self.unit_localisation
        unit_ids = we.sorting.unit_ids

        if unit_localisation is None:
            assert self.method in ('center_of_mass',)

            if self.method == 'center_of_mass':
                coms = compute_unit_centers_of_mass(we, **self.method_kwargs)
                unit_localisation = np.array([e for e in coms.values()])
            else:
                raise ValueError('UnitLocalizationWidget: method not implemented.')

        ax = self.ax
        probegroup = we.recording.get_probegroup()
        probe_shape_kwargs = dict(facecolor='w', edgecolor='k', lw=0.5, alpha=1.)
        contacts_kargs = dict(alpha=1., edgecolor='k', lw=0.5)
        
        for probe in probegroup.probes:
            poly_contact, poly_contour = plot_probe(probe, ax=ax,
                                                    contacts_colors='w', contacts_kargs=contacts_kargs,
                                                    probe_shape_kwargs=probe_shape_kwargs)
            poly_contact.set_zorder(2)
            if poly_contour is not None:
                poly_contour.set_zorder(1)

        ax.set_title('')

        color = np.array([self.unit_colors[unit_id] for unit_id in unit_ids])
        loc = ax.scatter(
            unit_localisation[:, 0], unit_localisation[:, 1], marker='1', color=color, s=80, lw=3)
        loc.set_zorder(3)
예제 #5
0
def test_wire_probe():

    manufacturer = 'neuronexus'
    probe_name = 'A1x32-Poly3-10mm-50-177'
    probe = get_probe(manufacturer, probe_name)

    probe.wiring_to_device('H32>RHD2132')

    plot_probe(probe, with_channel_index=True)

    manufacturer = 'cambridgeneurotech'
    probe_name = 'ASSY-156-P-1'
    probe = get_probe(manufacturer, probe_name)

    probe.wiring_to_device('ASSY-156>RHD2164')

    plot_probe(probe, with_channel_index=True)
예제 #6
0
    def _do_plot(self):
        rec = self.recording

        peaks = self.peaks
        if peaks is None:
            from spikeinterface.sortingcomponents import detect_peaks
            self.detect_peaks_kwargs['outputs'] = 'numpy_compact'
            peaks = detect_peaks(rec, **self.detect_peaks_kwargs)

        fs = rec.get_sampling_frequency()
        duration = rec.get_total_duration()

        probe = rec.get_probe()
        positions = probe.contact_positions

        # TODO: @alessio weight_with_amplitudes is not implemented yet
        rates = np.zeros(rec.get_num_channels(), dtype='float64')
        for chan_ind, chan_id in enumerate(rec.channel_ids):
            mask = peaks['channel_ind'] == chan_ind
            num_spike = np.sum(mask)
            rates[chan_ind] = num_spike / duration

        if self.with_contact_color:
            plot_probe(probe,
                       ax=self.ax,
                       contacts_values=rates,
                       probe_shape_kwargs={
                           'facecolor': 'w',
                           'alpha': .1
                       },
                       contacts_kargs={'alpha': 1.})

        if self.with_interpolated_map:
            image, xlims, ylims = probe.to_image(rates,
                                                 pixel_size=0.5,
                                                 num_pixel=None,
                                                 method='linear',
                                                 xlims=None,
                                                 ylims=None)
            self.ax.imshow(image,
                           extent=xlims + ylims,
                           origin='lower',
                           alpha=0.5)
예제 #7
0
def test_plot_probe():
    probe = generate_dummy_probe()
    plot_probe(probe)
    plot_probe(probe, with_channel_index=True)

    # with color
    n = probe.get_electrode_count()
    electrode_colors = np.random.rand(n, 3)
    plot_probe(probe, electrode_colors=electrode_colors)

    # 3d
    probe_3d = probe.to_3d(plane='xz')
    plot_probe(probe_3d)
예제 #8
0
    def plot(self):
        we = self.waveform_extractor
        probe = we.recording.get_probe()

        probe_shape_kwargs = dict(facecolor='w',
                                  edgecolor='k',
                                  lw=0.5,
                                  alpha=1.)

        all_poly_contact = []
        for i, unit_id in enumerate(self.unit_ids):
            ax = self.axes.flatten()[i]
            template = we.get_template(unit_id)
            # static
            if self.animated:
                contacts_values = np.zeros(template.shape[1])
            else:
                contacts_values = np.max(np.abs(template), axis=0)
            poly_contact, poly_contour = plot_probe(
                probe,
                contacts_values=contacts_values,
                ax=ax,
                probe_shape_kwargs=probe_shape_kwargs)

            poly_contact.set_zorder(2)
            if poly_contour is not None:
                poly_contour.set_zorder(1)

            if self.colorbar:
                self.figure.colorbar(poly_contact, ax=ax)

            poly_contact.set_clim(0, np.max(np.abs(template)))
            all_poly_contact.append(poly_contact)

            ax.set_title(str(unit_id))

        if self.animated:
            num_frames = template.shape[0]

            def animate_func(frame):
                for i, unit_id in enumerate(self.unit_ids):
                    template = we.get_template(unit_id)
                    contacts_values = np.abs(template[frame, :])
                    poly_contact = all_poly_contact[i]
                    poly_contact.set_array(contacts_values)
                return all_poly_contact

            self.animation = FuncAnimation(self.figure,
                                           animate_func,
                                           frames=num_frames,
                                           interval=20,
                                           blit=True)
예제 #9
0
    def plot(self):
        we = self.waveform_extractor
        unit_localisation = self.unit_localisation

        if unit_localisation is None:
            assert self.method in ('center_of_mass', )

            if self.method == 'center_of_mass':
                coms = compute_unit_centers_of_mass(we, **self.method_kwargs)
                localisation = np.array([e for e in coms.values()])
            else:
                raise ValueError(
                    'UnitLocalizationWidget: method not implemenetd')

        ax = self.ax
        probe = we.recording.get_probe()
        plot_probe(probe, ax=ax)
        ax.set_title('')

        ax.scatter(localisation[:, 0],
                   localisation[:, 1],
                   marker='1',
                   color='r')
예제 #10
0
    def plot(self):
        we = self.waveform_extractor
        unit_location = self.unit_location
        unit_ids = we.sorting.unit_ids

        if unit_location is None:
            unit_location = localize_unit(we,
                                          method=self.method,
                                          **self.method_kwargs)

        ax = self.ax
        probegroup = we.recording.get_probegroup()
        probe_shape_kwargs = dict(facecolor='w',
                                  edgecolor='k',
                                  lw=0.5,
                                  alpha=1.)
        contacts_kargs = dict(alpha=1., edgecolor='k', lw=0.5)

        for probe in probegroup.probes:
            poly_contact, poly_contour = plot_probe(
                probe,
                ax=ax,
                contacts_colors='w',
                contacts_kargs=contacts_kargs,
                probe_shape_kwargs=probe_shape_kwargs)
            poly_contact.set_zorder(2)
            if poly_contour is not None:
                poly_contour.set_zorder(1)

        ax.set_title('')

        color = np.array([self.unit_colors[unit_id] for unit_id in unit_ids])
        loc = ax.scatter(unit_location[:, 0],
                         unit_location[:, 1],
                         marker='1',
                         color=color,
                         s=80,
                         lw=3)
        loc.set_zorder(3)
# Import

import numpy as np
import matplotlib.pyplot as plt

from probeinterface import Probe, ProbeGroup
from probeinterface.plotting import plot_probe, plot_probe_group
from probeinterface import generate_multi_columns_probe, generate_linear_probe

##############################################################################
# Some examples in 2d

fig, ax = plt.subplots()

probe0 = generate_multi_columns_probe()
plot_probe(probe0, ax=ax)

# make some colors for each probe
probe1 = generate_linear_probe(num_elec=9)
probe1.rotate(theta=15)
probe1.move([200, 0])
plot_probe(probe1, ax=ax, electrode_colors=['red', 'cyan', 'yellow'] * 3)

# prepare yourself for carnival!
probe2 = generate_linear_probe()
probe2.rotate(theta=-35)
probe2.move([400, 0])
n = probe2.get_electrode_count()
rand_colors = np.random.rand(n, 3)
plot_probe(probe2,
           ax=ax,
예제 #12
0
 def _do_plot(self):
     plot_probe(self._probe, ax=self.ax)
예제 #13
0
manufacturer = 'neuronexus'
probe_name = 'A1x32-Poly3-10mm-50-177'

probe = get_probe(manufacturer, probe_name)
probe.rotate(23)

##############################################################################
# fake values

values = np.random.randn(32)

##############################################################################
# plot with value

fig, ax = plt.subplots()
poly, poly_contour = plot_probe(probe, electrode_values=values,
            cmap='jet', ax=ax, electrodes_kargs={'alpha' : 1})
poly.set_clim(-2, 2)
fig.colorbar(poly)


##############################################################################
# generated an interpolated image and plot it on top

image, xlims, ylims = probe.to_image(values, pixel_size=4, method='linear')

print(image.shape)

fig, ax = plt.subplots()
plot_probe(probe, ax=ax)
im = ax.imshow(image, extent=xlims+ylims, origin='lower', cmap='jet')
im.set_clim(-2,2)
예제 #14
0
import numpy as np
import matplotlib.pyplot as plt

from probeinterface import Probe, ProbeGroup
from probeinterface import generate_linear_probe, generate_multi_shank
from probeinterface import combine_probes
from probeinterface.plotting import plot_probe

##############################################################################
# Let's use a generator to create a multi shank probe:

multi_shank = generate_multi_shank(num_shank=3,
                                   num_columns=2,
                                   num_elec_per_column=6)
plot_probe(multi_shank)

##############################################################################
# `multi_shank` is one `probe` object, but internally the `Probe.shank_ids` vector handles the shank ids.

print(multi_shank.shank_ids)

##############################################################################
# The dataframe displays the `shank_ids` column:

df = multi_shank.to_dataframe()
df

##############################################################################
#  We can iterate over a multi-shank probe and get :py:class:`Shank` objects.
# A `Shank` is link to a `Probe` object and can also retrieve
예제 #15
0
# The geometry of the Probe is handle with the :code:`probeinterface`.
# Let's generate a linear probe:

from probeinterface import generate_linear_probe
from probeinterface.plotting import plot_probe

probe = generate_linear_probe(num_elec=7,
                              ypitch=20,
                              contact_shapes='circle',
                              contact_shape_params={'radius': 6})

# the probe has to be wired to the recording
probe.set_device_channel_indices(np.arange(7))

recording = recording.set_probe(probe)
plot_probe(probe)

##############################################################################
# Some extractors also implement a :code:`write` function.

file_paths = ['traces0.raw', 'traces1.raw']
se.BinaryRecordingExtractor.write_recording(recording, file_paths)

##############################################################################
# We can read the written recording back with the proper extractor.
# Note that this new recording is now "on disk" and not "in memory" as the Numpy recording.
# This meand that the loading is "lazy" and the data are not loaded in memory.

recording2 = se.BinaryRecordingExtractor(file_paths, sampling_frequency,
                                         num_channels, traces0.dtype)
print(recording2)
예제 #16
0
probe = get_probe(manufacturer, probe_name)
probe.rotate(23)

##############################################################################
# fake values

values = np.random.randn(32)

##############################################################################
# plot with value

fig, ax = plt.subplots()
poly, poly_contour = plot_probe(probe,
                                contacts_values=values,
                                cmap='jet',
                                ax=ax,
                                contacts_kargs={'alpha': 1},
                                title=False)
poly.set_clim(-2, 2)
fig.colorbar(poly)

##############################################################################
# generated an interpolated image and plot it on top

image, xlims, ylims = probe.to_image(values, pixel_size=4, method='linear')

print(image.shape)

fig, ax = plt.subplots()
plot_probe(probe, ax=ax, title=False)
im = ax.imshow(image, extent=xlims + ylims, origin='lower', cmap='jet')
# The shape of probe_3d.contact_positions is now (n_elec, 3)

probe_3d = probe_2d.to_3d(axes='xz')
print(probe_2d.contact_positions.shape)
print(probe_3d.contact_positions.shape)

##############################################################################
#  Note that all **"y"** coordinates are 0

df = probe_3d.to_dataframe()
df[['x', 'y', 'z']].head()

##############################################################################
#  The plotting function autiomatically displays the `Probe` in 3d:

plot_probe(probe_3d)

##############################################################################
# We can create another probe lying on another plane:

other_3d = probe_2d.to_3d(axes='yz')
plot_probe(other_3d)

##############################################################################
#  `Probe` can be moved and rotated in 3d:

probe_3d.move([0, 30, -50])
probe_3d.rotate(theta=35, center=[0, 0, 0], axis=[0, 1, 1])

plot_probe(probe_3d)
예제 #18
0
import numpy as np
import matplotlib.pyplot as plt

from probeinterface import Probe, get_probe
from probeinterface.plotting import plot_probe

##############################################################################
#  Download one probe:

manufacturer = 'neuronexus'
probe_name = 'A1x32-Poly3-10mm-50-177'

probe = get_probe(manufacturer, probe_name)
print(probe)

##############################################################################
# Files from the library also contain annotations specific to manufacturers.
# We can see here that Neuronexus probes have contact indices starting at "1" (one-based)

pprint(probe.annotations)

##############################################################################
# When plotting, the channel indices are automatically displayed with
# one-based notation (even if internally everything is still zero based):

plot_probe(probe, with_channel_index=True)

##############################################################################

plt.show()
    probegroup.add_probe(tetrode)
probegroup.set_global_device_channel_indices(np.arange(16))

df = probegroup.to_dataframe()
df

plot_probe_group(probegroup, with_channel_index=True, same_axes=True)

##############################################################################
# Generate a linear probe:
# 

from probeinterface import generate_linear_probe

linear_probe = generate_linear_probe(num_elec=16, ypitch=20)
plot_probe(linear_probe, with_channel_index=True)

##############################################################################
# Generate a multi-column probe:
# 

from probeinterface import generate_multi_columns_probe

multi_columns = generate_multi_columns_probe(num_columns=3,
                                             num_contact_per_column=[10, 12, 10],
                                             xpitch=22, ypitch=20,
                                             y_shift_per_column=[0, -10, 0],
                                             contact_shapes='square', contact_shape_params={'width': 12})
plot_probe(multi_columns, with_channel_index=True, )

##############################################################################
예제 #20
0
probe0.create_auto_shape(probe_type='tip')
probe1 = generate_tetrode(r=25)
probe1.create_auto_shape(probe_type='tip')
probe1.move([150, 0])

probe = combine_probes([probe0, probe1])

pos = probe.electrode_positions
pos[np.abs(pos) < 0.0001] = 0
probe.electrode_positions = pos

# do not include wiring in example : too complicated
#  probe.set_device_channel_indices([3,2,1,0, 7, 6, 5, 4])

probe.annotate(name='2 shank tetrodes', manufacturer='homemade')

print(probe.shank_ids)
d = probe.to_dict()
print(d.keys())

fig, ax = plt.subplots(figsize=(8, 8))
plot_probe(probe, with_channel_index=True, ax=ax)
ax.set_xlim(-50, 200)
ax.set_ylim(-150, 120)

write_probeinterface('probe_format_example.json', probe)

fig.savefig('img/probe_format_example.png')

plt.show()
##############################################################################
#  `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):

probe_3d = probe.to_3d(axes='xz')
plot_probe(probe_3d)

plt.show()
예제 #22
0
##############################################################################
# First, let's create a toy example:

recording, sorting_true = se.toy_example(duration=10,
                                         num_channels=32,
                                         seed=0,
                                         num_segments=2)
print(recording)

###############################################################################
# This genertor already contain a probe object you can retreive directly an plot

probe = recording.get_probe()
print(probe)
from probeinterface.plotting import plot_probe
plot_probe(probe)

###############################################################################
#  You can also change the probe
# In that case you need to manually make the wiring
# Lets use a probe from cambridgeneurotech with 32ch

from probeinterface import get_probe
other_probe = get_probe('cambridgeneurotech', 'ASSY-37-E-1')
print(other_probe)
other_probe.set_device_channel_indices(np.arange(32))
recording_2_shanks = recording.set_probe(other_probe, group_mode='by_shank')
plot_probe(recording_2_shanks.get_probe())

###############################################################################
# Now let's check what we have loaded.