def test_wave_reader(n=10000):
    #plt.interactive(True)
    try:
        update = 0
        FIG = plt.figure()
        rb = None
        Q = Queue()
        bs_reader = BS3Reader(WAVEProtocolHandler, Q, verbose=False,
                              ident='TestWAVE')
        bs_reader.start()
        for _ in xrange(n):
            #print Q.qsize()
            try:
                item = Q.get(block=True, timeout=2)
                for wave in item.event_lst:
                    gid, uid, tv, nc, ns, wf = wave
                    if rb is None:
                        rb = MxRingBuffer(dimension=(ns, nc), capacity=2000)
                    rb.append(wf)
                    #print 'rb:', len(rb)
                    update += 1
                if update > 1000:
                    print 'plotting enter'
                    FIG.clear()
                    waveforms({0: rb[:]}, tf=ns, plot_handle=FIG,
                                        plot_separate=False, show=False)
                    #plt.draw()
                    save_figure(FIG, 'wave', file_dir='E:\SpiDAQ')
                    update = 0
                    print 'plotting exit'
            except Empty:
                continue
    except Exception, ex:
        print ex
Exemple #2
0
    def plot_filter_set(self, ph=None, show=False):
        """plot the filter set in a waveform plot"""

        # get plotting tools
        try:
            from spikeplot import waveforms
        except ImportError:
            return None

        # checks
        if self.nf == 0:
            warnings.warn("skipping plot, no active units!")
            return None

        # init
        units = {}
        for k in self._idx_active_set:
            units[k] = sp.atleast_2d(self.bank[k].f_conc)

        return waveforms(
            units,
            tf=self._tf,
            plot_separate=True,
            plot_mean=False,
            plot_single_waveforms=False,
            plot_handle=ph,
            show=show,
        )
Exemple #3
0
    def plot_template_set(self, ph=None, show=False):
        """plot the template set in a waveform plot"""

        # get plotting tools
        try:
            from spikeplot import waveforms, plt
        except ImportError:
            return None

        # checks
        if self.nf == 0:
            logging.warn('skipping plot, no active units!')
            return None

        # init
        units = {}
        for k in self._idx_active_set:
            units[k] = self.bank[k]._xi_buf[:]

        return waveforms(
            units,
            tf=self._tf,
            plot_separate=True,
            plot_mean=True,
            plot_single_waveforms=True,
            plot_handle=ph, show=show)
Exemple #4
0
    def plot_sorting_waveforms(self, ph=None, show=False):
        """plot the waveforms of the sorting of the last data chunk

        :type ph: plot handle
        :param ph: plot handle to use for the
        :type show: bool
        :param show: if True, call plt.show()
        """

        # get plotting tools
        try:
            from spikeplot import waveforms
        except ImportError:
            return None

        # check
        if self._data is None or self.rval is None or len(
            self._idx_active_set) == 0:
            warnings.warn('not initialised properly to plot a sorting!')
            return None

        # inits
        wf = {}
        temps = {}
        #if self._data is None or self.rval is None:
        #    return
        cut = get_cut(self._tf)


        # adapt filters with found waveforms
        nunits = 0
        for u in self.rval:
            spks_u = self.spikes_u(u, mc=False)
            if spks_u.size > 0:
                wf[u] = self.spikes_u(u)
                temps[u] = self.bank[u].xi_conc
                nunits += 1
        print 'waveforms for units:', nunits

        """
        waveforms(waveforms, samples_per_second=None, tf=None, plot_mean=False,
              plot_single_waveforms=True, set_y_range=False,
              plot_separate=True, plot_handle=None, colours=None, title=None,
              filename=None, show=True):
        """
        return waveforms(wf, samples_per_second=None, tf=self._tf,
                         plot_mean=True, templates=temps,
                         plot_single_waveforms=True, set_y_range=False,
                         plot_separate=True, plot_handle=ph, show=show)
