Beispiel #1
0
def view(binaryfile, probefile, nbits, chs, time, span):
    '''
    view raw or mua file with or without spk_info:
    `spiketag view mua.bin spk.bin prb.json`
    '''
    from spiketag.base import probe
    from spiketag.base import MUA
    from vispy import app
    nbits, time, span = int(nbits), float(time), float(span)
    chs_tbview = slice(*[int(_) for _ in chs.split(',')])
    prb = probe()
    prb.load(probefile)
    if len(binaryfile) == 2:
        mua_filename, spk_filename = binaryfile
        click.echo('loadding {} and {}'.format(mua_filename, spk_filename))
        mua = MUA(mua_filename=mua_filename,
                  spk_filename=spk_filename,
                  probe=prb,
                  numbytes=nbits // 8,
                  scale=False)
        if span == -1: span = None
        mua.show(chs=prb.chs[chs_tbview], span=span, time=time)
        app.run()
    elif len(binaryfile) == 1:
        mua_filename = binaryfile[0]
        click.echo('loadding {}'.format(mua_filename))
        mua = MUA(mua_filename=mua_filename,
                  spk_filename=None,
                  probe=prb,
                  numbytes=nbits // 8,
                  scale=False)
        if span == -1: span = None
        mua.show(chs=prb.chs[chs_tbview], span=span, time=time)
        app.run()
Beispiel #2
0
def sort(binaryfile, probefile):
    '''
    sort without notebook:
    `spiketag sort mua.bin spk.bin prb.json`
    '''
    mua_filename, spk_filename = binaryfile
    click.echo('spiketag-sort: loadding {} and {}'.format(
        mua_filename, spk_filename))
    import sys
    from PyQt5.QtWidgets import QApplication
    from spiketag.mvc.Control import controller
    from spiketag.base import probe
    prb = probe()
    prb.load(probefile)
    app = QApplication(sys.argv)
    ctrl = controller(probe=prb,
                      mua_filename=mua_filename,
                      spk_filename=spk_filename,
                      binary_radix=13,
                      scale=False
                      # time_segs=[[0,320]]
                      )
    # ctrl.model.sort(clu_method='dpgmm', group_id=0, n_comp=8, max_iter=400)
    ctrl.show()
    sys.exit(app.exec_())
