コード例 #1
0
ファイル: test_all_stimuli.py プロジェクト: rpbaxter/psychopy
 def test_text(self):
     win = self.win
     if self.win.winType=='pygame':
         pytest.skip("Text is different on pygame")
     #set font
     fontFile = os.path.join(prefs.paths['resources'], 'DejaVuSerif.ttf')
     #using init
     stim = visual.TextStim(win,text=u'\u03A8a', color=[0.5,1.0,1.0], ori=15,
         height=0.8*self.scaleFactor, pos=[0,0], font='DejaVu Serif',
         fontFiles=[fontFile], autoLog=False)
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text1_%s.png' %(self.contextName), win, crit=20)
     win.flip()#AFTER compare screenshot
     #using set
     stim.setText('y', log=False)
     if sys.platform=='win32':
         stim.setFont('Courier New', log=False)
     else:
         stim.setFont('Courier', log=False)
     stim.setOri(-30.5, log=False)
     stim.setHeight(1.0*self.scaleFactor, log=False)
     stim.setColor([0.1,-1,0.8], colorSpace='rgb', log=False)
     stim.setPos([-0.5,0.5],'+', log=False)
     stim.setContrast(0.8, log=False)
     stim.setOpacity(0.8, log=False)
     stim.draw()
     str(stim) #check that str(xxx) is working
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text2_%s.png' %(self.contextName), win, crit=20)
コード例 #2
0
ファイル: test_all_stimuli.py プロジェクト: rpbaxter/psychopy
    def test_radial(self):
        if self.win.winType=='pygame':
            pytest.skip("RadialStim dodgy on pygame")
        win = self.win
        #using init
        wedge = visual.RadialStim(win, tex='sqrXsqr', color=1,size=2*self.scaleFactor,
            visibleWedge=[0, 45], radialCycles=2, angularCycles=2, interpolate=False, autoLog=False)
        wedge.draw()
        thresh = 10
        utils.compareScreenshot('wedge1_%s.png' %(self.contextName), win, crit=thresh)
        win.flip()#AFTER compare screenshot

        #using .set()
        wedge.setMask('gauss', log=False)
        wedge.setSize(3*self.scaleFactor, log=False)
        wedge.setAngularCycles(3, log=False)
        wedge.setRadialCycles(3, log=False)
        wedge.setOri(180, log=False)
        wedge.setContrast(0.8, log=False)
        wedge.setOpacity(0.8, log=False)
        wedge.setRadialPhase(0.1,operation='+', log=False)
        wedge.setAngularPhase(0.1, log=False)
        wedge.draw()
        str(wedge) #check that str(xxx) is working
        utils.compareScreenshot('wedge2_%s.png' %(self.contextName), win, crit=10.0)
コード例 #3
0
ファイル: testMany.py プロジェクト: richarddavis/psychopy
 def testText(self):
     win = self.win
     contextName=self.contextName
     #set font
     if win.winType=='pygame':
         if sys.platform=='win32': font = 'times'
         else:font = '/Library/Fonts/Times New Roman.ttf'
     else: font = 'Times New Roman'
     #using init
     stim = visual.TextStim(win,text=u'\u03A8a', color=[0.5,1.0,1.0], ori=15,
         height=0.8*self.scaleFactor, pos=[0,0], font=font) 
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ) 
     utils.compareScreenshot('data/text1_%s.png' %(contextName), win, crit=40)
     win.flip()#AFTER compare screenshot
     #using set
     stim.setText('y')
     stim.setFont(font)
     stim.setOri(-30.5)
     stim.setHeight(1.0*self.scaleFactor)
     stim.setColor([0.1,-1,0.8], colorSpace='rgb')
     stim.setPos([-0.5,0.5],'+')
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('data/text2_%s.png' %(contextName), win, crit=30)
コード例 #4
0
ファイル: test_all_stimuli.py プロジェクト: rpbaxter/psychopy
 def test_greyscaleImage(self):
     win = self.win
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'greyscale.jpg')
     imageStim = visual.ImageStim(win, fileName, autoLog=False)
     imageStim.draw()
     utils.compareScreenshot('greyscale_%s.png' %(self.contextName), win)
     str(imageStim) #check that str(xxx) is working
コード例 #5
0
    def test_shape(self):
        win = self.win

        shape = visual.ShapeStim(
            win,
            lineColor=[1, 1, 1],
            lineWidth=1.0,
            fillColor=[0.80000000000000004, 0.80000000000000004, 0.80000000000000004],
            vertices=[[-0.5 * self.scaleFactor, 0], [0, 0.5 * self.scaleFactor], [0.5 * self.scaleFactor, 0]],
            closeShape=True,
            pos=[0, 0],
            ori=0.0,
            opacity=1.0,
            depth=0,
            interpolate=True,
        )
        shape.draw()
        # NB shape rendering can differ a little, depending on aliasing
        utils.compareScreenshot("shape1_%s.png" % (self.contextName), win, crit=12.5)
        win.flip()

        # Using .set()
        shape.contrast = 0.8
        shape.opacity = 0.8
        shape.draw()
        str(shape)  # check that str(xxx) is working
        utils.compareScreenshot("shape2_%s.png" % (self.contextName), win, crit=12.5)
コード例 #6
0
ファイル: test_all_stimuli.py プロジェクト: rpbaxter/psychopy
    def test_gabor(self):
        win = self.win
        #using init
        gabor = visual.PatchStim(win, mask='gauss', ori=-45,
            pos=[0.6*self.scaleFactor, -0.6*self.scaleFactor],
            sf=2.0/self.scaleFactor, size=2*self.scaleFactor,
            interpolate=True, autoLog=False)
        gabor.draw()
        utils.compareScreenshot('gabor1_%s.png' %(self.contextName), win)
        win.flip()#AFTER compare screenshot

        #did buffer image also work?
        #bufferImgStim = visual.BufferImageStim(self.win, stim=[gabor])
        #bufferImgStim.draw()
        #utils.compareScreenshot('gabor1_%s.png' %(self.contextName), win)
        #win.flip()

        #using .set()
        gabor.setOri(45, log=False)
        gabor.setSize(0.2*self.scaleFactor, '-', log=False)
        gabor.setColor([45,30,0.3], colorSpace='dkl', log=False)
        gabor.setSF(0.2/self.scaleFactor, '+', log=False)
        gabor.setPos([-0.5*self.scaleFactor, 0.5*self.scaleFactor], '+', log=False)
        gabor.setContrast(0.8, log=False)
        gabor.setOpacity(0.8, log=False)
        gabor.draw()
        utils.compareScreenshot('gabor2_%s.png' %(self.contextName), win)
        win.flip()
        str(gabor) #check that str(xxx) is working
コード例 #7
0
ファイル: test_all_stimuli.py プロジェクト: yemu/psychopy
    def test_gabor(self):
        win = self.win
        #using init
        gabor = visual.PatchStim(win, mask='gauss', ori=-45,
            pos=[0.6*self.scaleFactor, -0.6*self.scaleFactor],
            sf=2.0/self.scaleFactor, size=2*self.scaleFactor,
            interpolate=True)
        gabor.draw()
        utils.compareScreenshot('gabor1_%s.png' %(self.contextName), win)
        win.flip()#AFTER compare screenshot

        #did buffer image also work?
        #bufferImgStim = visual.BufferImageStim(self.win, stim=[gabor])
        #bufferImgStim.draw()
        #utils.compareScreenshot('gabor1_%s.png' %(self.contextName), win)
        #win.flip()

        #using .set()
        gabor.ori = 45
        gabor.size -= 0.2*self.scaleFactor
        gabor.setColor([45,30,0.3], colorSpace='dkl')
        gabor.sf += 0.2/self.scaleFactor
        gabor.pos += [-0.5*self.scaleFactor, 0.5*self.scaleFactor]
        gabor.contrast = 0.8
        gabor.opacity = 0.8
        gabor.draw()
        utils.compareScreenshot('gabor2_%s.png' %(self.contextName), win)
        win.flip()
