bins = np.arange(0.5,20.5,1) # array of bins for location

# For each day and mouse, pull raw data, calculate stops/speed and plot graph
for dcount,day in enumerate(days):
    for mcount,mouse in enumerate(mice):
        print ('Processing...',day,mouse)
        try:
            saraharray = readhdfdata(filename,day,mouse,'raw_data')#load HDF5 data set for that day and mouse
        except KeyError: # if there is no datafile, skip that mouse & day
            print ('Error, no file')
            continue
        trialno = np.max(saraharray[:,9]) # total number of trials for that day and mouse (used later for defining y axis max)
        
        # make array of trial number for each row in dataset
        trialarray = maketrialarray(saraharray)
        saraharray[:,9] = trialarray[:,0] # replace trial column in dataset *see README for why this is done*
        
        # Extract data for beaconed, non-beaconed, probe
        dailymouse_b = np.delete(saraharray, np.where(saraharray[:, 8] > 0), 0) # delete all data not on beaconed tracks
        dailymouse_nb = np.delete(saraharray, np.where(saraharray[:, 8] != 10), 0)# delete all data not on non beaconed tracks
        dailymouse_p = np.delete(saraharray, np.where(saraharray[:, 8] != 20), 0)# delete all data not on probe tracks
        
        #extract stops
        stopsdata_b = extractstops(dailymouse_b)
        stopsdata_nb = extractstops(dailymouse_nb)
        stopsdata_p = extractstops(dailymouse_p)
        
        #get location and trial number of rewards
        reward_beac = extractrewards(dailymouse_b)
        reward_nbeac = extractrewards(dailymouse_nb)
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):
    for mcount, mouse in enumerate(mice):
        try:
            saraharray = readhdfdata(filename, day, mouse, 'raw_data')
        except KeyError:
            print('Error, no file')
            continue
        print('##...', mcount, day, '...##')

        # 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(dailymouse_b)
        stops_nb = extractstops(dailymouse_nb)
        stops_p = extractstops(dailymouse_p)
s2_teth_firststopstorebeac = np.zeros((len(days), len(mice),2));s2_teth_firststopstorenbeac = np.zeros((len(days), len(mice),2));s2_teth_firststopstoreprobe = np.zeros((len(days), len(mice),2))
s2_teth_firststopstorebeac[:,:,:] = np.nan;s2_teth_firststopstorenbeac[:,:,:] = np.nan; s2_teth_firststopstoreprobe[:,:,:] = np.nan
s2_teth_firststopstorebeac_s = np.zeros((len(days), len(mice),2));s2_teth_firststopstorenbeac_s = np.zeros((len(days), len(mice),2));s2_teth_firststopstoreprobe_s = np.zeros((len(days), len(mice),2))
s2_teth_firststopstorebeac_s[:,:,:] = np.nan;s2_teth_firststopstorenbeac_s[:,:,:] = np.nan; s2_teth_firststopstoreprobe_s[:,:,:] = np.nan


#loop days and mice to collect data
for mcount,mouse in enumerate(mice):
    for dcount,day in enumerate(days):
        try:
            saraharray = readhdfdata(filename,day,mouse,'raw_data')
        except KeyError:
            print ('Error, no file')
            continue
        # make array of trial number per row of data in dataset
        trialarray = maketrialarray(saraharray) # make array of trial number same size as saraharray
        saraharray[:,9] = trialarray[:,0] # replace trial number because of increment error (see README.py)
        
        # split data by trial type
        dailymouse_b = np.delete(saraharray, np.where(saraharray[:, 8] > 0), 0) # delete all data not on beaconed tracks
        dailymouse_nb = np.delete(saraharray, np.where(saraharray[:, 8] != 10), 0)# delete all data not on non beaconed tracks
        dailymouse_p = np.delete(saraharray, np.where(saraharray[:, 8] != 20), 0)# delete all data not on probe tracks
        
        #extract stops
        stopsdata_b = extractstops(dailymouse_b)
        stopsdata_p = extractstops(dailymouse_p)
        
        # filter stops
        stops_b = filterstops(stopsdata_b)
        stops_p = filterstops(stopsdata_p)
        
