Mouse coordinates doubled(?) when using deg units

PsychoPy version (e.g. 1.84.x): 3.2.4
OS: Mac OS Mojave 10.14.6
Standard Standalone?: Yes.

What are you trying to achieve?:
I want to register where mouse clicks are made, to see if they fall within a certain distance from a shape’s perimeter. The shape sizes are to be specified using degrees, and so I want to fetch the mouse’s coordinates in deg units as well, to simplify comparison of perimeter/mouse positions.

What did you try to make it work?:
I made a simple project to test coordinate registering out, and later simplified it even more to create a minimally reproducible example, available here: https://github.com/AnonZebra/psychopy_mouse_deg_coords
(note that if you try this out locally yourself, you need to change ‘Experiment Settings->Screen->Monitor’ from ‘myMacMonitor’ to a monitor specification that works with your setup)

In the experiment, there is a Polygon/Rectangle Component with width 5 and height 6 (size set to ‘(5, 6)’ ), and a Mouse Component that is set to save mouse state on every click. The Experiment Settings->Screen ‘Units’ option is set to ‘deg’.

As I understand the documentation for ShapeStim, the width specified should correspond to the distance from the left end to the right end of the object, as the documentation describes this example:

# This stimulus is 20% wide and 50% tall with respect to window
stim = visual.PatchStim(win, units='norm', size=(0.2, 0.5)

# This stimulus is 0.2 degrees wide and 0.5 degrees tall.
stim.units = 'deg'

That means that if I click the vertical center of the right end of the polygon, I expect the mouse coordinate to be roughly [2.5, 0].

So I tried to run the experiment and click the vertical center right end, horizontal center bottom, vertical center left end and horizontal center top of the polygon.

What specifically went wrong when you tried that?:
The coordinates in the data file are
mouse.x: [5.086002249832904, -5.043262735128426, 0.6838322352716509, 0.34191611763582547]
mouse.y: [1.1112273823164327, 0.8547902940895638, 5.983532058626945, -6.154490117444858]
So I am getting coordinate values that are twice as high as what I expect. I’ve tried to manually measure the polygon’s width on the screen and that seems OK when comparing the measurement to what the formula 5/360 * 2 * pi * [distance from screen] gives. So the polygon seems to be rendered as it should. It’s just that the mouse coordinates are odd.

I’ve also tried other kinds of shapes and clicking the edges of the screen - in all cases, the mouse coordinates seem to be about twice as large as they should.

In sum
Does anyone know what I might be doing wrong that leads to mouse coordinates in deg units being twice as large as what should be expected? If someone could download the .psyexp file on github and try to reproduce the error that would be very helpful.

Edit: I just tried to change the experiment settings and the polygon setting to ‘px’ units. Everything then works as expected - e. g. clicking the right end of the polygon when it’s set to width of 500px generates an x coordinate of 250. So the issue seems to be specific for when using ‘deg’ units.

1 Like

So in the meantime I proceeded with implementing some of the functionality that’s needed for the experiment I’m working on, you can find it in the file ‘stretch_circle_with_mouse.psyexp’:

I’ve managed to create a circle whose size can be adjusted by click-dragging with the mouse. But precisely because the mouse coordinates are wonky, as I describe above, one thing isn’t working that well. One has to place the cursor twice as close to the center compared to where the perimeter actually is to “grab” the perimeter, because PsychoPy thinks the cursor is twice as far from the centre of the object as it actually is. Hopefully this might make it clearer why this issue is a problem.

Update for closure in case anyone stumbles upon this thread in the future and has a similar issue:

I’ve tried running the experiment on a Windows computer and everything seems to work fine there. The mouse coordinates are correctly saved in the data file, with deg units. I can “grab” the rim of the circular (see the .psyexp file mentioned in the previous post) polygon and increase/decrease the polygon’s size in the expected way. The problem persists on my Mac. It might be that the issue has to do with the Mac’s Retina screen. It’s still very strange to me that using deg units for scaling polygons seems to work fine, while the mouse coordinates are wonky.

Hi, we can confirm this issue. Whereas it occurs with the internal Retina display of a colleagues Macbook, it works perfect once he runs the experiment with an external display connected to the very same Macbook. We will investigate further. It would be great if you could share any potential solution you might encounter.

1 Like

Hi,

here are some more detailed information about this issue on MacBooks (running MacOS 10.13.2, High Sierra; PsychoPy Standalone 3.2.4).

  1. Attaching an external monitor solves the issue: The coordinates then are correct (2.5, 3, etc.) and the mouse control works as well.

  2. When using the internal display of the MacBook, it’s getting messy. Setting the screen resolution to what is mentioned in the MacOS monitor settings (i.e. 1440 x 900 pixels; this is what the display is supposed to look like) results in the errors described below. In this case, the display is correct (extensions measured and calculated by hand), but the mouse coordinates are doubled.

  3. When using the actual resolution of the display (as captured by mywin.size; i.e. 2880 x 1800), the display is twice as large as intended (extensions measured and calculated by hand), but the mouse coordinates remain doubled.

So in a nutshell:
a) mouse coordinates are constantly wrong by the factor 2
b) the display is only correct when using the your-display-looks-like-values on the MacOS monitor settings.

Any hint for a solution would be highly welcome.

Best,
Hauke

1 Like

Any update here? I’m having the exact same problem – everything is doubled!

I see in the source code lines that deal with this doubling issue with Retina displays, but apparently it hasn’t been implemented for mouse coordinates, so I’ve opened an issue on Github.

In the meantime, you could use code like this to first determine if you are using a retina screen

has_retina_scrn = False
import subprocess
if subprocess.call("system_profiler SPDisplaysDataType | grep -i 'retina'", shell=True) == 0:
    has_retina_scrn = True #https://stackoverflow.com/questions/58349657/how-to-check-is-it-a-retina-display-in-python-or-terminal

Note that I don’t know whether this yields an error on a Windows machine. To cover that you may want to embed it in a try - except.

And then when it comes time to get mouse coordinates:

myMouse = psychopy.event.Mouse(visible = 'true',win=myWin)            
mouseX,mouseY = myMouse.getPos() 
mouseFactor = 1
if (has_retina_scrn and scrn==0): #Because of a bug in Psychopy triggered by retina displays
                mouseFactor = 0.5
mouseX = mouseX * mouseFactor 
mouseY = mouseY * mouseFactor

Note that scrn is a variable I created which determines whether when visual.Window is called which screen is used. Because the Retina screen on a Mac laptop is the first screen, it is 0.

Chiming in here to say that I’ve also come across this issue on a Mac, but it’s not specific to the internal retina screen. It also happens for my 4k external monitor.

Specifically, to have stimuli correctly display in degrees, I need to specify the “superpixels” of the monitor [1920, 1080] to the monitor center, instead of the actual physical pixels ([3840, 2160]). This displays stimuli rendered in units=deg correctly. However, if I ask for the position of the mouse, this is returned in degrees computed on physical pixels rather than superpixels – yielding double the actual visual angle.