def main():
    TF, SNR, PCADIM = 65, 0.5, 8
    NTRL = 10
    LOAD = False
    if LOAD is True:
        spks, spks_info, ndet = load_data()
    else:
        # spks, spks_info, ndet = get_data(tf=TF, trials=NTRL, snr=SNR,
        #                                  mean_correct=False, save=True)
        pass

    # plot.waveforms(spks, tf=TF, show=False)

    input_obs = pre_processing(spks, ndet, TF, pca_dim=PCADIM)
    plot.cluster(input_obs, show=False)

    # kmeans
    labels_km = cluster_kmeans(input_obs)
    obs_km = {}
    wf_km = {}
    for i in xrange(labels_km.max() + 1):
        obs_km[i] = input_obs[labels_km == i]
        wf_km[i] = spks[labels_km == i]
    if WITH_PLOT:
        plot.cluster(obs_km, title='kmeans', show=False)
        plot.waveforms(obs_km, tf=TF, title='kmeans', show=False)

    # gmm
    labels_gmm = cluster_gmm(input_obs)
    obs_gmm = {}
    wf_gmm = {}
    for i in xrange(labels_km.max() + 1):
        obs_gmm[i] = input_obs[labels_gmm == i]
        wf_gmm[i] = spks[labels_gmm == i]
    if WITH_PLOT:
        plot.cluster(obs_gmm, title='gmm', show=False)
        plot.waveforms(wf_gmm, tf=TF, title='gmm', show=False)

    # ward
    labels_ward = cluster_ward(input_obs)
    obs_ward = {}
    wf_ward = {}
    for i in xrange(labels_km.max() + 1):
        obs_ward[i] = input_obs[labels_ward == i]
        wf_ward[i] = spks[labels_ward == i]
    if WITH_PLOT:
        plot.cluster(obs_ward, title='ward', show=False)
        plot.waveforms(wf_ward, tf=TF, title='ward', show=False)

    # spectral
    #cluster_spectral(spks)

    if WITH_PLOT:
        plot.plt.show()
Exemple #6
0
def main():
    TF, SNR, PCADIM = 65, 0.5, 8
    NTRL = 10
    LOAD = False
    if LOAD is True:
        spks, spks_info, ndet = load_data()
    else:
        # spks, spks_info, ndet = get_data(tf=TF, trials=NTRL, snr=SNR,
        #                                  mean_correct=False, save=True)
        pass

    # plot.waveforms(spks, tf=TF, show=False)

    input_obs = pre_processing(spks, ndet, TF, pca_dim=PCADIM)
    plot.cluster(input_obs, show=False)

    # kmeans
    labels_km = cluster_kmeans(input_obs)
    obs_km = {}
    wf_km = {}
    for i in xrange(labels_km.max() + 1):
        obs_km[i] = input_obs[labels_km == i]
        wf_km[i] = spks[labels_km == i]
    if WITH_PLOT:
        plot.cluster(obs_km, title='kmeans', show=False)
        plot.waveforms(obs_km, tf=TF, title='kmeans', show=False)

    # gmm
    labels_gmm = cluster_gmm(input_obs)
    obs_gmm = {}
    wf_gmm = {}
    for i in xrange(labels_km.max() + 1):
        obs_gmm[i] = input_obs[labels_gmm == i]
        wf_gmm[i] = spks[labels_gmm == i]
    if WITH_PLOT:
        plot.cluster(obs_gmm, title='gmm', show=False)
        plot.waveforms(wf_gmm, tf=TF, title='gmm', show=False)

    # ward
    labels_ward = cluster_ward(input_obs)
    obs_ward = {}
    wf_ward = {}
    for i in xrange(labels_km.max() + 1):
        obs_ward[i] = input_obs[labels_ward == i]
        wf_ward[i] = spks[labels_ward == i]
    if WITH_PLOT:
        plot.cluster(obs_ward, title='ward', show=False)
        plot.waveforms(wf_ward, tf=TF, title='ward', show=False)

    # spectral
    #cluster_spectral(spks)

    if WITH_PLOT:
        plot.plt.show()
import scipy as sp
from spikeplot import waveforms

# get some data
my_data = {0: sp.randn(20, 50, 4), 1: sp.randn(10, 200) + 2}

# call the plot function on the axes
waveforms(my_data, tf=50, title="Test Plot", plot_mean=True, plot_single_waveforms=True, plot_separate=True)