def compute_model_ts(center_freq, sigma, spectrogram, freqs, target_times): # generate stimulus time-series rf = gaussian_1D(freqs, center_freq, sigma) # make sure sigma isn't too big # if np.any(np.round(rf[0],3) > 0): # return np.inf # if np.any(np.round(rf[-1],3) > 0): # return np.inf # create mask for speed distance = freqs - center_freq mask = np.zeros_like(distance, dtype='uint8') mask[distance < (5 * sigma)] = 1 # extract the response stim = generate_rf_timeseries_1D(spectrogram, rf, mask) # recast the stimulus into a time-series that i can source_times = np.linspace(0, target_times[-1], len(stim), endpoint=True) f = interp1d(source_times, stim, kind='linear') new_stim = f(target_times) # hard-set the hrf_delay hrf_delay = 0 # convolve it with the HRF hrf = utils.double_gamma_hrf(hrf_delay, 1.0, 10) stim_pad = np.tile(new_stim, 3) model = fftconvolve(stim_pad, hrf, 'same')[len(new_stim):len(new_stim) * 2] # normalize it model = utils.zscore(model) return model
def compute_model_ts(x, y, sigma, hrf_delay, theta, phi, cpd, deg_x, deg_y, stim_arr, tr_length, frames_per_tr, norm_func=utils.zscore): # otherwise generate a prediction ts_stim = MakeFastGaborPrediction(deg_x, deg_y, stim_arr, x, y, sigma, theta, phi, cpd) # convolve it hrf = utils.double_gamma_hrf(hrf_delay, tr_length, frames_per_tr) # normalize it model = norm_func(ss.fftconvolve(ts_stim, hrf)[0:len(ts_stim)]) # decimate it model = ss.decimate(model, int(frames_per_tr), 1) return model
def compute_model_ts(x, y, sigma, beta, hrf_delay, deg_x, deg_y, stim_arr, tr_length): """ The objective function for GaussianFi class. Parameters ---------- x : float The model estimate along the horizontal dimensions of the display. y : float The model estimate along the vertical dimensions of the display. sigma : float The model estimate of the dispersion across the the display. hrf_delay : float The model estimate of the relative delay of the HRF. The canonical HRF is assumed to be 5 s post-stimulus [1]_. beta : float The model estimate of the amplitude of the BOLD signal. tr_length : float The length of the repetition time in seconds. Returns ------- model : ndarray The model prediction time-series. References ---------- .. [1] Glover, GH. (1999). Deconvolution of impulse response in event-related BOLD fMRI. NeuroImage 9: 416-429. """ # otherwise generate a prediction stim = generate_og_timeseries(deg_x, deg_y, stim_arr, x, y, sigma) # scale it stim *= beta # create the HRF hrf = utils.double_gamma_hrf(hrf_delay, tr_length) # convolve it with the stimulus model = fftconvolve(stim, hrf)[0:len(stim)] return model*beta
def test_double_gamma_hrf(): # set the TR length ... this affects the HRF sampling rate ... tr_length = 1.0 hrf_0 = utils.double_gamma_hrf(-1, tr_length) hrf_1 = utils.double_gamma_hrf(0, tr_length) hrf_2 = utils.double_gamma_hrf(1, tr_length) npt.assert_almost_equal(hrf_0.sum(), hrf_1.sum(), 3) npt.assert_almost_equal(hrf_0.sum(), hrf_2.sum(), 3) npt.assert_almost_equal(hrf_1.sum(), hrf_2.sum(), 3) hrf_0 = utils.double_gamma_hrf(-1, tr_length, integrator=None) hrf_1 = utils.double_gamma_hrf(0, tr_length, integrator=None) hrf_2 = utils.double_gamma_hrf(1, tr_length, integrator=None) npt.assert_array_less(hrf_0.sum(), hrf_1.sum()) npt.assert_array_less(hrf_1.sum(), hrf_2.sum()) npt.assert_array_less(hrf_0.sum(), hrf_2.sum())
def test_double_gamma_hrf(): # set the TR length ... this affects the HRF sampling rate ... tr_length = 1.0 hrf_0 = utils.double_gamma_hrf(-1, tr_length) hrf_1 = utils.double_gamma_hrf(0, tr_length) hrf_2 = utils.double_gamma_hrf(1, tr_length) npt.assert_almost_equal(hrf_0.sum(), hrf_1.sum(), 3) npt.assert_almost_equal(hrf_0.sum(), hrf_2.sum(), 3) npt.assert_almost_equal(hrf_1.sum(), hrf_2.sum(), 3) hrf_0 = utils.double_gamma_hrf(-1, tr_length, integrator=None) hrf_1 = utils.double_gamma_hrf(0, tr_length, integrator=None) hrf_2 = utils.double_gamma_hrf(1, tr_length, integrator=None) npt.assert_array_less(hrf_0.sum(),hrf_1.sum()) npt.assert_array_less(hrf_1.sum(),hrf_2.sum()) npt.assert_array_less(hrf_0.sum(),hrf_2.sum())
def compute_model_ts(center_freq, sigma, spectrogram, freqs, target_times): # generate stimulus time-series rf = gaussian_1D(freqs, center_freq, sigma) # make sure sigma isn't too big # if np.any(np.round(rf[0],3) > 0): # return np.inf # if np.any(np.round(rf[-1],3) > 0): # return np.inf # create mask for speed distance = freqs - center_freq mask = np.zeros_like(distance, dtype='uint8') mask[distance < (5*sigma)] = 1 # extract the response stim = generate_rf_timeseries_1D(spectrogram,rf,mask) # recast the stimulus into a time-series that i can source_times = np.linspace(0,target_times[-1],len(stim),endpoint=True) f = interp1d(source_times,stim,kind='linear') new_stim = f(target_times) # hard-set the hrf_delay hrf_delay = 0 # convolve it with the HRF hrf = utils.double_gamma_hrf(hrf_delay, 1.0, 10) stim_pad = np.tile(new_stim,3) model = fftconvolve(stim_pad, hrf,'same')[len(new_stim):len(new_stim)*2] # normalize it model = utils.zscore(model) return model
def hemodynamic_response(self): return utils.double_gamma_hrf(self.hrf_delay, self.tr_length)
def compute_model_ts(x, y, sigma_center, sigma_surround, beta_center, beta_surround, hrf_delay, deg_x, deg_y, stim_arr, tr_length): """ The objective function for GaussianFi class. Parameters ---------- x : float The model estimate along the horizontal dimensions of the display. y : float The model estimate along the vertical dimensions of the display. sigma_center : float The model estimate of the dispersion of the excitatory center. sigma_surround : float The model estimate of the dispersion of the inhibitory surround. beta_center : float The amplitude of the excitatory center. beta_surround : float The amplitude of the inhibitory surround. hrf_delay : float The model estimate of the relative delay of the HRF. The canonical HRF is assumed to be 5 s post-stimulus [1]_. tr_length : float The length of the repetition time in seconds. Returns ------- model : ndarray The model prediction time-series. References ---------- .. [1] Glover, GH. (1999). Deconvolution of impulse response in event-related BOLD fMRI. NeuroImage 9: 416-429. """ # limiting cases for a center-surround receptive field if sigma_center >= sigma_surround: return np.inf if beta_center <= beta_surround: return np.inf # METHOD 1 # time-series for the center and surround stim_center, stim_surround = generate_dog_timeseries(deg_x, deg_y, stim_arr, x, y, sigma_center, sigma_surround) # scale them by betas stim_center *= beta_center stim_surround *= beta_surround # differnce them stim_dog = stim_center - stim_surround # # METHOD 2 # # scale the RFs, combine, then extract ts # rf_center = generate_og_receptive_field(deg_x, deg_y, x, y, sigma_center) # rf_center /= rf_center.max() # rf_center *= beta_center # # rf_surround = generate_og_receptive_field(deg_x, deg_y, x, y, sigma_surround) # rf_surround /= rf_surround.max() # rf_surround *= beta_surround # # rf_dog = rf_center - rf_surround # stim_dog = np.sum(np.sum(stim_arr * rf_dog[:,:,np.newaxis],axis=0),axis=0) # generate the hrf hrf = utils.double_gamma_hrf(hrf_delay, tr_length) # convolve it with the stimulus timeseries model = fftconvolve(stim_dog, hrf)[0:len(stim_dog)] return model