The same ShapeStim is displayed in one script but not in another

224 views
Skip to first unread message

Denis Matrov

unread,
Feb 8, 2016, 11:03:07 PM2/8/16
to psychopy-users
Hello,
I am trying to present the flickering Shapestimuli with my script.
circle = visual.Circle(myWin, radius=0.2, edges=32, size=1.0, lineWidth=1.5, contrast=1.0,
                opacity
=1.0, units='norm', autoDraw=False, autoLog=False, name='circle')

The problem is the stimulus on not visible in my main script but visible if I stick it to the Shapes.py demo

So the main loop is rather complex and includes communication with eye-tracker and sending out some TTLs

for frameN in range(EXP_DURATION):
    dt
= getEYELINK().getNewestSample() # check for new sample update
   
if(dt != None):
        gaze_position
= dt.getRightEye().getGaze()
        gazex
= float(info['gainX']) * gaze_position[0] + float(info['offsetX'])
        gazey
= float(info['gainY']) * gaze_position[1] + float(info['offsetY'])
        mask
.setPos([gazex, gazey])
   
if (frameN % periodColor) < periodColorOn:
        circle
.fillColor = "#FF8C00"
        circle
.lineColor = "#FF8C00"
   
else:
        circle
.fillColor = "#FFF8DC"
        circle
.lineColor = "#FFF8DC"
   
if (frameN % periodPos) > periodPosRight:
        circle
.pos=(-0.5,0)
   
else:
        circle
.pos=(0.5,0)  
   
if circle.contains([gazex, gazey]):
        circle
.fillColor = "#7FFF00"
        circle
.lineColor = "#7FFF00"
        circle
.radius *= 1.5
    mask
.draw()
    circle
.draw()
    myWin
.flip()
   
if frameN % 119 == 0:
       
print gazex, gazey
        device
.send_message("DIO{0/0}:VALUE=1")
        reward
= True                
   
if (reward == True) & (frameN % 119 == 110):
        device
.send_message("DIO{0/0}:VALUE=0")
        reward
= False  
   
if ((frameN + stimPeriodFrames) % stimPeriodFrames) == 1: #switch stimulation on
        time_now0
= datetime.now()
        time1
= time_now0.strftime("%H%M%S%f")
        getEYELINK
().sendMessage('TRIALID %s'%(trial_id));
        getEYELINK
().sendMessage('StimOn %s' % time1);
        device
.send_message("DIO{0/1}:VALUE=1")
        highA
.play()
        optogenetics
= True
        timer
= core.CountdownTimer(1)
        trial_id
+=1
   
if timer.getTime() <= 0:
        time_now1
= datetime.now()
        time2
= time_now1.strftime("%H%M%S%f")
        getEYELINK
().sendMessage('StimOff %s' % time2);
   
if (optogenetics == True) and ((frameN + stimPeriodFrames) % stimPeriodFrames) == 3: #switch stimulation off
        device
.send_message("DIO{0/1}:VALUE=0")
        optogenetics
= False        
   
if event.getKeys(keyList=['escape','q']):
        closingMessage
.draw()
        myWin
.flip()
        getEYELINK
().sendMessage("TRIAL_RESULT -1");
        dataFile
.close()
       
fi.stop_eyetracker()
        core
.wait(0.2)
        core
.quit() #abort experiment

It works correctly but shows just gray screen. If instead I make Gabor stimulus and rename it 'circle' it works correctly again and is drawn on every frame.
circle = visual.GratingStim(myWin,tex="sin",mask="gauss",texRes=256,
           size
=[0.5,0.5], sf=[4,0], ori = 0, name='gabor1')
If I put the original circle in the beginning of the trial before the loop with no flickering involved, again, nothing is shown, just gray background.

If I stick the same loop into shapes.py demo without eye-tracker and TTL parts, it works correctly again.

I tried other ShapeStim such as squares without success.

No error message is given of any kind. Can you advice me how to debug this code? I tried everything I can imagine and there is no change, Basically other Stim types work but not ShapeStim. I use the latest Psychopy on Linux, waitBlanking is turned off.

These are the modules I import in the beginning:
from pylink import *
import gc
import sys
import os
from psychopy import core, visual, event, sound, data, monitors, gui, logging
from psychopy.tools.filetools import fromFile, toFile
import time, numpy, random, math
from datetime import datetime, timedelta, date
import usb.core #import usb module to control the reward-delivery pump
import usb.util
import daqflex