コード例 #8
0
    def test_gabor(self):
        win = self.win
        # using init
        gabor = visual.PatchStim(
            win,
            mask="gauss",
            ori=-45,
            pos=[0.6 * self.scaleFactor, -0.6 * self.scaleFactor],
            sf=2.0 / self.scaleFactor,
            size=2 * self.scaleFactor,
            interpolate=True,
        )
        gabor.draw()
        utils.compareScreenshot("gabor1_%s.png" % (self.contextName), win)
        win.flip()  # AFTER compare screenshot

        # using .set()
        gabor.ori = 45
        gabor.size -= 0.2 * self.scaleFactor
        gabor.setColor([45, 30, 0.3], colorSpace="dkl")
        gabor.sf += 0.2 / self.scaleFactor
        gabor.pos += [-0.5 * self.scaleFactor, 0.5 * self.scaleFactor]
        gabor.contrast = 0.8
        gabor.opacity = 0.8
        gabor.draw()
        utils.compareScreenshot("gabor2_%s.png" % (self.contextName), win)
        win.flip()
        str(gabor)  # check that str(xxx) is working
コード例 #9
0
    def test_radial(self):
        win = self.win
        #using init
        wedge = visual.RadialStim(win, tex='sqrXsqr', color=1,size=2*self.scaleFactor,
            visibleWedge=[0, 45], radialCycles=2, angularCycles=2, interpolate=False)
        wedge.draw()
        thresh = 10
        if win.winType != 'pygame':  # pygame definitely gets radialstim wrong!
            utils.compareScreenshot('wedge1_%s.png' %(self.contextName), win, crit=thresh)
        win.flip()#AFTER compare screenshot

        #using .set()
        wedge.mask = 'gauss'
        wedge.size = 3 * self.scaleFactor
        wedge.angularCycles = 3
        wedge.radialCycles = 3
        wedge.ori = 180
        wedge.contrast = 0.8
        wedge.opacity = 0.8
        wedge.radialPhase += 0.1
        wedge.angularPhase = 0.1
        wedge.draw()
        "{}".format(wedge) #check that str(xxx) is working
        if win.winType != 'pygame':  # pygame definitely gets radialstim wrong!
            utils.compareScreenshot('wedge2_%s.png' %(self.contextName), win, crit=10.0)
        else:
            pytest.skip("Pygame fails to render RadialStim properly :-/")
コード例 #10
0
    def test_winScalePosOri(self):
        """test window.viewScale and .viewPos simultaneous
        negative-going scale should mirror-reverse, and position should account for that
        visually, the green square/rect should move clockwise around the text

        Non-zero viewOri would not currently pass with a nonzero viewPos
        """
        with pytest.raises(NotImplementedError):
            w = visual.Window(size=(200,200), viewPos=(1,1), viewOri=1)

        for ori in [0, 45]:
            self.win.viewOri = ori
            for offset in [(0,0), (-.4,0)]:
                if ori and (offset[0] or offset[1]):
                    continue  # this combination is NotImplemented
                self.win.viewPos = offset
                for scale in [[1,1],  # normal: green at lower left
                              [1,-1],  # mirror vert only: green appears to move up, text mirrored
                              [-1,-1],  # mirror horiz & vert: green appears to move right, text normal but upside down
                              [-1,1],  # mirror horiz only: green appears to move down, text mirrored
                        [2,2],[2,-2],[-2,-2],[-2,2]]:  # same, but both larger
                    self.win.viewScale = scale
                    self.win.flip()
                    grn = visual.ShapeStim(self.win, vertices=v, pos=pgrn, size=n, fillColor='darkgreen')
                    img = visual.ImageStim(self.win, image=img_name, size=2*n, pos=pimg)
                    grn.draw()
                    img.draw()

                    oristr = str(ori)
                    scalestr = str(scale[0]) + ',' + str(scale[1])
                    posstr = str(offset[0]) + ',' + str(offset[1])
                    filename = 'winScalePos_ori%s_scale%s_pos%s.png' % (oristr, scalestr, posstr)
                    utils.compareScreenshot(filename, self.win, crit=15)
コード例 #11
0
ファイル: test_all_stimuli.py プロジェクト: kastman/psychopy
 def test_text(self):
     win = self.win
     if self.win.winType=='pygame':
         pytest.skip("Text is different on pygame")
     #set font
     fontFile = os.path.join(prefs.paths['resources'], 'DejaVuSerif.ttf')
     #using init
     stim = visual.TextStim(win,text=u'\u03A8a', color=[0.5, 1.0, 1.0], ori=15,
         height=0.8*self.scaleFactor, pos=[0,0], font='DejaVu Serif',
         fontFiles=[fontFile])
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text1_%s.png' %(self.contextName), win, crit=20)
     win.flip()#AFTER compare screenshot
     #using set
     stim.text = 'y'
     if sys.platform=='win32':
         stim.font = 'Courier New'
     else:
         stim.font = 'Courier'
     stim.ori = -30.5
     stim.height = 1.0 * self.scaleFactor
     stim.setColor([0.1, -1, 0.8], colorSpace='rgb')
     stim.pos += [-0.5, 0.5]
     stim.contrast = 0.8
     stim.opacity = 0.8
     stim.draw()
     "{}".format(stim) #check that str(xxx) is working
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text2_%s.png' %(self.contextName), win, crit=20)
コード例 #12
0
 def test_text(self):
     win = self.win
     #set font
     fontFile = os.path.join(prefs.paths['resources'], 'DejaVuSerif.ttf')
     #using init
     stim = visual.TextStim(win,text=u'\u03A8a', color=[0.5,1.0,1.0], ori=15,
         height=0.8*self.scaleFactor, pos=[0,0], font='DejaVu Serif',
         fontFiles=[fontFile])
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text1_%s.png' %(self.contextName), win, crit=20)
     win.flip()#AFTER compare screenshot
     #using set
     stim.setText('y')
     if sys.platform=='win32':
         stim.setFont('Courier New')
     else:
         stim.setFont('Courier')
     stim.setOri(-30.5)
     stim.setHeight(1.0*self.scaleFactor)
     stim.setColor([0.1,-1,0.8], colorSpace='rgb')
     stim.setPos([-0.5,0.5],'+')
     stim.setContrast(0.8)
     stim.setOpacity(0.8)
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text2_%s.png' %(self.contextName), win, crit=20)
コード例 #13
0
ファイル: test_all_stimuli.py プロジェクト: Lx37/psychopy
    def test_radial(self):
        if self.win.winType=='pygame':
            pytest.skip("RadialStim dodgy on pygame")
        win = self.win
        #using init
        wedge = visual.RadialStim(win, tex='sqrXsqr', color=1,size=2*self.scaleFactor,
            visibleWedge=[0, 45], radialCycles=2, angularCycles=2, interpolate=False)
        wedge.draw()
        thresh = 10
        utils.compareScreenshot('wedge1_%s.png' %(self.contextName), win, crit=thresh)
        win.flip()#AFTER compare screenshot

        #using .set()
        wedge.mask = 'gauss'
        wedge.size = 3 * self.scaleFactor
        wedge.angularCycles = 3
        wedge.radialCycles = 3
        wedge.ori = 180
        wedge.contrast = 0.8
        wedge.opacity = 0.8
        wedge.radialPhase += 0.1
        wedge.angularPhase = 0.1
        wedge.draw()
        str(wedge) #check that str(xxx) is working
        utils.compareScreenshot('wedge2_%s.png' %(self.contextName), win, crit=10.0)
コード例 #14
0
ファイル: test_all_stimuli.py プロジェクト: isolver/psychopy
 def test_mov(self):
     win = self.win
     if self.win.winType == 'pygame':
         pytest.skip("movies only available for pyglet backend")
     elif _travisTesting and not _anacondaTesting:
         pytest.skip("Travis with system Python doesn't seem to have a "
                     "working ffmpeg")
     win.flip()
     #construct full path to the movie file
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testMovie.mp4')
     #check if present
     if not os.path.isfile(fileName):
         raise IOError('Could not find movie file: %s'
                       % os.path.abspath(fileName))
     #then do actual drawing
     pos = [0.6*self.scaleFactor, -0.6*self.scaleFactor]
     mov = visual.MovieStim3(win, fileName, pos=pos, noAudio=True)
     mov.setFlipVert(True)
     mov.setFlipHoriz(True)
     for frameN in range(10):
         mov.draw()
         if frameN==0:
             utils.compareScreenshot('movFrame1_%s.png' %self.contextName,
                                     win, crit=10)
         win.flip()
     "{}".format(mov) #check that str(xxx) is working
