Esempio n. 1
0
    def runexpweb(self):
        choose_tobii()
        print(self.id)
        self.tmp = get_monitors()
        self.new_width = self.tmp[
            0].width  # 0 for resolution of main screen, 1 for resolution of the second screen
        self.new_height = self.tmp[
            0].height  # 0 for resolution of main screen, 1 for resolution of the second screen
        print("Schermo rilevato: " + str(self.new_width) + " x " +
              str(self.new_height))

        self.MY_MONITOR = 'testMonitor'  # needs to exists in PsychoPy monitor center
        self.FULLSCREEN = True
        # conf['SCREEN_RES'] = [tmp[0].width, tmp[0].height]
        # SCREEN_WIDTH = 52.7  # cm
        self.SCREEN_RES = conf['SCREEN_RES']
        self.SCREEN_WIDTH = conf['SCREEN_WIDTH']
        self.VIEWING_DIST = conf[
            'VIEWING_DIST']  # distance from eye to center of screen (cm)
        self.monitor_refresh_rate = conf[
            'monitor_refresh_rate']  # frames per second (fps)
        self.mon = monitors.Monitor(
            self.MY_MONITOR)  # Defined in defaults file
        self.mon.setWidth(self.SCREEN_WIDTH)  # Width of screen (cm)
        self.mon.setDistance(self.VIEWING_DIST)  # Distance eye / monitor (cm)
        self.mon.setSizePix(self.SCREEN_RES)

        # %%  ET settings
        self.et_name = conf['et_name']
        self.dummy_mode = False
        bimonocular_calibration = False

        self.settings = Titta.get_defaults(self.et_name)
        self.settings.FILENAME = 'data/Video/' + str(
            self.id) + '/' + data.getDateStr() + '.tsv'
        GSRpath = 'data/Video/' + str(self.id) + '/GSR_data/'
        print(self.settings.FILENAME)
        self.settings.N_CAL_TARGETS = 3

        self.tracker = Titta.Connect(self.settings)

        if self.dummy_mode:
            self.tracker.set_dummy_mode()
        self.tracker.init()

        # Window set-up (this color will be used for calibration)

        win = visual.Window(monitor=self.mon,
                            fullscr=self.FULLSCREEN,
                            screen=1,
                            size=self.SCREEN_RES,
                            units='deg')
        fixation_point = helpers.MyDot2(win)

        self.tracker.calibrate(win)
        win.close()
        webInstruction.launch_browser(self.website, type, self.id, self.parent,
                                      self.root, self.frame)
Esempio n. 2
0
mon_op.setSizePix(SCREEN_RES_OP)

# Window set-up (this color will be used for calibration)
win = visual.Window(monitor=mon,
                    fullscr=FULLSCREEN,
                    screen=1,
                    size=SCREEN_RES,
                    units='deg')

win_op = visual.Window(monitor=mon_op,
                       fullscr=FULLSCREEN_OP,
                       screen=0,
                       size=SCREEN_RES_OP,
                       units='norm')

fixation_point = helpers.MyDot2(win)
image = visual.ImageStim(win, image='im1.jpeg', units='norm', size=(2, 2))

#%% ET settings
et_name = 'Tobii Pro Spectrum'
# et_name = 'Tobii4C'

dummy_mode = False
bimonocular_calibration = False

# Change any of the default dettings?e
settings = Titta.get_defaults(et_name)
settings.FILENAME = 'testfile.tsv'

