def __init__(self, session_id): self.session_id = session_id save_path_head = core.get_save_path() self.save_path = os.path.join(save_path_head, 'LocallySparseNoise') self.l0_events = core.get_L0_events(self.session_id) self.stim_table_sp, _, _ = core.get_stim_table(self.session_id, 'spontaneous') self.dxcm = core.get_running_speed(self.session_id) try: lsn_name = 'locally_sparse_noise' self.stim_table, self.numbercells, self.specimen_ids = core.get_stim_table( self.session_id, lsn_name) self.LSN = core.get_stimulus_template(self.session_id, lsn_name) self.sweep_events, self.mean_sweep_events, self.sweep_p_values, self.running_speed, self.response_events_on, self.response_events_off = self.get_stimulus_response( self.LSN) except: lsn_name = 'locally_sparse_noise_4deg' self.stim_table, self.numbercells, self.specimen_ids = core.get_stim_table( self.session_id, lsn_name) self.LSN_4deg = core.get_stimulus_template(self.session_id, lsn_name) self.sweep_events_4deg, self.mean_sweep_events_4deg, self.sweep_p_values_4deg, self.running_speed_4deg, self.response_events_on_4deg, self.response_events_off_4deg = self.get_stimulus_response( self.LSN_4deg) lsn_name = 'locally_sparse_noise_8deg' self.stim_table, _, _ = core.get_stim_table( self.session_id, lsn_name) self.LSN_8deg = core.get_stimulus_template(self.session_id, lsn_name) self.sweep_events_8deg, self.mean_sweep_events_8deg, self.sweep_p_values_8deg, self.running_speed_8deg, self.response_events_on_8deg, self.response_events_off_8deg = self.get_stimulus_response( self.LSN_8deg) self.peak = self.get_peak(lsn_name) self.save_data(lsn_name)
def __init__(self, session_id): self.session_id = session_id save_path_head = core.get_save_path() self.save_path = os.path.join(save_path_head, 'NaturalScenes') self.l0_events = core.get_L0_events(self.session_id) self.stim_table, self.numbercells, self.specimen_ids = core.get_stim_table(self.session_id, 'natural_scenes') self.stim_table_sp,_,_ = core.get_stim_table(self.session_id, 'spontaneous') self.dxcm = core.get_running_speed(self.session_id) self.sweep_events, self.mean_sweep_events, self.sweep_p_values, self.running_speed, self.response_events, self.response_trials = self.get_stimulus_response() self.peak = self.get_peak() self.save_data()
def __init__(self, session_id): self.session_id = session_id save_path_head = core.get_save_path() self.save_path = os.path.join(save_path_head, 'DriftingGratings') self.l0_events = core.get_L0_events(self.session_id) self.stim_table, self.numbercells, self.specimen_ids = core.get_stim_table( self.session_id, 'drifting_gratings') self.dxcm = core.get_running_speed(self.session_id) self.stim_table_sp, _, _ = core.get_stim_table(self.session_id, 'spontaneous') self.orivals = range(0, 360, 45) self.tfvals = [0, 1, 2, 4, 8, 15] self.sweep_events, self.mean_sweep_events, self.sweep_p_values, self.running_speed, self.response_events, self.response_trials = self.get_stimulus_response( ) self.peak = self.get_peak() self.save_data()
def __init__(self, session_id): self.session_id = session_id save_path_head = core.get_save_path() self.save_path = os.path.join(save_path_head, 'StaticGratings') self.l0_events = core.get_L0_events(self.session_id) self.stim_table, self.numbercells, self.specimen_ids = core.get_stim_table( self.session_id, 'static_gratings') self.stim_table_sp, _, _ = core.get_stim_table(self.session_id, 'spontaneous') self.dxcm = core.get_running_speed(self.session_id) self.orivals = range(0, 180, 30) self.sfvals = [0, 0.02, 0.04, 0.08, 0.16, 0.32] self.phasevals = [0, 0.25, 0.5, 0.75] self.sweep_events, self.mean_sweep_events, self.sweep_p_values, self.running_speed, self.response_events, self.response_trials = self.get_stimulus_response( ) self.peak = self.get_peak() self.save_data()
def __init__(self, session_id): self.session_id = session_id save_path_head = core.get_save_path() self.save_path = os.path.join(save_path_head, 'LocallySparseNoise') self.l0_events = core.get_L0_events(self.session_id) #TODO: enable lsn, lsn4, lsn8 lsn_name = 'locally_sparse_noise' self.stim_table, self.numbercells, self.specimen_ids = core.get_stim_table( self.session_id, 'locally_sparse_noise') self.LSN = core.get_stimulus_template('locally_sparse_noise') self.stim_table_sp, _, _ = core.get_stim_table(self.session_id, 'spontaneous') self.dxcm = core.get_running_speed(self.session_id) self.sweep_events, self.mean_sweep_events, self.sweep_p_values, self.running_speed, self.response_events, self.response_trials = self.get_stimulus_response( ) self.peak = self.get_peak() self.save_data()
def Speed_Tuning(session_id, binsize=900): save_path_head = core.get_save_path() save_path = os.path.join(save_path_head, 'SpeedTuning') l0_events = core.get_L0_events(session_id) dxcm = core.get_running_speed(session_id) _, numbercells, specimen_ids = core.get_stim_table(session_id, 'spontaneous') # numbercells = l0_events.shape numbins = 1 + len(dxcm[np.where(dxcm > 1)] / binsize) #remove any NaNs from running and activity traces dx_trim = dxcm[~np.isnan(dxcm)] l0_trim = l0_events[:, ~np.isnan(dxcm)] #rank sort traces by running speed dx_sorted = dx_trim[np.argsort(dx_trim)] events_sorted = l0_trim[:, np.argsort(dx_trim)] #bin running and activity binned_cells = np.zeros((numbercells, numbins, 2)) binned_dx = np.zeros((numbins, 2)) for i in range(numbins): offset = np.were(dx_sorted > 1)[0][0] if i == 0: binned_dx[i, 0] = np.mean(dx_sorted[:offset]) binned_dx[i, 1] = np.std(dx_sorted[:offset]) / np.sqrt(offset) binned_cells[:, i, 0] = np.mean(events_sorted[:, :offset], axis=1) binned_cells[:, i, 1] = np.std(events_sorted[:, :offset], axis=1) / np.sqrt(offset) else: start = offset + (i - 1) * binsize binned_dx[i, 0] = np.mean(dx_sorted[start:start + binsize]) binned_dx[i, 1] = np.std( dx_sorted[start:start + binsize]) / np.sqrt(binsize) binned_cells[:, i, 0] = np.mean(events_sorted[:, start:start + binsize], axis=1) binned_cells[:, i, 1] = np.std(events_sorted[:, start:start + binsize], axis=1) / np.sqrt(binsize) #shuffled activity to get significance binned_cells_shuffled = np.empty((numbercells, numbins, 2, 200)) for shuf in range(200): events_shuffled = l0_trim[:, np.random.permutation(np.size(l0_trim, 1))] events_shuffled_sorted = events_shuffled[:, np.argsort(dx_trim)] for i in range(numbins): offset = np.were(dx_sorted > 1)[0][0] if i == 0: binned_cells_shuffled[:, i, 0, shuf] = np.mean( events_shuffled_sorted[:, :offset], axis=1) binned_cells_shuffled[:, i, 1, shuf] = np.std( events_shuffled_sorted[:, :offset], axis=1) / np.sqrt(offset) else: start = offset + (i - 1) * binsize binned_cells_shuffled[:, i, 0, shuf] = np.mean( events_shuffled_sorted[:, start:start + binsize], axis=1) binned_cells_shuffled[:, i, 1, shuf] = np.std( events_shuffled_sorted[:, start:start + binsize], axis=1) / np.sqrt(binsize) shuffled_variance = binned_cells_shuffled[:, :, 0, :].std(axis=1)**2 variance_threshold = np.percentile(shuffled_variance, 99.9, axis=1) response_variance = binned_cells[:, :, 0].std(axis=1)**2 peak = pd.DataFrame(columns=('cell_specimen_id', 'run_mod'), index=range(numbercells)) peak.cell_specimen_id = specimen_ids peak.run_mod = response_variance > variance_threshold #save data save_file = os.path.join(save_path, str(session_id) + '_speed_tuning_events.h5') store = pd.HDFStore(save_file) store['peak'] = peak store.close() f = h5py.File(save_file, 'r+') dset = f.create_dataset('binned_dx', data=binned_dx) dset1 = f.create_dataset('binned_cells', data=binned_cells) dset2 = f.create_dataset('binned_cells_shuffled', data=binned_cells_shuffled) f.close()