コード例 #15
0
 def test_simpleimage(self):
     win = self.win
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testimage.jpg')
     if not os.path.isfile(fileName):
         raise IOError('Could not find image file: %s' % os.path.abspath(fileName))
     image = visual.SimpleImageStim(win, image=fileName, flipHoriz=True, flipVert=True)
     image.draw()
     utils.compareScreenshot('simpleimage1_%s.png' %(self.contextName), win, crit=5.0) # Should be exact replication
コード例 #16
0
 def test_imageAndGauss(self):
     win = self.win
     fileName = os.path.join(utils.TESTS_DATA_PATH, "testimage.jpg")
     # use image stim
     size = numpy.array([2.0, 2.0]) * self.scaleFactor
     image = visual.ImageStim(win, image=fileName, mask="gauss", size=size, flipHoriz=True, flipVert=True)
     image.draw()
     utils.compareScreenshot("imageAndGauss_%s.png" % (self.contextName), win)
     win.flip()
コード例 #17
0
ファイル: test_all_stimuli.py プロジェクト: Lx37/psychopy
 def test_dotsUnits(self):
     #to test this create a small dense circle of dots and check the circle
     #has correct dimensions
     fieldSize = numpy.array([1.0,1.0])*self.scaleFactor
     pos = numpy.array([0.5,0])*fieldSize
     dots = visual.DotStim(self.win, color=[-1.0,0.0,0.5], dotSize=5,
                           nDots=1000, fieldShape='circle', fieldPos=pos)
     dots.draw()
     utils.compareScreenshot('dots_%s.png' %(self.contextName), self.win, crit=20)
     self.win.flip()
コード例 #18
0
ファイル: testMany.py プロジェクト: richarddavis/psychopy
 def testRatingScale(self):
     # try to avoid text; avoid default / 'triangle' because it does not display on win XP
     win = self.win
     win.flip()
     rs = visual.RatingScale(win, low=0,high=1,precision=100, displaySizeFactor=3, pos=(0,-.4),
                     lowAnchorText=' ', highAnchorText=' ', scale=' ', 
                     markerStyle='glow', markerStart=0.7, markerColor='darkBlue')
     rs.draw()
     utils.compareScreenshot('data/ratingscale1_%s.png' %(self.contextName), win, crit=30.0)
     win.flip()#AFTER compare screenshot
コード例 #19
0
ファイル: test_winScalePos.py プロジェクト: dgfitch/psychopy
    def test_winScalePosOri(self):
        """test window.viewScale and .viewPos simultaneous
        negative-going scale should mirror-reverse, and position should
        account for that visually, the green square/rect should move clockwise
        around the text

        Non-zero viewOri would not currently pass with a nonzero viewPos
        """
        with pytest.raises(ValueError):
            # units must be define for viewPos!
            _, = visual.Window(size=(200, 200), viewPos=(1, 1), viewOri=1)
        with pytest.raises(NotImplementedError):
            # simultaneous viewPos and viewOri prohibited at present
            _, = visual.Window(size=(200, 200), units='pix',
                               viewPos=(1, 1), viewOri=1)

        for ori in [0, 45]:
            self.win.viewOri = ori
            for offset in [(0, 0), (-0.4, 0)]:
                if ori and (offset[0] or offset[1]):
                    continue  # this combination is NotImplemented
                else:  # NB assumes test win is in pixels!
                    # convert from normalised offset to pixels
                    offset_pix = (round(offs * siz / 2.) for offs, siz in
                                  zip(offset, self.win.size))

                    self.win.viewPos = offset_pix

                for scale in [[1, 1],  # normal: green at lower left
                              [1, -1],  # mirror vert only: green appears to
                                        # move up, text mirrored
                              [-1, -1],  # mirror horiz & vert: green appears
                                         # to move right, text normal but
                                         # upside down
                              [-1, 1],  # mirror horiz only: green appears to
                                        # move down, text mirrored
                              [2, 2],  # same, but both larger
                              [2, -2],
                              [-2, -2],
                              [-2, 2]]:
                    self.win.viewScale = scale
                    self.win.flip()
                    grn = visual.ShapeStim(self.win, vertices=v, pos=pgrn,
                                           size=n, fillColor='darkgreen')
                    img = visual.ImageStim(self.win, image=img_name, size=2*n,
                                           pos=pimg)
                    grn.draw()
                    img.draw()

                    oristr = str(ori)
                    scalestr = str(scale[0]) + '_' + str(scale[1])
                    posstr = str(offset[0]) + '_' + str(offset[1])
                    filename = 'winScalePos_ori%s_scale%s_pos%s.png' % \
                        (oristr, scalestr, posstr)
                    utils.compareScreenshot(filename, self.win, crit=15)
コード例 #20
0
ファイル: test_all_stimuli.py プロジェクト: isolver/psychopy
    def test_noiseFiltersAndRaisedCos(self):
        numpy.random.seed(1)
        win = self.win
        size = numpy.array([2.0,2.0])*self.scaleFactor
        tres=128
        elementsize=4
        sf=None
        ntype='Binary'
        comp='Amplitude'
        fileName = os.path.join(utils.TESTS_DATA_PATH, 'testimagegray.jpg')
        if win.units in ['pix']:
            ftype='Butterworth'
            size = numpy.array([128,128])
        elif win.units in ['degFlatPos']:
            ftype='Gabor'
            sf=0.125
            elementsize=1
        elif win.units in ['degFlat']:
            ftype='Isotropic'
            sf=0.125
            elementsize=1
        elif win.units in ['deg']:
            ntype='Image'
            ftype='Butterworth'
            sf=0.125
        elif win.units in ['cm']:
            ntype='Image'
            ftype='Butterworth'
            comp='Phase'
            sf=0.25
        else:
            if self.contextName=='stencil':
                ntype='White'
                ftype='Butterworth'
            elif self.contextName=='height':
                ntype='Uniform'
                ftype='Butterworth'
            else:
                ntype='Normal'
                ftype='Butterworth'
            elementsize=1.0/8.0
        image  = visual.NoiseStim(win=win, name='noise',units=win.units, 
            noiseImage=fileName, mask='raisedCos',
            ori=0, pos=(0, 0), size=size, sf=sf, phase=0,
            color=[1,1,1], colorSpace='rgb', opacity=1, blendmode='avg', contrast=0.5,
            texRes=tres,
            noiseType=ntype, noiseElementSize=elementsize, noiseBaseSf=32.0/size[0],
            noiseBW=0.5, noiseBWO=7, noiseFractalPower=-1,noiseFilterLower=4.0/size[0], 
            noiseFilterUpper=16.0/size[0], noiseFilterOrder=1, noiseOri=45.0,
            noiseClip=4.0, imageComponent=comp, filter=ftype, interpolate=False, depth=-1.0)
 
        image.draw()
        utils.compareScreenshot('noiseFiltersAndRcos_%s.png' %(self.contextName), win)
        win.flip()
        str(image)
コード例 #21
0
 def test_simpleimage(self):
     win = self.win
     if win.useRetina:
         pytest.skip("Rendering pixel-for-pixel is not identical on retina")
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testimage.jpg')
     if not os.path.isfile(fileName):
         raise IOError('Could not find image file: %s' % os.path.abspath(fileName))
     image = visual.SimpleImageStim(win, image=fileName, flipHoriz=True, flipVert=True)
     "{}".format(image) #check that str(xxx) is working
     image.draw()
     utils.compareScreenshot('simpleimage1_%s.png' %(self.contextName), win, crit=5.0) # Should be exact replication
コード例 #22
0
 def test_simpleimage(self):
     win = self.win
     fileName = os.path.join(utils.TESTS_DATA_PATH, "testimage.jpg")
     if not os.path.isfile(fileName):
         raise IOError("Could not find image file: %s" % os.path.abspath(fileName))
     image = visual.SimpleImageStim(win, image=fileName, flipHoriz=True, flipVert=True)
     str(image)  # check that str(xxx) is working
     image.draw()
     utils.compareScreenshot(
         "simpleimage1_%s.png" % (self.contextName), win, crit=5.0
     )  # Should be exact replication
コード例 #23
0
ファイル: testMany.py プロジェクト: bjanus/psychopy
 def testShape(self):
     win = self.win
     contextName=self.contextName
     
     shape = visual.ShapeStim(win, lineColor=[1, 1, 1], lineWidth=1.0, 
         fillColor=[0.80000000000000004, 0.80000000000000004, 0.80000000000000004], 
         vertices=[[-0.5, 0],[0, 0.5],[0.5, 0]], 
         closeShape=True, pos=[0, 0], ori=0.0, opacity=1.0, depth=0, interpolate=True)
     shape.draw()
     utils.compareScreenshot('data/shape1_%s.png' %(contextName), win, crit=5.0)
     win.flip()#AFTER compare screenshot
