from omb import OMB from stimulus import Stimulus exp, stim_nr = '20180710', 8 #exp, stim_nr = 'Kuehn', 13 st = OMB(exp, stim_nr) glmlabel = 'GLM_motion' savepath = os.path.join(st.stim_dir, glmlabel) os.makedirs(savepath, exist_ok=True) omb_stas = np.array(st.read_datafile()['stas']) texture_data = st.read_texture_analysis() all_spikes = st.allspikes() start = dt.datetime.now() kall = np.zeros((st.nclusters, 2, st.filter_length)) muall = np.zeros(st.nclusters) frs = np.zeros(all_spikes.shape) cross_corrs = np.zeros(st.nclusters) t = np.linspace(0, st.filter_length * st.frame_duration * 1000, st.filter_length) stimulus = st.bgsteps
npd_spikes = all_spikes.copy() # Exclude spikes that are not in desired direction to zero pd_spikes[~pd] = 0 npd_spikes[~npd] = 0 #%% filter_length = 20 contrast = st.generatecontrast( [100, 100], 100, filter_length - 1) # subtract one because rw generates one extra #contrast = st.generatecontrastmaxi([0, 0], 800, filter_length-1) # subtract one because rw generates one extra contrast_avg = contrast[:, :, filter_length + 1:].mean(axis=-1) rw = asc.rolling_window(contrast, filter_length, preserve_dim=False) #%% texture_file = st.read_texture_analysis() # Normally the texture stas are contrst avg subtracted # it will bedone again here, so we add it stas = texture_file['texturestas'][ choosecells, :] + texture_file['contrast_avg'][None, ..., None] from scratch_spikeshuffler import shufflebyrow shuffled_spikes = shufflebyrow(all_spikes) print('Calculating shuffled_stas') shuffled_stas = np.einsum('abcd,ec->eabd', rw, shuffled_spikes) shuffled_stas = shuffled_stas / shuffled_spikes.sum(axis=1)[:, None, None, None] print('Calculating pdstas')