Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        """
        Deprecated (as of version 1.74.00):
        please use the :class:`~psychopy.visual.GratingStim`
        or the :class:`~psychopy.visual.ImageStim` classes.

        The GratingStim has identical abilities to the PatchStim
        (but possibly different initial values)
        whereas the ImageStim is designed to be use for non-cyclic images
        (photographs, not gratings).
        """
        GratingStim.__init__(self, *args, **kwargs)
        self.setImage = self.setTex
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        """
        Deprecated (as of version 1.74.00):
        please use the :class:`~psychopy.visual.GratingStim`
        or the :class:`~psychopy.visual.ImageStim` classes.

        The GratingStim has identical abilities to the PatchStim
        (but possibly different initial values)
        whereas the ImageStim is designed to be use for non-cyclic images
        (photographs, not gratings).
        """
        GratingStim.__init__(self, *args, **kwargs)
        self.setImage = self.setTex
Exemplo n.º 3
0
    def __init__(self,
                 win,
                 buffer='back',
                 rect=(-1, 1, 1, -1),
                 sqPower2=False,
                 stim=(),
                 interpolate=True,
                 flipHoriz=False,
                 flipVert=False,
                 mask='None',
                 pos=(0, 0),
                 name='',
                 autoLog=True):
        """
        :Parameters:

            buffer :
                the screen buffer to capture from, default is 'back' (hidden).
                'front' is the buffer in view after win.flip()
            rect :
                a list of edges [left, top, right, bottom] defining a screen rectangle
                which is the area to capture from the screen, given in norm units.
                default is fullscreen: [-1, 1, 1, -1]
            stim :
                a list of item(s) to be drawn to the back buffer (in order). The back
                buffer is first cleared (without the win being flip()ed), then stim items
                are drawn, and finally the buffer (or part of it) is captured.
                Each item needs to have its own .draw() method, and have the same
                window as win.
            interpolate :
                whether to use interpolation (default = True, generally good,
                especially if you change the orientation)
            sqPower2 :
                - False (default) = use rect for size if OpenGL = 2.1+
                - True = use square, power-of-two image sizes
            flipHoriz :
                horizontally flip (mirror) the captured image, default = False
            flipVert :
                vertically flip (mirror) the captured image; default = False
        """
        # depends on: window._getRegionOfFrame

        #what local vars are defined (these are the init params) for use by __repr__
        self._initParams = dir()
        self._initParams.remove('self')

        self.autoLog = False  #set this False first and change after attribs are set
        _clock = core.Clock()
        if stim:  # draw all stim to the back buffer
            win.clearBuffer()
            buffer = 'back'
            for stimulus in list(stim):
                try:
                    if stimulus.win == win:
                        stimulus.draw()
                    else:
                        logging.warning(
                            'BufferImageStim.__init__: user requested "%s" drawn in another window'
                            % repr(stimulus))
                except AttributeError:
                    logging.warning(
                        'BufferImageStim.__init__: "%s" failed to draw' %
                        repr(stimulus))

        # take a screenshot of the buffer using win._getRegionOfFrame():
        glversion = pyglet.gl.gl_info.get_version()
        if glversion >= '2.1' and not sqPower2:
            region = win._getRegionOfFrame(buffer=buffer, rect=rect)
        else:
            if not sqPower2:
                logging.debug(
                    'BufferImageStim.__init__: defaulting to square power-of-2 sized image (%s)'
                    % glversion)
            region = win._getRegionOfFrame(buffer=buffer,
                                           rect=rect,
                                           squarePower2=True)
        if stim:
            win.clearBuffer()

        # turn the RGBA region into a GratingStim()-like object:
        if win.units in ['norm']:
            pos *= win.size / 2.
        GratingStim.__init__(self,
                             win,
                             tex=region,
                             units='pix',
                             mask=mask,
                             pos=pos,
                             interpolate=interpolate,
                             name=name,
                             autoLog=False)

        # to improve drawing speed, move these out of draw:
        self.desiredRGB = self._getDesiredRGB(self.rgb, self.colorSpace,
                                              self.contrast)
        self.thisScale = numpy.array([4, 4])
        self.flipHoriz = flipHoriz
        self.flipVert = flipVert
        self.autoLog = autoLog

        if self.autoLog:
            logging.exp('BufferImageStim %s: took %.1fms to initialize' %
                        (name, 1000 * _clock.getTime()))
