# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [default]
#     language: python
#     name: python2
# ---

# # launch sorter

# %pylab inline
import numexpr as ne
import seaborn as sns
from ipywidgets import interact
import time

# %load_ext autoreload
# %autoreload 2

ne.set_num_threads(32)

import sys
sys.path.append('../../..')

# %gui qt

from spiketag.mvc import Sorter

nCh=32
fs = 25000
app = Sorter('/Users/chiy/Documents/HHMI/Github/spiketag/spiketag_test_data/pcie.bin', '/Users/chiy/Documents/HHMI/Github/spiketag/spiketag_test_data/pcie_spktag.bin')

app.run()

# # launch firing_rate_view using the data from sorter

from spiketag.view import firing_rate_view

fv = firing_rate_view()

fv.bind(app.model.spktag)

fv.set_data(26, clu=app.model.clu[26])

fv.show()

# ## Test Performance 





# %lprun -f fv._draw fv._draw(app.model.clu[26].index_id)



# # The plot experiment in jupyter before write code

from scipy import signal

from ipywidgets import interact


@interact(avg_winlen=(0.1, 5, 0.1))
def show_fr(avg_winlen=1): 
    times = app.model.spktag.t[app.model.spktag.ch == 26] 
    time = times[app.model.clu[26][0]] / int(25000 * avg_winlen) 
    counts = (np.bincount(time)* (1./avg_winlen)).astype(np.int64)
    x,y = np.arange(1,counts.size+1), counts 
    gs = signal.gaussian(x.shape[0]/10,std=x.shape[0]/5) 
#    plot(gs)
    filtered = np.convolve(y, gs, mode='same') / sum(gs) 
    plot(x,y) 
    plot(x,filtered, 'r')


    times = app.model.spktag.t[app.model.spktag.ch == 26] 
    train = np.zeros(app.model.mua.data.size,dtype='int64')
    train[times] = 1
    time = times[app.model.clu[26][3]] / int(25000 * 0.1) 
    counts = np.bincount(time) * int(1/0.1)
    x,y = np.arange(1,counts.size+1), counts 
    gs = signal.gaussian(100,std=0.1 * 1000) 
    filtered = np.convolve(y, gs, mode='same') / sum(gs) 
    plot(x,y) 
    plot(x,filtered, 'r')

# # Try the plot function within Fig

# ## conclution: the performace of line view is better than Fig.plot

from vispy import plot

fig = plot.Fig()


def ff():
    for i in range(len(fv.poses)):
        fig[0,0].plot(fv.poses[i], fv.colors[i])

# %time ln.set_data(fv.poses, fv.colors)

# %time ff()

# # launch firing_rate_view using custom data



# # Just for Testing , deletable

app.view.firing_rate_view.camera.get_state()

app.view.firing_rate_view.camera._default_state

app.view.firing_rate_view.camera.set_default_state

from spiketag.view  import scatter_2d_view

sc = scatter_2d_view()

sc._view.camera._default_state

app.view.amplitude_view._view.camera._default_state

app.view.amplitude_view._view.camera._default_state

app.view.amplitude_view._view.camera.get_state()

# + active=""
# app.view.amplitude_view._view.camera.set_state(app.view.amplitude_view._view.camera._default_state)
# -



StarcoderdataJupyterScriptsDedupFiltered