#%% Connect to eye tracker and calibrate
tracker = Titta.Connect(settings)
Esempio n. 3
0
def runexpImage(participantId):
    print(participantId)
    tmp = get_monitors()
    new_width = tmp[
        0].width  # 0 for resolution of main screen, 1 for resolution of the second screen
    new_height = tmp[
        0].height  # 0 for resolution of main screen, 1 for resolution of the second screen
    # print("Schermo rilevato: " + str(new_width) + " x " + str(new_height))

    MY_MONITOR = 'testMonitor'  # needs to exists in PsychoPy monitor center
    FULLSCREEN = True
    # SCREEN_RES = [tmp[0].width, tmp[0].height]
    # SCREEN_WIDTH = tmp[1].width  # cm
    SCREEN_RES = conf['SCREEN_RES']
    SCREEN_WIDTH = conf['SCREEN_WIDTH']
    VIEWING_DIST = conf['VIEWING_DIST']
    monitor_refresh_rate = conf['monitor_refresh_rate']
    mon = monitors.Monitor(MY_MONITOR)  # Defined in defaults file
    mon.setWidth(SCREEN_WIDTH)  # Width of screen (cm)
    mon.setDistance(VIEWING_DIST)  # Distance eye / monitor (cm)
    mon.setSizePix(SCREEN_RES)
    # im_name = os.getcwd() + "/Image/beer_positioning.jpg"
    im_name = "C:/Users/defeo/PycharmProjects/Emotion_Recognition_Application/Image/beer_positioning.jpg"

    # im_name = filedialog.askopenfilename(initialdir=os.getcwd() + "/Image/")

    # %%  ET settings
    et_name = conf['et_name']
    dummy_mode = False
    bimonocular_calibration = False

    settings = Titta.get_defaults(et_name)
    settings.FILENAME = 'data/Image/' + str(
        participantId) + '/' + data.getDateStr() + '.tsv'
    GSRpath = 'data/Image/' + str(participantId) + '/GSR_data/'
    print(settings.FILENAME)
    settings.N_CAL_TARGETS = 3

    tracker = Titta.Connect(settings)

    if dummy_mode:
        tracker.set_dummy_mode()
    tracker.init()

    # Window set-up (this color will be used for calibration)

    win = visual.Window(monitor=mon,
                        fullscr=FULLSCREEN,
                        screen=1,
                        size=SCREEN_RES,
                        units='deg')
    fixation_point = helpers.MyDot2(win)
    image = visual.ImageStim(win, image=im_name, units='norm', size=(2, 2))

    #  Calibrate
    """if bimonocular_calibration:
        tracker.calibrate(win, eye='left', calibration_number='first')
        tracker.calibrate(win, eye='right', calibration_number='second')
    else:
        tracker.calibrate(win)"""

    tracker.calibrate(win)

    tracker.start_recording(gaze_data=True, store_data=True)
    # rec = gsr.Record()
    # rec.on_rec(GSRpath)

    # Present fixation dot and wait for one second
    for i in range(monitor_refresh_rate):
        if i == 0:
            tracker.send_message('fix on')
        fixation_point.draw()
        win.flip()
    tracker.send_message('fix off')

    # Wait exactly 3 * fps frames (3 s)

    for i in range(30 * monitor_refresh_rate):
        if i == 0:
            tracker.send_message(''.join(['stim on: ', im_name]))
        image.draw()
        t = win.flip()
    tracker.send_message(''.join(['stim off: ', im_name]))
    win.flip()

    # rec.on_stop()
    tracker.stop_recording(gaze_data=True)

    # Close window and save data

    win.close()
    tracker.save_data(mon)  # Also save screen geometry from the monitor object

    # %% Open pickle and write et-data and messages to tsv-files.

    f = open(settings.FILENAME[:-4] + '.pkl', 'rb')
    gaze_data = pickle.load(f)
    msg_data = pickle.load(f)
    #  Save data and messages
    df = pd.DataFrame(gaze_data, columns=tracker.header)
    df.to_csv(settings.FILENAME[:-4] + '.tsv', sep='\t')
    df_msg = pd.DataFrame(msg_data, columns=['system_time_stamp', 'msg'])
    df_msg.to_csv(settings.FILENAME[:-4] + '_msg.tsv', sep='\t')
