Howdy, Stranger!

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

Supported by

Pygaze wait_for_saccade_end with timeout?

Hi all,

I was wondering if it is possible to use the wait_for_saccade_end() function with a timeout. Specifically, we are using an Eyelink and would like to wait for completed saccade OR until 2000 ms have passed.

Since wait_for_saccade_end() essentially block the scripts until a saccade has been made, we're having trouble implementing the later.

While I think it should be possible to adapt the pygaze version of the saccade detection to add a timeout parameter, the 'native' functionality that is called for Eyelink seems a lot harder to adapt.

So I was hoping someone else has tackled this problem before.

One workaround I am currently considering / testing, but seems quite crude is to run wait_for_saccade_end() in a new thread using the threading module, and adding a trace so the thread can be killed if needed (https://www.geeksforgeeks.org/python-different-ways-to-kill-a-thread/)

Kind regards,

Kerwin

Comments

  • Hi @kolfers ,

    I would adapt the the wait_for_event() function from PyGaze to break after a timeout.

    I blind-coded the example below (I don't have an eye tracker now to test) but it should convey the general idea of how wait for a saccade using the EyeLink's native event detection with a timeout. This script should simply go into an inline_script item.

    import pylink
    
    t0 = clock.get_time()
    saccade = False
    timeout = 2000
    for ms in clock.loop_for(timeout):
        d = pylink.getEYELINK().getNextData()
        if d == pylink.STARTSACC:
            float_data  = pylink.getEYELINK().getFloatData()
            tc = float_data.getTime() - eyetracker._get_eyelink_clock_async()
            if tc > t0:
                saccade = True
                break
    

    One workaround I am currently considering / testing, but seems quite crude is to run wait_for_saccade_end() in a new thread using the threading module, and adding a trace so the thread can be killed if needed

    Threading is generally not a good idea for things like this because the timing is quite unreliable, and it's also easy to create race conditions that unpredictably make your experiment crash!

    — Sebastiaan

  • Hi Sebastiaan,

    Thank you, that approach did the trick. I couldn't get the clock.loop_for to work though. Perhaps because of the imported clock from pygaze.libtime? In case someone else finds it useful in the future:

        def wait_for_event_timeout(self, event, timeout):
    
            """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""
    
            if not self.recording:
                raise Exception(
                    "Error in libeyelink.libeyelink.wait_for_event(): Recording "
                    "was not started before collecting eyelink data!")
                
            start_time = clock.get_time()
            check_time = False
            if isinstance(timeout,int) and timeout > 0:
                check_time = True 
                end_time = start_time + timeout
            else:
                raise Exception("timeout (in ms) should be an integer larger than 0")
    
            if self.eye_used == None:
                self.set_eye_used()
            if self.eventdetection == 'native':
                # since the link buffer was not have been polled, old data has
                # accumulated in the buffer -- so ignore events that are old:
                t0 = clock.get_time() # time of call
                while True:
                    if check_time and clock.get_time() >= end_time: return "timeout", clock.get_time
                    d = pylink.getEYELINK().getNextData()
                    if d == event:
                        float_data  = pylink.getEYELINK().getFloatData()
                        # corresponding clock_time
                        tc = float_data.getTime() - self._get_eyelink_clock_async()
                        if tc > t0:
                            return tc, float_data
    
        def wait_for_saccade_start_timeout(self,timeout=None):
    
                """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""
                # # # # #
                # EyeLink method
    
                if self.eventdetection == 'native':
                    t,d = self.wait_for_event_timeout(pylink.STARTSACC, timeout)
                    if t == "timeout": return t, None
                    return t, d.getStartGaze()
    
        def wait_for_saccade_end_timeout(self,timeout=None):
    
            """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker"""
    
            # # # # #
            # EyeLink method
    
            if self.eventdetection == 'native':
                t,d = self.wait_for_event_timeout(pylink.ENDSACC,timeout)
                if t == "timeout": return t, None,None
                return t, d.getStartGaze(), d.getEndGaze()
    


Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games