コード例 #24
0
ファイル: testMany.py プロジェクト: richarddavis/psychopy
 def testShape(self):
     win = self.win
     contextName=self.contextName
     
     shape = visual.ShapeStim(win, lineColor=[1, 1, 1], lineWidth=1.0, 
         fillColor=[0.80000000000000004, 0.80000000000000004, 0.80000000000000004], 
         vertices=[[-0.5*self.scaleFactor, 0],[0, 0.5*self.scaleFactor],[0.5*self.scaleFactor, 0]], 
         closeShape=True, pos=[0, 0], ori=0.0, opacity=1.0, depth=0, interpolate=True)
     shape.draw()
     #NB shape rendering can differ a little, depending on aliasing
     utils.compareScreenshot('data/shape1_%s.png' %(contextName), win, crit=10.0)
コード例 #25
0
ファイル: test_all_stimuli.py プロジェクト: tstenner/psychopy
 def test_imageAndGauss(self):
     win = self.win
     incorrectName = 'testimage.tif'  # should correctly find testImage.jpg
     fileName = os.path.join(utils.TESTS_DATA_PATH, incorrectName)
     #use image stim
     size = numpy.array([2.0,2.0])*self.scaleFactor
     image = visual.ImageStim(win, image=fileName, mask='gauss',
                              size=size, flipHoriz=True, flipVert=True)
     image.draw()
     utils.compareScreenshot('imageAndGauss_%s.png' %(self.contextName), win)
     win.flip()
コード例 #26
0
ファイル: testMany.py プロジェクト: richarddavis/psychopy
 def testAperture(self):
     win = self.win
     contextName=self.contextName
     grating = visual.PatchStim(win, mask='gauss',sf=8.0, size=2,color='FireBrick', units='norm')
     aperture = visual.Aperture(win, size=1*self.scaleFactor,pos=[0.8*self.scaleFactor,0])
     aperture.disable()
     grating.draw()
     aperture.enable()
     grating.setOri(90)
     grating.setColor('black')
     grating.draw()
     utils.compareScreenshot('data/aperture1_%s.png' %(contextName), win)
コード例 #27
0
ファイル: testMany.py プロジェクト: chrox/psychopy
 def testAperture(self):
     win = self.win
     contextName = self.contextName
     grating = visual.PatchStim(win, mask="gauss", sf=8.0, size=2, color="FireBrick", units="norm")
     aperture = visual.Aperture(win, size=1 * self.scaleFactor, pos=[0.8 * self.scaleFactor, 0])
     aperture.disable()
     grating.draw()
     aperture.enable()
     grating.setOri(90)
     grating.setColor("black")
     grating.draw()
     utils.compareScreenshot("aperture1_%s.png" % (contextName), win)
コード例 #28
0
ファイル: test_all_stimuli.py プロジェクト: klq/psychopy
 def test_rating_scale(self):
     # try to avoid text; avoid default / 'triangle' because it does not display on win XP
     win = self.win
     win.flip()
     rs = visual.RatingScale(win, low=0,high=1,precision=100, displaySizeFactor=3, pos=(0,-.4),
                     lowAnchorText=' ', highAnchorText=' ', scale=' ',
                     markerStyle='glow', markerStart=0.7, markerColor='darkBlue')
     rs.draw()
     if self.win.winType=='pyglet' and utils._under_xvfb:
         pytest.xfail("not clear why fails under Xvfb") # skip late so we smoke test the code
     utils.compareScreenshot('ratingscale1_%s.png' %(self.contextName), win, crit=30.0)
     win.flip()#AFTER compare screenshot
コード例 #29
0
 def test_aperture(self):
     win = self.win
     if not win.allowStencil:
         pytest.skip("Don't run aperture test when no stencil is available")
     grating = visual.PatchStim(win, mask='gauss',sf=8.0, size=2,color='FireBrick', units='norm')
     aperture = visual.Aperture(win, size=1*self.scaleFactor,pos=[0.8*self.scaleFactor,0])
     aperture.disable()
     grating.draw()
     aperture.enable()
     grating.setOri(90)
     grating.setColor('black')
     grating.draw()
     utils.compareScreenshot('aperture1_%s.png' %(self.contextName), win)
コード例 #30
0
ファイル: test_all_stimuli.py プロジェクト: rpbaxter/psychopy
 def test_rating_scale(self):
     if self.win.winType=='pygame':
         pytest.skip("RatingScale not available on pygame")
     # try to avoid text; avoid default / 'triangle' because it does not display on win XP
     win = self.win
     win.flip()
     rs = visual.RatingScale(win, low=0, high=1, precision=100, size=3, pos=(0,-.4),
                     labels=[' ', ' '], scale=' ',
                     marker='glow', markerStart=0.7, markerColor='darkBlue', autoLog=False)
     str(rs) #check that str(xxx) is working
     rs.draw()
     utils.compareScreenshot('ratingscale1_%s.png' %(self.contextName), win, crit=30.0)
     win.flip()#AFTER compare screenshot
コード例 #31
0
 def test_gratingImageAndGauss(self):
     win = self.win
     size = numpy.array([2.0, 2.0]) * self.scaleFactor
     #generate identical image as test_imageAndGauss but using GratingStim
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testimage.jpg')
     if win.units in ['norm', 'height']:
         sf = -1.0
     else:
         sf = -1.0 / size  #this will do the flipping and get exactly one cycle
     image = visual.GratingStim(win,
                                tex=fileName,
                                size=size,
                                sf=sf,
                                mask='gauss',
                                autoLog=False)
     image.draw()
     utils.compareScreenshot('imageAndGauss_%s.png' % (self.contextName),
                             win)
     win.flip()
コード例 #32
0
ファイル: testMany.py プロジェクト: chrox/psychopy
 def testAperture(self):
     win = self.win
     contextName = self.contextName
     grating = visual.PatchStim(win,
                                mask='gauss',
                                sf=8.0,
                                size=2,
                                color='FireBrick',
                                units='norm')
     aperture = visual.Aperture(win,
                                size=1 * self.scaleFactor,
                                pos=[0.8 * self.scaleFactor, 0])
     aperture.disable()
     grating.draw()
     aperture.enable()
     grating.setOri(90)
     grating.setColor('black')
     grating.draw()
     utils.compareScreenshot('aperture1_%s.png' % (contextName), win)
コード例 #33
0
 def test_numpyFilterMask(self):
     """if the mask is passed in as a numpy array it goes through a different
     set of rules when turned into a texture. But the outcome should be as above
     """
     win = self.win
     from psychopy.visual import filters
     gaussMask = filters.makeMask(128, 'gauss')
     size = numpy.array([2.0, 2.0]) * self.scaleFactor
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testimage.jpg')
     image = visual.ImageStim(win,
                              image=fileName,
                              mask=gaussMask,
                              size=size,
                              flipHoriz=True,
                              flipVert=True)
     image.draw()
     utils.compareScreenshot('imageAndGauss_%s.png' % (self.contextName),
                             win)
     win.flip()
コード例 #34
0
 def test_pos_size(self):
     # If this test object has no obj, skip
     if not self.obj:
         return
     # Setup window for this test
     monitor = Monitor("testMonitor")
     monitor.setSizePix((256, 128))
     monitor.setWidth(4)
     monitor.setDistance(50)
     win = visual.Window(size=(256, 128), monitor=monitor)
     win.useRetina = False
     # Setup object for this test
     obj = copy(self.obj)
     obj.win = win
     if hasattr(obj, "fillColor"):
         obj.fillColor = 'red'
     if hasattr(obj, "foreColor"):
         obj.foreColor = 'blue'
     if hasattr(obj, 'borderColor'):
         obj.borderColor = 'green'
     if hasattr(obj, 'opacity'):
         obj.opacity = 1
     # Run positions through each size exemplar
     for size in self.sizeExemplars + self.sizeTykes:
         for pos in self.posExemplars + self.posTykes:
             for units in set(list(pos) + list(size)):
                 if units == 'suffix':
                     continue
                 # Set pos and size
                 obj.units = units
                 obj.size = size[units]
                 obj.pos = pos[units]
                 # Draw
                 obj.draw()
                 # Compare screenshot
                 filename = f"{self.__class__.__name__}_{size['suffix']}_{pos['suffix']}.png"
                 #win.getMovieFrame(buffer='back').save(Path(utils.TESTS_DATA_PATH) / filename)
                 utils.compareScreenshot(filename, win, crit=7)
                 win.flip()
     # Cleanup
     win.close()
     del obj
     del win
