Lev
2 years ago
18 changed files with 22174 additions and 165 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 568 KiB |
File diff suppressed because one or more lines are too long
@ -0,0 +1,43 @@
|
||||
import numpy as np |
||||
import pandas as pd |
||||
|
||||
|
||||
|
||||
data_folder = "../data/" |
||||
stim_file = "Stiminfo_PVCre_2021_0012_s06_e14.csv" |
||||
# Stimulus DataFrame |
||||
stim = pd.read_csv(data_folder+stim_file) |
||||
num_trial = len(stim) |
||||
stim_val = {} |
||||
trial_stim_id = {} |
||||
stim_val['pair'], trial_stim_id['pair'] = np.unique(stim[['grat_orientation', 'grat_phase']], return_inverse=True, axis=0) # 50 trials per orientation-phase pair |
||||
stim_val['orientation'], trial_stim_id['orientation'] = np.unique(stim['grat_orientation'], return_inverse=True) # 1000 trials per orientation |
||||
stim_val['phase'], trial_stim_id['phase'] = np.unique(stim['grat_phase'], return_inverse=True) # 1000 trials per phase |
||||
key_list = ['pair', 'orientation', 'phase'] |
||||
stim_id_trial = {} |
||||
num_stim = {} |
||||
for key in key_list: |
||||
stim_id_trial[key] = [np.where(trial_stim_id[key] == i)[0] for i in range(len(stim_val[key]))] |
||||
num_stim[key] = len(stim_val[key]) |
||||
|
||||
# stim_id_trial[i] returns an array of trial indices where the stimulus has the value of the ith stimulus. |
||||
def pair_id(i): |
||||
return (int(i//num_stim['orientation']), i%num_stim['orientation']) |
||||
|
||||
trial_pair_id = np.array([pair_id(i) for i in trial_stim_id['pair']], dtype=object) |
||||
pair_val = stim_val['pair'].reshape(num_stim['orientation'], num_stim['phase'],2) |
||||
|
||||
# for each (orientation_id = i, phase_id = j) find the trial indices |
||||
pair_trial_id = np.ndarray((num_stim['orientation'], num_stim['phase']), dtype=object) |
||||
for i in range(num_stim['pair']): |
||||
pair_trial_id[pair_id(i)] = stim_id_trial['pair'][i] |
||||
|
||||
# s.close() |
||||
|
||||
stim_data = {'stim_val':stim_val, 'trial_stim_id':trial_stim_id, 'key_list':key_list, 'num_trial':num_trial, |
||||
'trial_pair_id':trial_pair_id, 'pair_val':pair_val, 'pair_trial_id':pair_trial_id, 'stim_id_trial':stim_id_trial, 'num_stim':num_stim} |
||||
|
||||
import pickle |
||||
file = open('stim_data.pkl', 'wb') |
||||
pickle.dump(stim_data, file) |
||||
file.close() |
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -0,0 +1,44 @@
|
||||
import pandas as pd |
||||
import numpy as np |
||||
import pickle as pkl |
||||
|
||||
data_folder = "../data/" |
||||
|
||||
stim_file = "Stiminfo_PVCre_2021_0012_s06_e14.csv" |
||||
stim = pd.read_csv(data_folder+stim_file) |
||||
|
||||
spike_times_file = "Spiketimes_PVCre_2021_0012_s06_e14.npy" |
||||
spike_times = np.load(data_folder+spike_times_file, allow_pickle=True) |
||||
active = [len(spike_times[i]) > 0 for i in range(len(spike_times))] |
||||
spike_times = spike_times[np.where(active)] |
||||
|
||||
num_unit = len(spike_times) |
||||
num_trial = len(stim) |
||||
|
||||
# sort by firing rate |
||||
|
||||
num_spike = list(map(len, spike_times)) |
||||
# num_spike = np.array([len(spike_times[i]) for i in range(len(spike_times))]) |
||||
spike_times = spike_times[np.argsort(num_spike)[::-1]] |
||||
|
||||
files = ['stim_data.pkl', 'spike_data.pkl', 'corr_data.pkl'] |
||||
for file_name in files: |
||||
print(file_name) |
||||
file = open(file_name, 'rb') |
||||
data = pkl.load(file) |
||||
print(data.keys()) |
||||
for key, value in data.items(): |
||||
globals()[key] = value |
||||
|
||||
file.close() |
||||
|
||||
def pkl_save(filename:str, object:object): |
||||
file = open(filename+'.pkl', 'wb') |
||||
pkl.dump(object, file, pkl.HIGHEST_PROTOCOL) |
||||
file.close() |
||||
|
||||
def pkl_load(filename:str): |
||||
file = open(filename+'.pkl', 'rb') |
||||
a = pkl.load(file) |
||||
file.close() |
||||
return a |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue