Example #1
0
 def __init__(self, signal, Fs, tr_length, dtype):
     
     r"""A child of the StimulusModel class for auditory stimuli.
     
     Paramaters
     ----------
     
     
     dtype : string
         Sets the data type the stimulus array is cast into.
     
     tr_length : float
         The repetition time (TR) in seconds.
         
     """
     
     # this is a weird notation
     StimulusModel.__init__(self, signal, dtype, tr_length)
     
     # absorb the vars
     self.Fs = Fs
     self.tr_length = tr_length
     
     # # create spectrogram
     specgram, freqs, times, = generate_spectrogram(self.stim_arr, Fs, tr_length)
     
     # share them
     self.spectrogram = utils.generate_shared_array(specgram, ctypes.c_double)
     self.freqs = utils.generate_shared_array(freqs, ctypes.c_double)
     self.times = utils.generate_shared_array(times, ctypes.c_int16)
Example #2
0
    def __init__(self, signal, Fs, tr_length, dtype):
        r"""A child of the StimulusModel class for auditory stimuli.
        
        Paramaters
        ----------
        
        
        dtype : string
            Sets the data type the stimulus array is cast into.
        
        tr_length : float
            The repetition time (TR) in seconds.
            
        """

        # this is a weird notation
        StimulusModel.__init__(self, signal, dtype, tr_length)

        # absorb the vars
        self.Fs = Fs
        self.tr_length = tr_length

        # # create spectrogram
        specgram, freqs, times, = generate_spectrogram(self.stim_arr, Fs,
                                                       tr_length)

        # share them
        self.spectrogram = utils.generate_shared_array(specgram,
                                                       ctypes.c_double)
        self.freqs = utils.generate_shared_array(freqs, ctypes.c_double)
        self.times = utils.generate_shared_array(times, ctypes.c_int16)
Example #3
0
 def resurrect_cached_model(self):
     dat = pickle.load(open(self.cached_model_path, 'rb'))
     timeseries = utils.generate_shared_array(np.array([d[0] for d in dat]),
                                              np.double)
     parameters = utils.generate_shared_array(np.array([d[1] for d in dat]),
                                              np.double)
     return timeseries, parameters
Example #4
0
    def __init__(self, stim_arr, dtype=ctypes.c_int16, tr_length=1.0):
        r"""A base class for all encoding stimuli.
        
        This class houses the basic and common features of the encoding stimulus, which
        along with a `PopulationModel` constitutes what is commonly referred to as the 
        pRF model.
        
        Paramaters
        ----------
        
        stim_arr : ndarray
            An array containing the stimulus.  The dimensionality of the data is arbitrary
            but must be consistent with the pRF model, as specified in `PopulationModel` and 
            `PopluationFit` class instances.
        
        dtype : string
            Sets the data type the stimulus array is cast into.
        
        dtype : string
            Sets the data type the stimulus array is cast into.
        
        tr_length : float
            The repetition time (TR) in seconds.
            
        """

        self.dtype = dtype
        self.stim_arr = utils.generate_shared_array(stim_arr, self.dtype)
        self.tr_length = tr_length
Example #5
0
 def __init__(self, stim_arr, dtype=ctypes.c_int16, tr_length=1.0):
     
     r"""A base class for all encoding stimuli.
     
     This class houses the basic and common features of the encoding stimulus, which
     along with a `PopulationModel` constitutes what is commonly referred to as the 
     pRF model.
     
     Paramaters
     ----------
     
     stim_arr : ndarray
         An array containing the stimulus.  The dimensionality of the data is arbitrary
         but must be consistent with the pRF model, as specified in `PopulationModel` and 
         `PopluationFit` class instances.
     
     dtype : string
         Sets the data type the stimulus array is cast into.
     
     dtype : string
         Sets the data type the stimulus array is cast into.
     
     tr_length : float
         The repetition time (TR) in seconds.
         
     """
     
     self.dtype = dtype
     self.stim_arr = utils.generate_shared_array(stim_arr, self.dtype)
     self.tr_length = tr_length