コード例 #35
0
 def test_unit_mismatch(self):
     """
     Test that a given stimulus can be drawn without error in all combinations of stimulus units x window units and
     checking that it looks the same as when both units are pix.
     """
     # Test all unit types apart from None and ""
     unitTypes = layout.unitTypes[2:]
     # Create window (same size as was used for other tests)
     win = visual.Window(self.obj.win.size, pos=self.obj.win.pos, monitor="testMonitor")
     # Create object
     obj = copy(self.obj)
     obj.win = win
     # Create model image (pix units for both)
     win.units = 'pix'
     obj.units = 'pix'
     obj.draw()
     filename = Path(utils.TESTS_DATA_PATH) / "test_unit_mismatch.png"
     win.getMovieFrame(buffer='back').save(filename)
     if hasattr(obj, "_size"):
         # Get model sizes
         targetSizes = {units: getattr(obj._size, units) for units in unitTypes}
     # Flip screen
     win.flip()
     # Iterate through window and object units
     for winunits in unitTypes:
         for objunits in unitTypes:
             # Create a window and object
             win.units = winunits
             obj.units = objunits
             # Draw object
             obj.draw()
             # Compare appearance
             utils.compareScreenshot(filename, win, tag=f"{winunits}X{objunits}")
             if hasattr(obj, "_size"):
                 # Compare reported size
                 assert layout.Size(obj.size, obj.units, obj.win) == layout.Size(targetSizes[objunits], objunits, obj.win)
             # Flip screen
             win.flip()
     # Close window
     win.close()
     # Delete model image
     filename.unlink()
コード例 #36
0
 def test_noiseAndRaisedCos(self):
     numpy.random.seed(1)
     win = self.win
     size = numpy.array([2.0,2.0])*self.scaleFactor
     tres=128
     elementsize=4
     sf=None
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testimagegray.jpg')
     if win.units in ['pix']:
         ntype='Binary'
         size = numpy.array([128,128])
     elif win.units in ['degFlatPos']:
         ntype='Gabor'
         sf=0.125
     elif win.units in ['degFlat']:
         ntype='Isotropic'
         sf=0.125
     elif win.units in ['deg']:
         ntype='Filtered'
         sf=0.125
     elif win.units in ['cm']:
         ntype='Image'
         sf=0.25
     else:
         if self.contextName=='stencil':
             ntype='White'
         elif self.contextName=='height':
             ntype='Uniform'
         else:
             ntype='Normal'
         elementsize=1.0/8.0
     image  = visual.NoiseStim(win=win, name='noise',units=win.units, 
         noiseImage=fileName, mask='raisedCos',
         ori=0, pos=(0, 0), size=size, sf=sf, phase=0,
         color=[1,1,1], colorSpace='rgb', opacity=1, blendmode='avg', contrast=0.5,
         texRes=tres,
         noiseType=ntype, noiseElementSize=elementsize, noiseBaseSf=32.0/size[0],
         noiseBW=0.5, noiseBWO=7, noiseFractalPower=-1,noiseFilterLower=4.0/size[0], noiseFilterUpper=16.0/size[0], noiseFilterOrder=1, noiseClip=4.0, interpolate=False, depth=-1.0)
     image.draw()
     utils.compareScreenshot('noiseAndRcos_%s.png' %(self.contextName), win)
     win.flip()
     str(image)
コード例 #37
0
 def test_aperture(self):
     win = self.win
     if not win.allowStencil:
         pytest.skip("Don't run aperture test when no stencil is available")
     grating = visual.PatchStim(win,
                                mask='gauss',
                                sf=8.0,
                                size=2,
                                color='FireBrick',
                                units='norm')
     aperture = visual.Aperture(win,
                                size=1 * self.scaleFactor,
                                pos=[0.8 * self.scaleFactor, 0])
     aperture.disable()
     grating.draw()
     aperture.enable()
     grating.setOri(90)
     grating.setColor('black')
     grating.draw()
     utils.compareScreenshot('aperture1_%s.png' % (self.contextName), win)
コード例 #38
0
 def test_aperture(self):
     win = self.win
     if not win.allowStencil:
         pytest.skip("Don't run aperture test when no stencil is available")
     grating = visual.GratingStim(win, mask='gauss',sf=8.0, size=2,color='FireBrick', units='norm')
     aperture = visual.Aperture(win, size=1*self.scaleFactor,pos=[0.8*self.scaleFactor,0])
     aperture.enabled = False
     grating.draw()
     aperture.enabled = True
     str(aperture) #check that str(xxx) is working
     grating.ori = 90
     grating.color = 'black'
     grating.draw()
     utils.compareScreenshot('aperture1_%s.png' %(self.contextName), win)
     #aperture should automatically disable on exit
     for shape, nVert, pos in [(None, 120, (0,0)), ('circle', 17, (.2, -.7)),
                               ('square', 4, (-.5,-.5)), ('triangle', 3, (1,1))]:
         aperture = visual.Aperture(win, pos=pos, shape=shape, nVert=nVert)
         assert len(aperture.vertices) == nVert  # true for BaseShapeStim; expect (nVert-2)*3 if tesselated
         assert aperture.contains(pos)
コード例 #39
0
    def test_bufferImage(self):
        """BufferImage inherits from ImageStim, so test .ori. .pos etc there not here
        """
        win = self.win
        gabor = visual.PatchStim(
            win,
            mask='gauss',
            ori=-45,
            pos=[0.6 * self.scaleFactor, -0.6 * self.scaleFactor],
            sf=2.0 / self.scaleFactor,
            size=2 * self.scaleFactor,
            interpolate=True)

        bufferImgStim = visual.BufferImageStim(self.win,
                                               stim=[gabor],
                                               interpolate=True)
        bufferImgStim.draw()
        utils.compareScreenshot('bufferimg_gabor_%s.png' % (self.contextName),
                                win)
        win.flip()
コード例 #40
0
 def test_gabor(self):
     win = self.win
     #using init
     gabor = visual.PatchStim(win, mask='gauss', ori=-45,
         pos=[0.6*self.scaleFactor, -0.6*self.scaleFactor],
         sf=2.0/self.scaleFactor, size=2*self.scaleFactor,
         interpolate=True)
     gabor.draw()
     utils.compareScreenshot('gabor1_%s.png' %(self.contextName), win)
     win.flip()#AFTER compare screenshot
     
     #using .set()
     gabor.setOri(45)
     gabor.setSize(0.2*self.scaleFactor, '-')
     gabor.setColor([45,30,0.3], colorSpace='dkl')
     gabor.setSF(0.2/self.scaleFactor, '+')
     gabor.setPos([-0.5*self.scaleFactor,0.5*self.scaleFactor],'+')
     gabor.setContrast(0.8)
     gabor.setOpacity(0.8)
     gabor.draw()
     utils.compareScreenshot('gabor2_%s.png' %(self.contextName), win)
コード例 #41
0
 def test_rating_scale(self):
     # try to avoid text; avoid default / 'triangle' because it does not display on win XP
     win = self.win
     win.flip()
     rs = visual.RatingScale(win,
                             low=0,
                             high=1,
                             precision=100,
                             displaySizeFactor=3,
                             pos=(0, -.4),
                             lowAnchorText=' ',
                             highAnchorText=' ',
                             scale=' ',
                             markerStyle='glow',
                             markerStart=0.7,
                             markerColor='darkBlue')
     rs.draw()
     utils.compareScreenshot('ratingscale1_%s.png' % (self.contextName),
                             win,
                             crit=30.0)
     win.flip()  #AFTER compare screenshot
