Esempio n. 1
0
 def test_timeseries(self):
     sw.plot_timeseries(self._rec, mode='auto')
     sw.plot_timeseries(self._rec, mode='line', show_channel_ids=True)
     sw.plot_timeseries(self._rec, mode='map', show_channel_ids=True)
     sw.plot_timeseries(self._rec,
                        mode='map',
                        show_channel_ids=True,
                        order_channel_by_depth=True)
def plot_trace(recording, o_dir, t_len=10):
    # Plot a trace of the raw data
    o_loc = os.path.join(o_dir, "trace_" + str(t_len) + "s.png")
    print("Plotting a {}s trace of the raw data to {}".format(t_len, o_loc))
    w_ts = sw.plot_timeseries(recording, trange=[0, t_len])
    plt.savefig(o_loc, dpi=200)
    plt.close()
# First, let's create a toy example with the :code:`extractors` module:

recording, sorting_true = se.example_datasets.toy_example(duration=10,
                                                          num_channels=4,
                                                          seed=0)

##############################################################################
# :code:`recording` is a :code:`RecordingExtractor` object, which extracts information about channel ids, channel locations
# (if present), the sampling frequency of the recording, and the extracellular  traces. :code:`sorting_true` is a
# :code:`SortingExtractor` object, which contains information about spike-sorting related information,  including unit ids,
# spike trains, etc. Since the data are simulated, :code:`sorting_true` has ground-truth information of the spiking
# activity of each unit.
#
# Let's use the :code:`widgets` module to visualize the traces and the raster plots.

w_ts = sw.plot_timeseries(recording, trange=[0, 5])
w_rs = sw.plot_rasters(sorting_true, trange=[0, 5])

##############################################################################
# This is how you retrieve info from a :code:`RecordingExtractor`...

channel_ids = recording.get_channel_ids()
fs = recording.get_sampling_frequency()
num_chan = recording.get_num_channels()

print('Channel ids:', channel_ids)
print('Sampling frequency:', fs)
print('Number of channels:', num_chan)

##############################################################################
# ...and a :code:`SortingExtractor`
Esempio n. 4
0
import spikeinterface.extractors as se
import spikeinterface.widgets as sw

##############################################################################
# First, let's create a toy example with the `extractors` module:

recording, sorting = se.toy_example(duration=10,
                                    num_channels=4,
                                    seed=0,
                                    num_segments=1)

##############################################################################
# plot_timeseries()
# ~~~~~~~~~~~~~~~~~

w_ts = sw.plot_timeseries(recording)

w_ts1 = sw.plot_timeseries(recording, time_range=(5, 8))

recording2 = recording.clone()
recording2.set_channel_groups(channel_ids=recording.get_channel_ids(),
                              groups=[0, 0, 1, 1])
w_ts2 = sw.plot_timeseries(recording2, time_range=(5, 8), color_groups=True)

##############################################################################
# **Note**: each function returns a widget object, which allows to access the figure and axis.

w_ts.figure.suptitle("Recording by group")
w_ts.ax.set_ylabel("Channel_ids")

##############################################################################
Esempio n. 5
0
local_path = si.download_dataset(remote_path='mearec/mearec_test_10s.h5')
recording, sorting_true = se.read_mearec(local_path)
print(recording)
print(sorting_true)

##############################################################################
# :code:`recording` is a :code:`RecordingExtractor` object, which extracts information about channel ids, channel locations
# (if present), the sampling frequency of the recording, and the extracellular  traces. :code:`sorting_true` is a
# :code:`SortingExtractor` object, which contains information about spike-sorting related information,  including unit ids,
# spike trains, etc. Since the data are simulated, :code:`sorting_true` has ground-truth information of the spiking
# activity of each unit.
#
# Let's use the :code:`widgets` module to visualize the traces and the raster plots.

