Timecourse functionality

We fit the receptive field structure on signal time courses, so we need to be able to manipulate those. This module provides some functionality to do just that.

prfpy.timecourse.convolve_stimulus_dm(stimulus, hrf)[source]

convolve_stimulus_dm convolves an N-D (N>=2) stimulus array with an hrf

Parameters

stimulusnumpy.ndarray, N-D (N>=2)

stimulus experimental design, with the final dimension being time

hrfnumpy.ndarray, 1D

contains kernel for convolution

prfpy.timecourse.dcfilter_predictions(predictions, first_modes_to_remove=5, last_modes_to_remove_percent=0, add_mean=True, task_lengths=None, task_names=None, late_iso_dict=None, **kwargs)[source]

discrete cosine filter predictions, to conform to data filtering

Parameters

predictionsnumpy.ndarray

array containing predictions, last dimension is time

first_modes_to_removeint, optional

Number of low-frequency eigenmodes to remove (highpass)

last_modes_to_remove_percentint, optional

Percentage of high-frequency eigenmodes to remove (lowpass)

add_meanbool, optional

whether to add the mean of the time-courses back to the signal after filtering (True, default) or not (False)

task_lengthslist of ints, optional

If there are multiple tasks, specify their lengths in TRs. The default is None.

task_nameslist of str, optional

Task names. The default is None.

late_iso_dictdict, optional

Dictionary whose keys correspond to task_names. Entries are ndarrays containing the TR indices used to compute the BOLD baseline for each task. The default is None.

Returns

numpy.ndarray

filtered version of the array

prfpy.timecourse.filter_predictions(predictions, filter_type, filter_params)[source]

Generic filtering function, calling the different types of filters implemented.

Parameters

See individual filters for description.

Returns

numpy.ndarray

filtered version of the array

prfpy.timecourse.generate_arima_noise(ar=(1, 0.4), ma=(1, 0.0), dimensions=(1000, 120), **kwargs)[source]

generate_arima_noise creates temporally correlated noise

Parameters

artuple, optional

arima autoregression parameters for statsmodels generation of noise (the default is (1,0.4), which should be a reasonable setting for fMRI noise)

matuple, optional

arima moving average parameters for statsmodels generation of noise (the default is (1,0.0), which should be a reasonable setting for fMRI noise)

dimensionstuple, optional

the first dimension is the nr of separate timecourses, the second dimension is the timeseries length. (the default is (1000,120), a reasonable if brief length for an fMRI run)

**kwargs are passed on to statsmodels.tsa.arima_process.arma_generate_sample

Returns

numpy.ndarray

noise of requested dimensions and properties

prfpy.timecourse.generate_random_cosine_drifts(dimensions=(1000, 120), amplitude_ranges=[[500, 600], [-50, 50], [-20, 20], [-10, 10], [-5, 5]])[source]

generate_random_cosine_drifts generates random slow drifts

Parameters

dimensionstuple, optional

shape of the desired data, latter dimension = timepoints the default is (1000,120), which creates 1000 timecourses for a brief fMRI run

amplitude_rangeslist, optional

Amplitudes of each of the components. Ideally, this should follow something like 1/f. the default is [[500,600],[-50,50],[-20,20],[-10,10],[-5,5]]

Returns

numpy.ndarray

discrete cosine drifts with dimensions [dimensions]

numpy.ndarray

random multiplication factors that created the drifts

prfpy.timecourse.generate_random_legendre_drifts(dimensions=(1000, 120), amplitude_ranges=[[500, 600], [-50, 50], [-20, 20], [-10, 10], [-5, 5]])[source]

generate_random_legendre_drifts generates random slow drifts

Parameters

dimensionstuple, optional

shape of the desired data, latter dimension = timepoints the default is (1000,120), which creates 1000 timecourses for a brief fMRI run

amplitude_rangeslist, optional

Amplitudes of each of the components. Ideally, this should follow something like 1/f. the default is [[500,600],[-50,50],[-20,20],[-10,10],[-5,5]]

Returns

numpy.ndarray

legendre poly drifts with dimensions [dimensions]

numpy.ndarray

random multiplication factors that created the drifts

prfpy.timecourse.sgfilter_predictions(predictions, window_length=201, polyorder=3, highpass=True, add_mean=True, task_lengths=None, task_names=None, late_iso_dict=None, **kwargs)[source]

savitzky golay filter predictions, to conform to data filtering

Parameters

predictionsnumpy.ndarray

array containing predictions, last dimension is time

window_lengthint, optional

window length for SG filter (the default is 201, which is ok for prf experiments, and a bit long for event-related experiments)

polyorderint, optional

polynomial order for SG filter (the default is 3, which performs well for fMRI signals when the window length is longer than 2 minutes)

highpassbool, optional

whether to use the sgfilter as highpass (True, default) or lowpass (False)

add_meanbool, optional

whether to add the mean of the time-courses back to the signal after filtering (True, default) or not (False)

task_lengthslist of ints, optional

If there are multiple tasks, specify their lengths in TRs. The default is None.

task_nameslist of str, optional

Task names. The default is None.

late_iso_dictdict, optional

Dictionary whose keys correspond to task_names. Entries are ndarrays containing the TR indices used to compute the BOLD baseline for each task. The default is None.

Raises

ValueError

when window_length is even

Returns

numpy.ndarray

filtered version of the array

prfpy.timecourse.stimulus_through_prf(prfs, stimulus, dx, mask=None)[source]

dot the stimulus and the prfs

Parameters

prfsnumpy.ndarray

the array of prfs.

stimulusnumpy.ndarray

the stimulus design matrix, either convolved with hrf or not.

masknumpy.ndarray

a mask in feature space, of dimensions equal to the spatial dimensions of both stimulus and receptive field