Esempio n. 4
0
def runexpBrowser(search_key_var, type, participantId, parent, root, frame):
    print(participantId)
    tmp = get_monitors()
    new_width = tmp[
        0].width  # 0 for resolution of main screen, 1 for resolution of the second screen
    new_height = tmp[
        0].height  # 0 for resolution of main screen, 1 for resolution of the second screen
    print("Schermo rilevato: " + str(new_width) + " x " + str(new_height))

    MY_MONITOR = 'testMonitor'  # needs to exists in PsychoPy monitor center
    FULLSCREEN = True
    # SCREEN_RES = [tmp[0].width, tmp[0].height]
    # SCREEN_WIDTH = 52.7  # cm
    SCREEN_RES = conf['SCREEN_RES']
    SCREEN_WIDTH = conf['SCREEN_WIDTH']
    VIEWING_DIST = conf['VIEWING_DIST']
    monitor_refresh_rate = conf['monitor_refresh_rate']
    mon = monitors.Monitor(MY_MONITOR)  # Defined in defaults file
    mon.setWidth(SCREEN_WIDTH)  # Width of screen (cm)
    mon.setDistance(VIEWING_DIST)  # Distance eye / monitor (cm)
    mon.setSizePix(SCREEN_RES)

    # %%  ET settings
    et_name = conf['et_name']
    dummy_mode = False

    settings = Titta.get_defaults(et_name)
    if type == 1:
        settings.FILENAME = 'data/Browser/' + str(
            participantId) + '/' + data.getDateStr() + '.tsv'
        GSRpath = 'data/Browser/' + str(participantId) + '/GSR_data/'
    else:
        settings.FILENAME = 'data/Browser/' + str(
            participantId) + '/' + data.getDateStr() + '.tsv'
        GSRpath = 'data/Browser/' + str(participantId) + '/GSR_data/'
    sec = 30
    print(settings.FILENAME)

    settings.N_CAL_TARGETS = 3

    tracker = Titta.Connect(settings)

    if dummy_mode:
        tracker.set_dummy_mode()
    tracker.init()

    # Window set-up (this color will be used for calibration)
    win = visual.Window(monitor=mon,
                        fullscr=FULLSCREEN,
                        screen=1,
                        size=SCREEN_RES,
                        units='deg')
    fixation_point = helpers.MyDot2(win)

    tracker.calibrate(win)
    win.close()

    tracker.start_recording(gaze_data=True, store_data=True)
    webInstruction.launch_browser(search_key_var,
                                  type,
                                  participantId,
                                  parent,
                                  root,
                                  frame=frame)

    tracker.stop_recording(gaze_data=True)
    tracker.save_data(mon)  # Also save screen geometry from the monitor object

    # %% Open pickle and write et-data and messages to tsv-files.

    f = open(settings.FILENAME[:-4] + '.pkl', 'rb')
    gaze_data = pickle.load(f)
    msg_data = pickle.load(f)
    #  Save data and messages
    df = pd.DataFrame(gaze_data, columns=tracker.header)
    df.to_csv(settings.FILENAME[:-4] + '.tsv', sep='\t')
    df_msg = pd.DataFrame(msg_data, columns=['system_time_stamp', 'msg'])
    df_msg.to_csv(settings.FILENAME[:-4] + '_msg.tsv', sep='\t')

    print("saved")
Esempio n. 5
0
def runexpVideo(participantId):
    print(participantId)
    tmp = get_monitors()
    new_width = tmp[
        0].width  # 0 for resolution of main screen, 1 for resolution of the second screen
    new_height = tmp[
        0].height  # 0 for resolution of main screen, 1 for resolution of the second screen
    print("Schermo rilevato: " + str(new_width) + " x " + str(new_height))

    MY_MONITOR = 'testMonitor'  # needs to exists in PsychoPy monitor center
    FULLSCREEN = True
    # SCREEN_RES = [tmp[0].width, tmp[0].height]
    # SCREEN_WIDTH = 52.7  # cm
    SCREEN_RES = conf['SCREEN_RES']
    SCREEN_WIDTH = conf['SCREEN_WIDTH']
    VIEWING_DIST = conf['VIEWING_DIST']
    monitor_refresh_rate = conf['monitor_refresh_rate']
    mon = monitors.Monitor(MY_MONITOR)  # Defined in defaults file
    mon.setWidth(SCREEN_WIDTH)  # Width of screen (cm)
    mon.setDistance(VIEWING_DIST)  # Distance eye / monitor (cm)
    mon.setSizePix(SCREEN_RES)

    # %%  ET settings
    et_name = conf['et_name']
    dummy_mode = False
    bimonocular_calibration = False

    settings = Titta.get_defaults(et_name)
    settings.FILENAME = 'data/Video/' + str(
        participantId) + '/' + data.getDateStr() + '.tsv'
    GSRpath = 'data/Video/' + str(participantId) + '/GSR_data/'
    print(settings.FILENAME)
    settings.N_CAL_TARGETS = 3

    tracker = Titta.Connect(settings)

    if dummy_mode:
        tracker.set_dummy_mode()
    tracker.init()

    # Window set-up (this color will be used for calibration)

    win = visual.Window(monitor=mon,
                        fullscr=FULLSCREEN,
                        screen=1,
                        size=SCREEN_RES,
                        units='deg')
    fixation_point = helpers.MyDot2(win)

    tracker.calibrate(win)
    win.close()

    tracker.start_recording(gaze_data=True, store_data=True)

    def createVideoFrame():
        top = tk.Toplevel()
        top.title("Experiment VLC media player")
        top.state('zoomed')
        player = None
        player = vp.Player(top,
                           title="tkinter vlc")  # no gsr recorded this way

        def closeTop():
            player.OnStop()
            player.quit()
            top.destroy()

            # save file
            tracker.stop_recording(gaze_data=True)
            # Close window and save data
            tracker.save_data(
                mon)  # Also save screen geometry from the monitor object

            # %% Open pickle and write et-data and messages to tsv-files.
            f = open(settings.FILENAME[:-4] + '.pkl', 'rb')
            gaze_data = pickle.load(f)
            msg_data = pickle.load(f)

            #  Save data and messages
            df = pd.DataFrame(gaze_data, columns=tracker.header)
            df.to_csv(settings.FILENAME[:-4] + '.tsv', sep='\t')
            df_msg = pd.DataFrame(msg_data,
                                  columns=['system_time_stamp', 'msg'])
            df_msg.to_csv(settings.FILENAME[:-4] + '_msg.tsv', sep='\t')
            # postprocessing.process(settings.FILENAME)
            os.startfile(
                "https://docs.google.com/forms/d/e/1FAIpQLScyO5BiSStjkT3pBeV3PApzsOnxHwuhw0DiSszZZEKstdUUEg/viewform"
            )

        top.protocol("WM_DELETE_WINDOW", closeTop)

        def pause():
            player.OnPause()

        top.bind('<space>', pause)

    createVideoFrame()
