예제 #1
0
    def _event_explained(self, ev, padding=15):
        """check event for explanation by the filter bank"""

        # early exit if no discriminants are present
        if not self._disc.size:
            return False

        # cut relevant piece of the discriminants
        data_ep = ev - self._learn_templates,\
                  ev - self._learn_templates + self.tf
        disc_ep = data_ep[0] + self._tf / 2,\
                  data_ep[1] + self._tf / 2
        if self.verbose.has_plot:
            try:
                from spikeplot import mcdata

                ep = data_ep[0] - padding, disc_ep[1] + padding
                mcdata(
                    data=self._chunk[ep[0]:ep[1]],
                    #other=self._disc[at[0]:at[1]], events=evts,
                    other=self._disc[ep[0]:ep[1]],
                    x_offset=ep[0],
                    events={0: [ev], 1: [data_ep[0] + self._tf]},
                    epochs={0: [data_ep], 1: [disc_ep]},
                    title='det@%s(%s) disc@%s' % (
                        ev, self._learn_templates, ev + self._tf),
                    show=True)
            except ImportError:
                pass
        return self._disc[disc_ep[0] - padding:disc_ep[1] + padding,
               :].max() >= 0.0
예제 #2
0
    def plot(self, show=False):
        """plot detection in mcdata plot"""

        try:
            from spikeplot import plt, mcdata, COLOURS
        except ImportError:
            return None

        fig = mcdata(self.data, other=self.energy, events={0: self.events},
                     show=False)
        for i, th in enumerate(self.threshold):
            fig.axes[-1].axhline(th, c=COLOURS[i % len(COLOURS)])
        self._plot_additional(fig)
        if show is True:
            plt.show()
        return fig
예제 #3
0
    def plot_sorting(self, ph=None, show=False):
        """plot the sorting of the last data chunk

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

        # get plotting tools
        try:
            from spikeplot import COLOURS, mcdata
        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

        # create events
        ev = {}
        if self.rval is not None:
            temps = self.template_set
            for i in self._idx_active_set:
                if i in self.rval:
                    if self.rval[i].any():
                        ev[i] = (self.bank[i].xi, self.rval[i])

        # create colours
        cols = COLOURS[:self.nf]

        # calc discriminants for single units
        other = None
        if self.nf > 0:
            self.reset_history()
            other = super(FilterBankSortingNode, self)._execute(self._data)
            other += getattr(self, '_lpr_s', sp.log(1.e-6))
            other -= [.5 * self.get_xcorrs_at(i)
                      for i in xrange(self.nf)]

        # plot mcdata
        return mcdata(self._data, other=other, events=ev,
                      plot_handle=ph, colours=cols, show=show)
예제 #4
0
try:
    import unittest2 as ut
except ImportError:
    import unittest as ut

from botmpy.common import mad_scaling
from botmpy.common.datafile import XpdFile
import scipy as sp

try:
    from spikeplot import mcdata, plt
    WITH_PLOT = True
except ImportError:
    WITH_PLOT = False

if __name__ == '__main__':
    xpd = XpdFile('/home/pmeier/Data/Munk/Louis/L014/L0140001.xpd')

    data = xpd.get_data(item=1)
    if WITH_PLOT:
        mcdata(data, show=False)

    data_scaled, scale = mad_scaling(data)
    if WITH_PLOT:
        mcdata(data_scaled, show=False)

    print 'magic eq', sp.stats.norm.ppf(0.75)
    print 'STD:', sp.std(data, 0), sp.std(data_scaled, 0)
    if WITH_PLOT:
        plt.show()
예제 #5
0
import scipy as sp
from spikeplot import mcdata

ns, nc = 300 + 1000, 4
tf = 65
cut = (-int(sp.floor(tf / 2.0)), int(sp.ceil(tf / 2.0)))
mydata = sp.randn(ns, nc)
wf = sp.array([sp.sin(sp.linspace(0, 2 * sp.pi, tf)) * (i + 1)
               for i in xrange(nc)]).T
unit_ev = sp.array([50, 300, 750])
for i in unit_ev:
    mydata[i + cut[0]:i + cut[1], :] += wf
myother = sp.randn(ns, 4)
ep = sp.array([[150, 200], [800, 950]])
ev = {0:(wf, unit_ev), 1:unit_ev}

mcdata(
    mydata,
    other=myother,
    colours=None,
    epochs=ep,
    events=ev,
    x_offset=-100)