コード例 #42
0
 def test_mov(self):
     win = self.win
     if self.win.winType=='pygame':
         pytest.skip("movies only available for pyglet backend")
     win.flip()
     #construct full path to the movie file
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testMovie.mp4')
     #check if present
     if not os.path.isfile(fileName):
         raise IOError('Could not find movie file: %s' % os.path.abspath(fileName))
     #then do actual drawing
     pos = [0.6*self.scaleFactor, -0.6*self.scaleFactor]
     mov = visual.MovieStim3(win, fileName, pos=pos)
     mov.setFlipVert(True)
     mov.setFlipHoriz(True)
     for frameN in range(10):
         mov.draw()
         if frameN==0:
             utils.compareScreenshot('movFrame1_%s.png' %(self.contextName), win)
         win.flip()
     str(mov) #check that str(xxx) is working
コード例 #43
0
ファイル: testMany.py プロジェクト: chrox/psychopy
 def testElementArray(self):
     win = self.win
     contextName = self.contextName
     if not win._haveShaders:
         raise nose.plugins.skip.SkipTest(
             "ElementArray requires shaders, which aren't available")
     win.flip()
     #using init
     thetas = numpy.arange(0, 360, 10)
     N = len(thetas)
     radii = numpy.linspace(0, 1.0, N) * self.scaleFactor
     x, y = misc.pol2cart(theta=thetas, radius=radii)
     xys = numpy.array([x, y]).transpose()
     spiral = visual.ElementArrayStim(win,
                                      nElements=N,
                                      sizes=0.5 * self.scaleFactor,
                                      sfs=3.0,
                                      xys=xys,
                                      oris=thetas)
     spiral.draw()
     utils.compareScreenshot('elarray1_%s.png' % (contextName), win)
コード例 #44
0
    def test_text_with_add(self):
        # pyglet text will reset the blendMode to 'avg' so check that we are
        # getting back to 'add' if we want it
        win = self.win
        text = visual.TextStim(win, pos=[0, 0.9])
        grat1 = visual.GratingStim(win, size=2*self.scaleFactor,
                                   opacity=0.5,
                                   pos=[0.3,0.0], ori=45, sf=2*self.scaleFactor)
        grat2 = visual.GratingStim(win, size=2 * self.scaleFactor,
                                   opacity=0.5,
                                   pos=[-0.3, 0.0], ori=-45,
                                   sf=2*self.scaleFactor)

        text.draw()
        grat1.draw()
        grat2.draw()
        if _vmTesting:
            pytest.skip("Blendmode='add' doesn't work under a virtual machine for some reason")
        if self.win.winType != 'pygame':
            utils.compareScreenshot('blend_add_%s.png' %self.contextName,
                                    win, crit=20)
コード例 #45
0
ファイル: test_all_stimuli.py プロジェクト: hm0612/psychopy
    def test_numpyTexture(self):
        win = self.win
        grating = filters.makeGrating(res=64,
                                      ori=20.0,
                                      cycles=3.0,
                                      phase=0.5,
                                      gratType='sqr',
                                      contr=1.0)
        imageStim = visual.ImageStim(win,
                                     image=grating,
                                     size=3 * self.scaleFactor,
                                     interpolate=True)
        imageStim.draw()

        utils.compareScreenshot('numpyImage_%s.png' % (self.contextName), win)
        str(imageStim)  #check that str(xxx) is working
        win.flip()
        #set lowcontrast using color
        imageStim.color = [0.1, 0.1, 0.1]
        imageStim.draw()
        utils.compareScreenshot('numpyLowContr_%s.png' % (self.contextName),
                                win)
        win.flip()
        #now try low contrast using contr
        imageStim.color = 1
        imageStim.contrast = 0.1  #should have identical effect to color=0.1
        imageStim.draw()
        utils.compareScreenshot('numpyLowContr_%s.png' % (self.contextName),
                                win)
        win.flip()
コード例 #46
0
ファイル: test_all_stimuli.py プロジェクト: karolaug/psychopy
 def test_text(self):
     win = self.win
     if self.win.winType == 'pygame':
         pytest.skip("Text is different on pygame")
     #set font
     fontFile = os.path.join(prefs.paths['resources'], 'DejaVuSerif.ttf')
     #using init
     stim = visual.TextStim(win,
                            text=u'\u03A8a',
                            color=[0.5, 1.0, 1.0],
                            ori=15,
                            height=0.8 * self.scaleFactor,
                            pos=[0, 0],
                            font='DejaVu Serif',
                            fontFiles=[fontFile],
                            autoLog=False)
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text1_%s.png' % (self.contextName),
                             win,
                             crit=20)
     win.flip()  #AFTER compare screenshot
     #using set
     stim.setText('y', log=False)
     if sys.platform == 'win32':
         stim.setFont('Courier New', log=False)
     else:
         stim.setFont('Courier', log=False)
     stim.setOri(-30.5, log=False)
     stim.setHeight(1.0 * self.scaleFactor, log=False)
     stim.setColor([0.1, -1, 0.8], colorSpace='rgb', log=False)
     stim.setPos([-0.5, 0.5], '+', log=False)
     stim.setContrast(0.8, log=False)
     stim.setOpacity(0.8, log=False)
     stim.draw()
     str(stim)  #check that str(xxx) is working
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text2_%s.png' % (self.contextName),
                             win,
                             crit=20)
コード例 #47
0
ファイル: test_all_stimuli.py プロジェクト: apitiot/psychopy
 def test_text(self):
     win = self.win
     #set font
     fontFile = str(
         Path(prefs.paths['resources']) / "fonts" / 'DejaVuSerif.ttf')
     #using init
     stim = visual.TextStim(win,
                            text=u'\u03A8a',
                            color=[0.5, 1.0, 1.0],
                            ori=15,
                            height=0.8 * self.scaleFactor,
                            pos=[0, 0],
                            font='DejaVu Serif',
                            fontFiles=[fontFile])
     stim.draw()
     if self.win.winType != 'pygame':
         #compare with a LIBERAL criterion (fonts do differ)
         utils.compareScreenshot('text1_%s.png' % (self.contextName),
                                 win,
                                 crit=20)
     win.flip()  # AFTER compare screenshot
     #using set
     stim.text = 'y'
     if sys.platform == 'win32':
         stim.font = 'Courier New'
     else:
         stim.font = 'Courier'
     stim.ori = -30.5
     stim.height = 1.0 * self.scaleFactor
     stim.setColor([0.1, -1, 0.8], colorSpace='rgb')
     stim.pos += [-0.5, 0.5]
     stim.contrast = 0.8
     stim.opacity = 0.8
     stim.draw()
     "{}".format(stim)  #check that str(xxx) is working
     if self.win.winType != 'pygame':
         #compare with a LIBERAL criterion (fonts do differ)
         utils.compareScreenshot('text2_%s.png' % self.contextName,
                                 win,
                                 crit=20)
コード例 #48
0
    def test_radial(self):
        win = self.win
        #using init
        wedge = visual.RadialStim(win,
                                  tex='sqrXsqr',
                                  color=1,
                                  size=2 * self.scaleFactor,
                                  visibleWedge=[0, 45],
                                  radialCycles=2,
                                  angularCycles=2,
                                  interpolate=False)
        wedge.draw()
        thresh = 15  # there are often a slight interpolation differences
        if win.winType != 'pygame':  # pygame definitely gets radialstim wrong!
            utils.compareScreenshot('wedge1_%s.png' % (self.contextName),
                                    win,
                                    crit=thresh)
        win.flip()  #AFTER compare screenshot

        #using .set()
        wedge.mask = 'gauss'
        wedge.size = 3 * self.scaleFactor
        wedge.angularCycles = 3
        wedge.radialCycles = 3
        wedge.ori = 180
        wedge.contrast = 0.8
        wedge.opacity = 0.8
        wedge.radialPhase += 0.1
        wedge.angularPhase = 0.1
        wedge.draw()
        "{}".format(wedge)  #check that str(xxx) is working
        if win.winType != 'pygame' and (
                sys.version_info.major, sys.version_info.minor) != (
                    3, 6):  # pygame and 3.6 definitely get radialstim wrong!
            utils.compareScreenshot('wedge2_%s.png' % (self.contextName),
                                    win,
                                    crit=thresh)
        else:
            pytest.skip("Pygame fails to render RadialStim properly :-/")