Example #6
0
 def __init__(self, stim_arr, viewing_distance, screen_width,
              scale_factor, tr_length, dtype, interp='nearest'):
     
     """
     
     A child of the StimulusModel class for visual stimuli.
     
     
     Paramaters
     ----------
     
     stim_arr : ndarray
         An array containing the visual stimulus at the native resolution. The 
         visual stimulus is assumed to be three-dimensional (x,y,time).
     
     viewing_distance : float
         The distance between the participant and the display (cm).
         
     screen_width : float
         The width of the display (cm). This is used to compute the visual angle
         for determining the pixels per degree of visual angle.
     
     scale_factor : float
         The downsampling rate for ball=parking a solution. The `stim_arr` is
         downsampled so as to speed up the fitting procedure.  The final model
         estimates will be derived using the non-downsampled stimulus.
         
     """
     
     StimulusModel.__init__(self, stim_arr, dtype, tr_length)
     
     # absorb the vars
     self.viewing_distance = viewing_distance
     self.screen_width = screen_width
     self.scale_factor = scale_factor
     self.interp = interp
     
     # ascertain stimulus features
     self.pixels_across = self.stim_arr.shape[1]
     self.pixels_down = self.stim_arr.shape[0]
     self.run_length = self.stim_arr.shape[2]
     self.ppd = pixels_per_degree(self.pixels_across, self.screen_width, self.viewing_distance)
     
     # generate coordinate matrices
     deg_x, deg_y = generate_coordinate_matrices(self.pixels_across, self.pixels_down, self.ppd)
     
     # share coordinate matrices
     self.deg_x = utils.generate_shared_array(deg_x, ctypes.c_double)
     self.deg_y = utils.generate_shared_array(deg_y, ctypes.c_double)
     self.stim_arr = utils.generate_shared_array(stim_arr, dtype)
     
     if self.scale_factor == 1.0:
         
         
         self.stim_arr0 = self.stim_arr
         self.deg_x0 = self.deg_x
         self.deg_y0 = self.deg_y
         
     else:
         
         # create downsampled stimulus
         stim_arr0 = resample_stimulus(self.stim_arr, self.scale_factor)
         
         # generate the coordinate matrices
         deg_x0, deg_y0 = generate_coordinate_matrices(self.pixels_across, self.pixels_down, self.ppd, self.scale_factor)
         
         # share the arrays
         self.deg_x0 = utils.generate_shared_array(deg_x0, ctypes.c_double)
         self.deg_y0 = utils.generate_shared_array(deg_y0, ctypes.c_double)
         self.stim_arr0 = utils.generate_shared_array(stim_arr0, dtype)
Example #7
0
 def resurrect_cached_model(self):
     dat = pickle.load(open(self.cached_model_path, 'rb'))
     timeseries = utils.generate_shared_array(np.array([d[0] for d in dat]), np.double)
     parameters = utils.generate_shared_array(np.array([d[1] for d in dat]), np.double)
     return timeseries, parameters
Example #8
0
 def __init__(self, stim_arr, viewing_distance, screen_width,
              scale_factor, tr_length, dtype, interp='nearest'):
     
     """
     
     A child of the StimulusModel class for visual stimuli.
     
     
     Paramaters
     ----------
     
     stim_arr : ndarray
         An array containing the visual stimulus at the native resolution. The 
         visual stimulus is assumed to be three-dimensional (x,y,time).
     
     viewing_distance : float
         The distance between the participant and the display (cm).
         
     screen_width : float
         The width of the display (cm). This is used to compute the visual angle
         for determining the pixels per degree of visual angle.
     
     scale_factor : float
         The downsampling rate for ball=parking a solution. The `stim_arr` is
         downsampled so as to speed up the fitting procedure.  The final model
         estimates will be derived using the non-downsampled stimulus.
         
     """
     
     StimulusModel.__init__(self, stim_arr, dtype, tr_length)
     
     # absorb the vars
     self.viewing_distance = viewing_distance
     self.screen_width = screen_width
     self.scale_factor = scale_factor
     self.interp = interp
     
     # ascertain stimulus features
     self.pixels_across = self.stim_arr.shape[1]
     self.pixels_down = self.stim_arr.shape[0]
     self.run_length = self.stim_arr.shape[2]
     self.ppd = pixels_per_degree(self.pixels_across, self.screen_width, self.viewing_distance)
     
     # generate coordinate matrices
     deg_x, deg_y = generate_coordinate_matrices(self.pixels_across, self.pixels_down, self.ppd)
     
     # share coordinate matrices
     self.deg_x = utils.generate_shared_array(deg_x, ctypes.c_double)
     self.deg_y = utils.generate_shared_array(deg_y, ctypes.c_double)
     self.stim_arr = utils.generate_shared_array(stim_arr, dtype)
     
     if self.scale_factor == 1.0:
         
         self.stim_arr0 = self.stim_arr
         self.deg_x0 = self.deg_x
         self.deg_y0 = self.deg_y
         
     else:
         
         # create downsampled stimulus
         stim_arr0 = resample_stimulus(self.stim_arr, self.scale_factor)
         
         # generate the coordinate matrices
         deg_x0, deg_y0 = generate_coordinate_matrices(self.pixels_across, self.pixels_down, self.ppd, self.scale_factor)
         
         # share the arrays
         self.deg_x0 = utils.generate_shared_array(deg_x0, ctypes.c_double)
         self.deg_y0 = utils.generate_shared_array(deg_y0, ctypes.c_double)
         self.stim_arr0 = utils.generate_shared_array(stim_arr0, dtype)
     
     # add ppd for the down-sampled stimulus
     self.ppd0 = pixels_per_degree(self.pixels_across*self.scale_factor, self.screen_width, self.viewing_distance)