Esempio n. 1
0
class StimulusPoolController(SweepController, Pyro.core.ObjBase):
    """ Maintain a stimulus pool and synchronize the pool with sweep viewport
    """
    def __init__(self, *arg, **kw):
        super(StimulusPoolController, self).__init__(*arg, **kw)
        Pyro.core.ObjBase.__init__(self)

    def add_stimulus(self, stimulus):
        self.framesweep.add_stimulus(stimulus)

    def remove_stimulus(self, stimulus):
        pass


sweep = FrameSweep()
dummy_stimulus = Dummy_Stimulus()
sweep.add_stimulus(dummy_stimulus)

pyro_server = PyroServer()

#quit_controller = PyroConstantController(during_go_value=0)
#pyro_server.connect(quit_controller,'quit_controller')
#sweep.add_controller(sweep,'quit', quit_controller)
#sweep.add_controller(None,None, pyro_server.create_listener_controller())

stimulus_pool = StimulusPoolController(framesweep=sweep)
pyro_server.connect(stimulus_pool, 'stimulus_pool')
sweep.add_controller(None, None, stimulus_pool)
sweep.add_controller(None, None, pyro_server.create_listener_controller())

sweep.go()
Esempio n. 2
0
class Disparity(object):
    def __init__(self, subject):
        """ Fixation """
        fp = dictattr()
        fp.bgbrightness = 0.5
        fp.color = (1.0, 0.0, 0.0, 1.0)
        fp.width = 0.25

        self.fixation_left = Fixation(viewport='left',
                                      subject=subject,
                                      params=fp)
        self.fixation_right = Fixation(viewport='right',
                                       subject=subject,
                                       params=fp)
        """ Random Dots with disc"""
        dp = dictattr()
        dp.bgbrightness = 0.5
        dp.antialiase = True

        dp.dotSquareWidth = 7.5
        dp.dotsNumber = 2000
        dp.randomSeed = 0
        dp.dotColor = (0.8, 0.8, 0.8)
        dp.dotSize = 3
        dp.discDistDeg = 2.5
        dp.discDiameter = 1.25
        dp.disparity = 0

        self.dp = dp
        self.subject = subject
        self.disc_left = StereoDisc(viewport='left',
                                    subject=subject,
                                    params=dp)
        self.disc_right = StereoDisc(viewport='right',
                                     subject=subject,
                                     params=dp)
        """ Mask: Random Dots """
        mp = dictattr()
        mp.bgbrightness = 0.5
        mp.antialiase = True

        mp.dotSquareWidth = 7.5
        mp.dotsNumber = 4500
        mp.randomSeed = 1
        mp.dotColor = (1, 1, 1)
        mp.dotSize = 2

        self.mp = mp
        self.mask_left = RandomDots(viewport='left',
                                    subject=subject,
                                    params=mp)
        self.mask_right = RandomDots(viewport='right',
                                     subject=subject,
                                     params=mp)
        """ Hint """
        hp = dictattr()
        hp.bgbrightness = 0.5
        hp.text = "Press left or right for disc interval."
        hp.xorigDeg = 5.0
        hp.yorigDeg = 0.0
        hp.color = (1.0, 0.0, 0.0, 1.0)
        hp.fontsize = 25
        self.hint_left = Hint(viewport="left", params=hp)
        hp.xorigDeg = -5.0
        self.hint_right = Hint(viewport="right", params=hp)

        self.sweep = FrameSweep()
        self.key_response = LeftRightKeyResponse(self.sweep)
        self.mouse_response = LeftRightMouseResponse(self.sweep)

    def set_disparity(self, disp):
        self.disparity = disp

    def update_disparity(self, cross):
        if random.choice([True, False]):
            self.disc_left.parameters.disparity = self.disparity if cross else 0
            self.disc_right.parameters.disparity = 0
        else:
            self.disc_left.parameters.disparity = 0
            self.disc_right.parameters.disparity = self.disparity if cross else 0

    def get_cross_interval(self):
        return self.cross_interval

    def demo(self):
        self.update_disparity(cross=True)
        self.sweep.add_stimulus(self.disc_left)
        self.sweep.add_stimulus(self.disc_right)
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.add_controller(None, None, self.key_response)
        self.sweep.add_controller(None, None, self.mouse_response)
        self.sweep.go(duration=('forever', ''))

    def run(self):
        random.seed()
        self.cross_interval = random.choice([1, 2])
        """ Randomize dots """
        self.dp.randomSeed = random.randint(0, 1000)
        self.disc_left = StereoDisc(viewport='left',
                                    subject=self.subject,
                                    params=self.dp)
        self.disc_right = StereoDisc(viewport='right',
                                     subject=self.subject,
                                     params=self.dp)
        self.mp.randomSeed = random.randint(0, 1000)
        self.mask_left = RandomDots(viewport='left',
                                    subject=self.subject,
                                    params=self.mp)
        self.mask_right = RandomDots(viewport='right',
                                     subject=self.subject,
                                     params=self.mp)
        """ Fixation """
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(2.0, 'seconds'))
        """ Interval-1 """
        self.update_disparity(self.cross_interval == 1)
        self.sweep.add_stimulus(self.disc_left)
        self.sweep.add_stimulus(self.disc_right)
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.2, 'seconds'))
        """ Blank """
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.4, 'seconds'))
        """ Interval-2 """
        self.update_disparity(self.cross_interval == 2)
        self.sweep.add_stimulus(self.disc_left)
        self.sweep.add_stimulus(self.disc_right)
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.2, 'seconds'))
        """ Blank """
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.4, 'seconds'))
        """ Mask """
        self.sweep.add_stimulus(self.mask_left)
        self.sweep.add_stimulus(self.mask_right)
        self.sweep.go(duration=(0.5, 'seconds'))

        self.sweep.add_controller(None, None, self.key_response)
        self.sweep.add_controller(None, None, self.mouse_response)
        #self.sweep.add_stimulus(self.hint_left)
        #self.sweep.add_stimulus(self.hint_right)
        self.sweep.go(duration=('forever', ''))
        key_response = self.key_response.get_last_response_since_go()
        mouse_response = self.mouse_response.get_last_response_since_go()
        if key_response == "left" or mouse_response == "left_button":
            return self.cross_interval == 1
        elif key_response == "right" or mouse_response == "right_button":
            return self.cross_interval == 2
        else:
            raise RuntimeError("Key or button press is not direction.")
