Пример #1
0
def load_with_parms(site, **kwargs):
    # defaults

    options = {'batch': 316,
               'cellid': site,
               'stimfmt': 'envelope',
               'rasterfs': 100,
               'runclass': 'CPN',
               'stim': False,
               'resp':True}

    options.update(**kwargs)

    manager = BAPHYExperiment(siteid=site, batch=options['batch'])

    loaded_rec = manager.get_recording(recache=True, **options)
    parameters = manager.get_baphy_exptparams()

    # load_URI, _ = nb.baphy_load_recording_uri(**options)
    # loaded_rec = recording.load_recording(load_URI)

    CPN_rec = cpe.set_recording_subepochs(loaded_rec)
    recordings  = split_recording(CPN_rec)

    return recordings, parameters
Пример #2
0
def load(site, boxload=True, **kwargs):

    # defaults
    options = {'batch': 316,
               'cellid': site,
               'stimfmt': 'envelope',
               'rasterfs': 100,
               'recache': False,
               'runclass': 'CPN',
               'stim': False}

    options.update(**kwargs)

    if boxload is True:
        toname = options.copy()
        del toname['recache']
        filename = pl.Path(config['paths']['recording_cache']) / set_name(toname)

        if not filename.parent.exists():
            filename.parent.mkdir()

        if filename.exists() and options['recache'] is False:
            print('loading recording from box')
            loaded_rec = jl.load(filename)

        elif filename.exists() is False or options['recache'] is True:
            load_URI, _ = nb.baphy_load_recording_uri(**options)
            loaded_rec = recording.load_recording(load_URI)
            print('cacheing recoring in box')
            jl.dump(loaded_rec, filename)
        else:
            raise SystemError('WTF?')

    elif boxload is False:
        load_URI, _ = nb.baphy_load_recording_uri(**options)
        loaded_rec = recording.load_recording(load_URI)

    else:
        raise ValueError('boxload must be boolean')

    CPN_rec = cpe.set_recording_subepochs(loaded_rec)

    recordings  = split_recording(CPN_rec)
    return recordings
Пример #3
0
from src.data import epochs as cpe, PCA as cpca
import joblib as jl
import matplotlib.pyplot as plt
import numpy as np

test_rec_path = '/home/mateo/context_probe_analysis/pickles/BRT037b'
loaded_rec = jl.load(test_rec_path)

rec = cpe.set_recording_subepochs(loaded_rec, set_pairs=True)
sig = rec['resp']
eps = sig.epochs

# normalize matrix
full_mat = sig.rasterize()._data
mean = np.mean(full_mat.T, axis=0)
full_mat = (full_mat.T - mean).T

folded_mat = sig.rasterize().extract_epoch('C0_P1')

sk_sig, pca_sig = cpca.signal_PCA(sig, center=True)
sk_rec, pca_rec = cpca.recording_PCA(rec, signal_names='all', inplace=False, center=True)

U = pca_sig.components_ # 2d array nComponents x nFeatures
V = sk_sig._data

U = pca_rec['resp'].components_
V = sk_rec['resp_PCs']._data


#### plotting
Пример #4
0
        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

pop_sigs = col.defaultdict(dict)
for site_key, model_recs in pop_recs.items():
    for modelname, rec in model_recs.items():
        rec = cep.set_recording_subepochs(rec, set_pairs=False)
        pop_sigs[site_key][modelname] = rec['pred'].rasterize()
    pop_sigs[site_key]['resp'] = rec['resp'].rasterize()

# calculates the PCAs for each site, for each model prediction and response
PCA_stats = col.defaultdict(dict)
site_PCA = col.defaultdict(dict)
for site_key, site_models in pop_sigs.items():
    for sig_key, signal in site_models.items():
        PCA_sig, stats = cpca.signal_PCA(signal)
        site_PCA[site_key][sig_key] = PCA_sig
        PCA_stats[site_key][sig_key] = stats

# plots the variance explained by PCs for each site
for site_key, site_vals in PCA_stats.items():
    fig, ax = plt.subplots()
Пример #5
0
        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 = col.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()

del (pop_sigs['BRT057b'])

################################################
# iterates over each site id, and calculates the dispersion for predictions of each different model
site_disps = dict()
site_pvals = dict()
site_cnames = dict()
for disp_val in ['metric', 'pvalue']:
    for site, recs in pop_recs.items():
        # for multi core running
        # site_IDs = list(pop_recs.keys())
        # site = site_IDs[4]
Пример #6
0
Test = True

if Test == True:
    # # sets automatic path finding
    # this_script_dir = os.path.dirname(os.path.realpath(__file__))
    # pickle_path = '{}/pickles'.format(this_script_dir)
    # test_rec_path = os.path.normcase('{}/BRT037b'.format(pickle_path))
    test_rec_path = '/home/mateo/code/context_probe_analysis/pickles/BRT037b'
    loaded_rec = jl.load(test_rec_path)

else:
    load_URI = nb.baphy_load_recording_uri(**options)
    loaded_rec = recording.load_recording(load_URI)

# sets eps correpsondign to individual sounds as well as stim_num prb pairs
rec = cpe.set_recording_subepochs(loaded_rec)
sig = rec['resp']
eps = sig.epochs

# transforms the recording into its PCA equivalent
rec_pca, pca_stats = cpca.recording_PCA(rec, inplace=False, center=True)
sig_pca = rec_pca['resp_PCs']

plot = False

if plot == True:

    # variance explained by PCs

    for sig_name, pca in pca_stats.items():
        fig, ax = plt.subplots()