def shuffle_analysis(stopsdata, trialids): # Calculate stop rate for each section of the track srbin = create_srdata(stopsdata, trialids) # Array(BINNR, trialnum) srbin_mean = np.mean(srbin, axis=0) # Array(BINNR) srbin_std = np.std(srbin, axis=0) # Array(BINNR) return srbin_mean, srbin_std
#filterstops stops_b = filterstops(stops_b) stops_nb = filterstops(stops_nb) stops_p = filterstops(stops_p) # get first stop for each trial trarray = np.arange(np.min(saraharray[:, 9]), np.max(saraharray[:, 9] + 0.1), 1) # array of trial numbers beac = [] nbeac = [] probe = [] # make empty arrays to store data trialids_b = np.unique(stops_b[:, 2]) # find unique trial numbers stops_f_b = FirstStops( trarray, stops_b) # get locations of first stop for each trial stops_f_b = create_srdata(stops_f_b, trialids_b) # bin first stop data beac = np.nanmean( stops_f_b, axis=0) # average times mouse stops first in each bin if stops_nb.size > 0: trialids_nb = np.unique(stops_nb[:, 2]) stops_f_nb = FirstStops( trarray, stops_nb) # get locations of first stop for each trial stops_f_nb = create_srdata(stops_f_nb, trialids_nb) # bin first stop data nbeac = np.nanmean( stops_f_nb, axis=0) # average times mouse stops first in each bin if stops_p.size > 0: trialids_p = np.unique(stops_p[:, 2]) stops_f_p = FirstStops(
#reassign trial number if dcount >0: trialno_b =np.amax(stops_b[:, 2]) stops_b[:, 2] += b b +=trialno_b stopsdata_b = np.vstack((stopsdata_b, stops_b)) if stops_p.size >0: trialno_p =np.amax(stops_p[:, 2]) stops_p[:, 2] += p p +=trialno_p stopsdata_p = np.vstack((stopsdata_p, stops_p)) dcount +=1 trialids_b = np.unique(stops_b[:, 2]) data_b = create_srdata( stops_b, trialids_b ) beac = np.nansum(data_b, axis = 0)/trialids_b.shape[0] if stops_p.size>0: trialids_p = np.unique(stops_p[:, 2]) # get stopping data data_p = create_srdata( stops_p, trialids_p ) probe = np.nansum(data_p, axis = 0)/trialids_p.shape[0] print('##...', mcount,day, '...##') # store data if mcount == 0 or mcount == 2 or mcount == 3 or mcount == 9: loc = np.argmax(beac[3:17]) control_b[mcount] = loc+3 loc = np.argmax(probe[3:17]) control_p[mcount] = loc+3 print(loc, 'loc')
mean = (np.nanmean(timedata[:, 0])) - 3 SD = np.nanstd(timedata[:, 0]) CV = SD / mean var[mcount, 0] = CV var[mcount, 1] = mean var[mcount, 2] = SD mean = np.nanmean(timedata[:, 1]) SD = np.nanstd(timedata[:, 1]) CV = SD / mean var[mcount, 3] = CV var[mcount, 4] = mean var[mcount, 5] = SD #data for example plots if mcount == 5: m5 = datastore stops = create_srdata(datastore, trialids) avg_stops = np.nanmean(stops, axis=0) allstops[mcount, :] = avg_stops mcount += 1 # TASK 12 # IMPORT DATA filename = 'Data_Input/Behaviour_DataFiles/Task12_0600.h5' # SPECIFY MICE days = ['Day' + str(int(x)) for x in np.arange(15, 27.1)] mice = ['M' + str(int(x)) for x in np.arange(1, 9.1)] # choose specific day/s # Stores quartiles1 = np.zeros((len(mice), 4, 2))
def plot_fig1D(session_paths, save_path): days = [1] n_bins = 20 # specify mouse/mice and day/s to analyse days = ['Day' + str(int(x)) for x in np.arange(1)] # Arrays for storing data (output) firststopstorebeac = np.zeros((len(days), len(session_paths), n_bins, 2)) firststopstorenbeac = np.zeros((len(days), len(session_paths), n_bins, 2)) firststopstoreprobe = np.zeros((len(days), len(session_paths), n_bins, 2)) firststopstorebeac[:, :, :, :] = np.nan firststopstorenbeac[:, :, :, :] = np.nan firststopstoreprobe[:, :, :, :] = np.nan # For each day and mouse, pull raw data, calculate first stops and store data for dcount, day in enumerate(days): session_count = 0 for session_path in session_paths: saraharray, track_start, track_end = translate_to_legacy_format( session_path) rz_start = saraharray[0, 11] rz_end = saraharray[0, 12] # make array of trial number for each row in dataset trialarray = maketrialarray( saraharray) # write array of trial per row in datafile saraharray[:, 9] = trialarray[:, 0] # replace trial column in dataset *see README for why this is done* # split data by trial type dailymouse_b = np.delete(saraharray, np.where(saraharray[:, 8] > 0), 0) dailymouse_nb = np.delete(saraharray, np.where(saraharray[:, 8] != 10), 0) dailymouse_p = np.delete(saraharray, np.where(saraharray[:, 8] != 20), 0) # get stops stops_b = extractstops_HUMAN(dailymouse_b) stops_nb = extractstops_HUMAN(dailymouse_nb) stops_p = extractstops_HUMAN(dailymouse_p) #filterstops stops_b = filterstops(stops_b) stops_nb = filterstops(stops_nb) stops_p = filterstops(stops_p) # get first stop for each trial trarray = np.arange(np.min(saraharray[:, 9]), np.max(saraharray[:, 9] + 0.1), 1) # array of trial numbers beac = [] nbeac = [] probe = [] # make empty arrays to store data trialids_b = np.unique(stops_b[:, 2]) # find unique trial numbers stops_f_b = FirstStops_humans( trarray, stops_b, track_start, track_end) # get locations of first stop for each trial stops_f_b = create_srdata(stops_f_b, trialids_b) # bin first stop data beac = np.nanmean( stops_f_b, axis=0) # average times mouse stops first in each bin if stops_nb.size > 0: trialids_nb = np.unique(stops_nb[:, 2]) stops_f_nb = FirstStops_humans( trarray, stops_nb, track_start, track_end) # get locations of first stop for each trial stops_f_nb = create_srdata(stops_f_nb, trialids_nb) # bin first stop data nbeac = np.nanmean( stops_f_nb, axis=0) # average times mouse stops first in each bin if stops_p.size > 0: trialids_p = np.unique(stops_p[:, 2]) stops_f_p = FirstStops_humans( trarray, stops_p, track_start, track_end) # get locations of first stop for each trial stops_f_p = create_srdata(stops_f_p, trialids_p) # bin first stop data probe = np.nanmean( stops_f_p, axis=0) # average times mouse stops first in each bin # store data #if mcount == 3 or mcount == 5 or mcount == 6 or mcount == 7 or mcount == 8: firststopstorebeac[dcount, session_count, :, 0] = beac # store first stop data srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3( stops_b, trialids_b) # get average stops per location bin firststopstorebeac[dcount, session_count, :, 1] = srbin_mean # store stops data if stops_nb.size > 0: firststopstorenbeac[dcount, session_count, :, 0] = nbeac # store first stop data srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3( stops_nb, trialids_nb) # get average stops per location bin firststopstorenbeac[dcount, session_count, :, 1] = srbin_mean # store stops data if stops_p.size > 0: firststopstoreprobe[dcount, session_count, :, 0] = probe # store first stop data srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3( stops_p, trialids_p) # get average stops per location bin firststopstoreprobe[dcount, session_count, :, 1] = srbin_mean # store stops data session_count += 1 # Average over days for all mice # week 1 (first stop) con_beac_w1 = np.nanmean(((firststopstorebeac[0, :, :, 0])), axis=0) con_nbeac_w1 = np.nanmean(((firststopstorenbeac[0, :, :, 0])), axis=0) con_probe_w1 = np.nanmean(((firststopstoreprobe[0, :, :, 0])), axis=0) sd_con_beac_w1 = np.nanstd( ((firststopstorebeac[0, :, :, 0])), axis=0) / math.sqrt(session_count) sd_con_nbeac_w1 = np.nanstd( ((firststopstorenbeac[0, :, :, 0])), axis=0) / math.sqrt(session_count) sd_con_probe_w1 = np.nanstd( ((firststopstoreprobe[0, :, :, 0])), axis=0) / math.sqrt(session_count) # week 1 (all stops) con_beac1_w1 = np.nanmean(((firststopstorebeac[0, :, :, 1])), axis=0) con_nbeac1_w1 = np.nanmean(((firststopstorenbeac[0, :, :, 1])), axis=0) con_probe1_w1 = np.nanmean(((firststopstoreprobe[0, :, :, 1])), axis=0) sd_con_beac1_w1 = np.nanstd( ((firststopstorebeac[0, :, :, 1])), axis=0) / math.sqrt(session_count) sd_con_nbeac1_w1 = np.nanstd( ((firststopstorenbeac[0, :, :, 1])), axis=0) / math.sqrt(session_count) sd_con_probe1_w1 = np.nanstd( ((firststopstoreprobe[0, :, :, 1])), axis=0) / math.sqrt(session_count) ''' # week 4 (first stop) con_beac_w4 = np.nanmean(np.nanmean(((firststopstorebeac[18:22,:,:,0])), axis = 0), axis = 0) con_nbeac_w4 = np.nanmean(np.nanmean(((firststopstorenbeac[18:22,:,:,0])), axis =0), axis = 0) con_probe_w4 = np.nanmean(np.nanmean(((firststopstoreprobe[18:22,:,:,0])), axis = 0), axis = 0) sd_con_beac_w4 = np.nanstd(np.nanmean(((firststopstorebeac[18:22,:,:,0])), axis = 0), axis = 0)/math.sqrt(8) sd_con_nbeac_w4 = np.nanstd(np.nanmean(((firststopstorenbeac[18:22,:,:,0])), axis =0), axis = 0)/math.sqrt(8) sd_con_probe_w4 = np.nanstd(np.nanmean(((firststopstoreprobe[18:22,:,:,0])), axis = 0), axis = 0)/math.sqrt(8) # week 4 (all stops) con_beac1_w4 = np.nanmean(np.nanmean(((firststopstorebeac[18:22,:,:,1])), axis = 0), axis = 0) con_nbeac1_w4 = np.nanmean(np.nanmean(((firststopstorenbeac[18:22,:,:,1])), axis =0), axis = 0) con_probe1_w4 = np.nanmean(np.nanmean(((firststopstoreprobe[18:22,:,:,1])), axis = 0), axis = 0) sd_con_beac1_w4 = np.nanstd(np.nanmean(((firststopstorebeac[18:22,:,:,1])), axis = 0), axis = 0)/math.sqrt(8) sd_con_nbeac1_w4 = np.nanstd(np.nanmean(((firststopstorenbeac[18:22,:,:,1])), axis =0), axis = 0)/math.sqrt(8) sd_con_probe1_w4 = np.nanstd(np.nanmean(((firststopstoreprobe[18:22,:,:,1])), axis = 0), axis = 0)/math.sqrt(8) ''' # PLOT GRAPHS bins = np.arange(0.5, n_bins + 0.5, 1) # first stop histogram fig = plt.figure(figsize=(12, 4)) ax = fig.add_subplot(1, 3, 1) #stops per trial ax.set_title('Beaconed', fontsize=20, verticalalignment='bottom', style='italic') # title ax.axvspan( rz_start, rz_end, facecolor='g', alpha=0.25, hatch='/', linewidth=0) # green box spanning the rewardzone - to mark reward zone ax.axvspan(0, track_start, facecolor='k', alpha=0.15, hatch='/', linewidth=0) # black box ax.axvspan(track_end, 20, facecolor='k', alpha=0.15, hatch='/', linewidth=0) # black box ax.axvline(0, linewidth=3, color='black') # bold line on the y axis ax.axhline(0, linewidth=3, color='black') # bold line on the x axis ax.plot(bins, con_beac_w1, color='blue', label='Beaconed', linewidth=2) #plot becaoned trials ax.fill_between(bins, con_beac_w1 - sd_con_beac_w1, con_beac_w1 + sd_con_beac_w1, facecolor='blue', alpha=0.3) #ax.plot(bins,con_beac_w4,color = 'red',label = 'Beaconed', linewidth = 2) #plot becaoned trials #ax.fill_between(bins,con_beac_w4-sd_con_beac_w4,con_beac_w4+sd_con_beac_w4, facecolor = 'red', alpha = 0.3) ax.tick_params(axis='x', pad=10, top='off', right='off', direction='out', width=2, length=7, labelsize=16) ax.tick_params(axis='y', pad=10, top='off', right='off', direction='out', width=2, length=7, labelsize=16) ax.set_xlim(0, 20) ax.set_ylim(0, 0.95) adjust_spines(ax, ['left', 'bottom']) # removes top and right spines ax.locator_params(axis='x', nbins=3) # set number of ticks on x axis ax.locator_params(axis='y', nbins=4) # set number of ticks on y axis ax.set_xticklabels(['0', '10', '20']) ax.set_yticklabels(['0', '0.3', '0.6', '0.9']) ax.set_ylabel('1st stop probability', fontsize=16, labelpad=18) ax = fig.add_subplot(1, 3, 2) #stops per trial ax.set_title('Non-Beaconed', fontsize=20, verticalalignment='bottom', style='italic') # title ax.axvspan( rz_start, rz_end, facecolor='g', alpha=0.25, hatch='/', linewidth=0) # green box spanning the rewardzone - to mark reward zone ax.axvspan(0, track_start, facecolor='k', alpha=0.15, hatch='/', linewidth=0) # black box ax.axvspan(track_end, 20, facecolor='k', alpha=0.15, hatch='/', linewidth=0) # black box ax.axvline(0, linewidth=3, color='black') # bold line on the y axis ax.axhline(0, linewidth=3, color='black') # bold line on the x axis ax.plot(bins, con_nbeac_w1, color='blue', linewidth=2) #plot becaoned trials ax.fill_between(bins, con_nbeac_w1 - sd_con_nbeac_w1, con_nbeac_w1 + sd_con_nbeac_w1, facecolor='blue', alpha=0.3) #ax.plot(bins,con_nbeac_w4,color = 'red', linewidth = 2) #plot becaoned trials #ax.fill_between(bins,con_nbeac_w4-sd_con_nbeac_w4,con_nbeac_w4+sd_con_nbeac_w4, facecolor = 'red', alpha = 0.3) ax.tick_params(axis='x', pad=10, top='off', right='off', direction='out', width=2, length=7, labelsize=16) ax.tick_params(axis='y', pad=10, top='off', right='off', direction='out', width=2, length=7, labelsize=16) ax.set_xlim(0, 20) ax.set_ylim(0, 0.95) adjust_spines(ax, ['left', 'bottom']) # re;moves top and right spines ax.locator_params(axis='x', nbins=3) # set number of ticks on x axis ax.locator_params(axis='y', nbins=4) # set number of ticks on y axis ax.set_xticklabels(['0', '10', '20']) ax.set_yticklabels(['', '', '', '']) ax.set_xlabel('Distance (VU)', fontsize=16, labelpad=18) ax = fig.add_subplot(1, 3, 3) #stops per trial ax.set_title('Probe', fontsize=20, verticalalignment='bottom', style='italic') # title ax.axvspan( rz_start, rz_end, facecolor='g', alpha=0.25, hatch='/', linewidth=0) # green box spanning the rewardzone - to mark reward zone ax.axvspan(0, track_start, facecolor='k', alpha=0.15, hatch='/', linewidth=0) # black box ax.axvspan(track_end, 20, facecolor='k', alpha=0.15, hatch='/', linewidth=0) # black box ax.axvline(0, linewidth=3, color='black') # bold line on the y axis ax.axhline(0, linewidth=3, color='black') # bold line on the x axis ax.plot(bins, con_probe_w1, color='blue', label='Beaconed', linewidth=2) #plot becaoned trials ax.fill_between(bins, con_probe_w1 - sd_con_probe_w1, con_probe_w1 + sd_con_probe_w1, facecolor='blue', alpha=0.3) #ax.plot(bins,con_probe_w4,color = 'red', label = 'Beaconed', linewidth = 2) #plot becaoned trials #ax.fill_between(bins,con_probe_w4-sd_con_probe_w4,con_probe_w4+sd_con_probe_w4, facecolor = 'red', alpha = 0.3) ax.tick_params(axis='x', pad=10, top='off', right='off', direction='out', width=2, length=7, labelsize=16) ax.tick_params(axis='y', pad=10, top='off', right='off', direction='out', width=2, length=7, labelsize=16) ax.set_xlim(0, 20) ax.set_ylim(0, 0.95) adjust_spines(ax, ['left', 'bottom']) # removes top and right spines ax.locator_params(axis='x', nbins=3) # set number of ticks on x axis ax.locator_params(axis='y', nbins=4) # set number of ticks on y axis ax.set_yticklabels(['', '', '', '']) ax.set_xticklabels(['0', '10', '20']) plt.subplots_adjust(hspace=.35, wspace=.35, bottom=0.25, left=0.15, right=0.82, top=0.85) fig.savefig(save_path, dpi=200) plt.close()
u = np.percentile(ut[:], 75) m = np.percentile(ut[:], 50) # #split trials based on time low1 = np.delete(datastore, np.where(datastore[:, 1] > m), 0) high1 = np.delete(datastore, np.where(datastore[:, 1] < m), 0) lower_p = np.delete(low1, np.where(low1[:, 1] > l), 0) upper_p = np.delete(high1, np.where(high1[:, 1] < u), 0) low_p = np.delete(low1, np.where(low1[:, 1] < l), 0) high_p = np.delete(high1, np.where(high1[:, 1] > u), 0) # get trial numbers for each of the quartiles h_trials_p = np.unique(high_p[:,2]) l_trials_p = np.unique(low_p[:,2]) h2_trials_p = np.unique(upper_p[:,2]) l2_trials_p = np.unique(lower_p[:,2]) #calculate average stops high_stops_p = create_srdata(high_p, h_trials_p) avg_high_stops_p = np.nanmean(high_stops_p, axis=0) low_stops_p = create_srdata(low_p, l_trials_p) avg_low_stops_p = np.nanmean(low_stops_p, axis=0) upper_stops_p = create_srdata(upper_p, h2_trials_p) avg_upper_stops_p = np.nanmean(upper_stops_p, axis=0) lower_stops_p = create_srdata(lower_p, l2_trials_p) avg_lower_stops_p = np.nanmean(lower_stops_p, axis=0) #store average stops s2_con_high_probe[mcount,:,0] = avg_high_stops_p s2_con_low_probe[mcount,:,0] = avg_low_stops_p s2_con_high_probe[mcount,:,1] = avg_upper_stops_p s2_con_low_probe[mcount,:,1] = avg_lower_stops_p stops = create_srdata(datastore, trialids) avg_stops= np.nanmean(stops, axis=0) allstops[mcount,:] = avg_stops