Exemplo n.º 4
0
    def __init__(self, win, buffer='back', rect=(-1, 1, 1, -1), sqPower2=False,
        stim=(), interpolate=True, flipHoriz=False, flipVert=False, mask='None', pos=(0,0),
        name='', autoLog=True):
        """
        :Parameters:

            buffer :
                the screen buffer to capture from, default is 'back' (hidden).
                'front' is the buffer in view after win.flip()
            rect :
                a list of edges [left, top, right, bottom] defining a screen rectangle
                which is the area to capture from the screen, given in norm units.
                default is fullscreen: [-1, 1, 1, -1]
            stim :
                a list of item(s) to be drawn to the back buffer (in order). The back
                buffer is first cleared (without the win being flip()ed), then stim items
                are drawn, and finally the buffer (or part of it) is captured.
                Each item needs to have its own .draw() method, and have the same
                window as win.
            interpolate :
                whether to use interpolation (default = True, generally good,
                especially if you change the orientation)
            sqPower2 :
                - False (default) = use rect for size if OpenGL = 2.1+
                - True = use square, power-of-two image sizes
            flipHoriz :
                horizontally flip (mirror) the captured image, default = False
            flipVert :
                vertically flip (mirror) the captured image; default = False
        """
        # depends on: window._getRegionOfFrame

        #what local vars are defined (these are the init params) for use by __repr__
        self._initParams = dir()
        self._initParams.remove('self')

        self.autoLog=False #set this False first and change after attribs are set
        _clock = core.Clock()
        if stim: # draw all stim to the back buffer
            win.clearBuffer()
            logging.debug('BufferImageStim.__init__: clearing back buffer')
            buffer = 'back'
            for stimulus in list(stim):
                try:
                    if stimulus.win == win:
                        stimulus.draw()
                    else:
                        logging.warning('BufferImageStim.__init__: user requested "%s" drawn in another window' % repr(stimulus))
                except AttributeError:
                    logging.warning('BufferImageStim.__init__: "%s" failed to draw' % repr(stimulus))

        # take a screenshot of the buffer using win._getRegionOfFrame():
        glversion = pyglet.gl.gl_info.get_version()
        if glversion >= '2.1' and not sqPower2:
            region = win._getRegionOfFrame(buffer=buffer, rect=rect)
        else:
            if not sqPower2:
                logging.debug('BufferImageStim.__init__: defaulting to square power-of-2 sized image (%s)' % glversion )
            region = win._getRegionOfFrame(buffer=buffer, rect=rect, squarePower2=True)
        if stim:
            win.clearBuffer()

        # turn the RGBA region into a GratingStim()-like object:
        if win.units in ['norm']:
            pos *= win.size/2.
        GratingStim.__init__(self, win, tex=region, units='pix', mask=mask, pos=pos,
                             interpolate=interpolate, name=name, autoLog=False)

        # to improve drawing speed, move these out of draw:
        self.desiredRGB = self._getDesiredRGB(self.rgb, self.colorSpace, self.contrast)
        self.thisScale = numpy.array([4, 4])
        self.flipHoriz = flipHoriz
        self.flipVert = flipVert
        self.autoLog = autoLog

        logging.exp('BufferImageStim %s: took %.1fms to initialize' % (name, 1000 * _clock.getTime()))
Exemplo n.º 5
0
from psychopy import core
from psychopy import misc
from psychopy.visual.windowwarp import Warper
from psychopy.monitors import Monitor
from psychopy.visual.grating import GratingStim
from psychopy.visual.window import Window

mon = Monitor('GenericMonitor', width=33.169, distance=10)
mon.setSizePix((1440, 900))
win = Window((1440, 900),
             monitor=mon,
             fullscr=True,
             useFBO=True,
             allowStencil=True)
warper = Warper(win, warp='spherical', warpGridsize=300, eyepoint=[0.5, 0.5])
stim = GratingStim(win=win,
                   units='deg',
                   tex='sin',
                   sf=0.1,
                   size=misc.pix2deg(win.size, win.monitor))
