'site': site, 'probe': probe, 'meta': meta }, classobj_name=dPCA_anal_name, cache_folder= f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}') # dPCA_real, dPCA_shuffled, dPCA_simulated = get_cache(dPCA_anal) except: bad_sites.append(f"{site}_P{probe}_dPCA") continue for transformation, cache in zip(['LDA', 'dPCA'], [LDA_anal, dPCA_anal]): real, shuffled, simulated = get_cache(cache) for montecarlo, MCarray in zip( ['context discrimination', 'population effect'], [shuffled, simulated]): # calculates a signed pvalue, the signs is indicative of the direction, with possitive being higher and # negative being lower than the mean of the Montecarlo distribution. Bi virtue of this distinction # the p value is calculated on a single tail. mont_mean = np.mean(MCarray, axis=0) neg_pval = np.sum((MCarray < real), axis=0) / meta['montecarlo'] pos_pval = np.sum((MCarray > real), axis=0) / meta['montecarlo'] pvalues = np.where(real >= mont_mean, pos_pval, -neg_pval)
'probe_names': [probe], 'context_transitions': trans_pair, 'probe_order': [probe], 'trans_order': meta['transitions'], 'shuffle_num': meta['nonparam_shuffle'], 'trial_combinations': True } shuffled_dispersion_time = make_cache( function=ndisp.transition_pair_comparison_by_trials, func_args=func_args, classobj_name=signal_name, recache=False, cache_folder= f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}') real, trans_shuffle, trial_shuffle = get_cache( shuffled_dispersion_time) # pvalue = (msd_floor > obs_msd).sum() / shuffle_n pvalues = np.sum( (real < trans_shuffle), axis=0) / meta['nonparam_shuffle'] for pval_threshold in [0.05, 0.01, 0.001]: signif = pvalues < pval_threshold total_sig = np.sum(signif) try: last_sig = np.max(np.argwhere(signif)) except: # if there is not significant last_sig = 0 d = { 'site': site,
nway = make_cache( function=dPrime_from_NIT_site, func_args={ 'site': site, 'duration': duration, 'source': source, 'position': position, 'meta': meta }, classobj_name=fourway_name, cache_folder= f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}', recache=False) real, shuffled, simulated, transitions, contexts = get_cache( nway) # get_cache(twoway) if real is None: continue trans_pairs = itt.combinations(transitions, 2) trans_pairs = [sorted(tp) for tp in trans_pairs ] # makes sure to not have repeated pairs as a-b b-a for tt, trans_pair in enumerate(trans_pairs): pair_name = f'{trans_pair[0]}_{trans_pair[1]}' all_real[pair_name].append(real[tt, :]) all_shuffled[pair_name].append(shuffled[:, tt, :]) all_simulated[pair_name].append(simulated[:, tt, :]) # stacs all the individual probe instances across a new axis
'site': site, 'probe': probe, 'meta': meta }, classobj_name=fourway_name, cache_folder= f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}') # twoway_name = f'191014_{site}_P{probe}_twoway_analysis' # # twoway = make_cache(function=twoway_analysis, # func_args={'site': site, 'probe': probe, 'meta': meta}, # classobj_name=twoway_name, # cache_folder=f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}') four = get_cache(fourway) # get_cache(twoway) for analysis, a_name in zip([four], ['fourway']): real, shuffled, simulated = analysis # pairwise dprime trans_pairs = list(itt.combinations(meta['transitions'], 2)) trans_count = 0 nrow = 2 ncol = 3 fig, axes = plt.subplots(nrow, ncol, sharey=True, sharex=True,
sites = load.get_site_ids(310) pop_recs = col.defaultdict(dict) for (site_name, cells), modelname in itt.product(sites.items(), all_models): print('#####\nreconstituting site {} with model {}\n '.format( site_name, modelname)) recons_args = {'batch': 310, 'cellid_list': cells, 'modelname': modelname} recons_cache = ccache.make_cache( crec.reconsitute_rec, func_args=recons_args, classobj_name='reconstitution', recache=False, cache_folder='/home/mateo/mycache/reconstitute_recs', use_hash=True) reconstituted_recording = ccache.get_cache(recons_cache) # rasterizes and takes the PSTH of full length signals (containing multiple contex probes) reconstituted_recording.signals = { key: val.rasterize() for key, val in reconstituted_recording.signals.items() } reconstituted_recording = npre.average_away_epoch_occurrences( reconstituted_recording) pop_recs[site_name][modelname] = reconstituted_recording # removese the flat response of BRT057b todo solve the bug del (pop_recs['BRT057b']) # reorders in dictionary of signals, including only the response and the prediction of each mode # reformats the epochs
'probe_names': [probe], 'context_transitions': trans_pair, 'probe_order': [probe], 'trans_order': meta['transitions'], 'shuffle_num': meta['nonparam_shuffle'], 'trial_combinations': True } shuffled_dispersion_time = make_cache( function=ndisp.transition_pair_comparison_by_trials, func_args=func_args, classobj_name=signal_name, recache=False, cache_folder= f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}') real, shuffled, scrambled = get_cache(shuffled_dispersion_time) #define subplots PairAx = plt.subplot2grid((4, 7), (pp, tt + 1), rowspan=1, colspan=1, fig=fig) if meta['include_ctx'] is True: fig, ax = plot.plot_dist_with_CI(real, [shuffled], ['p < 0.05'], ['gray'], smp_start=0, smp_end=200, smp_line=100, fs=100, ax=PairAx)
start = 0 end = 200 t1 = (start / 100) - 1 t2 = (end / 100) - 1 ## signal_name = '190431_{}_{}'.format(site, modelname) func_args = {'signal': sig, 'probe_names': prbs, 'context_names': ctxs, 'shuffle_num': 1000, 'trial_combinations': False} shuffled_dispersion_time = cch.make_cache(function=cdisp.signal_single_trial_dispersion_pooled_shuffled, func_args=func_args, classobj_name=signal_name, recache=False, cache_folder='/home/mateo/mycache/shuffled_euclideans') real, distribution = cch.get_cache(shuffled_dispersion_time) fig, ax = plt.subplots() line = real[start:end] shade = distribution[:, start:end] shade = np.mean(shade, axis=0) + np.std(shade, axis=0) * 2 t = np.linspace(t1, t2, len(line)) ax.plot(t, line , label='{}'.format(site), color='C0') ax.fill_between(t, -shade , shade , alpha=0.5, color='C0') ax.axvline(0, color='black', linestyle='--') # ax.legend(prop={'size': 15}) ax.set_xlabel('time (s)', fontsize=18) ax.set_ylabel('euclidean distance', fontsize=18) ax.tick_params(axis='both', which='major', labelsize=15)
func_args = { 'signal': sig, 'probe_names': prbs, 'context_transitions': int_tran, 'channels': what_cells, 'shuffle_num': 1000, 'trial_combinations': True } shuffled_dispersion_time = cch.make_cache( function=cdisp.signal_single_trial_dispersion_pooled_shuffled, func_args=func_args, classobj_name=signal_name, recache=False, cache_folder='/home/mateo/mycache/shuffled_euclideans') real, shuffled = cch.get_cache(shuffled_dispersion_time) ######################################################################################################################## # plots only a subset site = 'AMT029a' for int_tran in interesting_transition_pairs: options = { 'batch': 316, 'siteid': site, 'stimfmt': 'envelope', 'rasterfs': 100, 'recache': False, 'runclass': 'CPN', 'stim': False
voc_cmpat = {'voc_0': 'Blues', 'voc_1': 'Oranges', 'voc_2': 'Greens', 'voc_3': 'Reds', 'voc_4': 'Purples'} sites = load.get_site_ids(310) ################################################ # get and reconstitute single cell recordings into population recording pop_recs = coll.defaultdict(dict) for (site_name, cells), modelname in itt.product(sites.items(), all_models): print('#####\nreconstituting site {} with model {}\n '.format(site_name, modelname)) recons_args = {'batch':310, 'cellid_list':cells, 'modelname': modelname} recons_cache = ccache.make_cache(crec.reconsitute_rec, func_args=recons_args, classobj_name='reconstitution', recache=False, cache_folder='/home/mateo/mycache/reconstitute_recs', use_hash=True) reconstituted_recording = ccache.get_cache(recons_cache) pop_recs[site_name][modelname] = reconstituted_recording # if pop_recs['BRT057b']: # del(pop_recs['BRT057b']) ################################################ # reorders in dictionary of signals, including only the response and the prediction of each mode # reformats the epochs pop_sigs = coll.defaultdict(dict) for site_key, model_recs in pop_recs.items(): for modelname, rec in model_recs.items(): cpp_rec = cep.set_recording_subepochs(rec, set_pairs=True) pop_sigs[site_key][modelname] = cpp_rec['pred'].rasterize() pop_sigs[site_key]['resp'] = cpp_rec['resp'].rasterize()
'probe_names': [probe], 'context_transitions': trans_pair, 'probe_order': [probe], 'trans_order': meta['transitions'], 'shuffle_num': meta['nonparam_shuffle'], 'trial_combinations': True } shuffled_dispersion_time = make_cache( function=ndisp.transition_pair_comparison_by_trials, func_args=func_args, classobj_name=signal_name, recache=False, cache_folder= f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}') real, cont_shuff, pop_shuff = get_cache(shuffled_dispersion_time) #define subplots PairAx = plt.subplot2grid((4, 7), (pp, tt + 1), rowspan=1, colspan=1, fig=fig) fig, ax = plot.plot_dist_with_CI(real, [cont_shuff], ['p < 0.05'], ['gray'], smp_start=0, smp_end=100, smp_line=0, fs=100, ax=PairAx)
['{}-{}'.format(key, str(val)) for key, val in meta.items()]) analysis_name = 'CPN_singel_cell_dprime' cache_folder = pl.Path('C:\\', 'users', 'mateo', 'mycache', analysis_name, analysis_parameters) SC_cache = make_cache(function=cell_dprime, func_args={ 'site': site, 'probe': probe, 'meta': meta }, classobj_name=object_name, cache_folder=cache_folder, recache=dprime_recache) dprime, shuf_dprime, cell_names, trans_pairs = get_cache(SC_cache) this_site_reals.append(dprime) this_site_shuffled.append(shuf_dprime) # single tailed p value base on the montecarlo shuffling SC_pvalues = np.sum( (shuf_dprime >= dprime), axis=0) / meta['montecarlo'] this_site_pvalues.append(SC_pvalues) this_site_reals = np.stack(this_site_reals, axis=0) this_site_shuffled = np.stack(this_site_shuffled, axis=0) this_site_pvalues = np.stack(this_site_pvalues, axis=0) # reorders date in dictionary of cells for cc, cell in enumerate(cell_names):
best_site = 'BRT056b' best_model = 'wc.2x2.c-stp.2-fir.2x15-lvl.1-stategain.S-dexp.1' cells = sites[best_site] # reconstitutes population recording print('#####\nreconstituting site {} with model {}\n '.format( best_site, best_model)) recons_args = {'batch': 310, 'cellid_list': cells, 'modelname': best_model} recons_cache = ccache.make_cache( crec.reconsitute_rec, func_args=recons_args, classobj_name='reconstitution', recache=False, cache_folder='/home/mateo/mycache/reconstitute_recs', use_hash=True) rrec = ccache.get_cache(recons_cache) # formats with CPP epochs and gets rec = cep.set_recording_subepochs(rrec, set_pairs=False) # get the envelopes all_stims = rec['stim'].rasterize().extract_epochs( ['voc_1', 'voc_2', 'voc_3', 'voc_4']) # gets an example of each stimulus for both channels all_stims = {stim_name: arr[0, :, :] for stim_name, arr in all_stims.items()} envelopes = { 'env_0': all_stims['voc_1'][0, :], 'env_1': all_stims['voc_3'][0, :] }