コード例 #49
0
 def test_aperture_image(self):
     win = self.win
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'testwedges.png')
     if not win.allowStencil:
         pytest.skip("Don't run aperture test when no stencil is available")
     grating = visual.GratingStim(win,
                                  mask='gauss',
                                  sf=8.0,
                                  size=2,
                                  color='FireBrick',
                                  units='norm')
     aperture = visual.Aperture(win,
                                size=1 * self.scaleFactor,
                                pos=[0.8 * self.scaleFactor, 0],
                                shape=fileName)
     aperture.enabled = False
     grating.draw()
     aperture.enabled = True
     str(aperture)  #check that str(xxx) is working
     grating.ori = 90
     grating.color = 'black'
     grating.draw()
     utils.compareScreenshot('aperture2_%s.png' % (self.contextName), win)
コード例 #50
0
 def test_aperture(self):
     win = self.win
     if not win.allowStencil:
         pytest.skip("Don't run aperture test when no stencil is available")
     grating = visual.GratingStim(win,
                                  mask='gauss',
                                  sf=8.0,
                                  size=2,
                                  color='FireBrick',
                                  units='norm',
                                  autoLog=False)
     aperture = visual.Aperture(win,
                                size=1 * self.scaleFactor,
                                pos=[0.8 * self.scaleFactor, 0],
                                autoLog=False)
     aperture.disable()
     grating.draw()
     aperture.enable()
     str(aperture)  #check that str(xxx) is working
     grating.setOri(90, log=False)
     grating.setColor('black', log=False)
     grating.draw()
     utils.compareScreenshot('aperture1_%s.png' % (self.contextName), win)
コード例 #51
0
    def test_gabor(self):
        win = self.win
        #using init
        gabor = visual.PatchStim(win, mask='gauss', ori=-45,
            pos=[0.6*self.scaleFactor, -0.6*self.scaleFactor],
            sf=2.0/self.scaleFactor, size=2*self.scaleFactor,
            interpolate=True)
        gabor.draw()
        utils.compareScreenshot('gabor1_%s.png' %(self.contextName), win)
        win.flip()#AFTER compare screenshot

        #using .set()
        gabor.ori = 45
        gabor.size -= 0.2 * self.scaleFactor
        gabor.setColor([45,30,0.3], colorSpace='dkl')
        gabor.sf += 0.2 / self.scaleFactor
        gabor.pos += [-0.5*self.scaleFactor, 0.5*self.scaleFactor]
        gabor.contrast = 0.8
        gabor.opacity = 0.8
        gabor.draw()
        utils.compareScreenshot('gabor2_%s.png' %(self.contextName), win)
        win.flip()
        str(gabor) #check that str(xxx) is working
コード例 #52
0
    def test_element_array(self):
        win = self.win
        if not win._haveShaders:
            pytest.skip("ElementArray requires shaders, which aren't available")
        #using init
        thetas = numpy.arange(0,360,10)
        N=len(thetas)

        radii = numpy.linspace(0,1.0,N)*self.scaleFactor
        x, y = pol2cart(theta=thetas, radius=radii)
        xys = numpy.array([x,y]).transpose()
        spiral = visual.ElementArrayStim(win, opacities = 0, nElements=N,sizes=0.5*self.scaleFactor,
            sfs=1.0, xys=xys, oris=-thetas)
        spiral.draw()
        #check that the update function is working by changing vals after first draw() call
        spiral.opacities = 1.0
        spiral.sfs = 3.0
        spiral.draw()
        str(spiral) #check that str(xxx) is working
        win.flip()
        spiral.draw()
        utils.compareScreenshot('elarray1_%s.png' %(self.contextName), win)
        win.flip()
コード例 #53
0
    def test_text_with_add(self):
        # pyglet text will reset the blendMode to 'avg' so check that we are
        # getting back to 'add' if we want it
        win = self.win
        text = visual.TextStim(win, pos=[0, 0.9])
        grat1 = visual.GratingStim(win,
                                   size=2 * self.scaleFactor,
                                   opacity=0.5,
                                   pos=[0.3, 0.0],
                                   ori=45,
                                   sf=2 * self.scaleFactor)
        grat2 = visual.GratingStim(win,
                                   size=2 * self.scaleFactor,
                                   opacity=0.5,
                                   pos=[-0.3, 0.0],
                                   ori=-45,
                                   sf=2 * self.scaleFactor)

        text.draw()
        grat1.draw()
        grat2.draw()
        utils.compareScreenshot('blend_add_%s.png' % (self.contextName),
                                win,
                                crit=20)
コード例 #54
0
ファイル: test_all_stimuli.py プロジェクト: karolaug/psychopy
    def test_radial(self):
        if self.win.winType == 'pygame':
            pytest.skip("RadialStim dodgy on pygame")
        win = self.win
        #using init
        wedge = visual.RadialStim(win,
                                  tex='sqrXsqr',
                                  color=1,
                                  size=2 * self.scaleFactor,
                                  visibleWedge=[0, 45],
                                  radialCycles=2,
                                  angularCycles=2,
                                  interpolate=False,
                                  autoLog=False)
        wedge.draw()
        thresh = 10
        utils.compareScreenshot('wedge1_%s.png' % (self.contextName),
                                win,
                                crit=thresh)
        win.flip()  #AFTER compare screenshot

        #using .set()
        wedge.setMask('gauss', log=False)
        wedge.setSize(3 * self.scaleFactor, log=False)
        wedge.setAngularCycles(3, log=False)
        wedge.setRadialCycles(3, log=False)
        wedge.setOri(180, log=False)
        wedge.setContrast(0.8, log=False)
        wedge.setOpacity(0.8, log=False)
        wedge.setRadialPhase(0.1, operation='+', log=False)
        wedge.setAngularPhase(0.1, log=False)
        wedge.draw()
        str(wedge)  #check that str(xxx) is working
        utils.compareScreenshot('wedge2_%s.png' % (self.contextName),
                                win,
                                crit=10.0)
コード例 #55
0
ファイル: test_all_stimuli.py プロジェクト: karolaug/psychopy
    def test_gabor(self):
        win = self.win
        #using init
        gabor = visual.PatchStim(
            win,
            mask='gauss',
            ori=-45,
            pos=[0.6 * self.scaleFactor, -0.6 * self.scaleFactor],
            sf=2.0 / self.scaleFactor,
            size=2 * self.scaleFactor,
            interpolate=True,
            autoLog=False)
        gabor.draw()
        utils.compareScreenshot('gabor1_%s.png' % (self.contextName), win)
        win.flip()  #AFTER compare screenshot

        #did buffer image also work?
        #bufferImgStim = visual.BufferImageStim(self.win, stim=[gabor])
        #bufferImgStim.draw()
        #utils.compareScreenshot('gabor1_%s.png' %(self.contextName), win)
        #win.flip()

        #using .set()
        gabor.setOri(45, log=False)
        gabor.setSize(0.2 * self.scaleFactor, '-', log=False)
        gabor.setColor([45, 30, 0.3], colorSpace='dkl', log=False)
        gabor.setSF(0.2 / self.scaleFactor, '+', log=False)
        gabor.setPos([-0.5 * self.scaleFactor, 0.5 * self.scaleFactor],
                     '+',
                     log=False)
        gabor.setContrast(0.8, log=False)
        gabor.setOpacity(0.8, log=False)
        gabor.draw()
        utils.compareScreenshot('gabor2_%s.png' % (self.contextName), win)
        win.flip()
        str(gabor)  #check that str(xxx) is working
コード例 #56
0
 def test_text(self):
     win = self.win
     #set font
     fontFile = os.path.join(prefs.paths['resources'], 'DejaVuSerif.ttf')
     #using init
     stim = visual.TextStim(win,
                            text=u'\u03A8a',
                            color=[0.5, 1.0, 1.0],
                            ori=15,
                            height=0.8 * self.scaleFactor,
                            pos=[0, 0],
                            font='DejaVu Serif',
                            fontFiles=[fontFile])
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text1_%s.png' % (self.contextName),
                             win,
                             crit=20)
     win.flip()  #AFTER compare screenshot
     #using set
     stim.setText('y')
     if sys.platform == 'win32':
         stim.setFont('Courier New')
     else:
         stim.setFont('Courier')
     stim.setOri(-30.5)
     stim.setHeight(1.0 * self.scaleFactor)
     stim.setColor([0.1, -1, 0.8], colorSpace='rgb')
     stim.setPos([-0.5, 0.5], '+')
     stim.setContrast(0.8)
     stim.setOpacity(0.8)
     stim.draw()
     #compare with a LIBERAL criterion (fonts do differ)
     utils.compareScreenshot('text2_%s.png' % (self.contextName),
                             win,
                             crit=20)
