<jupyter_start><jupyter_text>Making Monkey Breads: Chibi  (20120802)<jupyter_code>from SpectralCV import ecog_pipe as ep
import numpy as np
import scipy as sp
import scipy.io as io
import scipy.signal as sig
import math as math
import random 
from scipy import integrate
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline
#grab data path
data_path ="\\Users\\Lauren\\Data\\NeuroTycho\\20120802PF_Anesthesia+and+Sleep_Chibi_Toru+Yanagawa_mat_ECoG128\\Session%d\\"
monkeyChan = 129<jupyter_output><empty_output><jupyter_text>Setting up the Dough<jupyter_code>cond = 5 #amount of slices (thickness)
chan = monkeyChan #height of bread
data = ep.getECoGdata(data_path, 1, 1) 
f_axis, f_time, spg = sig.spectrogram(data, fs=1000., nperseg=1000, noverlap=500)
frequency = len(f_axis)
bread = np.zeros((cond, chan, frequency))
def getFreq(data, fs, nperseg, noverlap):
    f_axis, f_time, spg = sig.spectrogram(data, fs=fs, nperseg=fs, noverlap=fs)
    return len(f_axis)
# session 1
for i in range(1,monkeyChan):
    #grabbing session 1 channel i
    data = ep.getECoGdata(data_path, 1, i)
    #grabbing TimeFile from session 1 to set the indices for each condition
    tf1 = ep.getTimeFile(data_path, 1)    
    # AwakeEyesOpened
    s1start1 = ep.getStart(tf1, 0)
    s1end1 = ep.getEnd(tf1, 1)
    s1SP1 = ep.getSP(data, s1start1, s1end1, 1000, 1000, 500)
    bread[0][i-1][:] = ep.scv(s1SP1)
    #AwakeEyesClosed
    s1start2 = ep.getStart(tf1, 2)
    s1end2 = ep.getEnd(tf1, 3)
    s1SP2 = ep.getSP(data, s1start2, s1end2, 1000, 1000, 500)
    bread[1][i-1][:] =ep.scv(s1SP2)
# session 2
for i in range(1,monkeyChan):
    #grabbing session 2 channel i
    data = ep.getECoGdata(data_path, 2, i)
    #grabbing TimeFile from session 2 to set the indices for each condition
    tf2 = ep.getTimeFile(data_path, 2)    
    #Anesthetized-Start
    s2start1 = ep.getStart(tf2, 1)
    s2end1 = ep.getEnd(tf2, 2)
    s2SP1 = ep.getSP(data, s2start1, s2end1, 1000, 1000, 500)
    bread[2][i-1][:] = ep.scv(s2SP1)
    #RecoveryEyesClosed
    s2start2 = ep.getStart(tf2, 3)
    s2end2 = ep.getEnd(tf2, 4)
    s2SP2 = ep.getSP(data, s2start2, s2end2, 1000, 1000, 500)
    bread[3][i-1][:] = ep.scv(s2SP2)
# session 3
for i in range(1,monkeyChan):
    #grabbing session 3 channel i
    data = ep.getECoGdata(data_path, 3, i)
    #grabbing TimeFile from session 3 to set the indices for each condition
    tf3 = ep.getTimeFile(data_path, 3)    
    # RecoveryEyesOpened
    s3start = ep.getStart(tf3, 0)
    s3end = ep.getEnd(tf3, 1)
    s3SP = ep.getSP(data, s3start, s3end, 1000, 1000, 500)
    bread[4][i-1][:] = ep.scv(s3SP)
con1 = ep.conditionInfo(ep.getTimeFile(data_path, 1))[0][:ep.conditionInfo(ep.getTimeFile(data_path, 1))[0].find('-')]
con2 = ep.conditionInfo(ep.getTimeFile(data_path, 1))[2][:ep.conditionInfo(ep.getTimeFile(data_path, 1))[2].find('-')]
con3 = ep.conditionInfo(ep.getTimeFile(data_path, 2))[1][:ep.conditionInfo(ep.getTimeFile(data_path, 2))[1].find('-')]
con4 = ep.conditionInfo(ep.getTimeFile(data_path, 2))[3][:ep.conditionInfo(ep.getTimeFile(data_path, 2))[3].find('-')]
con5 = ep.conditionInfo(ep.getTimeFile(data_path, 3))[0][:ep.conditionInfo(ep.getTimeFile(data_path, 3))[0].find('-')]
labels = [con1,con2,con3,con4,con5]
num = np.arange(0,5)
att = dict(zip(labels,num))
att<jupyter_output><empty_output><jupyter_text>Baking Bread<jupyter_code>#create h5py path to chibi bread
import h5py
scvh5 = h5py.File('scv.h5', 'w')
monkey = scvh5.create_group("monkey")
chibi = monkey.create_dataset('chibiPF0802', data=bread)
scvh5.close()<jupyter_output><empty_output><jupyter_text>Load the Loaf<jupyter_code>import matplotlib.pyplot as plt
import h5py
#load data from h5 
h5_file = '../Voytek/scv.h5'
# plotting
with h5py.File(h5_file, 'r') as h5:
    chibiBread = h5['monkey/chibiPF0802']
    #print(chibiBread.shape)
    for i in range(5):
        plt.figure(i+1)
        plt.loglog(chibiBread[i][:][:].T)
plt.show()
def createLess(bread, dict_name,  breadSlice):
    for c in range(128):
        for i in range(bread[breadSlice][1].size): #range size of the data
            if bread[breadSlice][c][i] < 1:
                if c not in list(dict_name.keys()):
                    chan = c+1
                    dict_name[chan] = 1
                else:
                    chan = c+1
                    print(dict_name.get(chan))
                    #dict_name[chan] = dict_name.get(chan) + 1
s1con1_dict = {}
with h5py.File(h5_file, 'r') as h5:
    chibiBread = h5['monkey/chibiPF0802']
    ep.createLess(chibiBread, s1con1_dict, 0)
print(s1con1_dict)
s1con2_dict = {}
with h5py.File(h5_file, 'r') as h5:
    chibiBread = h5['monkey/chibiPF0802']
    ep.createLess(chibiBread,s1con2_dict,1)
print(s1con2_dict)
s2con1_dict = {}
with h5py.File(h5_file, 'r') as h5:
    chibiBread = h5['monkey/chibiPF0802']
    ep.createLess(chibiBread, s2con1_dict, 2)
print(s2con1_dict)
s2con2_dict = {}
with h5py.File(h5_file, 'r') as h5:
    chibiBread = h5['monkey/chibiPF0802']
    ep.createLess(chibiBread, s2con2_dict, 3)
print(s2con2_dict)
s3_dict = {}
with h5py.File(h5_file, 'r') as h5:
    chibiBread = h5['monkey/chibiPF0802']
    ep.createLess(chibiBread, s3_dict, 4)
print(s3_dict)
with h5py.File(h5_file, 'r') as h5:
    chibiBread = h5['monkey/chibiPF0802']
    print(chibiBread.shape)
    #for i in range(5):
        #print(chibiBread[i][0][:])
        #plt.loglog(chibiBread[i][0][:].T)<jupyter_output>(5, 129, 501)
{'fraction_non_alphanumeric': 0.14306596016809794, 'fraction_numerical': 0.06468116206833546, 'mean_word_length': 4.08263695450325, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '82384', 'license': 'MIT', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2301, 'n_words': 450, 'path': 'old_code/individual_notes/chibiBread20120802.ipynb', 'repo_name': 'voytekresearch/sca', 'size': '5473'}