Beispiel #3
0
def view_data(filename, prbfile, nbits, time=0, span=5):
    prb = probe()
    prb.load(prbfile)
    mua = MUA(filename, prb, numbytes=nbits // 8, scale=False)
    if span == -1: span = None
    mua.show(chs=prb.chs[:128], span=span, time=time)
    app.run()
Beispiel #4
0
def prb_check(prbfile, font_size=33):
    '''
    check prb by visualization
    '''
    from spiketag.base import probe
    prb = probe()
    prb.load(prbfile)
    prb.show(font_size)
Beispiel #5
0
def check_fpga(prbfile, var):
    prb = probe()
    prb.load(prbfile)
    prb.n_ch = 160
    prb.fs = 25000.
    fpga = xike_config(prb)
    if var in dir(fpga):
        exec('print(fpga.{})'.format(var))
Beispiel #6
0
def fpga(probefile):
    '''
    init fpga with probe file:
    `spiketag fpga prb.json`
    '''
    click.echo('init FPGA with probe file {}'.format(probefile))
    from spiketag.fpga import xike_config
    from spiketag.base import probe
    prb = probe()
    prb.load(probefile)
    prb.show()
    fpga = xike_config(prb)
    click.echo('init FPGA success, check fpga with "spiketag fpga-check"')
Beispiel #7
0
def report(binaryfile, probefile, nbits=32):
    '''
    view raw or mua file with or without spk_info:
    `spiketag view mua.bin spk.bin prb.json`
    '''
    from spiketag.base import probe
    from spiketag.base import MUA
    from collections import Counter
    import seaborn as sns
    import mplcursors
    nbits = int(nbits)
    prb = probe()
    prb.load(probefile)
    if len(binaryfile) == 2:
        mua_filename, spk_filename = binaryfile
        click.echo('loadding {} and {}'.format(mua_filename, spk_filename))
        mua = MUA(mua_filename=mua_filename,
                  spk_filename=spk_filename,
                  probe=prb,
                  numbytes=nbits // 8,
                  scale=False)

        ## report ch<-->nspks statistics
        spk_info = np.fromfile(spk_filename, np.int32).reshape(-1, 2)
        t, ch = spk_info[:, 0] / prb.fs, spk_info[:, 1]
        ch = ch[t > 0.004]
        t = t[t > 0.004]
        c = Counter(ch)
        nspks = np.array([c[ch] for ch in prb.chs])
        nspks_max = nspks.max()
        sns.set_context('paper')
        sns.set(font_scale=1.5)
        sns.set_style('white')
        plt.style.use('dark_background')

        fig, ax = plt.subplots(1,
                               2,
                               figsize=(25, 15),
                               gridspec_kw={'width_ratios': [3, 1]})
        sns.scatterplot(t,
                        prb.ch_idx[ch],
                        hue=prb.ch_idx[ch],
                        palette=plt.cm.hsv,
                        s=18,
                        marker='|',
                        legend=False,
                        ax=ax[0])
        ax[0].set_facecolor((.1, .1, .1, .0))
        ax[0].set_ylim(ax[0].get_ylim()[::-1])
        ax[0].set_xlabel('Time(secs)')
        ax[0].set_ylabel('Virtual Channel Number')
        ax[0].set_yticks(np.arange(0, 160, 8))
        ax[0].invert_yaxis()
        ax[0].set_title('#spikes found on (channels) vs (time)')
        nspks_img = ax[1].imshow(nspks.reshape(-1, prb.group_len),
                                 cmap=plt.cm.magma)  #ocean_r
        ax[1].grid(which='minor', color='w', linestyle='-', linewidth=2)
        ax[1].set_ylabel('Group Number')
        ax[1].set_xticks(range(prb.group_len))
        ax[1].set_yticks(range(prb.n_group))
        ax[1].set_xlabel('Channels in the Group')
        ax[1].set_title('#spikes found on (channels) in (group)')
        ax[1].invert_yaxis()
        sns.despine()

        for i in range(prb.grp_matrix.shape[0]):
            for j in range(prb.grp_matrix.shape[1]):
                if nspks[prb.grp_matrix[i, j]] < nspks_max * 0.7:
                    ax[1].text(j,
                               i,
                               str(prb.grp_matrix[i, j]),
                               color='white',
                               ha='center',
                               va='center',
                               fontsize=10)
                else:
                    ax[1].text(j,
                               i,
                               str(prb.grp_matrix[i, j]),
                               color='black',
                               ha='center',
                               va='center',
                               fontsize=10)

        fig.colorbar(nspks_img)
        plt.tight_layout()
        mplcursors.cursor()
        plt.show()

    elif len(binaryfile) == 1:
        mua_filename = binaryfile[0]
        click.echo('loadding {}'.format(mua_filename))
        mua = MUA(mua_filename=mua_filename,
                  spk_filename=None,
                  probe=prb,
                  numbytes=nbits // 8,
                  scale=False)
import numpy as np
from spiketag.base import probe
from spiketag.view import probe_view

prb_bowtie_LL = probe(shank_no=6, prb_type='bow_tie')

prb_bowtie_LL.shanks[0].l = [59, 60, 10, 58, 12, 11, 57, 56]
prb_bowtie_LL.shanks[0].r = [5, 52, 3, 54, 53, 4, 13, 2, 55]
prb_bowtie_LL.shanks[0].xl = -100.
prb_bowtie_LL.shanks[0].yl = 20
prb_bowtie_LL.shanks[0].xr = -80.
prb_bowtie_LL.shanks[0].yr = 5

prb_bowtie_LL.shanks[1].l = [15, 63, 48, 47, 0, 61, 9, 14, 62, 6]
prb_bowtie_LL.shanks[1].r = [8, 1, 51, 50, 18, 34, 31, 25, 33, 17, 22, 49]
prb_bowtie_LL.shanks[1].xl = -10.
prb_bowtie_LL.shanks[1].yl = 15
prb_bowtie_LL.shanks[1].xr = 10.
prb_bowtie_LL.shanks[1].yr = 0

prb_bowtie_LL.shanks[2].l = [39, 38, 20, 45, 44, 24, 7, 32, 16, 23, 46, 30]
prb_bowtie_LL.shanks[2].r = [
    19, 37, 21, 35, 36, 26, 29, 40, 27, 42, 41, 28, 43
]
prb_bowtie_LL.shanks[2].xl = 80.
prb_bowtie_LL.shanks[2].yl = 10
prb_bowtie_LL.shanks[2].xr = 100.
prb_bowtie_LL.shanks[2].yr = -5

prb_bowtie_LL.shanks[3].l = [123, 124, 74, 122, 76, 75, 121, 120]
prb_bowtie_LL.shanks[3].r = [69, 116, 67, 118, 117, 68, 77, 66, 119]
Beispiel #9
0
    def _to_txt(self, filename):
        with open(filename,'w') as f:
            for ch, pos in self.mapping.items():
                _str = str(ch)+": " + str(pos) + '\n'
                f.write(_str)
            for grpNo in range(self.n_group):
                _str = "groupNo_" + str(grpNo) + ":" + str(self[grpNo]) + '\n'
                f.write(_str)


if __name__ == '__main__':
    from spiketag.base import ch_group, shank, probe
    # shk = shank()
    # shk[1] = ch_group([3, 4, 10, 1])
    prb = probe(shank_no=3)
    prb[0].l = [59,60,10,58,12,11,57,56]
    prb[0].r = [5,52,3,54,53,4,13,2,55]
    prb[0].x = -100.
    prb[0].y = 10

    prb[1].l = [15,63,48,47,0,61,9,14,62,6]
    prb[1].r = [8, 1,51,50,18,34,31,25,33,17,22]
    prb[1].x = -50.
    prb[1].y = 5

    prb[2].l = [39,38,20,45,44,24,7,32,16,23,46,30]
    prb[2].r = [19,37,21,35,36,26,29,40,27,42,41,28,43]
    prb[2].x = 0.
    prb[2].y = 0
    # print prb[0]
Beispiel #10
0
    def keyPressEvent(self, e):
        print("event", e)
        # if e.key() == Qt.Key_F5:
        #     if self.view_timer.isActive():
        #         self.view_timer.stop()
        #     else:
        #         self.view_timer.start(self.update_interval)
        #     self.close()
        # if e.key()==Qt.Key_Space:
        #     self.close()


if __name__ == '__main__':
    # 1. prb, gui and bmi and binner
    app = QApplication(sys.argv)
    prb = probe(prbfile='./dusty/dusty.json')
    gui = BMI_RASTER_GUI(prb=prb, fet_file='./fet.bin')
    bin_size, B_bins = 25e-3, 10
    gui.bmi.set_binner(bin_size=bin_size, B_bins=B_bins)

    # 2. decoder
    # pos = np.fromfile('./sorting/dusty_pos.bin').reshape(-1,2)
    # pc = place_field(pos=pos, t_step=33.333e-3)
    # replay_offset = 2.004
    # start = 320
    # end   = 2500
    # pc.align_with_recording(start, end, replay_offset)
    # pc.initialize(bin_size=4, v_cutoff=25)
    # pc.load_spktag('./sorting/spktag/test_allspikes', show=True)
    # dec = NaiveBayes(t_step=bin_size, t_window=B_bins*bin_size)
    # dec.connect_to(pc)