#!/usr/bin/env python # -*- coding: utf-8 -*- """ This experiment was created using PsychoPy3 Experiment Builder (v2021.2.0), on Julio 26, 2021, at 14:19 If you publish work using this script the most relevant publication is: Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) PsychoPy2: Experiments in behavior made easy Behav Res 51: 195. https://doi.org/10.3758/s13428-018-01193-y """ from __future__ import absolute_import, division from psychopy import locale_setup from psychopy import prefs from psychopy import sound, gui, visual, core, data, event, logging, clock, colors from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER) import numpy as np # whole numpy lib is available, prepend 'np.' from numpy import (sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray) from numpy.random import random, randint, normal, shuffle, choice as randchoice import os # handy system and path functions import sys # to get file system encoding from psychopy.hardware import keyboard # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__)) os.chdir(_thisDir) # Store info about the experiment session psychopyVersion = '2021.2.0' expName = 'cosa random' # from the Builder filename that created this script expInfo = {'gender (m/f)': 'f', 'age': '', 'participant': ''} dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName expInfo['psychopyVersion'] = psychopyVersion # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + u'data' + os.sep + '%s_%s' %(expInfo['participant'], expInfo['date']) # An ExperimentHandler isn't essential but helps with data saving thisExp = data.ExperimentHandler(name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath='C:\\Users\\HP\\Downloads\\onlinematerials\\onlineMaterials\\2 - first experiment\\stroop\\experimento bonito.py', savePickle=True, saveWideText=True, dataFileName=filename) # save a log file for detail verbose info logFile = logging.LogFile(filename+'.log', level=logging.EXP) logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file endExpNow = False # flag for 'escape' or other condition => quit the exp frameTolerance = 0.001 # how close to onset before 'same' frame # Start Code - component code to be run after the window creation # Setup the Window win = visual.Window( size=[1366, 768], fullscr=True, screen=0, winType='pyglet', allowGUI=False, allowStencil=False, monitor='testMonitor', color=[1.0000, 0.9216, 0.8667], colorSpace='rgb', blendMode='avg', useFBO=True, units='norm') # store frame rate of monitor if we can measure it expInfo['frameRate'] = win.getActualFrameRate() if expInfo['frameRate'] != None: frameDur = 1.0 / round(expInfo['frameRate']) else: frameDur = 1.0 / 60.0 # could not measure, so guess # Setup eyetracking ioDevice = ioConfig = ioSession = ioServer = eyetracker = None # create a default keyboard (e.g. to check for escape) defaultKeyboard = keyboard.Keyboard() # Initialize components for Routine "instruct" instructClock = core.Clock() instrText = visual.TextStim(win=win, name='instrText', text='¿Listo (a) para el ejercicio?\nA continuación verás una serie de sílabas. Estas apareceran cada 5 segundos. Intenta recordarlas lo más que puedas, luego se te pedirá escribir las que recuerdes.\n\nPresiona espacio para continuar\n(Esc para salir del ejercicio)', font='Arial', pos=[0, 0], height=0.1, wrapWidth=None, ori=0, color=(0.2941, -0.6706, -0.6706), colorSpace='rgb', opacity=1, languageStyle='LTR', depth=0.0); ready = keyboard.Keyboard() # Initialize components for Routine "trial" trialClock = core.Clock() stim = visual.TextStim(win=win, name='stim', text='', font='Arial', pos=[0, 0], height=0.2, wrapWidth=None, ori=0, color='white', colorSpace='rgb', opacity=1, languageStyle='LTR', depth=0.0); text = visual.TextStim(win=win, name='text', text='', font='Open Sans', pos=(0, 0), height=0.2, wrapWidth=None, ori=0.0, color=[-1.0000, -1.0000, -1.0000], colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-1.0); text_2 = visual.TextStim(win=win, name='text_2', text='', font='Open Sans', pos=(0, 0), height=0.2, wrapWidth=None, ori=0.0, color=[-1.0000, -1.0000, -1.0000], colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-2.0); text_3 = visual.TextStim(win=win, name='text_3', text='', font='Open Sans', pos=(0, 0), height=0.2, wrapWidth=None, ori=0.0, color=[-1.0000, -1.0000, -1.0000], colorSpace='rgb', opacity=None, languageStyle='LTR', depth=-3.0); # Initialize components for Routine "RPTA" RPTAClock = core.Clock() textbox = visual.TextBox2( win, text='', font='Open Sans', pos=(0, 0), letterHeight=0.05, size=(None, None), borderWidth=2.0, color=[-1.0000, -1.0000, -1.0000], colorSpace='rgb', opacity=None, bold=False, italic=False, lineSpacing=1.0, padding=0.0, anchor='center', fillColor=None, borderColor=None, flipHoriz=False, flipVert=False, editable=True, name='textbox', autoLog=True, ) button = visual.ButtonStim(win, text='Haz click aqui para continuar', font='Arvo', pos=(0, -.4), letterHeight=0.05, size=None, borderWidth=0.0, fillColor='darkgrey', borderColor=None, color='white', colorSpace='rgb', opacity=None, bold=True, italic=False, padding=None, anchor='center', name='button' ) button.buttonClock = core.Clock() mouse = event.Mouse(win=win) x, y = [None, None] mouse.mouseClock = core.Clock() # Initialize components for Routine "thanks" thanksClock = core.Clock() thanksText = visual.TextStim(win=win, name='thanksText', text='Este es el fin del experimento\n\n¡Gracias!', font='arial', pos=[0, 0], height=0.3, wrapWidth=None, ori=0, color=(0.7255, -0.8431, -0.5294), colorSpace='rgb', opacity=1, languageStyle='LTR', depth=0.0); # Create some handy timers globalClock = core.Clock() # to track the time since experiment started routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine # ------Prepare to start Routine "instruct"------- continueRoutine = True # update component parameters for each repeat ready.keys = [] ready.rt = [] _ready_allKeys = [] # keep track of which components have finished instructComponents = [instrText, ready] for thisComponent in instructComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") instructClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "instruct"------- while continueRoutine: # get current time t = instructClock.getTime() tThisFlip = win.getFutureFlipTime(clock=instructClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *instrText* updates if instrText.status == NOT_STARTED and tThisFlip >= 0-frameTolerance: # keep track of start time/frame for later instrText.frameNStart = frameN # exact frame index instrText.tStart = t # local t and not account for scr refresh instrText.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(instrText, 'tStartRefresh') # time at next scr refresh instrText.setAutoDraw(True) # *ready* updates waitOnFlip = False if ready.status == NOT_STARTED and tThisFlip >= 0-frameTolerance: # keep track of start time/frame for later ready.frameNStart = frameN # exact frame index ready.tStart = t # local t and not account for scr refresh ready.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(ready, 'tStartRefresh') # time at next scr refresh ready.status = STARTED # keyboard checking is just starting waitOnFlip = True win.callOnFlip(ready.clock.reset) # t=0 on next screen flip win.callOnFlip(ready.clearEvents, eventType='keyboard') # clear events on next screen flip if ready.status == STARTED and not waitOnFlip: theseKeys = ready.getKeys(keyList=None, waitRelease=False) _ready_allKeys.extend(theseKeys) if len(_ready_allKeys): ready.keys = _ready_allKeys[-1].name # just the last key pressed ready.rt = _ready_allKeys[-1].rt # a response ends the routine continueRoutine = False # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in instructComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "instruct"------- for thisComponent in instructComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) thisExp.addData('instrText.started', instrText.tStartRefresh) thisExp.addData('instrText.stopped', instrText.tStopRefresh) # the Routine "instruct" was not non-slip safe, so reset the non-slip timer routineTimer.reset() # set up handler to look after randomisation of conditions etc trials = data.TrialHandler(nReps=1.0, method='fullRandom', extraInfo=expInfo, originPath=-1, trialList=data.importConditions('conditions random.xlsx'), seed=None, name='trials') thisExp.addLoop(trials) # add the loop to the experiment thisTrial = trials.trialList[0] # so we can initialise stimuli with some values # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb) if thisTrial != None: for paramName in thisTrial: exec('{} = thisTrial[paramName]'.format(paramName)) for thisTrial in trials: currentLoop = trials # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb) if thisTrial != None: for paramName in thisTrial: exec('{} = thisTrial[paramName]'.format(paramName)) # ------Prepare to start Routine "trial"------- continueRoutine = True routineTimer.add(20.000000) # update component parameters for each repeat stim.setColor([-1.0000, -1.0000, -1.0000], colorSpace='rgb') stim.setText(word) text.setText(word1 ) text_2.setText(word2) text_3.setText(word3) # keep track of which components have finished trialComponents = [stim, text, text_2, text_3] for thisComponent in trialComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") trialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "trial"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = trialClock.getTime() tThisFlip = win.getFutureFlipTime(clock=trialClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *stim* updates if stim.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later stim.frameNStart = frameN # exact frame index stim.tStart = t # local t and not account for scr refresh stim.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(stim, 'tStartRefresh') # time at next scr refresh stim.setAutoDraw(True) if stim.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > stim.tStartRefresh + 5-frameTolerance: # keep track of stop time/frame for later stim.tStop = t # not accounting for scr refresh stim.frameNStop = frameN # exact frame index win.timeOnFlip(stim, 'tStopRefresh') # time at next scr refresh stim.setAutoDraw(False) # *text* updates if text.status == NOT_STARTED and tThisFlip >= 5.0-frameTolerance: # keep track of start time/frame for later text.frameNStart = frameN # exact frame index text.tStart = t # local t and not account for scr refresh text.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text, 'tStartRefresh') # time at next scr refresh text.setAutoDraw(True) if text.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text.tStartRefresh + 5.0-frameTolerance: # keep track of stop time/frame for later text.tStop = t # not accounting for scr refresh text.frameNStop = frameN # exact frame index win.timeOnFlip(text, 'tStopRefresh') # time at next scr refresh text.setAutoDraw(False) # *text_2* updates if text_2.status == NOT_STARTED and tThisFlip >= 10.0-frameTolerance: # keep track of start time/frame for later text_2.frameNStart = frameN # exact frame index text_2.tStart = t # local t and not account for scr refresh text_2.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_2, 'tStartRefresh') # time at next scr refresh text_2.setAutoDraw(True) if text_2.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text_2.tStartRefresh + 5.0-frameTolerance: # keep track of stop time/frame for later text_2.tStop = t # not accounting for scr refresh text_2.frameNStop = frameN # exact frame index win.timeOnFlip(text_2, 'tStopRefresh') # time at next scr refresh text_2.setAutoDraw(False) # *text_3* updates if text_3.status == NOT_STARTED and tThisFlip >= 15.0-frameTolerance: # keep track of start time/frame for later text_3.frameNStart = frameN # exact frame index text_3.tStart = t # local t and not account for scr refresh text_3.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(text_3, 'tStartRefresh') # time at next scr refresh text_3.setAutoDraw(True) if text_3.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > text_3.tStartRefresh + 5.0-frameTolerance: # keep track of stop time/frame for later text_3.tStop = t # not accounting for scr refresh text_3.frameNStop = frameN # exact frame index win.timeOnFlip(text_3, 'tStopRefresh') # time at next scr refresh text_3.setAutoDraw(False) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in trialComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "trial"------- for thisComponent in trialComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) trials.addData('stim.started', stim.tStartRefresh) trials.addData('stim.stopped', stim.tStopRefresh) trials.addData('text.started', text.tStartRefresh) trials.addData('text.stopped', text.tStopRefresh) trials.addData('text_2.started', text_2.tStartRefresh) trials.addData('text_2.stopped', text_2.tStopRefresh) trials.addData('text_3.started', text_3.tStartRefresh) trials.addData('text_3.stopped', text_3.tStopRefresh) # ------Prepare to start Routine "RPTA"------- continueRoutine = True # update component parameters for each repeat textbox.reset() textbox.setText('Escribe aquí las sílabas que recuerdes separadas por una coma') # setup some python lists for storing info about the mouse mouse.clicked_name = [] gotValidClick = False # until a click is received # keep track of which components have finished RPTAComponents = [textbox, button, mouse] for thisComponent in RPTAComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") RPTAClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "RPTA"------- while continueRoutine: # get current time t = RPTAClock.getTime() tThisFlip = win.getFutureFlipTime(clock=RPTAClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *textbox* updates if textbox.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later textbox.frameNStart = frameN # exact frame index textbox.tStart = t # local t and not account for scr refresh textbox.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(textbox, 'tStartRefresh') # time at next scr refresh textbox.setAutoDraw(True) # *button* updates if button.status == NOT_STARTED and tThisFlip >= 0-frameTolerance: # keep track of start time/frame for later button.frameNStart = frameN # exact frame index button.tStart = t # local t and not account for scr refresh button.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(button, 'tStartRefresh') # time at next scr refresh button.setAutoDraw(True) if button.status == STARTED: # check whether button has been pressed if button.isClicked: if not button.wasClicked: button.timesOn.append(button.buttonClock.getTime()) # store time of first click button.timesOff.append(button.buttonClock.getTime()) # store time clicked until else: button.timesOff[-1] = button.buttonClock.getTime() # update time clicked until if not button.wasClicked: continueRoutine = False # end routine when button is clicked None button.wasClicked = True # if button is still clicked next frame, it is not a new click else: button.wasClicked = False # if button is clicked next frame, it is a new click else: button.buttonClock.reset() # keep clock at 0 if button hasn't started / has finished button.wasClicked = False # if button is clicked next frame, it is a new click # *mouse* updates if mouse.status == NOT_STARTED and t >= 0.0-frameTolerance: # keep track of start time/frame for later mouse.frameNStart = frameN # exact frame index mouse.tStart = t # local t and not account for scr refresh mouse.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(mouse, 'tStartRefresh') # time at next scr refresh mouse.status = STARTED mouse.mouseClock.reset() prevButtonState = mouse.getPressed() # if button is down already this ISN'T a new click if mouse.status == STARTED: # only update if started and not finished! buttons = mouse.getPressed() if buttons != prevButtonState: # button state changed? prevButtonState = buttons if sum(buttons) > 0: # state changed to a new click # check if the mouse was inside our 'clickable' objects gotValidClick = False try: iter(button) clickableList = button except: clickableList = [button] for obj in clickableList: if obj.contains(mouse): gotValidClick = True mouse.clicked_name.append(obj.name) if gotValidClick: # abort routine on response continueRoutine = False # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in RPTAComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "RPTA"------- for thisComponent in RPTAComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) trials.addData('textbox.text',textbox.text) trials.addData('textbox.started', textbox.tStartRefresh) trials.addData('textbox.stopped', textbox.tStopRefresh) trials.addData('button.started', button.tStartRefresh) trials.addData('button.stopped', button.tStopRefresh) trials.addData('button.numClicks', button.numClicks) if button.numClicks: trials.addData('button.timesOn', button.timesOn) trials.addData('button.timesOff', button.timesOff) else: trials.addData('button.timesOn', "") trials.addData('button.timesOff', "") # store data for trials (TrialHandler) x, y = mouse.getPos() buttons = mouse.getPressed() if sum(buttons): # check if the mouse was inside our 'clickable' objects gotValidClick = False try: iter(button) clickableList = button except: clickableList = [button] for obj in clickableList: if obj.contains(mouse): gotValidClick = True mouse.clicked_name.append(obj.name) trials.addData('mouse.x', x) trials.addData('mouse.y', y) trials.addData('mouse.leftButton', buttons[0]) trials.addData('mouse.midButton', buttons[1]) trials.addData('mouse.rightButton', buttons[2]) if len(mouse.clicked_name): trials.addData('mouse.clicked_name', mouse.clicked_name[0]) trials.addData('mouse.started', mouse.tStart) trials.addData('mouse.stopped', mouse.tStop) # the Routine "RPTA" was not non-slip safe, so reset the non-slip timer routineTimer.reset() thisExp.nextEntry() # completed 1.0 repeats of 'trials' # ------Prepare to start Routine "thanks"------- continueRoutine = True routineTimer.add(2.000000) # update component parameters for each repeat # keep track of which components have finished thanksComponents = [thanksText] for thisComponent in thanksComponents: thisComponent.tStart = None thisComponent.tStop = None thisComponent.tStartRefresh = None thisComponent.tStopRefresh = None if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # reset timers t = 0 _timeToFirstFrame = win.getFutureFlipTime(clock="now") thanksClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "thanks"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = thanksClock.getTime() tThisFlip = win.getFutureFlipTime(clock=thanksClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *thanksText* updates if thanksText.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later thanksText.frameNStart = frameN # exact frame index thanksText.tStart = t # local t and not account for scr refresh thanksText.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(thanksText, 'tStartRefresh') # time at next scr refresh thanksText.setAutoDraw(True) if thanksText.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > thanksText.tStartRefresh + 2.0-frameTolerance: # keep track of stop time/frame for later thanksText.tStop = t # not accounting for scr refresh thanksText.frameNStop = frameN # exact frame index win.timeOnFlip(thanksText, 'tStopRefresh') # time at next scr refresh thanksText.setAutoDraw(False) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): core.quit() # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in thanksComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "thanks"------- for thisComponent in thanksComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) thisExp.addData('thanksText.started', thanksText.tStartRefresh) thisExp.addData('thanksText.stopped', thanksText.tStopRefresh) # Flip one final time so any remaining win.callOnFlip() # and win.timeOnFlip() tasks get executed before quitting win.flip() # these shouldn't be strictly necessary (should auto-save) thisExp.saveAsWideText(filename+'.csv', delim='auto') thisExp.saveAsPickle(filename) logging.flush() # make sure everything is closed down thisExp.abort() # or data files will save again on exit win.close() core.quit()