示例#1
0
def generate_psth_from_resp(rec,
                            epoch_regex='^STIM_',
                            smooth_resp=False,
                            **context):
    '''
    generate PSTH prediction from rec['resp'] (before est/val split). Could
    be considered "cheating" b/c predicted PSTH then is based on data in
    val set, but this is because we're interested in testing state effects,
    not sensory coding models. The appropriate control, however is to run
    generate_psth_from_est_for_both_est_and_val_nfold on each nfold est/val
    split.
    '''

    rec = preproc.generate_psth_from_resp(rec,
                                          epoch_regex,
                                          smooth_resp=smooth_resp)

    return {'rec': rec}
示例#2
0
                                state_signals=['pupil'],
                                permute_signals=[''],
                                new_signalname='state')
rec = preproc.make_state_signal(rec,
                                state_signals=['pupil'],
                                permute_signals=['pupil'],
                                new_signalname='state')  #shuffled pupil

# mask out data from incorrect trials
#rec = preproc.mask_all_but_correct_references(rec)#not for allen?

# calculate a PSTH response for each stimulus, save to a new signal 'psth'
epoch_regex = "^STIM_"
#epoch_regex="^natural_scene" #only natural scene stimulus
rec = preproc.generate_psth_from_resp(rec,
                                      epoch_regex=epoch_regex,
                                      smooth_resp=False)
#rec=nwb_resp_psth(rec,epoch_regex) #should return similar results as above for allen data

# ----------------------------------------------------------------------------
# INSPECT THE DATA

resp = rec['resp'].rasterize()
epochs = resp.epochs
epoch_regex = "^STIM_"
#epoch_regex="^natural_scene" #only natural scene stimulus
epoch_list = ep.epoch_names_matching(epochs, epoch_regex)

# list all stimulus events
print(epochs[epochs['name'].isin(epoch_list)])
示例#3
0
subwin = 0.25  # sub window size (mean rate across all / sd across all)
# CV = sd of spike counts across all subwindows divided by the mean across all sub windows
# If all neurons are Poisson and statistically independent, then the CV of the population rate will approach zero

site = 'TAR010c'
batch = 289

manager = BAPHYExperiment(cellid=site, batch=batch)
options = {'rasterfs': 4, 'resp': True, 'stim': False, 'pupil': True}
rec = manager.get_recording(**options)
rec['resp'] = rec['resp'].rasterize()
if batch == 331:
    rec = nems_preproc.fix_cpn_epochs(rec)
else:
    rec = nems_preproc.mask_high_repetion_stims(rec)
rec = generate_psth_from_resp(rec)

# extract continuous data (subtract psth?)
data = rec.apply_mask()['resp']._data  #- rec.apply_mask()['psth_sp']._data
pupil = rec.apply_mask()['pupil']._data

# divide into bins
win_bin = int(rec['resp'].fs * win)
subwin_bin = int(rec['resp'].fs * subwin)
CV = []
bpupil = []
i = 0
while ((i * win_bin) <= data.shape[-1]):
    mean = data[:, int(i * win_bin):int((i + 1) * win_bin)].mean()
    sd = data[:, int(i * win_bin):int((i + 1) * win_bin)].std()
    CV.append(sd / mean)
#manager = BAPHYExperiment(cellid='ARM033a', batch=331)
#manager = BAPHYExperiment(cellid='AMT026a', batch=331)
#manager = BAPHYExperiment(cellid='CRD018d', batch=331)
#manager = BAPHYExperiment(cellid='AMT020a', batch=331)
#manager = BAPHYExperiment(cellid='ARM031a', batch=331)
r = manager.get_recording(recache=True,
                          **{
                              'rasterfs': 4,
                              'resp': True,
                              'pupil': True,
                              'stim': False,
                              'pupil_variable_name': 'area'
                          })
r['resp'] = r['resp'].rasterize()
r = fix_cpn_epochs(r)
r = generate_psth_from_resp(r)

epochs = [e for e in r['resp'].epochs.name.unique() if e.startswith('STIM')]
r = r.and_mask(epochs)

binsizes = [0.5, 1, 2]  #, 3, 4]
thresh = 1
significant_pairs = False
for binsize in binsizes:
    rec = r.copy()
    # before masking, take raw signals and compute variance of an eyelid over a sliding window
    binsize = int(binsize * rec['resp'].fs)
    signal = rec['pupil_extras'].extract_channels(['eyelid_top_y'])._data
    signal2 = rec['pupil_extras'].extract_channels(['eyelid_bottom_y'])._data
    varsig = np.zeros(signal.shape)
    for i in range(varsig.shape[-1]):