def setup_fir_fitter(info_dict, events_dict, timecourses, windowlen=20):
    windowlen = windowlen - windowlen % info_dict['TR']
    rf = nideconv.ResponseFitter(
        input_signal=timecourses,
        sample_rate=1 / info_dict['TR'])
    for trial_type in events_dict:
        rf.add_event(event_name=trial_type,
                     onsets=events_dict[trial_type],
                     interval=[0, windowlen])
    return(rf)
Beispiel #2
0
    def test_vanilla_deconvolve(self,
                                event_1_gain=1,
                                event_2_gain=1,
                                noise_gain=1.5,
                                signal_sample_frequency=4,
                                **kwargs):
        """The simplest of possible tests, two impulse response functions
        with different shapes, both with gain = 1
        """
        self.create_signals(signal_sample_frequency=signal_sample_frequency,
                            event_1_gain=event_1_gain,
                            event_2_gain=event_2_gain,
                            event_1_sd=0,
                            event_2_sd=0,
                            noise_gain=noise_gain)

        self.rfy = nideconv.ResponseFitter(
            input_signal=self.input_data,
            sample_rate=self.signal_sample_frequency)

        # first event type, no covariate
        self.rfy.add_event(
            event_name='1',
            onset_times=self.events_1,
            durations=self.durations_1,
            # durations=None,
            interval=self.deconvolution_interval,
            **kwargs)
        # second
        self.rfy.add_event(
            event_name='2',
            onset_times=self.events_2,
            durations=self.durations_2,
            # durations=None,
            interval=self.deconvolution_interval,
            **kwargs)

        self.rfy.regress()
    def setUp(self, n_subjects=25, TR=1.5):

        self.TR = TR
        self.log = logging.getLogger('hb_test')

        self.data, self.onsets, self.parameters = (simulate_fmri_experiment(
            [{
                'name': 'Condition A',
                'mu_group': 5,
                'std_group': 3
            }, {
                'name': 'Condition B',
                'mu_group': 10,
                'std_group': 3
            }],
            n_subjects=n_subjects,
            run_duration=60,
            n_trials=10,
            TR=TR))

        self.hfit = HierarchicalBayesianModel()

        df = []

        for subject, d in self.data.reset_index().groupby(['subject']):
            fitter = nideconv.ResponseFitter(d.signal.values, 1. / self.TR)

            fitter.add_event('Condition A',
                             self.onsets.loc[subject, 'Condition A'].onset,
                             interval=[0, 20])

            fitter.add_event('Condition B',
                             self.onsets.loc[subject, 'Condition B'].onset,
                             interval=[0, 20])

            self.hfit.add_run(fitter, subject)
Beispiel #4
0
plt.legend([l1, l2], ['Cue', 'Stimulus'])
plt.gcf().set_size_inches(10, 4)

##############################################################################
# Naive approach: epoched averaging
# ---------------------------------
# A simple approach that is appropriate for fast electrphysiological signals
# like EEG and MEG, but not necessarily fMRI, would be to select little chunks of the 
# time series, corresponding to the onset of the events-of-interest and the subsequent
# 20 seconds of signal ("epoching").

##############################################################################
# We can do such a epoch-analysis using nideconv, by making a ResponseFitter
# object and using the `get_epochs()`-function:

rf =nideconv.ResponseFitter(input_signal=data,
                            sample_rate=1)

# Get all the epochs corresponding to cue-onsets for subject 1,
# run 1.
cue_epochs = rf.get_epochs(onsets=onsets.loc['cue'].onset, 
                           interval=[0, 20])

#############################################################################
# Now we have a 4 x 21 DataFrame of epochs, that we can all plot 
# in the same figure:
print(cue_epochs)
cue_epochs.T.plot(c=palette[0], alpha=.5, ls='--', legend=False)
cue_epochs.mean().plot(c=palette[0], lw=2, alpha=1.0)
sns.despine()
plt.xlabel('Time (s)')
plt.title('Epoched average of cue-locked response')
                    print 'Event named ' + theseEventNames[
                        oneEventTypeIndex] + ' excluded from ' + onePlotDict[
                            'plotTitle'] + ' for observer ' + oneObserver + ' because insufficient events'

            theseEventsActuallyUsed = [
                theseEvents[eventTypeIndex]
                for eventTypeIndex in eventTypesIndicesIncluded
            ]
            theseEventNamesActuallyUsed = [
                theseEventNames[eventTypeIndex]
                for eventTypeIndex in eventTypesIndicesIncluded
            ]

            #------------
            rfy = nideconv.ResponseFitter(
                input_signal=paddedPupilSamplesCleaned,
                sample_rate=newSampleRate)

            for eventIndex, eventName in enumerate(
                    theseEventNamesActuallyUsed):
                if eventName == 'saccades_Any':
                    thisInterval = decoIntervalSacc
                    numFuncs = numBasisFunctionsIncOffsetSacc
                elif eventName == 'blinks_Any':
                    thisInterval = decoIntervalBlink
                    numFuncs = numBasisFunctionsIncOffsetBlink
                else:
                    thisInterval = decoInterval
                    numFuncs = numBasisFunctionsIncOffset

                rfy.add_event(event_name=eventName,