#!/usr/bin/env python # -*- coding: utf-8 -*- """ This experiment was created using PsychoPy3 Experiment Builder (v3.2.4), on Wed May 27 21:18:23 2020 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 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 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 = '3.2.4' expName = 'exp' # from the Builder filename that created this script expInfo = {'participant': '', 'session': '001'} 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/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date']) # An ExperimentHandler isn't essential but helps with data saving thisExp = data.ExperimentHandler(name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath='/Users/azaleareyesaguilar/Documents/Bisquet/tronco_comun/practicas_PB/ExperimentosPsychoPy/PPB_Eroticas/nback_erotica_lastrun.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 before the window creation # Setup the Window win = visual.Window( size=(1024, 768), fullscr=True, screen=0, winType='pyglet', allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb', blendMode='avg', useFBO=True) # 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 # create a default keyboard (e.g. to check for escape) defaultKeyboard = keyboard.Keyboard() # Initialize components for Routine "instrucciones" instruccionesClock = core.Clock() text_2 = visual.TextStim(win=win, name='text_2', text='Bienvenido(a) a este experimento.\n\nA continuación, se te presentará una serie de imágenes. \n\nTu tarea es indicar si la imagen que aparece en pantalla es la misma que la inmediatamente anterior, si sí es la misma que la anterior, responde presionando la barra espaciadora.\nPero si no es la misma que la inmediata anterior, no respondas nada. \n\nPresiona la barra espaciadora para comenzar la tarea.\n', font='Arial', pos=(0, 0), height=0.07, wrapWidth=None, ori=0, color='white', colorSpace='rgb', opacity=1, languageStyle='LTR', depth=0.0); key_resp_1 = keyboard.Keyboard() # Initialize components for Routine "r2" r2Clock = core.Clock() image1 = visual.ImageStim( win=win, name='image1', image='sin', mask=None, ori=0, pos=(0, 0), size=(0.9, 0.9), color=[1,1,1], colorSpace='rgb', opacity=1, flipHoriz=False, flipVert=False, texRes=128, interpolate=True, depth=0.0) image2 = visual.ImageStim( win=win, name='image2', image='sin', mask=None, ori=0, pos=(0, 0), size=(0.9, 0.9), color=[1,1,1], colorSpace='rgb', opacity=1, flipHoriz=False, flipVert=False, texRes=128, interpolate=True, depth=-1.0) key_resp_3 = keyboard.Keyboard() # 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 "instrucciones"------- # update component parameters for each repeat key_resp_1.keys = [] key_resp_1.rt = [] # keep track of which components have finished instruccionesComponents = [text_2, key_resp_1] for thisComponent in instruccionesComponents: 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") instruccionesClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 continueRoutine = True # -------Run Routine "instrucciones"------- while continueRoutine: # get current time t = instruccionesClock.getTime() tThisFlip = win.getFutureFlipTime(clock=instruccionesClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *text_2* updates if text_2.status == NOT_STARTED and tThisFlip >= 0.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) # *key_resp_1* updates waitOnFlip = False if key_resp_1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later key_resp_1.frameNStart = frameN # exact frame index key_resp_1.tStart = t # local t and not account for scr refresh key_resp_1.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(key_resp_1, 'tStartRefresh') # time at next scr refresh key_resp_1.status = STARTED # keyboard checking is just starting win.callOnFlip(key_resp_1.clearEvents, eventType='keyboard') # clear events on next screen flip if key_resp_1.status == STARTED and not waitOnFlip: theseKeys = key_resp_1.getKeys(keyList=['space'], waitRelease=False) if len(theseKeys): theseKeys = theseKeys[0] # at least one key was pressed # check for quit: if "escape" == theseKeys: endExpNow = True # 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 instruccionesComponents: 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 "instrucciones"------- for thisComponent in instruccionesComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) thisExp.addData('text_2.started', text_2.tStartRefresh) thisExp.addData('text_2.stopped', text_2.tStopRefresh) # the Routine "instrucciones" was not non-slip safe, so reset the non-slip timer routineTimer.reset() # set up handler to look after randomisation of conditions etc trials_2 = data.TrialHandler(nReps=1, method='sequential', extraInfo=expInfo, originPath=-1, trialList=data.importConditions('estimErotica.xlsx'), seed=None, name='trials_2') thisExp.addLoop(trials_2) # add the loop to the experiment thisTrial_2 = trials_2.trialList[0] # so we can initialise stimuli with some values # abbreviate parameter names if possible (e.g. rgb = thisTrial_2.rgb) if thisTrial_2 != None: for paramName in thisTrial_2: exec('{} = thisTrial_2[paramName]'.format(paramName)) for thisTrial_2 in trials_2: currentLoop = trials_2 # abbreviate parameter names if possible (e.g. rgb = thisTrial_2.rgb) if thisTrial_2 != None: for paramName in thisTrial_2: exec('{} = thisTrial_2[paramName]'.format(paramName)) # ------Prepare to start Routine "r2"------- routineTimer.add(3.000000) # update component parameters for each repeat image1.setImage(imagen1) image2.setImage(imagen2) key_resp_3.keys = [] key_resp_3.rt = [] # keep track of which components have finished r2Components = [image1, image2, key_resp_3] for thisComponent in r2Components: 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") r2Clock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 continueRoutine = True # -------Run Routine "r2"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = r2Clock.getTime() tThisFlip = win.getFutureFlipTime(clock=r2Clock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *image1* updates if image1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance: # keep track of start time/frame for later image1.frameNStart = frameN # exact frame index image1.tStart = t # local t and not account for scr refresh image1.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(image1, 'tStartRefresh') # time at next scr refresh image1.setAutoDraw(True) if image1.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > image1.tStartRefresh + 1-frameTolerance: # keep track of stop time/frame for later image1.tStop = t # not accounting for scr refresh image1.frameNStop = frameN # exact frame index win.timeOnFlip(image1, 'tStopRefresh') # time at next scr refresh image1.setAutoDraw(False) # *image2* updates if image2.status == NOT_STARTED and tThisFlip >= 1.5-frameTolerance: # keep track of start time/frame for later image2.frameNStart = frameN # exact frame index image2.tStart = t # local t and not account for scr refresh image2.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(image2, 'tStartRefresh') # time at next scr refresh image2.setAutoDraw(True) if image2.status == STARTED: # is it time to stop? (based on global clock, using actual start) if tThisFlipGlobal > image2.tStartRefresh + 1-frameTolerance: # keep track of stop time/frame for later image2.tStop = t # not accounting for scr refresh image2.frameNStop = frameN # exact frame index win.timeOnFlip(image2, 'tStopRefresh') # time at next scr refresh image2.setAutoDraw(False) # *key_resp_3* updates waitOnFlip = False if key_resp_3.status == NOT_STARTED and tThisFlip >= 1.5-frameTolerance: # keep track of start time/frame for later key_resp_3.frameNStart = frameN # exact frame index key_resp_3.tStart = t # local t and not account for scr refresh key_resp_3.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(key_resp_3, 'tStartRefresh') # time at next scr refresh key_resp_3.status = STARTED # keyboard checking is just starting waitOnFlip = True win.callOnFlip(key_resp_3.clock.reset) # t=0 on next screen flip win.callOnFlip(key_resp_3.clearEvents, eventType='keyboard') # clear events on next screen flip if key_resp_3.status == STARTED: # is it time to stop? (based on local clock) if tThisFlip > 3.0-frameTolerance: # keep track of stop time/frame for later key_resp_3.tStop = t # not accounting for scr refresh key_resp_3.frameNStop = frameN # exact frame index win.timeOnFlip(key_resp_3, 'tStopRefresh') # time at next scr refresh key_resp_3.status = FINISHED if key_resp_3.status == STARTED and not waitOnFlip: theseKeys = key_resp_3.getKeys(keyList=['space'], waitRelease=False) if len(theseKeys): theseKeys = theseKeys[0] # at least one key was pressed # check for quit: if "escape" == theseKeys: endExpNow = True key_resp_3.keys = theseKeys.name # just the last key pressed key_resp_3.rt = theseKeys.rt # was this 'correct'? if (key_resp_3.keys == str(respcorr)) or (key_resp_3.keys == respcorr): key_resp_3.corr = 1 else: key_resp_3.corr = 0 # 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 r2Components: 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 "r2"------- for thisComponent in r2Components: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) trials_2.addData('image1.started', image1.tStartRefresh) trials_2.addData('image1.stopped', image1.tStopRefresh) trials_2.addData('image2.started', image2.tStartRefresh) trials_2.addData('image2.stopped', image2.tStopRefresh) # check responses if key_resp_3.keys in ['', [], None]: # No response was made key_resp_3.keys = None # was no response the correct answer?! if str(respcorr).lower() == 'none': key_resp_3.corr = 1; # correct non-response else: key_resp_3.corr = 0; # failed to respond (incorrectly) # store data for trials_2 (TrialHandler) trials_2.addData('key_resp_3.keys',key_resp_3.keys) trials_2.addData('key_resp_3.corr', key_resp_3.corr) if key_resp_3.keys != None: # we had a response trials_2.addData('key_resp_3.rt', key_resp_3.rt) trials_2.addData('key_resp_3.started', key_resp_3.tStartRefresh) trials_2.addData('key_resp_3.stopped', key_resp_3.tStopRefresh) thisExp.nextEntry() # completed 1 repeats of 'trials_2' # 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') 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()