print win.size
print 'win size', win.size
print 'mon size', win.monitor.getSizePix()
print 'as deg', misc.pix2deg(win.size, win.monitor)
stim.draw()
win.flip()
core.wait(0.5)
win.close()
Exemplo n.º 6
0
    def __init__(self,
                 win,
                 carrier="noise",
                 mask="none",
                 envelope="sin",
                 units="",
                 pos=(0.0, 0.0),
                 size=None,
                 sf=None,
                 envsf=None,
                 ori=0.0,
                 envori=0.0,
                 phase=(0.0, 0.0),
                 envphase=(0.0, 0.0),
                 beat=False,
                 texRes=128,
                 rgb=None,
                 dkl=None,
                 lms=None,
                 color=(1.0, 1.0, 1.0),
                 colorSpace='rgb',
                 contrast=0.5,  # see doc
                 moddepth=1.0,  # modulation depth for envelope
                 power=1.0, # power to raise modulator to.
                 opacity=1.0,
                 depth=0,
                 rgbPedestal=(0.0, 0.0, 0.0),
                 interpolate=False,
                 blendmode='avg',
                 name=None,
                 autoLog=None,
                 autoDraw=False,
                 maskParams=None):
        """ """  # Empty docstring. All doc is in attributes
        # what local vars are defined (these are the init params) for use by
        # __repr__
        assert win._haveShaders is True, ("Currently EnvelopeGratings needs "
                                         "your graphics card to have shaders"
                                         " and yours does not seem to.")
        self._initParams = dir()
        for unecess in ['self', 'rgb', 'dkl', 'lms']:
            self._initParams.remove(unecess)
        # initialise parent class
        GratingStim.__init__(self, win,
                             units=units, pos=pos, size=size, sf=sf,
                             ori=ori, phase=phase,
                             color=color, colorSpace=colorSpace,
                             contrast=contrast, opacity=opacity,
                             depth=depth, interpolate=interpolate,
                             name=name, autoLog=autoLog, autoDraw=autoDraw,
                             maskParams=None)
        # use shaders if available by default, this is a good thing
        self.__dict__['useShaders'] = win._haveShaders
        # UGLY HACK: Some parameters depend on each other for processing.
        # They are set "superficially" here.
        # TO DO: postpone calls to _createTexture, setColor and
        # _calcCyclesPerStim whin initiating stimulus

        #AJS
        self.__dict__['carrier'] = carrier
        self.__dict__['envelope'] = envelope
        self.__dict__['maskParams'] = maskParams

        # initialise textures and masks for stimulus
        self._carrierID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._carrierID))
        self._envelopeID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._envelopeID))
        self._powerID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._powerID))
        self.interpolate = interpolate
        del self._texID  # created by GratingStim.__init__
        self.texRes = int(texRes)
        self.mask = mask

        self.envelope = envelope
        self.carrier = carrier
        self.envsf = val2array(envsf)
        self.envphase = val2array(envphase, False)
        self.envori = float(envori)
        self.moddepth = float(moddepth)
        self.power = float(power)
        if beat in ['True','true','Yes','yes','Y','y']:
            self.beat = True
        elif beat in ['False','false','No','no','N','n']:
            self.beat = False
        else:
            self.beat = bool(beat)
        self._needUpdate = True
        self.blendmode=blendmode
        self._shaderProgBeat = _shaders.compileProgram(
            _shaders.vertSimple, carrierEnvelopeMaskFrag)
        self._shaderProgPow = _shaders.compileProgram(
            _shaders.vertSimple, carrierEnvelopeMaskFragPow)

        self.local = numpy.ones((texRes, texRes), dtype=numpy.ubyte)
        self.local_p = self.local.ctypes
        # fix scaling to window coords
        self._calcEnvCyclesPerStim()
        
        del self.__dict__['tex']
Exemplo n.º 7
0
 def test_elements(self):
     s = Slider(self.win, size=(1, 0.1))
     assert type(s.line) == type(GratingStim(self.win))
     assert type(s.tickLines) == type(ElementArrayStim(self.win))
     assert type(s.marker) == type(Circle(self.win))
     assert type(s.validArea) == type(Rect(self.win))
Exemplo n.º 8
0
    def __init__(self,
                 win,
                 carrier="noise",
                 mask="none",
                 envelope="sin",
                 units="",
                 pos=(0.0, 0.0),
                 size=None,
                 sf=None,
                 envsf=None,
                 ori=0.0,
                 envori=0.0,
                 phase=(0.0, 0.0),
                 envphase=(0.0, 0.0),
                 beat=False,
                 texRes=128,
                 rgb=None,
                 dkl=None,
                 lms=None,
                 color=(1.0, 1.0, 1.0),
                 colorSpace='rgb',
                 contrast=0.5,  # contrast of carrier default this to 0.5 to avoid overmodulation - contrast and moddepth must work together, for moddepth=1 the max carrier contrast is 0.5. If moddepth < 1 higher contrasts can be accomodated
                 moddepth=1.0, # modulation depth for envelope
                 opacity=1.0, # not sure what this will do with an envelope stimulus.
                 depth=0,
                 rgbPedestal=(0.0, 0.0, 0.0),
                 interpolate=False,
                 name=None,
                 autoLog=None,
                 autoDraw=False,
                 maskParams=None):
        """ """  # Empty docstring. All doc is in attributes
        #what local vars are defined (these are the init params) for use by __repr__
        assert(win._haveShaders==True),"Currently EnvelopeGratings need your graphics card to have shaders and yours does not seem to comply - sorry"
        self._initParams = dir()
        for unecess in ['self', 'rgb', 'dkl', 'lms']:
            self._initParams.remove(unecess)
        #initialise parent class
        GratingStim.__init__(self, win,
                 units=units, pos=pos, size=size, sf=sf, ori=ori, phase=phase,
                 color=color, colorSpace=colorSpace,
                 contrast=contrast, opacity=opacity,
                 depth=depth, interpolate=interpolate,
                 name=name, autoLog=autoLog, autoDraw=autoDraw,
                 maskParams=None)
        self.__dict__['useShaders'] = win._haveShaders  #use shaders if available by default, this is a good thing
        # UGLY HACK: Some parameters depend on each other for processing.
        # They are set "superficially" here.
        # TO DO: postpone calls to _createTexture, setColor and _calcCyclesPerStim whin initiating stimulus
        self.__dict__['carrier'] = carrier
        self.__dict__['envelope'] = envelope
        self.__dict__['maskParams'] = maskParams

        #initialise textures and masks for stimulus
        self._carrierID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._carrierID))
        self._envelopeID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._envelopeID))
        self.interpolate = interpolate
        del self._texID #created by GratingStim.__init__

        self.mask = mask
        self.envelope = envelope
        self.carrier = carrier
        self.envsf=val2array(envsf)
        self.envphase=val2array(envphase, False)
        self.envori=float(envori)
        self.moddepth=float(moddepth)
        self.beat=bool(beat)
        #print(self.CMphase)
        self._shaderProg = _shaders.compileProgram(_shaders.vertSimple, carrierEnvelopeMaskFrag)
        
        self.local=numpy.ones((texRes,texRes),dtype=numpy.ubyte)
        self.local_p=self.local.ctypes
        #self.local=GL.GL_UNSIGNED_BYTE(self.local)
        #fix scaling to window coords
        #self._calcCyclesPerStim()
        self._calcEnvCyclesPerStim()
        del self.__dict__['tex']