Exemplo n.º 4
0
def plot_fig1F(session_paths, save_path):


    # specify mouse/mice and day/s to analyse
    days = [1]
    n_bins = 20
    # specify mouse/mice and day/s to analyse
    days = ['Day' + str(int(x)) for x in np.arange(1)]

    # empty arrays for storing data
    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

    #loop days and mice to collect 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]

            trialarray = maketrialarray(saraharray) # make array of trial number same size as saraharray
            saraharray[:,9] = trialarray[:,0] # replace trial number because of increment error (see README.py)

            # split data by trial type
            dailymouse_b = np.delete(saraharray, np.where(saraharray[:, 8] > 0), 0) # delete all data not on beaconed tracks
            dailymouse_nb = np.delete(saraharray, np.where(saraharray[:, 8] != 10), 0)# delete all data not on non beaconed tracks
            dailymouse_p = np.delete(saraharray, np.where(saraharray[:, 8] != 20), 0)# delete all data not on probe tracks

            #extract stops
            stopsdata_b = extractstops_HUMAN(dailymouse_b)
            stopsdata_nb = extractstops_HUMAN(dailymouse_nb)
            stopsdata_p = extractstops_HUMAN(dailymouse_p)

            # filter stops
            stopsdata_b = filterstops(stopsdata_b)
            stopsdata_nb = filterstops(stopsdata_nb)
            stopsdata_p = filterstops(stopsdata_p)

            trialids_b = np.unique(stopsdata_b[:, 2])  # make array of unique trial numbers
            srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stopsdata_b,trialids_b)  # get average real stops & shuffled stops per lcoation bin
            zscore_b = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)  # calculate z-scores
            firststopstorebeac[dcount, session_count,:,1] = zscore_b  # store zscores
            if stopsdata_nb.size > 0:  # if there is non-beaconed data
                trialids_nb = np.unique(stopsdata_nb[:, 2])  # make array of unique trial numbers
                srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stopsdata_nb, trialids_nb)  # get average real stops & shuffled stops per lcoation bin
                zscore_nb = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)  # calculate z-scores
                firststopstorenbeac[dcount, session_count,:,1] = zscore_nb  # store zscores
            if stopsdata_p.size > 0:  # if there is probe data
                trialids_p = np.unique(stopsdata_p[:, 2])  # make array of unique trial numbers
                srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stopsdata_p, trialids_p)  # get average real stops & shuffled stops per lcoation bin
                zscore_p = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)  # calculate z-scores
                firststopstoreprobe[dcount, session_count,:,1] = zscore_p  # store zscores
                session_count += 1


    # AVERAGE DATA FOR PLOTS
    # stack experiments then average over days then mice
    con_b1 = np.nanmean(((firststopstorebeac[0, :, :,1])), axis=0)
    con_nb1 = np.nanmean(((firststopstorenbeac[0, :, :,1])), axis=0)
    con_p1 = np.nanmean(((firststopstoreprobe[0,:, :, 1])), axis=0)
    sdcon_b1 = np.nanstd(((firststopstorebeac[0, :, :,1])), axis=0)/math.sqrt(session_count)
    sdcon_nb1 = np.nanstd(((firststopstorenbeac[0, :, :,1])), axis=0)/ math.sqrt(session_count)
    sdcon_p1 = np.nanstd(((firststopstoreprobe[0, :, :,1])), axis=0)/ math.sqrt(session_count)


    # PLOT GRAPHS

    bins = np.arange(0.5,n_bins+0.5,1) # track bins

    fig = plt.figure(figsize = (12,4))
    ax = fig.add_subplot(1,3,1)
    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(-10, linewidth = 3, color = 'black') # bold line on the x axis
    ax.axhline(0, linewidth = 1,ls='--', color = 'black') # bold line on the x axis
    #ax.plot(bins*5,con_b,color = 'red',label = 'AAV-fl-GFP', linewidth = 2) #plot becaoned trials
    #ax.fill_between(bins*5,con_b-sdcon_b,con_b+sdcon_b, facecolor = 'red', alpha = 0.3)
    ax.plot(bins,con_b1,'',color = 'blue',label = 'AAV-fl-GFP', linewidth = 2) #plot becaoned trials
    ax.fill_between(bins,con_b1-sdcon_b1,con_b1+sdcon_b1, facecolor = 'blue', 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(-10,35)
    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=5) # set number of ticks on y axis
    ax.set_xticklabels(['0', '10', '20'])
    ax.set_yticklabels(['-10','0','10','20', '30'])
    ax = plt.ylabel('Stops (Zscore)', 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(-10, linewidth = 3, color = 'black') # bold line on the x axis
    ax.axhline(0, linewidth = 1,ls='--', color = 'black') # bold line on the x axis
    #ax.plot(bins*5,con_nb,color = 'red', linewidth = 2) #plot becaoned trials
    #ax.fill_between(bins*5,con_nb-sdcon_nb,con_nb+sdcon_nb, facecolor = 'red', alpha = 0.3)
    ax.plot(bins,con_nb1,color = 'blue', linewidth = 2) #plot becaoned trials
    ax.fill_between(bins,con_nb1-sdcon_nb1,con_nb1+sdcon_nb1, facecolor = 'blue', 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(-10,35)
    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=5) # set number of ticks on y axis
    ax.set_xticklabels(['0', '10', '20'])
    ax.set_yticklabels(['','','','', ''])
    ax = plt.xlabel('Location (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.axhline(0, linewidth = 1,ls='--', color = 'black') # bold line on the x axis
    ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
    ax.axhline(-10, linewidth = 3, color = 'black') # bold line on the x axis
    #ax.plot(bins*5,con_p,color = 'red', label = 'Beaconed', linewidth = 2) #plot becaoned trials
    #ax.fill_between(bins*5,con_p-sdcon_p,con_p+sdcon_p, facecolor = 'red', alpha = 0.3)
    ax.plot(bins,con_p1,color = 'blue', label = 'Beaconed', linewidth = 2) #plot becaoned trials
    ax.fill_between(bins,con_p1-sdcon_p1,con_p1+sdcon_p1, facecolor = 'blue', 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(-10,35)
    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=5) # set number of ticks on y axis
    ax.set_xticklabels(['0', '10', '20'])
    ax.set_yticklabels(['','','','', ''])

    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()
Exemplo n.º 5
0
def plot_fig1E(session_paths, save_path):


    days = [1]
    # specify mouse/mice and day/s to analyse
     # choose specific day/s
    number_of_trials = 1000 # arbitrarily large amount of trials so we can catch all the trials

    # Arrays for storing data (output)
    firststopstorebeac = np.zeros(((number_of_trials), len(session_paths)))
    firststopstorenbeac = np.zeros(((number_of_trials), len(session_paths)))
    firststopstoreprobe = np.zeros(((number_of_trials), len(session_paths)))
    firststopstorebeac[:,:] = np.nan
    firststopstorenbeac[:,:] = np.nan
    firststopstoreprobe[:,:] = np.nan

    sd_con_FirstStopsstorebeac = np.zeros(((number_of_trials), len(session_paths)))
    sd_con_FirstStopsstorenbeac = np.zeros(((number_of_trials), len(session_paths)))
    sd_con_FirstStopsstoreprobe = np.zeros(((number_of_trials), len(session_paths)))
    sd_con_FirstStopsstorebeac[:, :] = np.nan
    sd_con_FirstStopsstorenbeac[:, :] = np.nan
    sd_con_FirstStopsstoreprobe[:, :] = 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.unique(trialarray[:, 0])  # get unique trial numbers

            stops_f_b = FirstStops_humans(trarray, stops_b, track_start, track_end)  # get locations of first stop for each trial
            #beac = np.nanmean(stops_f_b, axis=0)  # find average first stop location
            #sdbeac = np.nanstd(stops_f_b, axis=0)  # get sd of first stop location

            if stops_nb.size > 0:
                stops_f_nb = FirstStops_humans(trarray, stops_nb, track_start, track_end)  # get locations of first stop for each trial
                #nbeac = np.nanmean(stops_f_nb, axis=0)  # find average first stop location
                #sdnbeac = np.nanstd(stops_f_nb, axis=0)  # get sd of first stop location
            if stops_p.size > 0:
                stops_f_p = FirstStops_humans(trarray, stops_p, track_start, track_end)  # get locations of first stop for each trial
                #probe = np.nanmean(stops_f_p, axis=0)  # find average first stop location
                #sdprobe = np.nanstd(stops_f_p, axis=0)  # get sd of first stop location

            for i in range(len(stops_f_b)):
                firststopstorebeac[i, session_count] = stops_f_b[i][0]
                #sd_con_FirstStopsstorebeac[dcount, session_count] = beac[0]

            if stops_nb.size > 0:
                for i in range(len(stops_f_nb)):
                    firststopstorenbeac[i, session_count] = stops_f_nb[i][0]
                    #sd_con_FirstStopsstorenbeac[dcount, session_count] = nbeac[0]

            if stops_p.size > 0:
                for i in range(len(stops_f_p)):
                    firststopstoreprobe[i, session_count] = stops_f_p[i][0]
                    #sd_con_FirstStopsstoreprobe[dcount, session_count] = probe[0]

            session_count += 1


            # Average over days for all mice

    con_beac = np.nanmean(((firststopstorebeac)), axis=1)
    con_beac = con_beac[~np.isnan(con_beac)]
    con_nbeac = np.nanmean(((firststopstorenbeac)), axis=1)
    con_nbeac = con_nbeac[~np.isnan(con_nbeac)]
    con_probe = np.nanmean(((firststopstoreprobe)), axis=1)
    con_probe = con_probe[~np.isnan(con_probe)]
    sd_con_beac = np.nanstd(((firststopstorebeac)), axis=1) / math.sqrt(session_count)
    sd_con_beac = sd_con_beac[~np.isnan(sd_con_beac)]
    sd_con_nbeac = np.nanstd(((firststopstorenbeac)), axis=1) / math.sqrt(session_count)
    sd_con_nbeac = sd_con_nbeac[~np.isnan(sd_con_nbeac)]
    sd_con_probe = np.nanstd(((firststopstoreprobe)), axis=1) / math.sqrt(session_count)
    sd_con_probe = sd_con_probe[~np.isnan(sd_con_probe)]

    # PLOT GRAPHS

    b_trial_max = np.arange(0,len(con_beac),1)
    nb_trial_max = np.arange(0,len(con_nbeac),1)
    p_trial_max = np.arange(0,len(sd_con_probe),1)

    # array of days
    #x = con_beac[0]

    # plot average first stop over days for all mice
    fig = plt.figure(figsize = (12,4))  # make figure, this shape (width, height)
    ax = fig.add_subplot(1,3,1)
    ax.set_title('Beaconed', fontsize=20, verticalalignment='bottom', style='italic') #title
    ax.axhspan(rz_start, rz_end, facecolor='g', alpha=0.15, hatch='/',linewidth=0)  # green box of reward zone
    ax.axhspan(0, 4, facecolor='k', alpha=0.15, hatch='/', linewidth=0)  # black box (4 is used for appearance)
    ax.axhline(4, linewidth=1, ls='--', color='black')  # mark black box border
    ax.axvline(0, linewidth=3, color='black')  # bold line on the y axis
    ax.axhline(2, linewidth=3, color='black')  # bold line on the x axis

    ax.plot(b_trial_max, con_beac, 'o',color = '0.3', label = 'Non reward zone score', linewidth = 2, markersize = 6, markeredgecolor = 'black')
    ax.errorbar(b_trial_max,con_beac,sd_con_beac, fmt = 'o', color = '0.3', capsize = 1.5, markersize = 2, elinewidth = 1.5)
    ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 7,labelsize =15) # tick parameters: pad is tick label relative to
    ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 7,labelsize =15)
    ax.set_xlim(0,len(b_trial_max))
    ax.set_ylim(2,rz_end+2)
    adjust_spines(ax, ['left','bottom']) # remove right and top axis
    plt.locator_params(nbins=7, axis ='y') # set tick number on y axis
    plt.locator_params(nbins=3, axis ='x') # set tick number on x axis
    ax = plt.ylabel('Location (VU)', fontsize=16, labelpad = 18)

    ax = fig.add_subplot(1,3,2)
    ax.set_title('Non-Beaconed', fontsize=20, verticalalignment='bottom', style='italic')
    ax.axhspan(rz_start, rz_end, facecolor='g', alpha=0.15, hatch='/', linewidth=0)  # green box spanning the rewardzone - to mark reward zone
    ax.axhspan(0, 4, facecolor='k', alpha=0.15, hatch='/', linewidth=0)  # black box
    ax.axhline(4, linewidth=1, ls='--', color='black')  # mark black box border
    ax.axvline(0, linewidth = 3, color = 'black')# bold line on the y axis
    ax.axhline(2, linewidth = 3, color = 'black')# bold line on the x axis

    ax.plot(nb_trial_max, con_nbeac, 'o', color = '0.3', label = 'Non reward zone score', linewidth = 2, markersize = 6, markeredgecolor = 'black')
    ax.errorbar(nb_trial_max,con_nbeac,sd_con_nbeac, fmt = 'o', color = '0.3', capsize = 1.5, markersize = 2, elinewidth = 1.5)
    ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 7,labelsize =15)
    ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 7,labelsize =15)
    ax.set_xlim(0,len(nb_trial_max))
    ax.set_ylim(2,rz_end+2)
    adjust_spines(ax, ['left','bottom']) # remove right and top axis
    plt.locator_params(nbins=7, axis ='y') # set tick number on y axis
    plt.locator_params(nbins=3, axis ='x') # set tick number on x axis
    ax = plt.xlabel('Number of trials', fontsize=16,labelpad=18)

    ax = fig.add_subplot(1,3,3)
    ax.set_title('Probe', fontsize=20, verticalalignment='bottom', style='italic')  # title
    ax.axhspan(rz_start, rz_end, facecolor='g', alpha=0.15, hatch='/', linewidth=0)  # green box of reward zone
    ax.axhspan(0, 4, facecolor='k', alpha=0.15, hatch='/', linewidth=0)  # black box (4 is used for appearance)
    ax.axhline(4, linewidth=1, ls='--', color='black')  # mark black box border
    ax.axvline(0, linewidth=3, color='black')  # bold line on the y axis
    ax.axhline(2, linewidth=3, color='black')  # bold line on the x axis

    ax.plot(p_trial_max, con_probe, 'o', color = '0.3', label = 'Non reward zone score', linewidth = 2, markersize = 6, markeredgecolor = 'black')
    ax.errorbar(p_trial_max,con_probe,sd_con_probe, fmt = 'o', color = '0.3', capsize = 1.5, markersize = 2, elinewidth = 1.5)
    ax.tick_params(axis='x', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 7,labelsize =15)
    ax.tick_params(axis='y', pad = 10, top='off', right = 'off', direction = 'out',width = 2, length = 7,labelsize =15)
    ax.set_xlim(0,len(p_trial_max))
    ax.set_ylim(2,rz_end+2)
    adjust_spines(ax, ['left','bottom']) # remove right and top axis
    plt.locator_params(nbins=7, axis ='y') # set tick number on y axis
    plt.locator_params(nbins=3, axis ='x') # set tick number on x axis

    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()
