def connecting_to_pkl(pkl_name, lvm_filepath): cue_pkl_file = open(pkl_name, 'rb') ori = pkl.load(cue_pkl_file) odor1, odor2, lick, pump, action, airpuff, laser = make_list(lvm_filepath) print(sum(laser)) dlaser = np.array(diff(laser)) print(sum(np.abs(dlaser))) odor1_lick, odor2_lick = make_gonogolick(odor1, odor2, lick, delay=200) odor1_action, odor1_airpuff, odor1_pump, odor1_laser, odor2_action, odor2_airpuff, odor2_pump, odor2_laser = div_by_odor( odor1, odor2, action, airpuff, pump, laser, delay=200) lasers = 0 for i in range(np.alen(odor1_laser[:, 1])): if np.sum(odor1_laser[i, 0:200]) > 10: lasers += 1 for i in range(np.alen(odor2_laser[:, 1])): if np.sum(odor2_laser[i, 200]) > 10: lasers += 1 print(lasers) print(np.sum(odor1_laser)) print(np.sum(odor2_laser)) odor1_lick = np.delete(odor1_lick, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor2_lick = np.delete(odor2_lick, [0, 1], 0) odor1_action = np.delete(odor1_action, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor1_airpuff = np.delete(odor1_airpuff, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor1_pump = np.delete(odor1_pump, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor1_laser = np.delete(odor1_laser, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor2_action = np.delete(odor2_action, [0, 1], 0) odor2_airpuff = np.delete(odor2_airpuff, [0, 1], 0) odor2_pump = np.delete(odor2_pump, [0, 1], 0) odor2_laser = np.delete(odor2_laser, [0, 1], 0) print("1") ori['odor1_lick'] = np.vstack((ori['odor1_lick'], odor1_lick)) ori['odor2_lick'] = np.vstack((ori['odor2_lick'], odor2_lick)) ori['odor1_action'] = np.vstack((ori['odor1_action'], odor1_action)) ori['odor1_airpuff'] = np.vstack((ori['odor1_airpuff'], odor1_airpuff)) ori['odor1_pump'] = np.vstack((ori['odor1_pump'], odor1_pump)) ori['odor1_laser'] = np.vstack((ori['odor1_laser'], odor1_laser)) ori['odor2_action'] = np.vstack((ori['odor2_action'], odor2_action)) ori['odor2_airpuff'] = np.vstack((ori['odor2_airpuff'], odor2_airpuff)) ori['odor2_pump'] = np.vstack((ori['odor2_pump'], odor2_pump)) ori['odor2_laser'] = np.vstack((ori['odor2_laser'], odor2_laser)) tr, ti = np.shape(ori['odor1_lick']) ntr, nti = np.shape(ori['odor2_lick']) out_file = open(pkl_name, 'wb') pkl.dump(ori, out_file) out_file.close() cue_pkl_file.close() print("3") print(lvm_filepath + " has been added ! now whole odor1 trial number is " + str(tr) + '. odor2 tn is ' + str(ntr)) return pkl_name
exname = "Raster_of_" + name + ".png" savepath = "figures/raster" saved_filelist = os.listdir(savepath) if exname in saved_filelist: print("this raster is exist already! Skip" + raw_file) continue print(name) if name in saved_files: print("already exist, skip " + name) continue number, jieduan, day, godor, Hz, *_ = raw_file.split("_") odor1, odor2, lick, pump, action, airpuff, laser = make_list(filename) odor1_lick,odor2_lick = make_gonogolick(odor1,odor2,lick,delay=200) odor1_action, odor1_airpuff, odor1_pump, odor1_laser, odor2_action, odor2_airpuff, odor2_pump, odor2_laser = div_by_odor(odor1,odor2,action,airpuff,pump,laser,delay=200) # odor1 / odor2_lick_laser/nolaser # odor1 / odor2_action_laser/nolaser tr,ti = np.shape(odor1_lick) tr2, ti2 = np.shape(odor2_lick) i = 0 for j in range(tr): while i < ti: try: if odor1_lick[j][i] == 1: odor1_lick[j][i + 1] = 1 odor1_lick[j][i + 2] = 1 odor1_lick[j][i + 3] = 1
sys.path.append("C:/Users/manggny/PycharmProjects/Project-pre/func") import matplotlib.pyplot as plt from go.funcs import make_list from go.funcs import make_gonogolick, raster path = "C:/Users/manggny/Desktop/expdata/block" file1 = "#3_gonogonolaser_d5_odor2_1.lvm" nolaser_file = path + '/' + file1 file2 = "#3_gonogolaser_d5_odor2_1.lvm" laser_file = path + '/' + file2 number, jieduan, day, godor, Hz, *_ = file1.split("_") odor1, odor2, lick, pump, action, airpuff, laser = make_list(nolaser_file) lodor1, lodor2, llick, lpump, laction, lairpuff, llaser = make_list(laser_file) print(file1 + " and " + file2) laser_odor1_lick, laser_odor2_lick = make_gonogolick(lodor1, lodor2, llick) nolaser_odor1_lick, nolaser_odor2_lick = make_gonogolick(odor1, odor2, lick) tr1, ti1 = numpy.shape(laser_odor1_lick) tr2, ti2 = numpy.shape(laser_odor2_lick) ntr1, nti1 = numpy.shape(nolaser_odor1_lick) ntr2, nti2 = numpy.shape(nolaser_odor2_lick) print(sum(llaser)) print("laser licks:") print("odor1: %f\nodor2: %f" % (numpy.sum(laser_odor1_lick[0:int(tr1 / 2), :]), numpy.sum(laser_odor2_lick[0:int(tr2 / 2), :]))) print("no-laser licks:") print("odor1: %f\nodor2: %f" % (numpy.sum(nolaser_odor1_lick[int(ntr1 / 2):int(ntr1), :]), numpy.sum(nolaser_odor2_lick[int(ntr2 / 2):int(ntr2), :])))
def make_lvm_to_pkl(lvm_filepath): resultpath = 'F:/ACC-Camk2/0109~gonogo/gonogopkl' a = lvm_filepath.split('/') filename = a[-1] #print(filename) name, *_ = filename.split('.') result_filename = name + '.pkl' files = os.listdir(resultpath) if result_filename in files: print(result_filename + " is already exist! skip~") return resultpath + '/' + name + '.pkl' #print(name) odor1, odor2, lick, pump, action, airpuff, laser = make_list(lvm_filepath) print(sum(laser)) dlaser = np.array(diff(laser)) print(sum(np.abs(dlaser))) odor1_lick, odor2_lick = make_gonogolick(odor1, odor2, lick, delay=200) #print(np.sum(odor1_lick)) odor1_action, odor1_airpuff, odor1_pump, odor1_laser, odor2_action, odor2_airpuff, odor2_pump, odor2_laser = div_by_odor( odor1, odor2, action, airpuff, pump, laser, delay=200) # lasers = 0 # for i in range(np.alen(odor1_laser[:,1])): # if np.sum(odor1_laser[i,0:200]) > 10: # lasers += 1 # for i in range(np.alen(odor2_laser[:,1])): # if np.sum(odor2_laser[i,0:200]) > 10: # lasers += 1 print(np.sum(odor1_laser)) print(np.sum(odor2_laser)) # print(np.sum(np.abs(np.diff(odor1_laser)))) # print(np.sum(np.abs(np.diff(odor2_laser)))) tr, ti = np.shape(odor1_lick) #print(tr, ti) odor1_lick = np.delete(odor1_lick, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor2_lick = np.delete(odor2_lick, [0, 1], 0) odor1_action = np.delete(odor1_action, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor1_airpuff = np.delete(odor1_airpuff, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor1_pump = np.delete(odor1_pump, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor1_laser = np.delete(odor1_laser, [0, 1, 2, 3, 4, 5, 6, 7], 0) odor2_action = np.delete(odor2_action, [0, 1], 0) odor2_airpuff = np.delete(odor2_airpuff, [0, 1], 0) odor2_pump = np.delete(odor2_pump, [0, 1], 0) odor2_laser = np.delete(odor2_laser, [0, 1], 0) result_dict = { 'odor1_lick': odor1_lick, 'odor2_lick': odor2_lick, 'odor1_action': odor1_action, 'odor1_airpuff': odor1_airpuff, 'odor1_pump': odor1_pump, 'odor1_laser': odor1_laser, 'odor2_action': odor2_action, 'odor2_airpuff': odor2_airpuff, 'odor2_pump': odor2_pump, 'odor2_laser': odor2_laser } result_filename = resultpath + '/' + name + '.pkl' output = open(result_filename, 'wb') pkl.dump(result_dict, output) #print(result_dict.items()) output.close() return result_filename
print( "================================================ start =======================================" ) filename = path + "/" + raw_file name, _ = raw_file.split(".") print(name) if name in saved_files: print("already exist, skip " + name) continue number, jieduan, day, godor, Hz, *_ = raw_file.split("_") odor1, odor2, lick, pump, action, airpuff, laser = make_list(filename) odor1_lick, odor2_lick = make_gonogolick(odor1, odor2, lick) odor1_action, odor1_airpuff, odor1_pump, odor1_laser, odor2_action, odor2_airpuff, odor2_pump, odor2_laser = div_by_odor( odor1, odor2, action, airpuff, pump, laser) odor1_action_laser, odor1_action_nolaser = div_by_laser( odor1_action, odor1_laser) odor1_lick_laser, odor1_lick_nolaser = div_by_laser( odor1_lick, odor1_laser) odor2_action_laser, odor2_action_nolaser = div_by_laser( odor2_action, odor2_laser) odor2_lick_laser, odor2_lick_nolaser = div_by_laser( odor2_lick, odor2_laser) # odor1 / odor2_lick_laser/nolaser # odor1 / odor2_action_laser/nolaser tr, ti = np.shape(odor1_lick) tr2, ti2 = np.shape(odor2_lick)