def smoothing(): logging.basicConfig(level=logging.INFO) room = [[-55, 55], [-55, 55]] bin_size = 5 xs = range(room[0][0], room[0][1], bin_size) ys = range(room[1][0], room[1][1], bin_size) X, Y = np.meshgrid(xs, ys) session = 60 animal = 66 _, good_clusters = get_good_clusters(0) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal, fn) cls = {tetrode: load_cl(animal, fn, tetrode) for tetrode in range(1, 17)} t_cells = count_cells(vl, cls, trigger_tm, good_clusters) x = vl['xs'] y = vl['ys'] tpp = np.mean(vl['Time'][1:] - vl['Time'][:-1]) * 24 * 60 * 60 label_l = vl['Task'] # rates[cell id, lbl, xbin, ybin] = rate rates1 = get_fracs(x, y, label_l, room, bin_size, t_cells, smooth_flag=True) rates1 /= tpp logging.info('Got smoothed rates') rates2 = get_fracs(x, y, label_l, room, bin_size, t_cells, smooth_flag=False) rates2 /= tpp logging.info('Got unsmoothed rates') for i in range(5): # or rates1.shape[0] logging.info('Cell %i', i) plt.figure() plt.pcolor(X, Y, rates1[i, 0]) plt.colorbar() plt.autoscale(tight=True) plt.xlabel('Position (in)') plt.ylabel('Position (in)') plt.figure() plt.pcolor(rates2[i, 0]) plt.autoscale(tight=True) plt.xlabel('Position (in)') plt.ylabel('Position (in)') plt.show()
def rate_graph(): animal = 66 session = 60 # This is August 7, 2013 run room_shape = [[-55, 55], [-55, 55]] tetrodes = range(1, 17) cluster_profile = 0 bin_size = 5 _, good_clusters = get_good_clusters(cluster_profile) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal, fn) cls = {tetrode: load_cl(animal, fn, tetrode) for tetrode in tetrodes} tpp = 1.0 * np.mean(vl["Time"][1:] - vl["Time"][:-1]) t_cells = count_cells(vl, cls, trigger_tm, good_clusters) label_l = vl["Task"] # rates[cell, lbl, xbin, ybin] = firing rate rates = get_fracs(vl["xs"], vl["ys"], label_l, room_shape, bin_size, t_cells) rates /= tpp plot_rates(rates, label_l, t_cells) plt.show()
def rate_graph(): animal = 66 session = 60 # This is August 7, 2013 run room_shape = [[-55, 55], [-55, 55]] tetrodes = range(1, 17) cluster_profile = 0 bin_size = 5 _, good_clusters = get_good_clusters(cluster_profile) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal, fn) cls = {tetrode: load_cl(animal, fn, tetrode) for tetrode in tetrodes} tpp = 1.0 * np.mean(vl['Time'][1:] - vl['Time'][:-1]) t_cells = count_cells(vl, cls, trigger_tm, good_clusters) label_l = vl['Task'] # rates[cell, lbl, xbin, ybin] = firing rate rates = get_fracs(vl['xs'], vl['ys'], label_l, room_shape, bin_size, t_cells) rates /= tpp plot_rates(rates, label_l, t_cells) plt.show()
def rate_graph(): #mpl.rcParams['axes.titlesize'] = 18 #mpl.rcParams['axes.labelsize'] = 18 mpl.rcParams['font.size'] = 26 animal = 66 session = 60 # This is August 7, 2013 run room_shape = [[-55,55],[-55,55]] tetrodes = [1] cluster_profile = 0 bin_size = 5 _, good_clusters = get_good_clusters(cluster_profile) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal,fn) cls = {tetrode:load_cl(animal,fn,tetrode) for tetrode in tetrodes} t_cells = count_cells(vl,cls,trigger_tm,good_clusters) label_l = vl['Task'] # rates[cell, lbl, xbin, ybin] = firing rate rates = get_fracs(vl['xs'], vl['ys'], label_l, room_shape, bin_size, t_cells) for lbl in range(len(np.unique(label_l))): plt.figure(figsize=(10,10)) x = np.concatenate([np.arange(room_shape[0][0],room_shape[0][1],bin_size),[room_shape[0][1]]]) y = np.concatenate([np.arange(room_shape[1][0],room_shape[1][1],bin_size),[room_shape[1][1]]]) Xs, Ys = np.meshgrid(x, y) cntr = plt.pcolor(Ys,Xs,rates[3,lbl]) t=plt.colorbar(cntr, extend='both') t.set_label('Frequency (Hz)') plt.xlabel('Position (in)') plt.ylabel('Position (in)') if lbl == 0: plt.title('Clockwise') else: plt.title('Counterclockwise') #plt.axis('equal') plt.xlim(room_shape[0]) plt.ylim(room_shape[1]) ''' plt.figure() x = np.arange(room_shape[0][0],room_shape[0][1],bin_size) y = np.arange(room_shape[1][0],room_shape[1][1],bin_size) Xs, Ys = np.meshgrid(x, y) cntr = plt.contourf(Ys,Xs,rate_dict[contxt][2]) t = plt.colorbar(cntr, extend='both') t.set_label('Frequency (Hz)') plt.xlabel('Position (in)') plt.ylabel('Position (in)')''' plt.show()
def smoothing(): logging.basicConfig(level=logging.INFO) room = [[-55,55],[-55,55]] bin_size = 5 xs = range(room[0][0],room[0][1],bin_size) ys = range(room[1][0],room[1][1],bin_size) X,Y = np.meshgrid(xs,ys) session = 60 animal=66 _, good_clusters = get_good_clusters(0) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal,fn) cls = {tetrode:load_cl(animal,fn,tetrode) for tetrode in range(1,17)} t_cells = count_cells(vl,cls,trigger_tm,good_clusters) x = vl['xs'] y = vl['ys'] tpp = np.mean(vl['Time'][1:]-vl['Time'][:-1])*24*60*60 label_l = vl['Task'] # rates[cell id, lbl, xbin, ybin] = rate rates1 = get_fracs(x,y,label_l, room, bin_size, t_cells, smooth_flag=True) rates1 /= tpp logging.info('Got smoothed rates') rates2 = get_fracs(x,y,label_l, room, bin_size, t_cells, smooth_flag=False) rates2 /= tpp logging.info('Got unsmoothed rates') for i in range(5): # or rates1.shape[0] logging.info('Cell %i',i) plt.figure() plt.pcolor(X,Y,rates1[i,0]) plt.colorbar() plt.autoscale(tight=True) plt.xlabel('Position (in)') plt.ylabel('Position (in)') plt.figure() plt.pcolor(rates2[i,0]) plt.autoscale(tight=True) plt.xlabel('Position (in)') plt.ylabel('Position (in)') plt.show()
def gpv_rates(): logging.basicConfig(level=logging.INFO) animal = 66 session = 60 room_shape = [[-55, 55], [-55, 55]] tetrodes = [1] cells = range(2, 10) bin_size = 5 K = 50 # Segment length used to calculate firing rates #xbins = ybins = (room_shape[0][1]-room_shape[0][0])/bin_size good_clusters = {tetrode: cells for tetrode in tetrodes} #good_clusters = get_good_clusters(0) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal, fn) cls = {tetrode: load_cl(animal, fn, tetrode) for tetrode in tetrodes} label_l = vl['Task'] t_cells = count_cells(vl, cls, trigger_tm, good_clusters) logging.info('About to generate population vector.') X, Y = gpv(vl, t_cells, label_l, K, bin_size, room_shape) logging.info('%i population vectors generated.', X.shape[0]) Y = Y.reshape([-1]) # GPV rates rates = fracs_from_pv(X, Y, bin_size, room_shape, smooth_flag=True) # Now get normally calculate rates real_rates = get_fracs(vl['xs'], vl['ys'], label_l, room_shape, bin_size, t_cells, smooth_flag=True) try: assert np.all(rates == real_rates) except: print 'DOESNT WORK!!' plot_rates(rates, Y, t_cells) plot_rates(real_rates, Y, t_cells) plt.show()
def gpv_rates(): logging.basicConfig(level=logging.INFO) animal = 66 session = 60 room_shape = [[-55,55],[-55,55]] tetrodes = [1] cells = range(2,10) bin_size = 5 K = 50# Segment length used to calculate firing rates #xbins = ybins = (room_shape[0][1]-room_shape[0][0])/bin_size good_clusters = {tetrode:cells for tetrode in tetrodes} #good_clusters = get_good_clusters(0) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal,fn) cls = {tetrode:load_cl(animal,fn,tetrode) for tetrode in tetrodes} label_l = vl['Task'] t_cells = count_cells(vl,cls,trigger_tm, good_clusters) logging.info('About to generate population vector.') X, Y = gpv(vl, t_cells, label_l, K, bin_size, room_shape) logging.info('%i population vectors generated.',X.shape[0]) Y = Y.reshape([-1]) # GPV rates rates = fracs_from_pv(X,Y,bin_size,room_shape,smooth_flag=True) # Now get normally calculate rates real_rates = get_fracs(vl['xs'],vl['ys'],label_l,room_shape,bin_size, t_cells,smooth_flag=True) try: assert np.all(rates == real_rates) except: print 'DOESNT WORK!!' plot_rates(rates,Y,t_cells) plot_rates(real_rates,Y,t_cells) plt.show()
def checkGPV(): logging.basicConfig(level=5) animal = 66 session = 60 room_shape = [[-55, 55], [-55, 55]] tetrodes = [1] cells = range(2, 10) bin_size = 5 K = 1 # Segment length used to calculate firing rates maxs = 10000 assert maxs % K == 0 #xbins = ybins = (room_shape[0][1]-room_shape[0][0])/bin_size good_clusters = {tetrode: cells for tetrode in tetrodes} #good_clusters = get_good_clusters(0) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal, fn) cls = {tetrode: load_cl(animal, fn, tetrode) for tetrode in tetrodes} label_l = vl['Task'] t_cells = count_cells(vl, cls, trigger_tm, good_clusters) '''''' # For debugging purposes, make sure it's not too big if len(label_l) > maxs: vl['xs'] = vl['xs'][:maxs * 10:10] vl['ys'] = vl['ys'][:maxs * 10:10] label_l = label_l[:maxs * 10:10] for key in t_cells: tmp = np.array(t_cells[key]) tmp = tmp[tmp < maxs] t_cells[key] = tmp for gpv in [gpv1]: logging.info('About to generate population vector.') X, Y = gpv(vl, t_cells, label_l, K, bin_size, room_shape) logging.info('%i population vectors generated.', X.shape[0]) Y = Y.reshape([-1]) # Debug code # This is only true if no points are thrown away if X.shape[0] * K == maxs: tot_spks = np.sum( [len(np.unique(spki)) for spki in t_cells.values()]) assert tot_spks == np.sum(X[:, :len(t_cells)]) * K # GPV rates rates = fracs_from_pv(X, Y, bin_size, room_shape, smooth_flag=False) # Now get normally calculate rates real_rates = get_fracs(vl['xs'], vl['ys'], label_l, room_shape, bin_size, t_cells, smooth_flag=False) try: assert np.all(rates == real_rates) except: print 'DOESNT WORK!!' plot_rates(rates, Y, t_cells) plot_rates(real_rates, Y, t_cells) plt.show()
def rate_graph(): #mpl.rcParams['axes.titlesize'] = 18 #mpl.rcParams['axes.labelsize'] = 18 mpl.rcParams['font.size'] = 26 animal = 66 session = 60 # This is August 7, 2013 run room_shape = [[-55, 55], [-55, 55]] tetrodes = [1] cluster_profile = 0 bin_size = 5 _, good_clusters = get_good_clusters(cluster_profile) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal, fn) cls = {tetrode: load_cl(animal, fn, tetrode) for tetrode in tetrodes} t_cells = count_cells(vl, cls, trigger_tm, good_clusters) label_l = vl['Task'] # rates[cell, lbl, xbin, ybin] = firing rate rates = get_fracs(vl['xs'], vl['ys'], label_l, room_shape, bin_size, t_cells) for lbl in range(len(np.unique(label_l))): plt.figure(figsize=(10, 10)) x = np.concatenate([ np.arange(room_shape[0][0], room_shape[0][1], bin_size), [room_shape[0][1]] ]) y = np.concatenate([ np.arange(room_shape[1][0], room_shape[1][1], bin_size), [room_shape[1][1]] ]) Xs, Ys = np.meshgrid(x, y) cntr = plt.pcolor(Ys, Xs, rates[3, lbl]) t = plt.colorbar(cntr, extend='both') t.set_label('Frequency (Hz)') plt.xlabel('Position (in)') plt.ylabel('Position (in)') if lbl == 0: plt.title('Clockwise') else: plt.title('Counterclockwise') #plt.axis('equal') plt.xlim(room_shape[0]) plt.ylim(room_shape[1]) ''' plt.figure() x = np.arange(room_shape[0][0],room_shape[0][1],bin_size) y = np.arange(room_shape[1][0],room_shape[1][1],bin_size) Xs, Ys = np.meshgrid(x, y) cntr = plt.contourf(Ys,Xs,rate_dict[contxt][2]) t = plt.colorbar(cntr, extend='both') t.set_label('Frequency (Hz)') plt.xlabel('Position (in)') plt.ylabel('Position (in)')''' plt.show()
def checkGPV(): logging.basicConfig(level=5) animal = 66 session = 60 room_shape = [[-55,55],[-55,55]] tetrodes = [1] cells = range(2,10) bin_size = 5 K = 1# Segment length used to calculate firing rates maxs = 10000 assert maxs%K==0 #xbins = ybins = (room_shape[0][1]-room_shape[0][0])/bin_size good_clusters = {tetrode:cells for tetrode in tetrodes} #good_clusters = get_good_clusters(0) fn, trigger_tm = load_mux(animal, session) vl = load_vl(animal,fn) cls = {tetrode:load_cl(animal,fn,tetrode) for tetrode in tetrodes} label_l = vl['Task'] t_cells = count_cells(vl,cls,trigger_tm, good_clusters) '''''' # For debugging purposes, make sure it's not too big if len(label_l) > maxs: vl['xs'] = vl['xs'][:maxs*10:10] vl['ys'] = vl['ys'][:maxs*10:10] label_l = label_l[:maxs*10:10] for key in t_cells: tmp = np.array(t_cells[key]) tmp = tmp[tmp<maxs] t_cells[key] = tmp for gpv in [gpv1]: logging.info('About to generate population vector.') X, Y = gpv(vl, t_cells, label_l, K, bin_size, room_shape) logging.info('%i population vectors generated.',X.shape[0]) Y = Y.reshape([-1]) # Debug code # This is only true if no points are thrown away if X.shape[0]*K == maxs: tot_spks = np.sum([len(np.unique(spki)) for spki in t_cells.values()]) assert tot_spks == np.sum(X[:,:len(t_cells)])*K # GPV rates rates = fracs_from_pv(X,Y,bin_size,room_shape,smooth_flag=False) # Now get normally calculate rates real_rates = get_fracs(vl['xs'],vl['ys'],label_l,room_shape,bin_size, t_cells,smooth_flag=False) try: assert np.all(rates == real_rates) except: print 'DOESNT WORK!!' plot_rates(rates,Y,t_cells) plot_rates(real_rates,Y,t_cells) plt.show()