Пример #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)
Пример #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)
Пример #3
0
 def __init__(self, stim_arr, NFFT, Fs, noverlap, tr_length, dtype):
     
     # this is a weird notation
     StimulusModel.__init__(self, stim_arr, dtype=dtype)
     
     # absorb the vars
     self.NFFT = NFFT
     self.Fs = Fs
     self.noverlap = noverlap
     self.tr_length = tr_length
             
     spectrogram, freqs, times = generate_spectrogram(self.stim_arr, self.NFFT, self.Fs, self.noverlap)
     self.spectrogram = sharedmem.empty(spectrogram.shape, dtype='float64')
     self.spectrogram[:] = spectrogram[:]
     
     self.freqs = sharedmem.empty(freqs.shape, dtype='float64')
     self.freqs[:] = freqs[:]
     
     self.times = sharedmem.empty(times.shape, dtype='float64')
     self.times[:] = times[:]
     
     
Пример #4
0
 def __init__(self, stim_arr, tr_length, freq_window = 2**10,
              time_window = 0.1, freq_factor=1.0, sampling_rate=44100,
              tr_sampling_rate=10, scale_factor=1.0):
     
     # this is a weird notation
     StimulusModel.__init__(self, stim_arr)
     
     if time_window > tr_length / 2:
         print("You must give a time window size in seconds that is half your TR length or less.")
         return None
     
     # absorb the vars
     self.tr_length = tr_length # the TR in s
     self.freq_factor = freq_factor # the scaling factor of the freqs, i think its only for plotting
     self.sampling_rate = sampling_rate # the sampling rate of the wav
     self.tr_sampling_rate = tr_sampling_rate # the number of samples from a single TR
     self.scale_factor = scale_factor
     self.time_window = time_window # in s, this is the number of slices we'll make for each TR
     self.freq_window = freq_window
     
     stft = compute_stft(self.stim_arr, self.freq_window)
     self.stft = np.memmap('%s%s_%d.npy' %('/tmp/','stft',self.__hash__()),dtype = np.double, mode = 'w+',shape = np.shape(stft))
     self.stft[:] = stft[:]
     
     log_stft = logscale_stft(self.stft, self.scale, self.timebins)
     self.log_stft = np.memmap('%s%s_%d.npy' %('/tmp/','log_stft',self.__hash__()),dtype = np.double, mode = 'w+',shape = np.shape(log_stft))
     self.log_stft[:] = log_stft[:]
     
     spectrogram = generate_spectrogram(self.log_stft, self.all_freqs, self.num_timepoints, self.tr_sampling_rate)
     self.spectrogram = np.memmap('%s%s_%d.npy' %('/tmp/','spectrogram',self.__hash__()),dtype = np.double, mode = 'w+',shape = np.shape(spectrogram))
     self.spectrogram[:] = spectrogram[:]
     
     time_coord, freq_coord = generate_coordinate_matrices(self.tr_times, self.all_freqs)
     self.time_coord = np.memmap('%s%s_%d.npy' %('/tmp/','time_coord',self.__hash__()),dtype = np.double, mode = 'w+',shape = np.shape(time_coord))
     self.time_coord[:] = time_coord[:]
     
     self.freq_coord = np.memmap('%s%s_%d.npy' %('/tmp/','freq_coord',self.__hash__()),dtype = np.double , mode = 'w+',shape = np.shape(freq_coord))
     self.freq_coord[:] = freq_coord[:]
Пример #5
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)
Пример #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)
     
     # add ppd for the down-sampled stimulus
     self.ppd0 = pixels_per_degree(self.pixels_across*self.scale_factor, self.screen_width, self.viewing_distance)
Пример #7
0
 def __init__(self, stim_arr, viewing_distance, screen_width, scale_factor, dtype):
     
     """
     
     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)
     
     # absorb the vars
     self.viewing_distance = viewing_distance
     self.screen_width = screen_width
     self.scale_factor = scale_factor
     
     # 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 = np.pi*self.pixels_across/np.arctan(self.screen_width/self.viewing_distance/2.0)/360.0 # degrees of visual angle
     
     # create downsampled stimulus
     stim_arr_coarse = resample_stimulus(self.stim_arr,self.scale_factor)
     
     # generate the coordinate matrices
     deg_x, deg_y = generate_coordinate_matrices(self.pixels_across, self.pixels_down, self.ppd)
     deg_x_coarse, deg_y_coarse = generate_coordinate_matrices(self.pixels_across, self.pixels_down, self.ppd, self.scale_factor)
     
     # share the rest of the arrays ...
     self.deg_x = sharedmem.empty(deg_x.shape, dtype='float64')
     self.deg_x[:] = deg_x[:]
     
     self.deg_y = sharedmem.empty(deg_y.shape, dtype='float64')
     self.deg_y[:] = deg_y[:]
     
     self.deg_x_coarse = sharedmem.empty(deg_x_coarse.shape, dtype='float64')
     self.deg_x_coarse[:] = deg_x_coarse[:]
     
     self.deg_y_coarse = sharedmem.empty(deg_y_coarse.shape, dtype='float64')
     self.deg_y_coarse[:] = deg_y_coarse[:]
     
     self.stim_arr_coarse = sharedmem.empty(stim_arr_coarse.shape, dtype=self.dtype)
     self.stim_arr_coarse[:] = stim_arr_coarse[:]