for source, position in itt.product(range(20), range(positions)): probe = NTI_epoch_name(duration, source, position) fourway_name = f'191014_{site}_P{probe}_fourway_analysis' analysis_parameters = '_'.join( ['{}-{}'.format(key, str(val)) for key, val in meta.items()]) analysis_name = 'NTI_LDA_dprime' 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
bad_sites = list() df = list() # for site, probe in zip(['AMT029a', 'ley070a'],[5,2]): for site, probe in itt.product(all_sites, all_probes): try: LDA_anal_name = f'191014_{site}_P{probe}_fourway_analysis' LDA_anal = make_cache( function=fourway_analysis, func_args={ 'site': site, 'probe': probe, 'meta': meta }, classobj_name=LDA_anal_name, cache_folder= f'/home/mateo/mycache/{analysis_name}/{analysis_parameters}') # LDA_real, LDA_shuffled, LDA_simulated = get_cache(LDA_anal) except: bad_sites.append(f"{site}_P{probe}_LDA") continue try: dPCA_anal_name = f'191015_{site}_P{probe}_fourway_analysis' dPCA_anal = make_cache( function=dPCA_fourway_analysis,
signal_name = f'190709_{site}_P{probe}_ct-marg' func_args = { 'transitions_array': trans_arr, '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))
'voc_2': 'Greens', 'voc_3': 'Reds', 'voc_4': 'Purples' } 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'])
modelname = 'resp' site = 'AMT031a' 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)
voc_color = {'voc_{}'.format(cc): 'C{}'.format(cc) for cc in range(5)} 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()
this_site_shuffled = list() this_site_pvalues = list() for pp, probe in enumerate(all_probes): # single cell analysis object_name = f'200221_{site}_P{probe}_single_cell_dprime' analysis_parameters = '_'.join( ['{}-{}'.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)