コード例 #57
0
ファイル: test_all_stimuli.py プロジェクト: hm0612/psychopy
 def test_rating_scale(self):
     if self.win.winType == 'pygame':
         pytest.skip("RatingScale not available on pygame")
     # try to avoid text; avoid default / 'triangle' because it does not display on win XP
     win = self.win
     win.flip()
     rs = visual.RatingScale(win,
                             low=0,
                             high=1,
                             precision=100,
                             size=3,
                             pos=(0, -.4),
                             labels=[' ', ' '],
                             scale=' ',
                             marker='glow',
                             markerStart=0.7,
                             markerColor='darkBlue',
                             autoLog=False)
     str(rs)  #check that str(xxx) is working
     rs.draw()
     utils.compareScreenshot('ratingscale1_%s.png' % (self.contextName),
                             win,
                             crit=30.0)
     win.flip()  #AFTER compare screenshot
コード例 #58
0
 def test_greyscaleImage(self):
     win = self.win
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'greyscale.jpg')
     imageStim = visual.ImageStim(win, fileName)
     imageStim.draw()
     utils.compareScreenshot('greyscale_%s.png' %(self.contextName), win)
     str(imageStim) #check that str(xxx) is working
     win.flip()
     imageStim.color = [0.1,0.1,0.1]
     imageStim.draw()
     utils.compareScreenshot('greyscaleLowContr_%s.png' %(self.contextName), win)
     win.flip()
     imageStim.color = 1
     imageStim.contrast = 0.1#should have identical effect to color=0.1
     imageStim.draw()
     utils.compareScreenshot('greyscaleLowContr_%s.png' %(self.contextName), win)
     win.flip()
     imageStim.contrast = 1.0
     fileName = os.path.join(utils.TESTS_DATA_PATH, 'greyscale2.png')
     imageStim.image = fileName
     imageStim.size *= 3
     imageStim.draw()
     utils.compareScreenshot('greyscale2_%s.png' %(self.contextName), win)
     win.flip()
コード例 #59
0
    def test_glyph_rendering(self):
        # Prepare textbox
        self.textbox.colorSpace = 'rgb'
        self.textbox.color = 'white'
        self.textbox.fillColor = (0, 0, 0)
        self.textbox.borderColor = None
        self.textbox.opacity = 1

        # Add all Noto Sans fonts to cover widest possible base of handles characters
        for font in [
                "Noto Sans", "Noto Sans HK", "Noto Sans JP", "Noto Sans KR",
                "Noto Sans SC", "Noto Sans TC", "Niramit", "Indie Flower"
        ]:
            self.textbox.fontMGR.addGoogleFont(font)
        # Some exemplar text to test basic TextBox rendering
        exemplars = [
            # An English pangram
            {
                "text":
                "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question.",
                "font": "Noto Sans",
                "size": 16,
                "screenshot": "exemplar_1.png"
            },
            # The same pangram in IPA
            {
                "text":
                "ə saɪkəʊpaɪ zɛlət nəʊz ə smidge ɒv wx, bʌt ˈʤɑːvəskrɪpt ɪz ðə ˈkwɛsʧən",
                "font": "Noto Sans",
                "size": 16,
                "screenshot": "exemplar_2.png"
            },
            # The same pangram in Hangul
            {
                "text": "아 프시초피 제알롣 크노W스 아 s믿게 오f wx, 붇 자v앗c립t 잇 테 q왯디온",
                "font": "Noto Sans KR",
                "size": 16,
                "screenshot": "exemplar_3.png"
            },
            # A noticeably non-standard font
            {
                "text":
                "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question.",
                "font": "Indie Flower",
                "size": 16,
                "screenshot": "exemplar_4.png",
            }
        ]
        # Some text which is likely to cause problems if something isn't working
        tykes = [
            # Text which doesn't render properly on Mac (Issue #3203)
            {
                "text": "कोशिकायें",
                "font": "Noto Sans",
                "size": 16,
                "screenshot": "tyke_1.png"
            },
            # Thai text which old Text component couldn't handle due to Pyglet
            {
                "text": "ขาว แดง เขียว เหลือง ชมพู ม่วง เทา",
                "font": "Niramit",
                "size": 16,
                "screenshot": "tyke_2.png"
            },
            # Text which had the top cut off
            {
                "text": "โฬิปื้ด็ลู",
                "font": "Niramit",
                "size": 36,
                "screenshot": "cutoff_top.png"
            },
        ]
        # Test each case and compare against screenshot
        for case in exemplars + tykes:
            self.textbox.reset()
            self.textbox.fontMGR.addGoogleFont(case['font'])
            self.textbox.letterHeight = layout.Size(case['size'], "pix",
                                                    self.win)
            self.textbox.font = case['font']
            self.textbox.text = case['text']
            self.win.flip()
            self.textbox.draw()
            if case['screenshot']:
                # Uncomment to save current configuration as desired
                filename = "textbox_{}_{}".format(self.textbox._lineBreaking,
                                                  case['screenshot'])
                #self.win.getMovieFrame(buffer='back').save(Path(utils.TESTS_DATA_PATH) / filename)
                utils.compareScreenshot(Path(utils.TESTS_DATA_PATH) / filename,
                                        self.win,
                                        crit=20)
コード例 #60
0
 def test_colors(self):
     # Do base tests
     _TestColorMixin.test_colors(self)
     # Do own custom tests
     self.textbox.text = "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question."
     # Some exemplar text to test basic colors
     exemplars = [
         # White on black in rgb
         {
             "color": (1, 1, 1),
             "fillColor": (-1, -1, -1),
             "borderColor": (-1, -1, -1),
             "space": "rgb",
             "screenshot": "colors_WOB.png"
         },
         # White on black in named
         {
             "color": "white",
             "fillColor": "black",
             "borderColor": "black",
             "space": "rgb",
             "screenshot": "colors_WOB.png"
         },
         # White on black in hex
         {
             "color": "#ffffff",
             "fillColor": "#000000",
             "borderColor": "#000000",
             "space": "hex",
             "screenshot": "colors_WOB.png"
         },
         {
             "color": "red",
             "fillColor": "yellow",
             "borderColor": "blue",
             "space": "rgb",
             "screenshot": "colors_exemplar1.png"
         },
         {
             "color": "yellow",
             "fillColor": "blue",
             "borderColor": "red",
             "space": "rgb",
             "screenshot": "colors_exemplar2.png"
         },
         {
             "color": "blue",
             "fillColor": "red",
             "borderColor": "yellow",
             "space": "rgb",
             "screenshot": "colors_exemplar3.png"
         },
     ]
     # Some colors which are likely to cause problems if something isn't working
     tykes = [
         # Text only
         {
             "color": "white",
             "fillColor": None,
             "borderColor": None,
             "space": "rgb",
             "screenshot": "colors_tyke1.png"
         },
         # Fill only
         {
             "color": None,
             "fillColor": "white",
             "borderColor": None,
             "space": "rgb",
             "screenshot": "colors_tyke2.png"
         },
         # Border only
         {
             "color": None,
             "fillColor": None,
             "borderColor": "white",
             "space": "rgb",
             "screenshot": "colors_tyke3.png"
         },
     ]
     # Test each case and compare against screenshot
     for case in exemplars + tykes:
         # Raise error if case spec does not contain all necessary keys
         if not all(
                 key in case for key in
             ["color", "fillColor", "borderColor", "space", "screenshot"]):
             raise KeyError(
                 f"Case spec for test_colors in class {self.__class__.__name__} ({__file__}) invalid, test cannot be run."
             )
         # Apply params from case spec
         self.textbox.colorSpace = case['space']
         self.textbox.color = case['color']
         self.textbox.fillColor = case['fillColor']
         self.textbox.borderColor = case['borderColor']
         for lineBreaking in ('default', 'uax14'):
             self.win.flip()
             self.textbox.draw()
         if case['screenshot']:
             # Uncomment to save current configuration as desired
             filename = "textbox_{}_{}".format(self.textbox._lineBreaking,
                                               case['screenshot'])
             # self.win.getMovieFrame(buffer='back').save(Path(utils.TESTS_DATA_PATH) / filename)
             utils.compareScreenshot(Path(utils.TESTS_DATA_PATH) / filename,
                                     self.win,
                                     crit=20)