Exemplo n.º 9
0
    def __init__(self,
                 win,
                 carrier="noise",
                 mask="none",
                 envelope="sin",
                 units="",
                 pos=(0.0, 0.0),
                 size=None,
                 sf=None,
                 envsf=None,
                 ori=0.0,
                 envori=0.0,
                 phase=(0.0, 0.0),
                 envphase=(0.0, 0.0),
                 beat=False,
                 texRes=128,
                 rgb=None,
                 dkl=None,
                 lms=None,
                 color=(1.0, 1.0, 1.0),
                 colorSpace='rgb',
                 contrast=0.5,  # see doc
                 moddepth=1.0,  # modulation depth for envelope
                 opacity=1.0,
                 depth=0,
                 rgbPedestal=(0.0, 0.0, 0.0),
                 interpolate=False,
                 blendmode='avg',
                 name=None,
                 autoLog=None,
                 autoDraw=False,
                 maskParams=None):
        """ """  # Empty docstring. All doc is in attributes
        # what local vars are defined (these are the init params) for use by
        # __repr__
        assert win._haveShaders is True, ("Currently EnvelopeGratings needs "
                                         "your graphics card to have shaders"
                                         " and yours does not seem to.")
        self._initParams = dir()
        for unecess in ['self', 'rgb', 'dkl', 'lms']:
            self._initParams.remove(unecess)
        # initialise parent class
        GratingStim.__init__(self, win,
                             units=units, pos=pos, size=size, sf=sf,
                             ori=ori, phase=phase,
                             color=color, colorSpace=colorSpace,
                             contrast=contrast, opacity=opacity,
                             depth=depth, interpolate=interpolate,
                             name=name, autoLog=autoLog, autoDraw=autoDraw,
                             maskParams=None)
        # use shaders if available by default, this is a good thing
        self.__dict__['useShaders'] = win._haveShaders
        # UGLY HACK: Some parameters depend on each other for processing.
        # They are set "superficially" here.
        # TO DO: postpone calls to _createTexture, setColor and
        # _calcCyclesPerStim whin initiating stimulus

        #AJS
        self.__dict__['carrier'] = carrier
        self.__dict__['envelope'] = envelope
        self.__dict__['maskParams'] = maskParams

        # initialise textures and masks for stimulus
        self._carrierID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._carrierID))
        self._envelopeID = GL.GLuint()
        GL.glGenTextures(1, ctypes.byref(self._envelopeID))
        self.interpolate = interpolate
        del self._texID  # created by GratingStim.__init__

        self.mask = mask

        self.envelope = envelope
        self.carrier = carrier
        self.envsf = val2array(envsf)
        self.envphase = val2array(envphase, False)
        self.envori = float(envori)
        self.moddepth = float(moddepth)
        if beat in ['True','true','Yes','yes','Y','y']:
            self.beat =True
        elif beat in ['False','false','No','no','N','n']:
            self.beat =False
        else:
            self.beat =bool(beat)
        self._needUpdate = True
        self.blendmode=blendmode
        self._shaderProg = _shaders.compileProgram(
            _shaders.vertSimple, carrierEnvelopeMaskFrag)

        self.local = numpy.ones((texRes, texRes), dtype=numpy.ubyte)
        self.local_p = self.local.ctypes
        # fix scaling to window coords
        self._calcEnvCyclesPerStim()
        self.texRes=int(texRes)
        del self.__dict__['tex']