Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Merging Pygaze with other experimental library.

rrrrrr
edited September 2015 in PyGaze

Hello,

The questions is about how can I merge Pygaze with other experimental library (http://www.expyriment.org/).

To measure eye movements, I try to add pygaze to my script which I have been using in experiment by python.
Is it possible just by adding some triger (stimulus onsets/offsets, keypress events) to my script for data analysis?
If so, do you have any examples or suggestions (which pygaze functions I should use)?

Best,

Comments

  • rrrrrr
    edited 1:17PM

    Hello,

    This is additional information.

    1. libscreen

    In Pygaze, the libscreen library is used to control the experiment display and stumuli.
    But, like in my case, which libraries should I use to control it, Pygaze (libscreen) or other experimental library?

    1. Value error

    When I tried to take Pygaze 'calibrate()' in my script, 'ValueError: Projection failed!' occurred.

    Best,

  • edited September 2015

    Hi,

    I'm not sure whether I understand what you mean with "merging Pygaze with expyriment". Would you mind explaining what exactly is your idea?

    Is it possible just by adding some trigger

    I think something like exp.pygaze_eyetracker.log("!V TRIAL_VAR <var_name> %s" % <value>) should do the trick. Doing it in this way, will create a variable with corresponding value in the logfile of your tracker that. If you just want to send a message, this will suffice:

    exp.pygaze_eyetracker.log("message")

    (At least that is what I do, when I use the eyelink eyetracker. I'm not sure whether it will work for any tracker.)

    Best,

    Eduard

  • rrrrrr
    edited 1:17PM

    Hello,

    1.
    What I mean is how send triggers and keep records (time, trialID, condition name, stimulus onsets/offsets, keypress, RT...) on edf files for data analysis using the Data Viewer.
    I already made python scripts for experiments, and try to add Pygaze to it.

    Is it sufficient to do it by exp.pygaze_eyetracker.log functions?

    2.
    When I tried to use Pygaze 'calibrate()' in my script, 'ValueError: Projection failed!' occurred. Do you have any ideas for this error?

    Best,

  • edited 1:17PM

    Hi,

    1) Yes, exp.pygaze_eyetracker.log() should be sufficient for that, but keep in mind that it generally only sends a message. If you want to have those variables in the data viewer and interact with them, you'll have to send them as a variable (the first I described above).

    2) Sorry, unfortunately, I don't know what this error is about.

    Eduard

  • edited 1:17PM

    Hi there,

    So, first things first: PyGaze is essentially an experimental library, so you could use it to run your experiments with, not unlike expyriment. If you prefer sticking with expyriment (probably the most time-effective thing here, considering you already have a script), we might need to do a bit of hacking here and there.

    There are two main options:

    1) You write your own back-end based on expyriment, and use this to get a handle to the active expyriment window. Then the rest of your script should run fine. Note that this is the most time-consuming solution, as it requires you to create your own Display implementation (and likely also others, such as Screen and Keyboard).

    2) You use the currently existing tools, and hack your way to the PyGame active Surface handle within expyriment:

    import pygaze
    from pygaze import EyeTracker
    from expyriment import control
    
    # EXAMPLE initialisation of expyriment
    exp = control.initialize()
    
    # get the active PyGame Surface
    window = exp.screen._surface
    
    # define a custom Display class
    # the parent is the actual Display class,
    # but we're going to overwrite the initialisation function
    class Display(pygaze.display):
    
        def __init__(self, pygamewindow):
    
            # use the passed handle to the active surface
            pygaze.expdisplay = window
            self.dispsize = window.get_size()
            self.fgc = (0, 0, 0)
            self.bgc = (128, 128, 128)
            self.mousevis = False
    
    # now initialise a dummy Display,
    # and pass the active PyGame window
    disp = Display(window)
    
    # and initialise an EyeTracker object
    tracker = EyeTracker(disp)
    
    # REST OF YOUR SCRIPT
    

    Now I can't promise this will work, but it should in theory. That is: as far as I understand the logic behind expyriment.

    On your other question: You can simply use tracker.log("example message") to log things to the EDF.

    Good luck!

  • rrrrrr
    edited 1:17PM

    Hello,

    This script causes an error,

    class Display(pygaze.display):
    TypeError: Error when calling the metaclass bases
    module.init() takes at most 2 arguments (3 given)

    What should I do?

    Best,

  • rrrrrr
    edited 1:17PM

    Hello,

    When I added just eyetracker.log to the onset/offset for triggers (no hacking of display as Edwin above), the error occurred below.

    Traceback (most recent call last):
    File "/Users〜/test.py", line 56, in
    eyetracker.log("start_trial %d" % trialnr)
    AttributeError: 'module' object has no attribute 'log'

    Should I add other modules or functions, except for tracker.start and end, logfile write and close, eyetracker.log (e.g., "trial %d" % trialnr)?

    Best,

Sign In or Register to comment.