Pyro.config.PYRO_PICKLE_FORMAT = 1


class StimulusPoolController(SweepController,Pyro.core.ObjBase):
    """ Maintain a stimulus pool and synchronize the pool with sweep viewport
    """
    def __init__(self,*arg,**kw):
        super(StimulusPoolController, self).__init__(*arg,**kw)
        Pyro.core.ObjBase.__init__(self)
    def add_stimulus(self,stimulus):
        self.framesweep.add_stimulus(stimulus)
    def remove_stimulus(self,stimulus):
        pass

sweep = FrameSweep()
dummy_stimulus = Dummy_Stimulus()
sweep.add_stimulus(dummy_stimulus)

pyro_server = PyroServer()

#quit_controller = PyroConstantController(during_go_value=0)
#pyro_server.connect(quit_controller,'quit_controller')
#sweep.add_controller(sweep,'quit', quit_controller)
#sweep.add_controller(None,None, pyro_server.create_listener_controller())

stimulus_pool = StimulusPoolController(framesweep=sweep)
pyro_server.connect(stimulus_pool,'stimulus_pool')
sweep.add_controller(None,None, stimulus_pool)
sweep.add_controller(None,None, pyro_server.create_listener_controller())

sweep.go()
Esempio n. 4
0
class SED(object):
    def __init__(self, subject, eye):
        """ Fixation """
        fp = dictattr()
        fp.bgbrightness = 0.5
        fp.color = (1.0, 0.0, 0.0, 1.0)
        fp.width = 0.25
        
        self.fixation_left = Fixation(viewport='left', subject=subject, params=fp)
        self.fixation_right = Fixation(viewport='right', subject=subject, params=fp)
        
        """ SED Grating """
        gp = dictattr()
        gp.bgbrightness = 0.5
        gp.on = True
        gp.mask = "circle"
        gp.ml = 0.5
        gp.sfreqCycDeg = 3.0
        gp.tfreqCycSec = 0.0
        gp.phase0 = 0
        gp.contrast = 0.5
        gp.ori = 0.0
        gp.maskDiameterDeg = 1.25
        gp.radius = 2.0
        
        self.grating_left = SEDGrating(viewport='left', subject=subject, params=gp)
        gp.ori = 90.0
        self.grating_right = SEDGrating(viewport='right', subject=subject, params=gp)
        
        """ Mask """
        mp = dictattr()
        mp.bgbrightness = 0.5
        mp.ml = (0.5, 0.5)
        mp.ori = (0.0, 90.0)
        mp.sfreqCycDeg = (3.0, 3.0)
        mp.tfreqCycSec = (0.0, 0.0)
        
        self.plaid_left = Plaid(viewport="left", params=mp)
        self.plaid_right = Plaid(viewport="right", params=mp)
        
        """ Hint """
        hp = dictattr()
        hp.bgbrightness = 0.5
        hp.text = "Press left(right) or up(down) for grating orientation."
        hp.xorigDeg = 5.0
        hp.yorigDeg = 0.0
        hp.color = (1.0, 0.0, 0.0, 1.0)
        hp.fontsize = 25
        self.hint_left = Hint(viewport="left", params=hp)
        hp.xorigDeg = -5.0
        self.hint_right = Hint(viewport="right", params=hp)
        
        self.sweep = FrameSweep()
        self.key_response = LeftRightKeyResponse(self.sweep)
        self.mouse_response = LeftRightMouseResponse(self.sweep)
        
        self.test_eye = eye
        
    def update_orientation(self):
        self.test_eye_ori = random.choice([0, 90])
        if self.test_eye == "left":
            self.grating_left.parameters.ori = self.test_eye_ori
            self.grating_right.parameters.ori = abs(self.test_eye_ori - 90)
        else:
            self.grating_left.parameters.ori = abs(self.test_eye_ori - 90)
            self.grating_right.parameters.ori = self.test_eye_ori
        # if self.test_eye == "left":
            # self.grating_left.parameters.ori = self.orientation["test"][0]
            # self.grating_right.parameters.ori = self.orientation["control"][0]
        # else:
            # self.grating_left.parameters.ori = self.orientation["control"][0]
            # self.grating_right.parameters.ori = self.orientation["test"][0]

    def update_test_contrast(self, contrast):
        if self.test_eye == "left":
            self.grating_left.parameters.contrast = contrast
        elif self.test_eye == "right":
            self.grating_right.parameters.contrast = contrast
            
    def update_control_contrast(self, contrast):
        if self.test_eye == "left":
            self.grating_right.parameters.contrast = contrast
        elif self.test_eye == "right":
            self.grating_left.parameters.contrast = contrast
            
    def get_test_eye(self):
        return self.test_eye
    
    def get_test_eye_orientation(self):
        if self.test_eye_ori == 0:
            return "horizontal"
        else:
            return "vertical"
        #return self.orientation["test"][1]
    
    def run(self):
        #self.sweep = FrameSweep()
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(2.0,'seconds'))
        self.sweep.add_stimulus(self.grating_left)
        self.sweep.add_stimulus(self.grating_right)
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.5,'seconds'))
        self.sweep.add_stimulus(self.plaid_left)
        self.sweep.add_stimulus(self.plaid_right)
        self.sweep.go(duration=(0.2,'seconds'))
        self.sweep.add_controller(None, None, self.key_response)
        self.sweep.add_controller(None, None, self.mouse_response)
        #self.sweep.add_stimulus(self.hint_left)
        #self.sweep.add_stimulus(self.hint_right)
        self.sweep.go(duration=('forever',''))
        key_response = self.key_response.get_last_response_since_go()
        mouse_response = self.mouse_response.get_last_response_since_go()
        if key_response in ("left", "right") or mouse_response == "left_button":
            return "horizontal"
        elif key_response in ("up", "down") or mouse_response == "right_button":
            return "vertical"            
        else:
            raise RuntimeError("Key or button press is not direction.")