import Optogen_fixation_info as fi





 

Jonathan Peirce

unread,
Feb 10, 2016, 8:55:24 AM2/10/16
to psychop...@googlegroups.com
Hi Denis,

It would help if you created a "minimal example" that demonstrated the problem. Just create the window and draw the stimulus, then gradually add the other complexity (changing color etc) until you find the point where it breaks. That way we can try replicating the problem ourselves to see if this is a problem everywhere or just on your machine.

Also, could you tell us the exact version you have installed rather than saying "newest"? Newest depends on where you installed from.

thanks
Jon
--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/842994a5-a113-4fca-88bc-51fe8ce8a177%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Jonathan Peirce
University of Nottingham

http://www.peirce.org.uk


This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

Denis Matrov

unread,
Feb 10, 2016, 11:20:58 PM2/10/16
to psychopy-users

Hi Jon,

Thanks for the advice about the minimal experiment. After slicing away all the layers in my script it turns out that another visual stimulus we use for the gaze-contingent display as a transparent annulus to signal the focus of the gaze (we work with primates, so this is necessary). It works perfectly on top of image stimuli, but together with shapeStim this stimulus seems to disturb the appearance of shapeStim by making it invisible

Please stick the following stimulus inside shapes demo or any other code with shapeStim and see what happens. I do not know if it is my computer dependent problem or not.
mask = visual.RadialStim(win, tex='sqrXsqr', color=[0,90,1], colorSpace='dkl', pos=(0, 0),
                        units
='pix', size=(100,100), mask=[0,0,0,0,0,0,0,1], radialCycles=0,
                        angularCycles
=0, opacity=0.5, contrast=1.0, interpolate=False)

I use Psychopy version 1.83.01. It is clean installed from depository via apt-get some days after tis version came out.

ps. Below is the full code of modified Shapes demo. Our radialStim causes problem even when it is not drawn in the While loop after For loop is done.

best regards,
denis

from psychopy import visual, event, core
from math import sin, cos
"""ShapeStim can be used to make geometric shapes where you specify the locations of each vertex
relative to some anchor point.

NB for now the fill of objects is performed using glBegin(GL_POLYGON) and that is limited to convex
shapes. With concavities you get unpredictable results (e.g. add a fill colour to the arrow stim below).
To create concavities, you can combine multiple shapes, or stick to just outlines. (If anyone wants
to rewrite ShapeStim to use glu tesselators that would be great!)
"""

win
= visual.Window([600,600], monitor='testMonitor', units='norm', waitBlanking=False)

arrowVertices
=[ [-0.2,0.05], [-0.2,-0.05], [0.0,-0.05], [0.0,-0.1], [0.2,0], [0.0,0.1],  [0.0,0.05] ]
sqrVertices
= [ [0.2,-0.2], [-0.2,-0.2], [-0.2,0.2], [0.2,0.2] ]

stim1
= visual.ShapeStim(win,
                 lineColor
='red',
                 lineWidth
=2.0, #in pixels
                 fillColor
=None, #beware, with convex shapes fill colors don't work
                 vertices
=arrowVertices,#choose something from the above or make your own
                 closeShape
=True,#do you want the final vertex to complete a loop with 1st?
                 pos
= [0,0], #the anchor (rotation and vertices are position with respect to this)
                 interpolate
=True,
                 opacity
=0.9,
                 autoLog
=False)#this stim changes too much for autologging to be useful

stim2
= visual.ShapeStim(win,
                 lineColor
='green',
                 lineWidth
=2.0, #in pixels
                 fillColor
=[-0.5,0.5,-0.5], #beware, with convex shapes this won't work
                 fillColorSpace
='rgb',
                 vertices
=sqrVertices,#choose something from the above or make your own
                 closeShape
=True,#do you want the final vertex to complete a loop with 1st?
                 pos
= [0.5,0.5], #the anchor (rotation and vertices are position with respect to this)
                 interpolate
=True,
                 opacity
=0.9,
                 autoLog
=False)#this stim changes too much for autologging to be useful
                 
circle
= visual.Circle(win, radius=0.2, edges=32, size=1.0, lineWidth=1.5, contrast=1.0,
                fillColor
= "#FF8C00", lineColor = "#FF8C00", opacity=1.0, units='norm',
                autoDraw
=False, autoLog=False, name='circle')
               
