Ejemplo n.º 1
0
    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, autoLog=False,
                                     size = 3*self.scaleFactor,
                                     interpolate=True)
        imageStim.draw()

        if self.win.winType=='pygame':
            pytest.xfail("Numpy texture is wrong polarity on pygame?")
        utils.compareScreenshot('numpyImage_%s.png' %(self.contextName), win)
        str(imageStim) #check that str(xxx) is working
        win.flip()
        #set lowcontrast using color
        imageStim.setColor([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()
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
    def setup_stimuli(self):
        grating_res = 256
        

        size = self.deg2pix(self.config.get('stimuli', 'size'))

        n_cycles = 1./self.deg2pix(1./self.config.get('stimuli','cycles_per_degree')) * size

        grating = filters.makeGrating(res=grating_res,
                                      cycles=n_cycles) * -1
        green_grating = np.ones((grating_res, grating_res, 3)) * -1.0
        green_grating[..., 1] = grating
        
        self.green_grating = GratingStim(self.screen,
                                 size=self.deg2pix(self.config.get('stimuli', 'size')),
                                 tex=green_grating,
                                 mask='raisedCos',
                                 maskParams={'fringeWidth':0.1},)

        red_grating = np.ones((grating_res, grating_res, 3)) * -1.0
        red_grating[..., 0] = grating

        self.red_grating = GratingStim(self.screen,
                                 size=self.deg2pix(self.config.get('stimuli', 'size')),
                                 tex=red_grating,
                                 ori=90,
                                 mask='raisedCos',
                                 maskParams={'fringeWidth':0.1},)

        self.rim = StimulusSet(self.screen,
                               (0, 0),
                               self.config.get('stimuli', 'size'),
                               self)
Ejemplo n.º 4
0
def setGratingPhase(phaseForm, patch):
    texture = num.zeros((256, 256), "d")
    maxPeak = 0
    for thisSF in num.arange(1, 2 * info["nComponents"] + 1, 2):
        texture += filters.makeGrating(256, cycles=thisSF, phase=phaseForm) / thisSF
        maxPeak = maxPeak + 1.0 / thisSF
    texture /= maxPeak
    patch.setTex(texture)
Ejemplo n.º 5
0
def flatAzim(res, cone, ori=0.0, cycles=1.0, phase=0.0, elevation = 0.0):
    """Creates a grating defined either by S or LM in DKL space. The elevation
    can be changed whilst keeping the azimuth flat - in effect changing the position
    of the azimuth
    
    Warning: May generate values >1 or <-1
    
    :Parameters:
        res: integer
            the size of the resulting matrix on both dimensions (e.g 256)
        cone: 'LM' or 'S'
            which axis in DKL space the grating should be created in
        ori: float or int (default=0.0)
            the orientation of the grating in degrees
        cycles:float or int (default=1.0)
            the number of grating cycles within the array
        phase: float or int (default=0.0)
            the phase of the grating in degrees (NB this differs to most
            PsychoPy phase arguments which use units of fraction of a cycle)
        elevation: float or int (default=0.0)
            the angle that the azimuth will be changed to

    :Returns:
        a square numpy array of size resXres
        """

    gabor = filters.makeGrating(res, ori=ori, cycles = cycles, phase=phase)

    colorGabor = np.zeros((len(gabor), len(gabor), 3))
    colorGabor[:,:,0] = copy.copy(gabor)
    colorGabor[:,:,1] = copy.copy(gabor)
    colorGabor[:,:,2] = copy.copy(gabor)

    dklGabor = misc.rgb2dklCart(colorGabor)
    if cone=='LM':
        dklGabor = misc.cart2sph(dklGabor[:,:,0]*0.0, dklGabor[:,:,0]*0.0, dklGabor[:,:,0])
    if cone=='S':
        dklGabor = misc.cart2sph(dklGabor[:,:,0]*0.0, dklGabor[:,:,0], dklGabor[:,:,0]*0.0)
    if cone=='Lum':
        dklGabor = misc.cart2sph(dklGabor[:,:,0], dklGabor[:,:,0]*0.0, dklGabor[:,:,0]*0.0)

    temp = copy.copy(dklGabor[:,:,1])+1
    temp = (temp/np.abs(temp))*+elevation
    dklGabor[:,:,0] += temp

    rgbGabor = misc. dkl2rgb(dklGabor)
    return rgbGabor
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
myWin = visual.Window((1024, 768), units='pix', allowGUI=True, bitsMode=None)
visual.TextStim(myWin, text='building stimuli').draw()

myWin.update()

globalClock = core.Clock()

#for luminance modulated noise
noiseMatrix = num.random.randint(0, 2, [pixels, pixels])  #*noiseContrast
noiseMatrix = noiseMatrix * 2.0 - 1  #into range -1:1

stimFrames = []
lumGratings = []
#create the 4 frames of the sequence (luminance and contrast modulated noise in quadrature)
lumGratings.append(filters.makeGrating(pixels, 0, cyclesSpace, phase=0))
stimFrames.append(
    visual.PatchStim(myWin,
                     texRes=pixels,
                     mask='circle',
                     size=pixels * 2,
                     sf=1.0 / pixels,
                     ori=90,
                     tex=(noiseMatrix * info['lumModNoise'] +
                          lumGratings[0] * info['lumModLum'])))
lumGratings.append(
    filters.makeGrating(pixels, 0, cyclesSpace, phase=90) / 2.0 + 0.5)
stimFrames.append(
    visual.PatchStim(myWin,
                     texRes=pixels,
                     mask='circle',
Ejemplo n.º 8
0
pixels=128

myWin = visual.Window((1024,768), units='pix', allowGUI=True, bitsMode=None)
visual.TextStim(myWin, text='building stimuli').draw()

myWin.update()

globalClock = core.Clock()

#for luminance modulated noise
noiseMatrix = num.random.randint(0,2,[pixels,pixels])#*noiseContrast
noiseMatrix = noiseMatrix*2.0-1 #into range -1:1
  
stimFrames=[]; lumGratings=[]
#create the 4 frames of the sequence (luminance and contrast modulated noise in quadrature)
lumGratings.append(filters.makeGrating(pixels, 0, cyclesSpace, phase=0))
stimFrames.append(visual.PatchStim(myWin, texRes=pixels, mask='circle',
        size=pixels*2, sf=1.0/pixels, ori=90,
        tex= (noiseMatrix*info['lumModNoise'] + lumGratings[0]*info['lumModLum'])
        ))
lumGratings.append(filters.makeGrating(pixels, 0, cyclesSpace, phase=90)/2.0 + 0.5)
stimFrames.append(visual.PatchStim(myWin, texRes=pixels, mask='circle',
        size=pixels*2, sf=1.0/pixels, ori=90,
        tex= (noiseMatrix*info['contrastModNoise']*lumGratings[1])
        ))
lumGratings.append(filters.makeGrating(pixels, 0, cyclesSpace, phase=180))
stimFrames.append(visual.PatchStim(myWin, texRes=pixels, mask='circle',
        size=pixels*2, sf=1.0/pixels, ori=90,
        tex= (noiseMatrix*info['lumModNoise'] + lumGratings[2]*info['lumModLum'])
        ))
lumGratings.append(filters.makeGrating(pixels, 0, cyclesSpace, phase=270)/2.0 + 0.5)
Ejemplo n.º 9
0
            intensity = numpy.sin(xrange)*numpy.sin(yrange)
    else:#might be a filename of an image
            try:
                    im = Image.open(gratType)
            except:
                    log.error( "couldn't find tex...",gratType)
                    return
    return intensity
#
myWin = visual.Window(size = (800,600), units = 'deg', monitor = 'testMonitor')
questionText=visual.TextStim(myWin, text='Was the perturbed image 1st(1) or 2nd(2)?')


for amp in stairs:
    
    grating2 = filters.makeGrating(128, cycles=10.0)
    lmGrating = np.empty((128,128,3))
    lmGrating[:,:,0] = copy.copy(grating2)
    lmGrating[:,:,1] = copy.copy(grating2)
    lmGrating[:,:,2] = copy.copy(grating2)
    
    
    grating1 = makeSineGrating(128, cycles=10.0, amplitude=amp, frequency=5)
    lumGrating = np.empty((128,128,3))
    lumGrating[:,:,0] = copy.copy(grating1)
    lumGrating[:,:,1] = copy.copy(grating1)
    lumGrating[:,:,2] = copy.copy(grating1)
    
    
    print amp     #Current amplitude
Ejemplo n.º 10
0
# ---------- Stimulus code begins here ---------- #

#set up window and stim
win=visual.Window(fullscr=True,screen=1)

#Set up the trigger behavior
trigger = None
if triggerType == "NoTrigger":
    trigger = noTrigger.noTrigger(None) 
elif triggerType == "DaqTrigger":
    trigger = daqTrigger.daqTrigger(None) 
else:
    print "Unknown trigger type", triggerType

grating = filters.makeGrating(256,cycles=1,gratType='sqr')#ranges-1 to 1 
texture = numpy.zeros([256,256,3]) 
#we need 1,-1,-1 at peak phase and 0,0,0 at trough phase 
texture[:,:,0] = grating*0.729-0.271#r 
texture[:,:,1] = grating*0.729-0.271#g 
texture[:,:,2] = grating*0.729-0.271#b 

blackTexture = -numpy.ones([256,256,3]) 

stim=visual.PatchStim(win, tex=texture,texRes=256,sf=spatialFreq, units='pix',size=(1280,1024),ori=45,mask='none') 
blankStim=visual.PatchStim(win, tex=blackTexture,texRes=256,sf=spatialFreq, units='pix',size=(1280,1024),ori=45,mask='none') 

#stim.autoLog=False#or we'll get many messages about phase change
#blankStim.autoLog=False#or we'll get many messages about phase change

stimcodes = range(1,10) #remember, ranges in python do not include the final number