Exemplo n.º 6
0
for mcount, mouse in enumerate(mice):  # for each mouse
    stopsdata_p = np.zeros(
        (0, 13))  # empty array that has same number of columns as raw data
    max_trialno = 0
    # get data for all days
    for dcount, day in enumerate(days):
        try:
            saraharray = readhdfdata(
                filename, day, mouse,
                'raw_data')  # get raw datafile for mouse and day
        except KeyError:
            print('Error, no file')
            continue
        print('##...', mcount, dcount, '...##')
        # get probe trial data for each day & stack
        trialarray = maketrialarray(
            saraharray)  # make list of trial number per row in data
        saraharray[:, 9] = trialarray[:, 0]  # replace trial number
        stopsdata = np.delete(saraharray, np.where(saraharray[:, 8] != 20),
                              0)  # get just probe trials
        if stopsdata.size > 0:
            # the point of the following is to stack days for individual mice. So need to replace trial numbers so it appears like one training day
            trialno = np.amax(
                stopsdata[:, 9])  # find max trial number of current session
            stopsdata[:, 9] += max_trialno
            max_trialno += trialno
            stopsdata_p = np.vstack((stopsdata_p, stopsdata))
        dcount += 1

    if stopsdata_p.size > 0:
        if mcount == 3 or mcount == 5 or mcount == 7 or mcount == 8:
            # get trials
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
def plot_fig1G (session_paths, save_path):

    days = [1] #
    number_of_trials = 1000 # arbitrarily large amount of trials so we can catch all the trials

    # Arrays for storing data (output)
    firststopstorebeac = np.zeros(((number_of_trials), len(session_paths)))
    firststopstorenbeac = np.zeros(((number_of_trials), len(session_paths)))
    firststopstoreprobe = np.zeros(((number_of_trials), len(session_paths)))
    firststopstorebeac[:,:] = np.nan
    firststopstorenbeac[:,:] = np.nan
    firststopstoreprobe[:,:] = np.nan

    sd_con_firststopstorebeac = np.zeros(((number_of_trials), len(session_paths)))
    sd_con_firststopstorenbeac = np.zeros(((number_of_trials), len(session_paths)))
    sd_con_firststopstoreprobe = np.zeros(((number_of_trials), len(session_paths)))
    sd_con_firststopstorebeac[:,:] = np.nan
    sd_con_firststopstorenbeac[:,:] = np.nan
    sd_con_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*

            # get stops and trial arrays
            dailymouse_b = np.delete(saraharray, np.where(saraharray[:, 8] > 0), 0) # delete all data not on beaconed tracks
            dailymouse_nb = np.delete(saraharray, np.where(saraharray[:, 8] != 10), 0)# delete all data not on non beaconed tracks
            dailymouse_p = np.delete(saraharray, np.where(saraharray[:, 8] != 20), 0)# delete all data not on

            # get stops
            stops_b = extractstops_HUMAN(dailymouse_b)
            stops_nb = extractstops_HUMAN(dailymouse_nb)
            stops_p= extractstops_HUMAN(dailymouse_p)

            # filter stops
            stops_b = filterstops(stops_b)
            stops_nb = filterstops(stops_nb)
            stops_p = filterstops(stops_p)

            if stops_b.size > 0:
                trialids_b = np.unique(stops_b[:, 2])  # make array of unique trial numbers

                for i in range(len(stops_b)):
                    srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stops_b,trialids_b)  # get average real stops & shuffled stops per lcoation bin
                shuff_beac = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)  # calculate z-scores
                bb = shuff_beac[3]; rz = shuff_beac[9]  # black box - reward zone zscore
                score = rz - bb


            if stops_nb.size > 0:
                trialids_nb = np.unique(stops_nb[:, 2])  # make array of unique trial numbers
                srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stops_nb,trialids_nb)  # get average real stops & shuffled stops per lcoation bin
                shuff_nbeac = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)  # calculate z-scores
                bb = shuff_nbeac[3];
                rz = shuff_nbeac[9]  # black box - reward zone zscore
                score = rz - bb
            for i in range(len(stops_nb)):
                firststopstorebeac[i, session_count] = score[i][0]

            if stops_p.size > 0:
                trialids_p = np.unique(stops_p[:, 2])  # make array of unique trial numbers
                srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stops_p,trialids_p)  # get average real stops & shuffled stops per lcoation bin
                shuff_probe = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)  # calculate z-scores
                bb = shuff_probe[3];
                rz = shuff_probe[9]  # black box - reward zone zscore
                score = rz - bb
                firststopstoreprobe[dcount, mcount] = score  # store data

                mcount += 1

         # get average real stops & shuffled stops per location bin
                zscore_b = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)
            for i in range(len(stops_b)):
                firststopstorebeac[i, session_count] = zscore_b[i][0]

            if stops_nb.size>0:
                trialids_nb = np.unique(stops_nb[:, 2])
                srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stops_nb,trialids_nb)  # get average real stops & shuffled stops per location bin
                zscore_nb = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)
            for i in range(len(stops_nb)):
                firststopstorebeac[i, session_count] = zscore_nb[i][0]

            if stops_p.nb.size>0:
                trialids_p = np.unique(stops_p[:, 2])
                srbin_mean, srbin_std, shuffled_mean, shuffled_std = shuffle_analysis_pertrial3(stops_p,trialids_p)  # get average real stops & shuffled stops per location bin
                zscore_p = z_score1(srbin_mean, srbin_std, shuffled_mean, shuffled_std)
            for i in range(len(stops_p)):
                firststopstorebeac[i, session_count] = zscore_p[i][0]

                session_count +=1


    # stack experiments then average over days for each mouse
    con_b = np.nanmean(((firststopstorebeac)), axis = 1)
    con_b = con_b[~np.isnan(con_b)]
    con_nb = np.nanmean(((firststopstorenbeac)), axis =1)
    con_nb = con_nb[~np.isnan(con_nb)]
    con_p = np.nanmean(((firststopstoreprobe)), axis = 1)
    con_p = con_p[~np.isnan(con_nb)]
    sd_con_b = np.nanstd(((firststopstorebeac)), axis=1)/math.sqrt(session_count)
    sd_con_b = sd_con_b[~np.isnan(sd_con_b)]
    sd_con_nb = np.nanstd(((firststopstorenbeac)), axis=1)/math.sqrt(session_count)
    sd_con_nb = sd_con_nb[~np.isnan(sd_con_nb)]
    sd_con_p = np.nanstd(((firststopstoreprobe)), axis=1)/math.sqrt(session_count)
    sd_con_p = sd_con_p[~np.isnan(sd_con_p)]


    # PLOT GRAPHS

    bins = np.arange(0.5,21.5+1e-6,1) # track bins

    fig = plt.figure(figsize = (12,3))
    ax = fig.add_subplot(1,3,1)
    ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
    ax.axhline(-10, linewidth = 3, color = 'black') # bold line on the x axis
    ax.axhline(0, linewidth = 1,ls='--', color = 'black') # bold line on the x axis
    ax.plot(bins,con_b,'o',color = 'Black',label = 'AAV-fl-GFP', linewidth = 2, markersize = 6, markeredgecolor = 'black') #plot becaoned trials
    ax.errorbar(bins,con_b,sd_con_b, fmt = 'o', color = 'black', capsize = 2, capthick = 1, markersize = 4, elinewidth = 1.5)
    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,22)
    ax.set_ylim(-10,20)
    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 = plt.ylabel('Training day)', fontsize=16, labelpad = 18)

    ax = fig.add_subplot(1,3,2) #stops per trial
    ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
    ax.axhline(-10, linewidth = 3, color = 'black') # bold line on the x axis
    ax.axhline(0, linewidth = 1,ls='--', color = 'black') # bold line on the x axis
    ax.plot(bins,con_nb,'o', color = 'Black', linewidth = 2, markersize = 6, markeredgecolor = 'black') #plot becaoned trials
    ax.errorbar(bins,con_nb,sd_con_nb, fmt = 'o', color = 'black',  capsize = 2, capthick = 1, markersize = 4, elinewidth = 1.5)
    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,22)
    ax.set_ylim(-10,20)
    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 = plt.xlabel('Training day', fontsize=16, labelpad = 18)

    ax = fig.add_subplot(1,3,3) #stops per trial
    ax.axhline(0, linewidth = 1,ls='--', color = 'black') # bold line on the x axis
    ax.axvline(0, linewidth = 3, color = 'black') # bold line on the y axis
    ax.axhline(-10, linewidth = 3, color = 'black') # bold line on the x axis
    ax.plot(bins,con_p, 'o', color = 'Black',label = 'Beaconed', linewidth = 2, markersize = 6, markeredgecolor = 'black') #plot becaoned trials
    ax.errorbar(bins,con_p,sd_con_p, fmt = 'o', color = 'black',  capsize = 2, capthick = 1, markersize = 4, elinewidth = 1.5)
    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,22)
    ax.set_ylim(-10,20)
    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 = plt.xlabel('Training day', fontsize=16, labelpad = 18)

    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()