mask
= visual.RadialStim(win, tex='sqrXsqr', color=[0,90,1], colorSpace='dkl', pos=(0, 0),
                        units
='pix', size=(100,100), mask=[0,0,0,0,0,0,0,1], radialCycles=0,
                        angularCycles
=0, opacity=0.5, contrast=1.0, interpolate=False)

circle3
= visual.Rect(win, width=100, height=100, lineWidth=1.5, contrast=1.0, opacity=1.0, fillColor = "#FF8C00", pos=(0, -150),
                        lineColor
= "#FF8C00",  units='pix', autoDraw=False, autoLog=False)

clock
= core.Clock()

periodColor
= 20 #period of biphasic color
periodColorOn
= 10 #Duty cicle with light color
periodPos
= 60 #30 seconds full period of left-right
periodPosRight
= 30 #15 seconds at the right side
# beginning of the control loop
for frameN in range(30):

   
if (frameN % periodColor) > periodColorOn:

       
print 'yes'

        circle
.fillColor = "#FF8C00"
        circle
.lineColor = "#FF8C00"
   
else:

       
print 'no'

        circle
.fillColor = "#FFF8DC"
        circle
.lineColor = "#FFF8DC"
   
if (frameN % periodPos) > periodPosRight:

       
print 'left'
        circle
.pos=(-0.5,0)
   
else:
       
print 'right'
        circle
.pos=(0.5,0)  
    mask
.draw()
    circle
.draw()
    win
.flip()

while True:
    stim1
.ori += 2  # increment by 2
    stim1
.draw()
   
    sqrVertices
[1] = [ -0.2-sin(clock.getTime())/6.0, -0.2-cos(clock.getTime())/6.0 ]#change one of the vertices
    stim2
.vertices = sqrVertices
    stim2
.draw()

    circle
.draw()
    win
.flip()

   
if event.getKeys(keyList=['escape', 'q']):

        core
.quit()

...

Michael MacAskill

unread,
Feb 11, 2016, 7:04:04 PM2/11/16
to psychop...@googlegroups.com
Hi Denis,

I suspect this might be another manifestation of this previously reported bug:

<https://github.com/psychopy/psychopy/issues/795>

The good news is that Jon fixed this a few weeks ago but I suspect that has not made it into the latest user release yet.

If not, the bug fix looks tiny:

<https://github.com/psychopy/psychopy/commit/af1af9a7a85cee9b4ec8ad5e2ff1f03140bd1a36>

So you could directly edit your own copy of the polygon.py file and see if it fixes things for you.

Regards,

Michael
> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
> To post to this group, send email to psychop...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/ce7f8229-b5b3-453c-9b0d-647d133c130e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

Michael MacAskill

unread,
Feb 11, 2016, 8:06:27 PM2/11/16
to psychop...@googlegroups.com
Sorry,

Ignore that message: I read it as if that issue was from last month but it was actually made a year ago (my memory is slipping…), so unlikely to be related to your problem.

Regards,

Michael

> On 12/02/2016, at 13:03, Michael MacAskill <michael....@nzbri.org> wrote:
>
> Hi Denis,
>
> I suspect this might be another manifestation of this previously reported bug:
>
> <https://github.com/psychopy/psychopy/issues/795>
>
> The good news is that Jon fixed this a few weeks ago but I suspect that has not made it into the latest user release yet.
>
> If not, the bug fix looks tiny:
>
> <https://github.com/psychopy/psychopy/commit/af1af9a7a85cee9b4ec8ad5e2ff1f03140bd1a36>
>
> So you could directly edit your own copy of the polygon.py file and see if it fixes things for you.
>
> Regards,
>
> Michael

Denis Matrov

unread,
Feb 11, 2016, 9:02:20 PM2/11/16
to psychopy-users
Hi Michael

I have updated Psychopy to version 1.83.04, which was released 8 days ago. The bug is still present.

Can you please open Shapes demo and add the stimulus

mask = visual.RadialStim(win, tex='sqrXsqr', color=[0,90,1], colorSpace='dkl', pos=(0, 0),
                        units
='pix', size=(100,100), mask=[0,0,0,0,0,0,0,1], radialCycles=0,
                        angularCycles
=0, opacity=0.5, contrast=1.0, interpolate=False)

plus add into the loop and check how your system draws it
mask.draw()

My computer draws only the mask while other shapeStrim-uli become invisible.

