Skip to content

Commit

Permalink
TEST: Fix tests for visual stim
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd OST committed Apr 18, 2024
1 parent 26e7545 commit 08d8f4f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
12 changes: 6 additions & 6 deletions psychopy_visionscience/components/radial/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def __init__(self, exp, parentName,

msg = _translate("Number of texture cycles from centre to periphery, i.e. it controls the number of ‘rings’.")
self.params['radialCycles'] = Param(
radialCycles, valType='num', inputType="single", allowedTypes=[], categ='Texture',
radialCycles, valType="code", inputType="single", allowedTypes=[], categ='Texture',
updates='constant',
allowedUpdates=['constant', 'set every repeat', 'set every frame'],
hint=msg,
label=_translate("Radial Cycles"))

msg = _translate("Number of cycles going around the stimulus. i.e. it controls the number of ‘spokes’.")
self.params['angularCycles'] = Param(
angularCycles, valType='num', inputType="single", allowedTypes=[], categ='Texture',
angularCycles, valType="code", inputType="single", allowedTypes=[], categ='Texture',
updates='constant',
allowedUpdates=['constant', 'set every repeat', 'set every frame'],
hint=msg,
Expand All @@ -96,7 +96,7 @@ def __init__(self, exp, parentName,
msg = _translate("This is the phase of the texture from the centre to the perimeter of the stimulus"
" (in radians). Can be used to drift concentric rings out/inwards.")
self.params['radialPhase'] = Param(
radialPhase, valType='num', inputType="single", allowedTypes=[], categ='Texture',
radialPhase, valType="code", inputType="single", allowedTypes=[], categ='Texture',
updates='constant',
allowedUpdates=['constant', 'set every repeat', 'set every frame'],
hint=msg,
Expand All @@ -105,15 +105,15 @@ def __init__(self, exp, parentName,
msg = _translate("This is akin to setting the orientation of the texture around the stimulus in radians."
" If possible, it is more efficient to rotate the stimulus using its ori setting instead.")
self.params['angularPhase'] = Param(
angularPhase, valType='num', inputType="single", allowedTypes=[], categ='Texture',
angularPhase, valType="code", inputType="single", allowedTypes=[], categ='Texture',
updates='constant',
allowedUpdates=['constant', 'set every repeat', 'set every frame'],
hint=msg,
label=_translate("Angular Phase"))

msg = _translate("Determines visible range.")
self.params['visibleWedge'] = Param(
visibleWedge, valType='num', inputType="single", allowedTypes=[], categ='Texture',
visibleWedge, valType="code", inputType="single", allowedTypes=[], categ='Texture',
updates='constant',
allowedUpdates=['constant', 'set every repeat', 'set every frame'],
hint=msg,
Expand All @@ -132,7 +132,7 @@ def __init__(self, exp, parentName,
"etc. For most cases a value of 256 pixels will suffice")
self.params['texture resolution'] = Param(
texRes,
valType='num', inputType="choice", allowedVals=['32', '64', '128', '256', '512'], categ='Texture',
valType="code", inputType="choice", allowedVals=['32', '64', '128', '256', '512'], categ='Texture',
updates='constant', allowedUpdates=[],
hint=msg,
label=_translate("Texture resolution"))
Expand Down
3 changes: 3 additions & 0 deletions psychopy_visionscience/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ def noiseClip(self, value):
self.__dict__['noiseClip'] = value
self._needUpdate = True
self._needBuild = True

def setNoiseOri(self, value):
self.noiseOri = value

@attributeSetter
def filter(self, value):
Expand Down
70 changes: 38 additions & 32 deletions tests/test_coder/test_all_stimuli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from psychopy.tests import utils
from psychopy.tests import skip_under_vm, requires_plugin
from psychopy.tools import systemtools
from psychopy_visionscience import secondorder, noise, radial
import numpy
import pytest
import shutil
Expand All @@ -19,12 +20,22 @@
"""

from psychopy.tests.test_visual.test_all_stimuli import _baseVisualTest

class _TestPluginVisualStim:
@classmethod
def setup_class(self):#run once for each test class (window)
self.win=None
self.contextName
raise NotImplementedError

@classmethod
def teardown_class(self):#run once for each test class (window)
self.win.close()#shutil.rmtree(self.temp_dir)

class TestPluginVisualStim(_baseVisualTest):
def setup_method(self):#this is run for each test individually
#make sure we start with a clean window
self.win.flip()

@requires_plugin("psychopy-visionscience")
def test_envelopeGratingAndRaisedCos(self):
win = self.win
size = numpy.array([2.0, 2.0]) * self.scaleFactor
Expand All @@ -33,7 +44,7 @@ def test_envelopeGratingAndRaisedCos(self):
else:
sf = 5.0 / size # this will do the flipping and get exactly one cycle
if win._haveShaders == True: # can't draw envelope gratings without shaders so skip this test
image = visual.EnvelopeGrating(win, carrier='sin', envelope='sin',
image = secondorder.EnvelopeGrating(win, carrier='sin', envelope='sin',
size=size, sf=sf, mask='raisedCos',
ori=-45, envsf=sf / 2, envori=45,
envphase=90, moddepth=0.5,
Expand All @@ -43,7 +54,6 @@ def test_envelopeGratingAndRaisedCos(self):
win.flip()
"{}".format(image)

@requires_plugin("psychopy-visionscience")
def test_envelopeGratingPowerAndRaisedCos(self):
win = self.win
size = numpy.array([2.0, 2.0]) * self.scaleFactor
Expand All @@ -52,7 +62,7 @@ def test_envelopeGratingPowerAndRaisedCos(self):
else:
sf = 5.0 / size # this will do the flipping and get exactly one cycle
if win._haveShaders == True: # can't draw envelope gratings without shaders so skip this test
image = visual.EnvelopeGrating(win, carrier='sin', envelope='sin',
image = secondorder.EnvelopeGrating(win, carrier='sin', envelope='sin',
size=size, sf=sf, mask='raisedCos',
ori=-45, envsf=sf / 2, envori=45,
envphase=90, moddepth=0.5, power=0.5,
Expand All @@ -62,30 +72,29 @@ def test_envelopeGratingPowerAndRaisedCos(self):
win.flip()
"{}".format(image)

@requires_plugin("psychopy-visionscience")
def test_NoiseStim_defaults(self):
noiseTypes = ['binary', 'uniform', 'normal', 'white', 'filtered']

for noiseType in noiseTypes:
stim = visual.NoiseStim(win=self.win,
noiseType=noiseType,
size=(32, 32),
units='pix')
stim = noise.NoiseStim(
win=self.win,
noiseType=noiseType,
size=(32, 32),
units='pix'
)
stim.updateNoise()
stim.draw()

@requires_plugin("psychopy-visionscience")
def test_NoiseStim_defaults_image(self):
noiseType = 'image'

# noiseImage kwarg missing.
with pytest.raises(ValueError):
visual.NoiseStim(win=self.win,
noise.NoiseStim(win=self.win,
noiseType=noiseType,
size=(32, 32),
units='pix')

@requires_plugin("psychopy-visionscience")
def test_noiseAndRaisedCos(self):
numpy.random.seed(1)
win = self.win
Expand Down Expand Up @@ -117,7 +126,7 @@ def test_noiseAndRaisedCos(self):
else:
ntype = 'Normal'
elementsize = 1.0 / 8.0
image = visual.NoiseStim(win=win, name='noise', units=win.units,
image = noise.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',
Expand All @@ -133,7 +142,6 @@ def test_noiseAndRaisedCos(self):
win.flip()
str(image)

@requires_plugin("psychopy-visionscience")
def test_noiseFiltersAndRaisedCos(self):
numpy.random.seed(1)
win = self.win
Expand Down Expand Up @@ -175,7 +183,7 @@ def test_noiseFiltersAndRaisedCos(self):
ntype = 'Normal'
ftype = 'Butterworth'
elementsize = 1.0 / 8.0
image = visual.NoiseStim(win=win, name='noise', units=win.units,
image = noise.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',
Expand All @@ -194,7 +202,6 @@ def test_noiseFiltersAndRaisedCos(self):
win.flip()
str(image)

@requires_plugin("psychopy-visionscience")
def test_envelopeBeatAndRaisedCos(self):
win = self.win
size = numpy.array([2.0, 2.0]) * self.scaleFactor
Expand All @@ -203,7 +210,7 @@ def test_envelopeBeatAndRaisedCos(self):
else:
sf = 5.0 / size # this will do the flipping and get exactly one cycle
if win._haveShaders == True: # can't draw envelope gratings without shaders so skip this test
image = visual.EnvelopeGrating(win, carrier='sin', envelope='sin',
image = secondorder.EnvelopeGrating(win, carrier='sin', envelope='sin',
size=size, sf=sf, mask='raisedCos',
ori=-45, envsf=sf / 2, envori=45,
envphase=90, beat=True, moddepth=0.5,
Expand All @@ -213,11 +220,10 @@ def test_envelopeBeatAndRaisedCos(self):
win.flip()
"{}".format(image)

@requires_plugin("psychopy-visionscience")
def test_radial(self):
win = self.win
#using init
wedge = visual.RadialStim(win, tex='sqrXsqr', color=1, size=2* self.scaleFactor,
wedge = radial.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
Expand Down Expand Up @@ -246,7 +252,7 @@ def test_radial(self):

# variants of the base tests with different backends (copied from psychopy)

class TestPygletNorm(TestPluginVisualStim):
class TestPygletNorm(_TestPluginVisualStim):
@classmethod
def setup_class(self):
self.win = visual.Window([128, 128], winType='pyglet', pos=[50, 50],
Expand All @@ -255,7 +261,7 @@ def setup_class(self):
self.scaleFactor = 1 # applied to size/pos values


class TestPygletHexColor(TestPluginVisualStim):
class TestPygletHexColor(_TestPluginVisualStim):
@classmethod
def setup_class(self):
self.win = visual.Window([128, 128], winType='pyglet', pos=[50, 50],
Expand All @@ -266,7 +272,7 @@ def setup_class(self):


if not systemtools.isVM_CI():
class TestPygletBlendAdd(TestPluginVisualStim):
class TestPygletBlendAdd(_TestPluginVisualStim):
@classmethod
def setup_class(self):
self.win = visual.Window([128, 128], winType='pyglet', pos=[50, 50],
Expand All @@ -275,7 +281,7 @@ def setup_class(self):
self.scaleFactor = 1 # applied to size/pos values


class TestPygletNormFBO(TestPluginVisualStim):
class TestPygletNormFBO(_TestPluginVisualStim):
@classmethod
def setup_class(self):
self.win = visual.Window([128, 128], units="norm", winType='pyglet', pos=[50, 50],
Expand All @@ -284,7 +290,7 @@ def setup_class(self):
self.scaleFactor = 1 # applied to size/pos values


class TestPygletHeight(TestPluginVisualStim):
class TestPygletHeight(_TestPluginVisualStim):
@classmethod
def setup_class(self):
self.win = visual.Window([128, 64], units="height", winType='pyglet', pos=[50, 50],
Expand All @@ -293,7 +299,7 @@ def setup_class(self):
self.scaleFactor = 1 # applied to size/pos values


class TestPygletNormStencil(TestPluginVisualStim):
class TestPygletNormStencil(_TestPluginVisualStim):
@classmethod
def setup_class(self):
self.win = visual.Window([128, 128], units="norm", monitor='testMonitor',
Expand All @@ -303,7 +309,7 @@ def setup_class(self):
self.scaleFactor = 1 # applied to size/pos values


class TestPygletPix(TestPluginVisualStim):
class TestPygletPix(_TestPluginVisualStim):
@classmethod
def setup_class(self):
mon = monitors.Monitor('testMonitor')
Expand All @@ -317,7 +323,7 @@ def setup_class(self):
self.scaleFactor = 60 # applied to size/pos values


class TestPygletCm(TestPluginVisualStim):
class TestPygletCm(_TestPluginVisualStim):
@classmethod
def setup_class(self):
mon = monitors.Monitor('testMonitor')
Expand All @@ -331,7 +337,7 @@ def setup_class(self):
self.scaleFactor = 2 # applied to size/pos values


class TestPygletDeg(TestPluginVisualStim):
class TestPygletDeg(_TestPluginVisualStim):
@classmethod
def setup_class(self):
mon = monitors.Monitor('testMonitor')
Expand All @@ -345,7 +351,7 @@ def setup_class(self):
self.scaleFactor = 2 # applied to size/pos values


class TestPygletDegFlat(TestPluginVisualStim):
class TestPygletDegFlat(_TestPluginVisualStim):
@classmethod
def setup_class(self):
mon = monitors.Monitor('testMonitor')
Expand All @@ -359,7 +365,7 @@ def setup_class(self):
self.scaleFactor = 4 # applied to size/pos values


class TestPygletDegFlatPos(TestPluginVisualStim):
class TestPygletDegFlatPos(_TestPluginVisualStim):
@classmethod
def setup_class(self):
mon = monitors.Monitor('testMonitor')
Expand Down

0 comments on commit 08d8f4f

Please sign in to comment.