Esempio n. 5
0
class Disparity(object):
    def __init__(self, subject):
        """ Fixation """
        fp = dictattr()
        fp.bgbrightness = 0.5
        fp.color = (1.0, 0.0, 0.0, 1.0)
        fp.width = 0.25
        
        self.fixation_left = Fixation(viewport='left', subject=subject, params=fp)
        self.fixation_right = Fixation(viewport='right', subject=subject, params=fp)        
        
        """ Random Dots with disc"""
        dp = dictattr()
        dp.bgbrightness = 0.5
        dp.antialiase = True
        
        dp.dotSquareWidth = 7.5
        dp.dotsNumber = 2000
        dp.randomSeed = 0
        dp.dotColor = (0.8, 0.8, 0.8)
        dp.dotSize = 3
        dp.discDistDeg = 2.5
        dp.discDiameter = 1.25
        dp.disparity = 0
        
        self.dp = dp
        self.subject = subject
        self.disc_left = StereoDisc(viewport='left', subject=subject, params=dp)
        self.disc_right = StereoDisc(viewport='right', subject=subject, params=dp)
        
        """ Mask: Random Dots """
        mp = dictattr()
        mp.bgbrightness = 0.5
        mp.antialiase = True
        
        mp.dotSquareWidth = 7.5
        mp.dotsNumber = 4500
        mp.randomSeed = 1
        mp.dotColor = (1, 1, 1)
        mp.dotSize = 2
        
        self.mp = mp
        self.mask_left = RandomDots(viewport='left', subject=subject, params=mp)
        self.mask_right = RandomDots(viewport='right', subject=subject, params=mp)
        
        """ Hint """
        hp = dictattr()
        hp.bgbrightness = 0.5
        hp.text = "Press left or right for disc interval."
        hp.xorigDeg = 5.0
        hp.yorigDeg = 0.0
        hp.color = (1.0, 0.0, 0.0, 1.0)
        hp.fontsize = 25
        self.hint_left = Hint(viewport="left", params=hp)
        hp.xorigDeg = -5.0
        self.hint_right = Hint(viewport="right", params=hp)
        
        self.sweep = FrameSweep()
        self.key_response = LeftRightKeyResponse(self.sweep)
        self.mouse_response = LeftRightMouseResponse(self.sweep)        
    
    def set_disparity(self, disp):
        self.disparity = disp
    
    def update_disparity(self, cross):
        if random.choice([True, False]):
            self.disc_left.parameters.disparity = self.disparity if cross else 0
            self.disc_right.parameters.disparity = 0
        else:
            self.disc_left.parameters.disparity = 0
            self.disc_right.parameters.disparity = self.disparity if cross else 0
    
    def get_cross_interval(self):
        return self.cross_interval
    
    def demo(self):
        self.update_disparity(cross=True)
        self.sweep.add_stimulus(self.disc_left)
        self.sweep.add_stimulus(self.disc_right)
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.add_controller(None, None, self.key_response)
        self.sweep.add_controller(None, None, self.mouse_response)
        self.sweep.go(duration=('forever',''))
        
    def run(self):
        random.seed()
        self.cross_interval = random.choice([1,2])
        """ Randomize dots """
        self.dp.randomSeed = random.randint(0,1000)
        self.disc_left = StereoDisc(viewport='left', subject=self.subject, params=self.dp)
        self.disc_right = StereoDisc(viewport='right', subject=self.subject, params=self.dp)
        self.mp.randomSeed = random.randint(0,1000)
        self.mask_left = RandomDots(viewport='left', subject=self.subject, params=self.mp)
        self.mask_right = RandomDots(viewport='right', subject=self.subject, params=self.mp)
        """ Fixation """
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(2.0,'seconds'))
        """ Interval-1 """
        self.update_disparity(self.cross_interval == 1)
        self.sweep.add_stimulus(self.disc_left)
        self.sweep.add_stimulus(self.disc_right)
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.2,'seconds'))
        """ Blank """
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.4,'seconds'))
        """ Interval-2 """
        self.update_disparity(self.cross_interval == 2)
        self.sweep.add_stimulus(self.disc_left)
        self.sweep.add_stimulus(self.disc_right)
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.2,'seconds'))
        """ Blank """
        self.sweep.add_stimulus(self.fixation_left)
        self.sweep.add_stimulus(self.fixation_right)
        self.sweep.go(duration=(0.4,'seconds'))
        """ Mask """
        self.sweep.add_stimulus(self.mask_left)
        self.sweep.add_stimulus(self.mask_right)
        self.sweep.go(duration=(0.5,'seconds'))
        
        self.sweep.add_controller(None, None, self.key_response)
        self.sweep.add_controller(None, None, self.mouse_response)
        #self.sweep.add_stimulus(self.hint_left)
        #self.sweep.add_stimulus(self.hint_right)
        self.sweep.go(duration=('forever',''))
        key_response = self.key_response.get_last_response_since_go()
        mouse_response = self.mouse_response.get_last_response_since_go()
        if key_response == "left" or mouse_response == "left_button":
            return self.cross_interval == 1
        elif key_response == "right" or mouse_response == "right_button":
            return self.cross_interval == 2
        else:
            raise RuntimeError("Key or button press is not direction.")