w_ts = sw.plot_timeseries(recording, time_range=(0, 5))
w_rs = sw.plot_rasters(sorting_true, time_range=(0, 5))

##############################################################################
# This is how you retrieve info from a :code:`RecordingExtractor`...

channel_ids = recording.get_channel_ids()
fs = recording.get_sampling_frequency()
num_chan = recording.get_num_channels()
num_seg = recording.get_num_segments()

print('Channel ids:', channel_ids)
print('Sampling frequency:', fs)
print('Number of channels:', num_chan)
print('Number of segments:', num_seg)
ka.set_config(fr='default_readonly')
print(
    f'Downloading recording: {recordingZero["studyName"]}/{recordingZero["name"]}'
)
ka.load_file(recordingZero['directory'] + '/raw.mda')
ka.load_file(recordingZero['directory'] + '/params.json')
ka.load_file(recordingZero['directory'] + '/geom.csv')
ka.load_file(recordingZero['directory'] + '/firings_true.mda')

#Attaching the results
recordingZero['results'] = dict()

#Tryting to plot the recordings
recordingInput = AutoRecordingExtractor(dict(path=recordingPath),
                                        download=True)
w_ts = sw.plot_timeseries(recordingInput)
w_ts.figure.suptitle("Recording by group")
w_ts.ax.set_ylabel("Channel_ids")

#We will also try to plot the rastor plot for the ground truth
gtOutput = AutoSortingExtractor(sortingPath)
#We need to change the indices of  the ground truth output
w_rs_gt = sw.plot_rasters(gtOutput, sampling_frequency=sampleRate)

