示例#1
0
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
示例#2
0
def test_zscore():

    x = np.array([[1, 1, 3, 3], [4, 4, 6, 6]])

    z = utils.zscore(x)
    npt.assert_equal(x.shape, z.shape)

    #Default axis is -1
    npt.assert_equal(utils.zscore(x),
                     np.array([[-1., -1., 1., 1.], [-1., -1., 1., 1.]]))

    #Test other axis:
    npt.assert_equal(utils.zscore(x, 0),
                     np.array([[-1., -1., -1., -1.], [1., 1., 1., 1.]]))

    # Test the 1D case:
    x = np.array([1, 1, 3, 3])
    npt.assert_equal(utils.zscore(x), [-1, -1, 1, 1])
示例#3
0
def test_zscore():

    x = np.array([[1, 1, 3, 3],
                  [4, 4, 6, 6]])

    z = utils.zscore(x)
    npt.assert_equal(x.shape, z.shape)

    #Default axis is -1
    npt.assert_equal(utils.zscore(x), np.array([[-1., -1., 1., 1.],
                                                      [-1., -1., 1., 1.]]))

    #Test other axis:
    npt.assert_equal(utils.zscore(x, 0), np.array([[-1., -1., -1., -1.],
                                                        [1., 1., 1., 1.]]))


    # Test the 1D case:
    x = np.array([1, 1, 3, 3])
    npt.assert_equal(utils.zscore(x), [-1, -1, 1, 1])
示例#4
0
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
示例#5
0
文件: gabor.py 项目: mekman/popeye
 def __init__(self, data, model, bounds, tr_length, voxel_index, uncorrected_rval, 
              verbose=True, lazy=None, auto_fit=True):
         
     self.data = utils.zscore(data)
     self.model = model
     self.tr_length = tr_length
     self.voxel_index = voxel_index
     self.uncorrected_rval = uncorrected_rval
     self.verbose = verbose
     self.has_gaussian = False
     
     if auto_fit:
         
         # if we want to solve the gaussian prior to the gabor
         if lazy == 'both':
             self.bounds = bounds[0:4]
             tic = time.clock()
             
             # compute the gaussian first
             self.gaussian_model = og.GaussianModel(self.model.stimulus)
             self.gaussian_fit = og.GaussianFit(self.data, self.gaussian_model, self.bounds,
                                                      self.tr_length, self.voxel_index, 
                                                      self.uncorrected_rval, False, True)
             self.has_gaussian = True
             self.bounds = bounds[4::]
             
             # finish off the rest of the gabor parameters
             self.ballpark_estimate_lazy;
             self.gabor_estimate_lazy;
             toc = time.clock()
         
         # if we want to estimate the coarse paramters with just a gaussian model
         elif lazy == 'brute':
             self.bounds = bounds[0:4]
             tic = time.clock()
             
             # compute the gaussian first
             self.gaussian_model = gaussian.GaussianModel(self.model.stimulus)
             self.gaussian_fit = gaussian.GaussianFit(self.data, self.gaussian_model, self.bounds,
                                                      self.tr_length, self.voxel_index, 
                                                      self.uncorrected_rval, False, True)
             self.has_gaussian = True
             self.bounds = bounds[4::]
             
             # finish off the rest of the gabor parameters
             self.ballpark_estimate_lazy;
             self.bounds = bounds
             self.gabor_estimate;
             toc = time.clock()
         
         # if we want to estimate 7 at once
         else:
             self.bounds = bounds
             tic = time.clock()
             self.ballpark_estimate;
             self.gabor_estimate;
             toc = time.clock()
             self.has_gaussian = False
         
         # print to screen if verbose
         if self.verbose:
             print("VOXEL=(%.03d,%.03d,%.03d)  TIME=%.03d  ERROR=%.03d  RVAL=%.02f" 
                   %(self.voxel_index[0],
                     self.voxel_index[1],
                     self.voxel_index[2],
                     toc-tic,
                     self.rss,
                     self.fit_stats[2]))