pass else: batch = 289 # get decoding results loader = decoding.DecodingResults() fn = os.path.join(DPRIME_DIR, site, modelname + '_TDR.pickle') results = loader.load_results(fn, cache_path=CACHE_PATH, recache=recache) df = results.numeric_results.loc[results.evoked_stimulus_pairs] df['noiseAlign'] = results.slice_array_results( 'cos_dU_evec_test', results.evoked_stimulus_pairs, 2, idx=(0, 0))[0] X, sp_bins, X_pup, pup_mask, epochs = decoding.load_site( site=site, batch=batch, return_epoch_list=True) ncells = X.shape[0] nreps = X.shape[1] nstim = X.shape[2] nbins = X.shape[3] sp_bins = sp_bins.reshape(1, sp_bins.shape[1], nstim * nbins) nstim = nstim * nbins # =========================== generate a list of stim pairs ========================== # these are the indices of the decoding results dataframes all_combos = list(combinations(range(nstim), 2)) spont_bins = np.argwhere(sp_bins[0, 0, :]) spont_combos = [ c for c in all_combos if (c[0] in spont_bins) & (c[1] in spont_bins) ]
regress_pupil = False el_only = False sim1 = False sim2 = False njacks = 10 # generate one random est / val set jk_set = 2 # which jack set to use for plotting combo = None #(56, 58) # if None, just using first evoked/evoked combo site = 'TAR010c' batch = 289 site = 'AMT020a' batch = 331 # ================================= load recording ================================== X, sp_bins, X_pup, pup_mask = decoding.load_site(site=site, batch=batch, sim_first_order=sim1, sim_second_order=sim2, regress_pupil=regress_pupil, verbose=False) ncells = X.shape[0] nreps = X.shape[1] nstim = X.shape[2] nbins = X.shape[3] X = X.reshape(ncells, nreps, nstim * nbins) sp_bins = sp_bins.reshape(1, sp_bins.shape[1], nstim * nbins) # mask pupil per stimulus, rather than overall pup_mask = pup_mask.reshape(1, nreps, nstim * nbins) nstim = nstim * nbins # =========================== generate list of est/val sets ========================== est, val, p_est, p_val = nat_preproc.get_est_val_sets(X,
beta2 = lv_results[site + str(batch)]['beta2'] else: beta1 = None beta2 = None else: beta1 = None beta2 = None # ================================= load recording ================================== X, sp_bins, X_pup, pup_mask, epochs = decoding.load_site( site=site, batch=batch, pca_ops=pca_ops, regress_pupil=regress_pupil, gain_only=gain_only, dc_only=dc_only, use_xforms=use_xforms, return_epoch_list=True, exclude_low_fr=exclude_low_fr, threshold=threshold, mask_movement=movement_mask, use_old_cpn=use_old_cpn) ncells = X.shape[0] nreps_raw = X.shape[1] nstim = X.shape[2] nbins = X.shape[3] sp_bins = sp_bins.reshape(1, sp_bins.shape[1], nstim * nbins) nstim = nstim * nbins # =========================== generate a list of stim pairs ========================== all_combos = list(combinations(range(nstim), 2))
res = loader.load_results(fn, cache_path=None, recache=recache) df = res.numeric_results.loc[pd.IndexSlice[res.evoked_stimulus_pairs, ndim], :] df['delta_dprime'] = (df['bp_dp'] - df['sp_dp']) / (df['bp_dp'] + df['sp_dp']) df['raw_delta'] = (df['bp_dp'] - df['sp_dp']) stims = (1, 8, 9) stims = (0, 1, 9) #stims = (5, 6, 9) # pretty good example, but numerically doesn't hold up #stims = np.sort(np.random.choice(range(12), 3, replace=False)) combos = ['_'.join([str(i) for i in x]) for x in list(combinations(stims, 2))] #stims = (2, 8, 11) # ====================== Get PC data ====================== xf_model = None X_raw, sp_bins, X_pup, pup_mask, epochs, spont_raw = decoding.load_site( site=site, batch=batch, xforms_modelname=None, mask_movement=(.25, 1), special=True) if xf_model is not None: X, _, _, _, _, _ = decoding.load_site(site=site, batch=batch, xforms_modelname=xf_model, special=True) else: X = X_raw.copy() ncells = X_raw.shape[0] nreps = X_raw.shape[1] nstim = X_raw.shape[2] nbins = X_raw.shape[3] sp_bins = sp_bins.reshape(1, sp_bins.shape[1], nstim * nbins) nstim = nstim * nbins
if 'mask' not in rec.signals: rec = rec.create_mask(True) rec['mask'] = rec['mask']._modified_copy(rec['mask']._data.astype(bool)) rec = rec.and_mask(['PreStimSilence', 'PostStimSilence'], invert=True) if batch != 331: nspont_bins = rec['resp'].extract_epoch('PreStimSilence').shape[-1] else: nspont_bins = 0 else: nspont_bins = 0 rec = rec.apply_mask(reset_epochs=True) # get the pupil range for each stimulus pair, then save the mean of this for the site use_xforms = regression_method2 X, sp_bins, X_pup, pup_mask = load_site(site=site, batch=batch, regress_pupil=pupil_regress, use_xforms=use_xforms) ncells = X.shape[0] nreps_raw = X.shape[1] nstim = X.shape[2] nbins = X.shape[3] sp_bins = sp_bins.reshape(1, sp_bins.shape[1], nstim * nbins) nstim = nstim * nbins X_pup = X_pup.reshape(1, nreps_raw, nstim) pup_mask = pup_mask.reshape(1, nreps_raw, nstim) pupil_range = get_pupil_range(X_pup, pup_mask) mean_pupil_range = pupil_range['range'].iloc[:-1].mean() log.info("Mask large and small pupil") # handle using xforms pupil mask rec_bp = rec.copy()