<jupyter_start><jupyter_text>将phy的histogram的opengl改一下的，每个点变颜色，是可以高亮histogram的<jupyter_code>view.visuals[0].program['u_color']=np.repeat(np.ones((1,4)),300,axis=0).astype(np.float32)
np.repeat(np.ones((1,4)),300,axis=0).astype(np.float32).shape
view.visuals[0].update()
app.view.wave_view.waves1.color.shape<jupyter_output><empty_output><jupyter_text>比较用vispy的Fig的效率 (结论是fig太慢了)<jupyter_code>import vispy.plot  as vp
from spiketag.view.color_scheme import palette
default_color = np.ones(4, dtype='int32')
fig = vp.Fig(bgcolor='k')
ccg = app.view.correlogram_view
hists = ccg._correlogram()
for i,j in ccg._pair_clusters():
    color = default_color if (i != j) else np.hstack((palette[i],1))
    row, col = ccg._clu.nclu - 1 - i, j
    fig[row,col].histogram(hists[i,j],color=color)
%time ccg._correlate(ccg._spike_time, ccg._clu.index)
%load_ext line_profiler
%lprun -f ccg._render ccg._render()
%lprun -f ccg._correlate ccg._correlate(ccg._spike_time, ccg._clu.index)<jupyter_output><empty_output><jupyter_text>比较numpy和scipy.sparse的速度<jupyter_code>import numpy as np
from scipy import sparse
a = sparse.lil_matrix((1,30149334), dtype='int64')
a.toarray()
 a[0,1:2] = 1
zero =  sparse.lil_matrix((1,3), dtype='int64')
sparse.hstack((zero,a)).toarray()
a.shape
from spiketag.core.correlate import _to_train
idx = app.model.spktag.t[app.model.spktag.ch == 26][app.model.clu[26].index[0]]
def test1():
    for i in range(5):
        t = np.zeros(30149334,dtype='int32')
        t[idx] = 1
%time test1
np.correlate([1,1,1,1],[1,0,1],'same')
np.correlate([1,0,1], [1,1,1,1])
a = sparse.csr_matrix(1,(100,1))
a.toarray().shape
from spiketag.core import correlate_sparse
from spiketag.core import correlate
ccg._correlate = correlate
pool = mp.Pool()
ccg._correlate(ccg._spike_time, ccg._clu.index)
%pdb
ccg._correlate(ccg._spike_time, ccg._clu.index)
%time ccg._correlate(ccg._spike_time, ccg._clu.index)
%lprun -f ccg._correlate ccg._correlate(ccg._spike_time, ccg._clu.index)
idx = app.model.clu[26].index[3]
def testNumpy():
    for j in range(5):
        a = np.zeros(30150587,dtype='int64')
    
def testScipy():
    t = sparse.lil_matrix((1,30150587), dtype='int64')
    t[0, idx] = 1
%time testNumpy()
idx[(idx>1000)&((idx<1002))]
%time np.array([])
%time a = np.zeros(30150587,dtype='int64')
import sys
sys.getsizeof(a)
%time a.fill(2)
import multiprocessing.dummy as mp
%time mp.Pool()
%lprun -f mp.pool.Pool mp.pool.Pool()
np.correlate([0,0,1,0,0,0,1,0,0,1,0,0],[1,0,0,0,1,0,0,0,1,0,0,0],'same')<jupyter_output><empty_output><jupyter_text>测试下phy的ccg<jupyter_code>from phy.stats import correlograms
times = app.model.spktag.t[app.model.spktag.ch==26]
clusters = app.model.clu[26].membership
ids = app.model.clu[26].index_id
ids
%time correlograms(times/25e3, clusters, sample_rate=25e3,bin_size=1e-3, window_size=5e-2)[1][1]
times
clusters
correlograms(times/25e3, clusters, sample_rate=25e3,bin_size=1e-3, window_size=5e-2).shape
app.view.correlogram_view._render()
app.model.clu[26].membership
selected = np.in1d(app.model.clu[26].membership, np.array([1,3]))
app.model.clu[26].membership[selected].shape
app.model.clu[26].index_count
(np.array([1,2]) == np.array([1,2])).all()
app.view.correlogram_view._render(clus = np.array([1,2]))

(np.array([1,2]) == np.array([1,2])).all()
np.array([1,2]) == app.view.correlogram_view._clu.index_id
app.view.correlogram_view._correlogram(np.array([1,2]))
np.random.random([2,2])
import os.path as op
op.join('../../','name')
app.view.gui.state.path
op.pardir
import os
os.getcwd()
os.path.dirname(os.path.abspath('__file__'))
op.expanduser('/')
%pwd
os.path.abspath(os.path.join(os.path.dirname("__file__"),os.path.pardir,os.path.pardir))
%ls
os.path.dirname("__file__")
op.dirname(op.abspath(op.expanduser('../..')))
%pwd
op.dirname(op.abspath(op.expanduser(dat_path))
os.getcwd()
os.path.split(os.getcwd())
os.path.abspath(os.curdir)



os.path.abspath('.')
os.getcwd()
os.path.splitdrive(os.getcwd())
path = ''
for fn in os.getcwd().split(os.path.sep):
    if len(fn) == 0:
        path = os.path.join(os.path.sep, path)
    else:
        path = os.path.join(path, fn)
    
    if fn == 'spiketag':
        break

path = os.path.join(path, 'spiketag/res')
path
    
os.getcwd()
os.path.join('/','U','B')
path
correlate(np.array([1,3,5,10,11]),np.array([1,0,1,0,1]),cluster_ids=np.array([0,1]), window_bins=2, bin_size=2, fs=1e3)
a = np.array(([[0, 0, 0],
        [1, 0, 2]],

       [[2, 0, 1],
        [0, 0, 0]]))
np.array_equal(a,correlate(np.array([1,3,5,10,11]),np.array([1,0,1,0,1]),cluster_ids=np.array([0,1]), window_bins=2, bin_size=2, fs=1e3))
correlograms(times/25e3, clusters, sample_rate=25e3,bin_size=1e-3, window_size=5e-2)
from spiketag.core import correlate
correlate(np.array([2, 3, 10, 12, 20, 24, 30, 40]),np.array([0, 1, 0, 0, 2, 1, 0, 2]),np.array([0,1,2]),fs=1, window_bins=6,bin_size=1e3)
correlograms(np.array([2, 3, 10, 12, 20, 24, 30, 40]),np.array([0, 1, 0, 0, 2, 1, 0, 2]),np.array([0,1,2]), window_size=7,bin_size=1)
%time correlate(times,clusters,ids,bin_size=1,window_bins=50).shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20164932259964657, 'fraction_numerical': 0.0636167288435107, 'mean_word_length': 5.782956058588549, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '541893', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2465, 'n_tokens_neox': 2316, 'n_words': 315, 'path': 'spiketag/view/tests/TestCCGView.ipynb', 'repo_name': 'aliddell/spiketag', 'size': '5093'}