Ejemplo n.º 1
0
    def start(self, current, selections):
        current.progress.begin('Creating spike waveform plot')
        current.progress.set_status('Loading spikes')

        spikes = {}
        strong = {}
        if self.spike_mode == 1:
            spikes = current.spikes_by_unit()
        elif self.spike_mode == 2:
            strong = current.spikes_by_unit()

        spike_trains = None
        if self.inc_spikes:
            current.progress.set_status('Loading spike trains')
            spike_trains = current.spike_trains_by_unit_and_segment()

            for u, trains in spike_trains.iteritems():
                s = []
                for st in trains.values():
                    if st.waveforms is not None:
                        s.extend(convert.spike_train_to_spikes(st))
                if not s:
                    continue
                spikes.setdefault(u, []).extend(s)

        if self.inc_extracted:
            current.progress.set_status('Extracting spikes from signals')
            signals = current.analog_signals_by_segment_and_channel(
                conversion_mode=3)
            if spike_trains is None:
                spike_trains = current.spike_trains_by_unit_and_segment()

            for u, trains in spike_trains.iteritems():
                s = []
                rcg = u.recordingchannelgroup
                for seg, train in trains.iteritems():
                    if seg not in signals:
                        continue

                    train_sigs = []
                    for rc in signals[seg]:
                        if rcg in rc.recordingchannelgroups:
                            train_sigs.append(signals[seg][rc])
                    if not train_sigs:
                        continue
                    s.extend(
                        extract_spikes(train, train_sigs, self.length * pq.ms,
                                       self.align * pq.ms))
                if not s:
                    continue
                spikes.setdefault(u, []).extend(s)

        fade = 0.2 if self.fade else 1.0
        plot.spikes(spikes,
                    self.plot_type * 2 + self.split_type + 1,
                    strong,
                    anti_alias=self.anti_aliased,
                    fade=fade,
                    subplot_layout=self.layout,
                    progress=current.progress)
Ejemplo n.º 2
0
    def start(self, current, selections):
        current.progress.begin("Creating spike waveform plot")
        current.progress.set_status("Loading spikes")

        spikes = {}
        strong = {}
        if self.spike_mode == 1:
            spikes = current.spikes_by_unit()
        elif self.spike_mode == 2:
            strong = current.spikes_by_unit()

        spike_trains = None
        if self.inc_spikes:
            current.progress.set_status("Loading spike trains")
            spike_trains = current.spike_trains_by_unit_and_segment()

            for u, trains in spike_trains.iteritems():
                s = []
                for st in trains.values():
                    if st.waveforms is not None:
                        s.extend(convert.spike_train_to_spikes(st))
                if not s:
                    continue
                spikes.setdefault(u, []).extend(s)

        if self.inc_extracted:
            current.progress.set_status("Extracting spikes from signals")
            signals = current.analog_signals_by_segment_and_channel(conversion_mode=3)
            if spike_trains is None:
                spike_trains = current.spike_trains_by_unit_and_segment()

            for u, trains in spike_trains.iteritems():
                s = []
                rcg = u.recordingchannelgroup
                for seg, train in trains.iteritems():
                    if seg not in signals:
                        continue

                    train_sigs = []
                    for rc in signals[seg]:
                        if rcg in rc.recordingchannelgroups:
                            train_sigs.append(signals[seg][rc])
                    if not train_sigs:
                        continue
                    s.extend(extract_spikes(train, train_sigs, self.length * pq.ms, self.align * pq.ms))
                if not s:
                    continue
                spikes.setdefault(u, []).extend(s)

        fade = 0.2 if self.fade else 1.0
        plot.spikes(
            spikes,
            self.plot_type * 2 + self.split_type + 1,
            strong,
            anti_alias=self.anti_aliased,
            fade=fade,
            subplot_layout=self.layout,
            progress=current.progress,
        )
Ejemplo n.º 3
0
    def test_extract_spikes(self):
        s1 = sp.zeros(10000)
        s2 = sp.ones(10000)
        t = sp.arange(0.0, 10.1, 1.0)

        sig1 = neo.AnalogSignal(s1 * pq.uV, sampling_rate=pq.kHz)
        sig2 = neo.AnalogSignal(s2 * pq.uV, sampling_rate=pq.kHz)
        train = neo.SpikeTrain(t * pq.s, 10 * pq.s)

        spikes = tools.extract_spikes(train, [sig1, sig2], 100 * pq.ms,
                                      10 * pq.ms)

        self.assertEqual(len(spikes), 9)
        for s in spikes:
            self.assertAlmostEqual(s.waveform[:, 0].mean(), 0.0)
            self.assertAlmostEqual(s.waveform[:, 1].mean(), 1.0)
Ejemplo n.º 4
0
    def test_extract_spikes(self):
        s1 = sp.zeros(10000)
        s2 = sp.ones(10000)
        t = sp.arange(0.0, 10.1, 1.0)

        sig1 = neo.AnalogSignal(s1 * pq.uV, sampling_rate=pq.kHz)
        sig2 = neo.AnalogSignal(s2 * pq.uV, sampling_rate=pq.kHz)
        train = neo.SpikeTrain(t * pq.s, 10 * pq.s)

        spikes = tools.extract_spikes(
            train, [sig1, sig2], 100 * pq.ms, 10 * pq.ms)

        self.assertEqual(len(spikes), 9)
        for s in spikes:
            self.assertAlmostEqual(s.waveform[:, 0].mean(), 0.0)
            self.assertAlmostEqual(s.waveform[:, 1].mean(), 1.0)
Ejemplo n.º 5
0
    def test_extract_different_spikes(self):
        s1 = sp.ones(10500)
        s2 = -sp.ones(10500)
        for i in xrange(10):
            s1[i * 1000 + 500:i * 1000 + 1500] *= i
            s2[i * 1000 + 500:i * 1000 + 1500] *= i
        t = sp.arange(0.0, 10.1, 1.0)

        sig1 = neo.AnalogSignal(s1 * pq.uV, sampling_rate=pq.kHz)
        sig2 = neo.AnalogSignal(s2 * pq.uV, sampling_rate=pq.kHz)
        train = neo.SpikeTrain(t * pq.s, 10 * pq.s)

        spikes = tools.extract_spikes(train, [sig1, sig2], 100 * pq.ms,
                                      10 * pq.ms)

        self.assertEqual(len(spikes), 10)
        for i, s in enumerate(spikes):
            self.assertAlmostEqual(s.waveform[:, 0].mean(), i)
            self.assertAlmostEqual(s.waveform[:, 1].mean(), -i)
Ejemplo n.º 6
0
    def test_extract_different_spikes(self):
        s1 = sp.ones(10500)
        s2 = -sp.ones(10500)
        for i in xrange(10):
            s1[i * 1000 + 500:i * 1000 + 1500] *= i
            s2[i * 1000 + 500:i * 1000 + 1500] *= i
        t = sp.arange(0.0, 10.1, 1.0)

        sig1 = neo.AnalogSignal(s1 * pq.uV, sampling_rate=pq.kHz)
        sig2 = neo.AnalogSignal(s2 * pq.uV, sampling_rate=pq.kHz)
        train = neo.SpikeTrain(t * pq.s, 10 * pq.s)

        spikes = tools.extract_spikes(
            train, [sig1, sig2], 100 * pq.ms, 10 * pq.ms)

        self.assertEqual(len(spikes), 10)
        for i, s in enumerate(spikes):
            self.assertAlmostEqual(s.waveform[:, 0].mean(), i)
            self.assertAlmostEqual(s.waveform[:, 1].mean(), -i)