<jupyter_start><jupyter_text>Get the tetrode depths for the sessions & the cluster information<jupyter_code>an = 'Li'
seTTInfo = pd.read_csv(str(oakPaths['Clustered'] / (an + '_SeTTInfo.csv' )),dtype={'Dates':str})
seTTInfo=seTTInfo.set_index('Dates')

CT_Path =  oakPaths['Clustered'] / an / (an+'_ClusteringSummary.json')
with CT_Path.open() as f:
    CT = json.load(f)<jupyter_output><empty_output><jupyter_text>Match the sessions based on the tetrode depth [for each tetrode]<jupyter_code>matchDepth = {}

for tt in np.arange(1,17):
    matchDepth[tt] = pd.DataFrame(0,columns=seTTInfo.index,index=seTTInfo.index)
    for d1 in seTTInfo.index:
        for d2 in seTTInfo.index:
            if d2>=d1:
                depth1 = seTTInfo.loc[d1,'depth_tt'+str(tt)]
                depth2 = seTTInfo.loc[d2,'depth_tt'+str(tt)]
                if depth1==depth2:
                    matchDepth[tt].loc[d1,d2] = 1

sns.heatmap(matchDepth[4])
an = 'Li'
task = 'T3g'
date = '052818'
se = '{}_{}_{}'.format(an,task,date)
AT = reload(AT)
if 
seDat[task] = AT.loadSessionData(sePaths[se],vars = ['wfi','ids'])
#if np.sum(seDates.loc[date,tasks]>0)>1
date = '052818'
nTotalUnits = seDates.loc[date,tasks].sum()
seDat = {}
seDatIndo = pd.DataFrame(index=np.arange(nTotalUnits),columns=['an','task','date','tt','cl','unitType','mFR','cv'])
for t in tasks:
    se = '{}_{}_{}'.format(an,t,date)
    if seDates.loc[date,t]>0:
        seDat[t] = AT.loadSessionData(sePaths[se],vars = ['wfi'])

nFeats = 64*4
n
seDat['OF']['wfi']['Cell'][0]['tstat'].T.flatten()
unitIDs
def wfi2mat(wfi):
    nUnits = len(wfi.keys())
    nF = 64*4
    mat = np.zeros((nUnits,nF))
    for cell in wfi.keys():
        #mat[cell] = np.array((wfi[cell]['mean'].T.flatten(),wfi[cell]['tstat'].T.flatten())).flatten()
        mat[cell] = wfi[cell]['mean'].T.flatten()
    return mat

Mc = {}
Mm = {}
for task,seInfo in CT[an][date].items():
    Mc[task] = wfi2mat(seDat[task]['wfi']['Cell'])
    Mm[task] = wfi2mat(seDat[task]['wfi']['Mua'])
def corr2_coeff(A,B):
    # Rowwise mean of input arrays & subtract from input arrays themeselves
    A_mA = A - A.mean(1)[:,None]
    B_mB = B - B.mean(1)[:,None]

    # Sum of squares across rows
    ssA = (A_mA**2).sum(1);
    ssB = (B_mB**2).sum(1);

    # Finally get corr coeff
    return np.dot(A_mA,B_mB.T)/np.sqrt(np.dot(ssA[:,None],ssB[None]))
Mc_corr = corr2_coeff(Mc['OF'],Mc['T3g'])
Mc_corr
M=stats.spearmanr(Mc['OF'],Mc['T3g'],axis=1)[0][]
#M=stats.pearsonr(Mc['OF'],Mc['T3g'],axis=1)[0]
M
M[0:4,4:]
seDat[task]['wfi']['Cell'][0].keys()
x=pd.DataFrame(columns=['xx'])
x.loc[0,'xx']=1
x.loc[1,'xx']=2
x
f,ax = plt.subplots(2,1,figsize=(6,10))

nUnits = seDates.loc[date][task]

for 
PF.plotSpikeWFs(seDat[task]['wfi']['Cell'][0],ax=ax[0])
PF.plotISIh(seDat[task]['wfi']['Cell'][0],ax=ax[1])

ax[0].set_title('se:{}, tt:{}, cl:{}, uT: {}, uID: {}'.format(se,tt,cl,uT, uID))
import scipy.stats as stats

M=stats.spearmanr(Mc['T3g'],Mc['OF'],axis=1)
sns.heatmap(M[0])
sns.heatmap(stats.spearmanr(Mc['OF'].T)[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.225130890052356, 'fraction_numerical': 0.02650523560209424, 'mean_word_length': 4.7679245283018865, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '661353', 'license': 'MIT', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1328, 'n_words': 195, 'path': 'Notebooks/match_clusters_dev.ipynb', 'repo_name': 'alexgonzl/TreeMazeAnalyses', 'size': '3056'}