#Spike-Sorting
#trying to run SPYKINGCIRCUS through spike interface
#spykingcircus
with ka.config(fr='default_readonly'):
    #with hither.config(cache='default_readwrite'):
    with hither.config(container='default'):
        result_spyKingCircus = sorters.spykingcircus.run(
Esempio n. 7
0
def visualize_units(recording, recording_f, sorting, wf, templates,
                    num_channels, file_name):
    wf2 = st.postprocessing.get_unit_waveforms(recording,
                                               sorting,
                                               ms_before=4,
                                               ms_after=0,
                                               verbose=True)
    color = cm.rainbow(np.linspace(0, 1, len(wf)))
    output_dir = "waveform_visualization/" + file_name + "/"
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    fig, axs = plt.subplots(3, 2, constrained_layout=True)
    axe = axs.ravel()
    sw.plot_timeseries(recording_f, ax=axe[0])
    for i in range(len(wf)):
        normalized = preprocessing.normalize(np.array(templates)[i][:, :])
        axe[1].plot(normalized.T, label=i + 1, color=color[i])
    sw.plot_rasters(sorting, ax=axe[2])
    sw.plot_pca_features(recording,
                         sorting,
                         colormap='rainbow',
                         nproj=3,
                         max_spikes_per_unit=100,
                         axes=axe[3:6])
    legend = axe[1].legend(loc='lower right')
    fig.set_size_inches((8.5, 11), forward=False)
    # name = file_name.split("_")
    # # acc_1_04052016_kurocoppola_pre
    fig.suptitle(file_name)
    fig.savefig(output_dir + '_full_info.png', dpi=500)
    for idx in range(len(wf)):
        for j in range(num_channels):
            fig, axs = plt.subplots(4, 3, constrained_layout=True)
            axe = axs.ravel()
            normalized = preprocessing.normalize(wf[idx][:, j, :])
            axe[2].plot(normalized.T, lw=0.3, alpha=0.3)
            normalized = preprocessing.normalize(
                np.array(templates)[idx][:, :])
            axe[2].plot(normalized.T, lw=0.8, color='black')
            axe[0].plot(templates[idx].T, lw=0.8)
            for i in range(len(wf)):
                normalized = preprocessing.normalize(
                    np.array(templates)[i][:, :])
                if idx == i:
                    axe[1].plot(normalized.T, label=i + 1)
                else:
                    axe[1].plot(normalized.T, label=i + 1, alpha=0.3)
            values = randint(0, len(wf), 3)
            for i, val in enumerate(values):
                axe[3 + i].plot(wf2[idx][val, j, :].T)
            sw.plot_pca_features(recording,
                                 sorting,
                                 colormap='binary',
                                 figure=fig,
                                 nproj=3,
                                 axes=axe[6:9],
                                 max_spikes_per_unit=100)
            sw.plot_pca_features(recording,
                                 sorting,
                                 unit_ids=[idx],
                                 figure=fig,
                                 nproj=3,
                                 axes=axe[6:9],
                                 max_spikes_per_unit=100)
            sw.plot_isi_distribution(sorting,
                                     unit_ids=[idx + 1],
                                     bins=100,
                                     window=1,
                                     axes=axe[9:11])
            sw.plot_amplitudes_distribution(recording,
                                            sorting,
                                            max_spikes_per_unit=300,
                                            unit_ids=[idx + 1],
                                            axes=axe[10:12])
            sp = sorting.get_unit_spike_train(unit_id=idx + 1)
            axe[11].plot(sp)
            legend = axe[1].legend(loc='lower right', shadow=True)
            axe[0].set_title('Template')
            axe[2].set_title('Waveforms, template')
            axe[3].set_title('Random waveforms')
            axe[6].set_title('PCA component analysis')
            axe[9].set_title('ISI distribution')
            axe[10].set_title('Amplitude distribution')
            axe[11].set_title('Spike frame')
            fig.set_size_inches((8.5, 11), forward=False)
            fig.suptitle("File name: " + file_name + '\nChannel: ' +
                         str(j + 1).zfill(2) + '\nUnit: ' +
                         str(idx + 1).zfill(2))
            fig.savefig(output_dir + file_name + '_ch' + str(j + 1).zfill(2) +
                        '_u' + str(idx + 1).zfill(2) + '.png',
                        dpi=500)
    plt.close('all')
Esempio n. 8
0
 def test_timeseries(self):
     sw.plot_timeseries(self._rec)
import spikeinterface.extractors as se
import spikeinterface.widgets as sw

##############################################################################
# First, let's create a toy example with the `extractors` module:

recording, sorting = se.example_datasets.toy_example(duration=10,
                                                     num_channels=4,
                                                     seed=0)

##############################################################################
# plot_timeseries()
# ~~~~~~~~~~~~~~~~~

w_ts = sw.plot_timeseries(recording)

w_ts1 = sw.plot_timeseries(recording, trange=[5, 8])

recording.set_channel_groups(channel_ids=recording.get_channel_ids(),
                             groups=[0, 0, 1, 1])
w_ts2 = sw.plot_timeseries(recording, trange=[5, 8], color_groups=True)

##############################################################################
# **Note**: each function returns a widget object, which allows to access the figure and axis.

w_ts.figure.suptitle("Recording by group")
w_ts.ax.set_ylabel("Channel_ids")

##############################################################################
# plot_electrode_geometry()
Esempio n. 10
0
import spikeinterface.extractors as se
import spikeinterface.widgets as sw

##############################################################################
# First, let's create a toy example with the `extractors` module:

recording, sorting = se.toy_example(duration=10,
                                    num_channels=4,
                                    seed=0,
                                    num_segments=1)

##############################################################################
# plot_timeseries()
# ~~~~~~~~~~~~~~~~~

w_ts = sw.plot_timeseries(recording)

##############################################################################
# We can select time range

w_ts1 = sw.plot_timeseries(recording, time_range=(5, 8))

##############################################################################
# We can color with groups

recording2 = recording.clone()
recording2.set_channel_groups(channel_ids=recording.get_channel_ids(),
                              groups=[0, 0, 1, 1])
w_ts2 = sw.plot_timeseries(recording2, time_range=(5, 8), color_groups=True)

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