Beispiel #1
0
class TimingStampController(SweepSequeTriggerController):
    def __init__(self,*args,**kwargs):
        super(TimingStampController, self).__init__(*args,**kwargs)
        self.gp = self.stimulus.gp
        self.indexed_pha = IndexedParam('phase_at_t0')
        self.logger = logging.getLogger('LightStim.Grating')
    def during_go_eval(self):
        stimulus_on = self.next_param()
        #   16-bits stimulus representation code will be posted to DAQ port
        #   00 1 1 0000 0000 0000 
        #   |  | |   |-----------------phase_at_t0 index (0.0, 360.0, 16)
        #   |  | |---------------------stimulus onset
        #   |  |-----------------------stimulus viewport
        #   |--------------------------reserved
        if self.viewport.get_name() == 'left':
            viewport = 1
        elif self.viewport.get_name() == 'right':
            viewport = 0
        else:
            self.logger.error('Currently TimingStamp can only support left and right viewport.')
        # lower 12 bits and upper 2 bits are reserved
        if stimulus_on:
            onset = 1
        else:
            onset = 0
        phase = self.gp.phase_at_t0
        if phase in self.indexed_pha:
            pha_index = self.indexed_pha.index(phase)
        else:
            pha_index = 0
        post_val = (viewport << 13) + (onset << 12) + (pha_index << 8)
        self.post_stamp(post_val)
Beispiel #2
0
class ParamStampController(SweepSequeTriggerController):
    def __init__(self,*args,**kwargs):
        super(ParamStampController, self).__init__(*args,**kwargs)
        self.indexed_ori = IndexedParam('orientation')
        self.indexed_sfq = IndexedParam('spatial_freq')
        self.indexed_pha = IndexedParam('phase_at_t0')
        self.logger = logging.getLogger('LightStim.Grating')
        
    def during_go_eval(self):
        post_val = self.get_post_val()
        if self.stimulus.trigger and post_val is not None:
            self.post_stamp(post_val)
            
    def get_post_val(self):
        next_param = self.next_param()
        if next_param is not None and not any(num != num for num in next_param):
            orientation, spatial_freq, phase_at_t0 = next_param
            ori_index, spf_index, pha_index = 0,0,0
            if orientation in self.indexed_ori:
                ori_index = self.indexed_ori.index(orientation)
            #else: self.logger.error('Cannot post param index for orientation parameter: %s' %str(orientation))
            if spatial_freq in self.indexed_sfq:
                spf_index = self.indexed_sfq.index(spatial_freq)
            #else: self.logger.error('Cannot post param index for spatial freqency parameter: %s' %str(spatial_freq))
            if phase_at_t0 in self.indexed_pha:
                pha_index = self.indexed_pha.index(phase_at_t0)
            #else: self.logger.error('Cannot post param index for phase parameter: %s' %str(phase_at_t0)) 
            # 16-bits stimulus representation code will be posted to DT port
            #   00 0  1 0101 0001 0011
            #   |  |  |   |    |    | 
            #   |  |  |   |    |    +------------orientation index (0.0, 180.0, 16)/(0.0, 360.0, 16)
            #   |  |  |   |    +-----------------spatial_freq index (0.05, 1.0, 16)
            #   |  |  |   +----------------------phase_at_t0 index (0.0, 360.0, 16)
            #   |  |  +--------------------------stimulus onset
            #   |  +-----------------------------stimulus offset
            #   +--------------------------------reserved
            onset = 1
            post_val = ori_index + (spf_index<<4) + (pha_index<<8) + (onset<<12)
            return post_val
        else:
            offset = 1
            post_val = offset<<13
            return post_val