In an unrelated note, the uncomment keyboard shortcut Shitf-Ctrl-' is not working for me, comment shortcut works in Psychopy GUI

Michael MacAskill

unread,
Feb 11, 2016, 9:37:26 PM2/11/16
to psychop...@googlegroups.com
Dear Denis,

I get a purple unfilled circle, with no change to the other two shape stimuli (using the 1.83.03 standalone).

Regards,

Michael

> On 12/02/2016, at 15:02, Denis Matrov <jazz...@gmail.com> wrote:
>
> Hi Michael
>
> I have updated Psychopy to version 1.83.04, which was released 8 days ago. The bug is still present.
>
> Can you please open Shapes demo and add the stimulus
> mask = visual.RadialStim(win, tex='sqrXsqr', color=[0,90,1], colorSpace='dkl', pos=(0, 0),
> units='pix', size=(100,100), mask=[0,0,0,0,0,0,0,1], radialCycles=0,
> angularCycles=0, opacity=0.5, contrast=1.0, interpolate=False)
>
> plus add into the loop and check how your system draws it
> mask.draw()
>
> My computer draws only the mask while other shapeStrim-uli become invisible.

Denis Matrov

unread,
Feb 11, 2016, 11:12:54 PM2/11/16
to psychopy-users
Ok, thanks!

I have attached my screenshots with RadialStim Interpolate set to False = shows just the annulus or True = shows parts of the shapes, annulus is invisible.

What shall I do next? Is it some kind of OpenGL issue? I have installed now the latest Mesa from here https://launchpad.net/~paulo-miguel-dias/+archive/ubuntu/mesa without any effect

It also does not matter how I run Psychopy, on the dedicated NVidia GPU only via primusrun or normally using Intel integrated chip.

denis
InterpolationFalse.png
InterpolationTrue.png

Michael MacAskill

unread,
Feb 11, 2016, 11:45:30 PM2/11/16
to <psychopy-users@googlegroups.com>
OK, for me (running on OS X), setting interpolate=True makes the RadialStim (basically) invisible.

It doesn't really affect the other stimuli in the substantial way it does for you. But I did find a subtle effect on the red arrow: where the two shapes intersect, even though the radialStim is invisible, it still masked the arrow at the points of intersection.

Although I don't see the major visual disruptions you are getting, there is definitely something odd going on. Unfortunately, it seems that it depends on graphics cards/drivers/OS though.

But for me, everything works well with interpolate=False

Regards,

Michael


> On 12/02/2016, at 15:02, Denis Matrov <jazz...@gmail.com> wrote:
>
> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
> To post to this group, send email to psychop...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/ab8f7892-a5ea-4c2c-8837-1920ddde0ace%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Denis Matrov

unread,
Mar 15, 2016, 4:09:32 AM3/15/16
to psychopy-users
Now I discovered that Grating stimulus completely breaks the playback of my MovieStim. So if I try to draw annulus with transparent center on top of the movie for a gaze contingent display, the movie is squished to the side of the screen.
Any other way to draw an annulus that will be completely transparent and will not change the spatial frequency of the overlapping movie. It needs only to have a visible border for calibration feedback. Or can anyone recommed a good Python package for drawing simple geometric shapes with RGBA data embedded? I can draw a circle with Scikit-Image as a numpy.array, but I do not know how to expand it with RGBA mask of the same shape.

mask = visual.RadialStim(myWin, tex='sqrXsqr', color=[0,90,1], colorSpace='dkl', pos=(0, 0), units='pix', size=(100,100), mask=[0,0,0,0,0,0,0,1], radialCycles=0, angularCycles=0, opacity=0.5, contrast=1.0, interpolate=False)

mov
= visual.MovieStim3(myWin, 'somemovie.mp4', size=[1280,1024],
                       flipVert
=False, flipHoriz=False, loop=False)

Michael MacAskill

unread,
Mar 15, 2016, 5:32:05 PM3/15/16
to psychop...@googlegroups.com

> On 15/03/2016, at 21:09, Denis Matrov <jazz...@gmail.com> wrote:
>
> Any other way to draw an annulus that will be completely transparent and will not change the spatial frequency of the overlapping movie.

Perhaps draw a simple circle, in conjunction with an inverted aperture to punch a hole through it? <http://www.psychopy.org/api/visual/aperture.html>

Michael
Reply all
Reply to author
Forward
0 new messages