Esempio n. 6
0
 def __init__(self, win, duration_central_target,
              saccade_amplitude=8, 
              duration_peripheral_target = 1,
              screen_refresh_rate = 60,
              Fs = 120,
              eye_tracking = True,
              screen_size = [1680, 1050],
              tracker=None, # Eye tracker object
              pro_lab_integration=False,
              upload_media=False,
              pid=None,
              project_name = None):
     
     self.trialClock = core.Clock() # Init clock
     
     self.pro_instr = 'Look at the central dot; as soon as a new dot appears on the left or right, LOOK AT IT as fast as you can.'
     self.anti_instr = 'Look at the central dot; as soon as a new dot appears look in the OPPOSITE DIRECTION as fast as you can. You will probably sometimes make mistakes, and this is perfectly normal.'
     self.goodByeMessage = 'Thanks! That is all!'
     self.keypress_test = '(Press any key to TEST the experiment)'
     self.keypress_exp = '(Press any key to START the experiment)'
     self.correct_msg = 'Correct!, press space to continue'
     self.incorrect_msg = 'Incorrect!, press space to continue'
     self.break_instruction_s = 'Pause'
     self.break_instruction_e = 'seconds. Please do not remove your head from the chinrest. \n\n Feel free to blink.' 
             
 
     self.win = win
     self.saccade_amplitude = saccade_amplitude
     self.eye_tracking = eye_tracking
     self.tracker = tracker
     self.screen_refresh_rate = screen_refresh_rate
     self.screen_size = screen_size
     self.Fs = Fs
     self.pro_lab_integration = pro_lab_integration
     self.upload_media = upload_media
     
     # Target durations in frames
     self.duration_central_target = np.round(duration_central_target * screen_refresh_rate)
     self.duration_peripheral_target = duration_peripheral_target * screen_refresh_rate
         
     #Initialize stimuli used in experiment
     self.dot_stim = helpers.MyDot2(win)
     self.et_sample = visual.GratingStim(win, color='black', tex=None, mask='circle',units='pix',size=2)
     self.line = visual.Line(win, start=(-0.5, -0.5), end=(0.5, 0.5), units='pix')
     self.instruction_text = visual.TextStim(win,text='',wrapWidth = 10,height = 0.5)   
     
     
     # Connect to Pro Lab and add participant
     if pro_lab_integration:
         self.ttl = TalkToProLab(project_name) # Connect to Lab
                       
         participant_info = self.ttl.add_participant(pid)
         
         if upload_media:
             self.upload_stimuli()
         else:
             # Collect information about the already uploaded stimuli
             self.stim_info = {}
             uploaded_media = self.ttl.list_media()['media_list']
             for m in uploaded_media:
                 self.stim_info[m['media_name']] = m['media_id']
             
     # Calibrate eye tracker
     tracker.calibrate(win)
      
     # Start recording in Lab
     if pro_lab_integration:        
         self.rec = self.ttl.start_recording("antisaccade", 
                 participant_info['participant_id'], 
                 screen_width=self.screen_size[0],
                 screen_height=self.screen_size[1])