rec['resp'] = rec['resp'].rasterize() rec['stim'] = rec['stim'].rasterize() rec = mask_high_repetion_stims(rec) rec = rec.apply_mask(reset_epochs=True) rec = rec.create_mask(True) if pupil_regress: rec = preproc.regress_state2(rec, state_sigs=['pupil'], regress=['pupil']) rec = rec.and_mask(['PreStimSilence', 'PostStimSilence'], invert=True) rec = rec.apply_mask(reset_epochs=True) # Create pupil masks p_ops = {'state': 'big', 'epoch': ['REFERENCE'], 'collapse': True} rec_bp = preproc.create_pupil_mask(rec, **p_ops) p_ops['state'] = 'small' rec_sp = preproc.create_pupil_mask(rec, **p_ops) # balanced epochs epochs = preproc.get_pupil_balanced_epochs(rec, rec_sp, rec_bp) rec_bp = rec_bp.and_mask(epochs) rec_sp = rec_sp.and_mask(epochs) rec_bp = rec_bp.apply_mask(reset_epochs=True) rec_sp = rec_sp.apply_mask(reset_epochs=True) # Compute coarse MI for each neuron, over all stimuli (balanced) Rbig = rec_bp['resp'].extract_epoch('REFERENCE').mean(0).mean(-1) Rsmall = rec_sp['resp'].extract_epoch('REFERENCE').mean(0).mean(-1) MI = (Rbig - Rsmall) / (Rbig + Rsmall)
rec['stim'] = rec['stim'].rasterize() rec = mask_high_repetion_stims(rec) rec = rec.apply_mask(reset_epochs=True) rec = preproc.generate_psth(rec) if balance_stims: epochs = preproc.get_pupil_balanced_epochs(rec) rec = rec.and_mask(epochs) rec = rec.apply_mask(reset_epochs=True) if evoked_only: rec = rec.and_mask(['PreStimSilence', 'PostStimSilence'], invert=True) rec = rec.apply_mask(reset_epochs=True) pup_ops = {'state': 'big', 'epoch': ['REFERENCE'], 'collapse': True} rec_bp = preproc.create_pupil_mask(rec.copy(), **pup_ops) pup_ops['state'] = 'small' rec_sp = preproc.create_pupil_mask(rec.copy(), **pup_ops) big_mask = rec_bp['mask'] small_mask = rec_sp['mask'] # Now, fit the model for the range of alpha2 values nCells = len(rec['resp'].chans) # intialize fit randomly. On other iterations, previous fit will be new x0 x0 = np.zeros( nCells * 3 ) # because of exp, this effectively initializes gain to 1 and baseline terms to 0 model_output = opt.minimize(glm.pupil_only_objective, x0, (rec),