# Store info about the experiment session expName = 'LearningTask' # from the Builder filename that created this script expInfo = {'participant':'', 'gender (m/f)':'', 'age':'', 'session':03} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # 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=u'/Users/patrickbissett/OneDrive/Poldrack/TrainedInhibition/PsychoPy/ShapeLearningTaskCounterbalanceRemovePrac2.psyexp', savePickle=True, saveWideText=True, dataFileName=filename) #save a log file for detail verbose info logFile = logging.LogFile(filename+'.log', level=logging.WARNING) logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file endExpNow = False # flag for 'escape' or other condition => quit the exp # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=(2560, 1440), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color='black', colorSpace='rgb', blendMode='avg', useFBO=True, )
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= 'C:\\Users\\Oskar\\Documents\\GitHub\\exjobb\\Experiment setup\\DecodingPhase_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
# Store info about the experiment session expName = 'stroop' # from the Builder filename that created this script expInfo = {u'session': u'01', u'participant': u''} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # 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=u'/Users/b392t356/Desktop/Python-for-social-scientists/Cases/\u56de\u590d\uff1a_psychopy\u95ee\u9898/demo-stroop/stroop.psyexp', savePickle=True, saveWideText=True, dataFileName=filename) # save a log file for detail verbose info logFile = logging.LogFile(filename+'.log', level=logging.WARNING) logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file endExpNow = False # flag for 'escape' or other condition => quit the exp # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window( size=(1440, 900), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color='black', colorSpace='rgb',
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= 'C:\\Users\\Taylor\\Downloads\\CSN Lab\\projects\\round_robin\\scripts\\scanner_portion\\psychopy_scripts\\runE\\runE.py', savePickle=True, saveWideText=True, dataFileName=filename) # save a log file for detail verbose info logFile = logging.LogFile(filename + '.log', level=logging.EXP) logfile = logging.LogFile(filename + '_data.log', level=logging.DATA) logging.console.setLevel( logging.WARNING) # this outputs to the screen, not a file endExpNow = False # flag for 'escape' or other condition => quit the exp # Start Code - component code to be run before the window creation # Setup the Window
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= 'C:\\Users\\ning\\Documents\\python works\\psychopy_experiments\\blind sight\\test_circle.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
# Store info about the experiment session expName = 'visneuro' # from the Builder filename that created this script expInfo = {'participant':'', 'session':'001'} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + '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=u'/Users/talithaford/Dropbox/Conference-Workshop/ResBaz/2016/psychopy_lesson/ResBaz_lesson.psyexp', 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=(1280, 800), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb', blendMode='avg', useFBO=True, )
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/gus/Documents/Durgin/test1_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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=(1024, 768),
expName = 'RemTag2' # from the Builder filename that created this script expInfo = {'participant': '', 'session': '001'} dlg = gui.DlgFromDict(dictionary=expInfo, sort_keys=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/bleonard/Downloads/attachments/RemTag2_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,
# Store info about the experiment session expName = 'experiment' # from the Builder filename that created this script expInfo = {u'gender': u'm', u'session': u'001', u'participant': u''} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + '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=u'X:\\training-materials\\PsychoPy-Part2\\Staff-only-files\\ex5-image-ratings-complete\\experiment.psyexp', 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window( size=(1920, 1080), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
# ----------------------------------------------------------------------------- # | Initialising Objects | # ----------------------------------------------------------------------------- win = visual.Window( [1280 * 0.7, 1024 * 0.7], # 70% of the size of the screen in WH205 fullscr=True, allowGUI=False, monitor='testMonitor', units='cm') thisExp = data.ExperimentHandler(name='', version='', extraInfo=exp_dict_dlg, runtimeInfo=None, originPath=None, dataFileName=datfilename, savePickle=True, saveWideText=True, autoLog=True) nTrials = exp_dict_dlg['nTrials'] # initialise an Oddball object myOddball = oddball.Oddball( win=win, expHandler=thisExp, mydir=_thisDir, subjectnr=exp_dict_dlg['Probandennummer'], sessionnr='1', triggerlen=0.01,
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/Jadyn/Desktop/mpr/mprax_lastrun.py', savePickle=True, saveWideText=True, dataFileName=filename) # save a log file for detail verbose info logFile = logging.LogFile(filename + '.log', level=logging.DEBUG) 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
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # 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= u'/Users/hejibo/Documents/Computer Application for Behavioral Sciences/Lecture 14. Psychopy 3 -Stimuli generation/stimuliDemostration.psyexp', 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=(800, 600),
def run_trial_experiment(order_directions, order_array): # Global variables global small_blocks global big_blocks global switching_blocks global experiment_name global experiment_info # Local variables experiment_blocks = [] # can be switching block, small or big block wait_time_response = 2.5 # time waiting for response wait_time_slides = 0.1 # time waiting between slides wait_time_blocks = 10.0 # time waiting between blocks keys = ['c', 't'] # m = circle, n = triangles key_tone = sound.Sound(u'A', secs=.2) # key sound # Set the file name for the output that contains the participant's infromation filename = os.getcwd() + os.sep + u'data/%s_%s_%s' % ( experiment_info['participant'], experiment_name, experiment_info['date']) # For order (small, big, switching) in array for order in order_array: experiment_blocks = order_directions[order] this_experiment = data.ExperimentHandler(name=experiment_name, version='', extraInfo=experiment_info, runtimeInfo=None, savePickle=True, saveWideText=True, dataFileName=filename + "_" + order) # For each image in experiment block, displayed them for image in experiment_blocks: stimulus = visual.ImageStim(window, image=image) stimulus.draw() window.flip() clock.reset() response_key = event.waitKeys(maxWait=wait_time_response, keyList=keys, timeStamped=clock) # If user response by pressing m for circles and n for triangles if response_key: key_tone.play() core.wait(wait_time_response - response_key[0][1]) window.flip() core.wait(wait_time_slides) else: response_key = [['', '']] # Check if user response correctly check_user_response(image, keys, this_experiment, response_key, wait_time_response) # Save each session at the experiment after finishing this_experiment.saveAsWideText(filename + "_" + order + '.csv') core.wait(wait_time_blocks) # Finish experiment and exit this_experiment.saveAsPickle(filename) this_experiment.abort() window.close() core.quit()
expName = 'headphone_calibration' # 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='C:\\Users\\k2032175\\Documents\\headphone_calibration.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=[1366, 768], fullscr=True, screen=0, winType='pyglet', allowGUI=False, allowStencil=False,
# Store info about the experiment session expName = 'untitled' # from the Builder filename that created this script expInfo = {'participant': '', 'session': '001'} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # 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='C:\\Users\\chris\\OneDrive\\Desktop\\NEW EXPERIMENTS\\PsychoPy Perceptual load task\\RSVP TASK\\untitled.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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window( size=[1366, 768], fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
# Store info about the experiment session expName = 'LDT2' # from the Builder filename that created this script expInfo = {u'session': u'01', u'participant': u''} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # 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=u'/Users/pollybarr/Documents/LDT_builder demo/LDT2.psyexp', 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 # Start Code - component code to be run before the window creation #define button box def initialiseButtonBox(): serialPorts = serial.tools.list_ports.comports() #List of connected items devices = [port.description for port in serialPorts] #description attributes of connected items try: #is there an arduino box connected?
directory_to_write_to = "C:\Users\erp.users\Desktop\Pieter\Data" + "/" + str( info["ppnr"] ) #"/Users/pieter/Documents/Catastrophic forgetting/empirical" if not os.path.isdir(directory_to_write_to): os.mkdir(directory_to_write_to) file_name = directory_to_write_to + "/Probabilistic_Reversal_task_subject_" + str( info["ppnr"]) + "_Session_" + str(info["Session"]) + "_data" if not os.path.isfile(file_name + ".tsv"): already_exists = False else: myDlg2 = gui.Dlg(title="Error") myDlg2.addText("Try another participant number") myDlg2.show() print("OK, let's get started!") thisExp = data.ExperimentHandler(dataFileName=file_name, extraInfo=info) my_clock = core.Clock() #make window window = visual.Window(fullscr=True, monitor='Benq_xl2411', color=[0, 0, 0], colorSpace='rgb') #size=(800,600),"MyLaptop" window.setMouseVisible(False) print('window_ok') # graphical elements welcome = visual.TextStim( window, text= ("Dag {}!,\n\n" + "Nu kunnen we over gaan tot de experimentele fase\n\n" + "Vanaf nu bepalen je punten je beloning!!\n\n" +
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = os.path.join(PartDataFolder, '%s_%s_%s_%s_%s' % (expInfo['Participant ID'],expName, task, Tag, expInfo['date'])) BGColor = u'grey' FontColor = u'white' FontSize = 60 InstrFontSize = 40 StroopKeyList = ['v', 'b', 'n', 'm'] # ################# #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=u'/home/jsteffen/Documents/GitHubOutsideOfDropbox/CognitiveTasks/Stroop/StroopColorWord.psyexp', savePickle=True, saveWideText=True, dataFileName=filename) # save a log file for detail verbose info #logFile = logging.LogFile(filename+'.log', level=logging.WARNING) #logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file endExpNow = False # flag for 'escape' or other condition => quit the exp # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window( size=(1200, 800), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor=u'testMonitor', color=BGColor, colorSpace='rgb',
# Store info about the experiment session expName = 'ChEC_movieratings' # from the Builder filename that created this script expInfo = {u'session': u'001', u'participant': u''} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # 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=u'C:\\Users\\iView X\\Desktop\\ChEC\\chec\\ChEC_movieratings.psyexp', 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window( size=(1920, 1080), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
expInfo = {'participant': '', 'session': '001'} dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName) if dlg.OK == False: core.quit() expInfo['date'] = data.getDateStr() expInfo['expName'] = expName expInfo['psychopyVersion'] = psychopyVersion filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date']) thisExp = data.ExperimentHandler( name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath= 'C:\\Users\\Jojo\\Downloads\\Helion Lab\\Experiment Files\\CardTask\\CardTaskFinal1.py', savePickle=True, saveWideText=True, dataFileName=filename) logFile = logging.LogFile(filename + '.log', level=logging.EXP) logging.console.setLevel(logging.WARNING) endExpNow = False frameTolerance = 0.001 win = visual.Window(size=(1024, 768), fullscr=True, screen=0, winType='pyglet', allowGUI=False,
# Store info about the experiment session expName = 'detectOddOne_categ' # from the Builder filename that created this script expInfo = {u'subject_id': u'', u'protocol_id': u''} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['subject_id'], expName, expInfo['date']) # An ExperimentHandler isn't essential but helps with data saving thisExp = data.ExperimentHandler(name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath=u'D:\\Documents\\git\\scenesCNN_DRM\\psychopy\\detectOddOne_categ.psyexp', 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window( size=[1920, 1200], fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
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/joe/Documents/GitHub/categorizationexample/color_mds_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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=(1024, 768),
def runExp(participantId): # Ensure that relative paths start from the same directory as this scripta _thisDir = os.path.dirname(os.path.abspath(__file__)) os.chdir(_thisDir) # Store info about the experiment session psychopyVersion = '2020.2.4' expName = 'ExpGiulia' # from the Builder filename that created this script expInfo = {'participant': participantId, 'session': '001'} #dlg = gui.DlgFromDict(dictionary=expInfo, sort_keys=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_%s' % (expInfo['participant'],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=os.getcwd(), 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, units='height') # 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 "trial" trialClock = core.Clock() welcomeText = visual.TextStim(win=win, name='welcomeText', text='Welcome to this experiment.\n\nPress the spacebar when you are ready and the video will start!', font='Arial', pos=(0, 0), height=0.1, wrapWidth=None, ori=0, color='white', colorSpace='rgb', opacity=1, languageStyle='LTR', depth=0.0); key_resp = keyboard.Keyboard() # Initialize components for Routine "Video" VideoClock = core.Clock() video = visual.MovieStim3( win=win, name='video', noAudio=False, #filename='C:\\Users\\matti\\OneDrive\\Desktop\\Tesi\\VideoEsperimenti\\filmato_Giulia.mp4', filename='videos\\filmato_Giulia.mp4', ori=0, pos=(0, 0), opacity=1, loop=False, 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 "trial"------- continueRoutine = True # update component parameters for each repeat key_resp.keys = [] key_resp.rt = [] _key_resp_allKeys = [] # keep track of which components have finished trialComponents = [welcomeText, key_resp] 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: # 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 # *welcomeText* updates if welcomeText.status == NOT_STARTED and tThisFlip >= 0.0 - frameTolerance: # keep track of start time/frame for later welcomeText.frameNStart = frameN # exact frame index welcomeText.tStart = t # local t and not account for scr refresh welcomeText.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(welcomeText, 'tStartRefresh') # time at next scr refresh welcomeText.setAutoDraw(True) # *key_resp* updates waitOnFlip = False if key_resp.status == NOT_STARTED and tThisFlip >= 0.0 - frameTolerance: # keep track of start time/frame for later key_resp.frameNStart = frameN # exact frame index key_resp.tStart = t # local t and not account for scr refresh key_resp.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(key_resp, 'tStartRefresh') # time at next scr refresh key_resp.status = STARTED # keyboard checking is just starting waitOnFlip = True win.callOnFlip(key_resp.clock.reset) # t=0 on next screen flip win.callOnFlip(key_resp.clearEvents, eventType='keyboard') # clear events on next screen flip if key_resp.status == STARTED and not waitOnFlip: theseKeys = key_resp.getKeys(keyList=['space'], waitRelease=False) _key_resp_allKeys.extend(theseKeys) if len(_key_resp_allKeys): key_resp.keys = _key_resp_allKeys[-1].name # just the last key pressed key_resp.rt = _key_resp_allKeys[-1].rt # a response ends the routine continueRoutine = False # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): win.close() 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) thisExp.addData('welcomeText.started', welcomeText.tStartRefresh) thisExp.addData('welcomeText.stopped', welcomeText.tStopRefresh) # check responses if key_resp.keys in ['', [], None]: # No response was made key_resp.keys = None thisExp.addData('key_resp.keys', key_resp.keys) if key_resp.keys != None: # we had a response thisExp.addData('key_resp.rt', key_resp.rt) thisExp.addData('key_resp.started', key_resp.tStartRefresh) thisExp.addData('key_resp.stopped', key_resp.tStopRefresh) thisExp.nextEntry() # the Routine "trial" was not non-slip safe, so reset the non-slip timer routineTimer.reset() # ------Prepare to start Routine "Video"------- continueRoutine = True # update component parameters for each repeat # keep track of which components have finished VideoComponents = [video] for thisComponent in VideoComponents: 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") VideoClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip frameN = -1 # -------Run Routine "Video"------- while continueRoutine: # get current time t = VideoClock.getTime() tThisFlip = win.getFutureFlipTime(clock=VideoClock) tThisFlipGlobal = win.getFutureFlipTime(clock=None) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *video* updates if video.status == NOT_STARTED and tThisFlip >= 0.0 - frameTolerance: # keep track of start time/frame for later video.frameNStart = frameN # exact frame index video.tStart = t # local t and not account for scr refresh video.tStartRefresh = tThisFlipGlobal # on global time win.timeOnFlip(video, 'tStartRefresh') # time at next scr refresh video.setAutoDraw(True) # check for quit (typically the Esc key) if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]): win.close() 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 VideoComponents: 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 "Video"------- for thisComponent in VideoComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) video.stop() # the Routine "Video" was not non-slip safe, so reset the non-slip timer routineTimer.reset() # 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() logging.flush() for thisThread in threading.enumerate(): if hasattr(thisThread, 'stop') and hasattr(thisThread, 'running'): # this is one of our event threads - kill it and wait for success thisThread.stop() while thisThread.running == 0: pass # wait until it has properly finished polling sys.exit(1) # quits the python session entirely
expInfo = {'participant': '', 'session': '001'} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + '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= u'/home/jason/Dropbox/SteffenerColumbia/Scripts/ExperimentalStimuli/Johannes/label_ang.psyexp', 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(
# Store info about the experiment session expName = 'runD' # from the Builder filename that created this script expInfo = {u'session': u'001', u'participant': u''} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # 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=u'C:\\Documents and Settings\\fmri\\Desktop\\PsychNet\\random_order\\ANDY\\runD.psyexp', 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=(1280, 1024), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color=[-1.000,-1.000,-1.000], colorSpace='rgb', blendMode='avg', useFBO=True, )
def displayInstructions(text, acceptedKeys=None): instruct = visual.TextStim(win, text=instrText, color='black') instruct.draw() win.flip() key = event.waitKeys(keyList=acceptedKeys) win.flip() # Experiment Handler filename = "data/" + info['Participant No'] jnd_exp = data.ExperimentHandler(name='Adjusting JND', version='1.0', extraInfo=info, dataFileName=filename) # Trial handler trials = data.TrialHandler(trialList=RandomOffsets(), nReps=1, method='random') jnd_exp.addLoop(trials) # Trial sequence displayInstructions(text=instrText) trialNo = 0 for thisTrial in trials:
INPUTFILE = 'InstructPart1.xlsx' # INPUTFILE = 'TwoTrials.xlsx' IntroTime = 10 End = 10 # This should be set so that it is at least ten seconds and so the experiment # total duration is a multiple of two seconds. MaxLetters = 6 if MaxLetters == 6: SETwrapWidth = 1.5 # The wrap width of text needs to be adjusted based on how manty letters there are SETletCycle = 13 # # Spaces are added between letters and this controls the loop which does it elif MaxLetters == 7: SETwrapWidth = 1.7 SETletCycle = 15 thisExp = data.ExperimentHandler(name="Instruct", version='', runtimeInfo=None, originPath=None, savePickle=True, saveWideText=True) endExpNow = False # flag for 'escape' or other condition => quit the exp # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=[800, 600], fullscr=True, screen=0, allowGUI=True, allowStencil=False, monitor=u'testMonitor', color=[-1,-1,-1], colorSpace=u'rgb', blendMode=u'add', useFBO=True, units=u'use preferences') # store frame rate of monitor if we can measure it successfully # Initialize components for Routine "trial"
def run4_func(expInfo): # main function # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__)).decode( sys.getfilesystemencoding()) os.chdir(_thisDir) # Store info about the experiment session expName = u'tnac_exp' # from the Builder filename that created this script expInfo['expName'] = expName # 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']) trg_dict = { "music": 1, "voice": 2, "song": 3, "sound_off": 100, "pause_block": 200, "stop_run": 300, "start_run": 400, "start_block": 500, } #define path to csvs run_var = _thisDir + '/run4.csv' # An ExperimentHandler isn't essential but helps with data saving thisExp = data.ExperimentHandler(name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath=None, 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 # Start Code - component code to be run before the window creation # Setup the Window ## TODO: set window to fullscreen win = visual.Window(size=[1366, 768], fullscr=True, screen=0, allowGUI=True, 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 # Initialize components for Routine "trial" trialClock = core.Clock() stim_1 = sound.Sound('A', secs=-1) stim_1.setVolume(1) fix_1 = visual.TextStim(win=win, name='fix_1', text='+', font='Arial', pos=(0, 0), height=0.1, wrapWidth=None, ori=0, color='white', colorSpace='rgb', opacity=1, depth=-1.0) # Initialize components for Routine "run_start" run_startClock = core.Clock() run_start_msg_screen = visual.TextStim(win=win, name='run_start_msg_screen', text=u'Kurze Pause.', font='Arial', units='norm', pos=[0, 0], height=0.12, wrapWidth=2, ori=0, color='white', colorSpace='rgb', opacity=1, depth=0.0) # Initialize components for Routine "run_trigger_sync" StartClock = core.Clock() run_trigger_syncClock = core.Clock() run_start_msg = visual.TextStim(win=win, name='run_start_msg', text='Durchgang beginnt!', font='Arial', units='norm', pos=[0, 0], height=0.15, wrapWidth=2, ori=0, color='white', colorSpace='rgb', opacity=1, depth=-1.0) movie = visual.MovieStim3( win=win, name='movie', units='pix', noAudio=True, # rename path filename='C:\Paradigmen\AG_Brain\Peer\TNAC\movies\mov4.mkv', ori=0, pos=(0, 0), opacity=1, 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 block_delay = [4, 5, 6] * 12 random.shuffle(block_delay) #print(block_delay) # ------Prepare to start Routine "run_start"------- t = 0 run_startClock.reset() # clock frameN = -1 continueRoutine = True # update component parameters for each repeat run_start_trigger_key = event.BuilderKeyResponse() # keep track of which components have finished run_startComponents = [run_start_msg_screen, run_start_trigger_key] for thisComponent in run_startComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # -------Start Routine "run_start"------- while continueRoutine: # get current time t = run_startClock.getTime() thisExp.addData('start_run', globalClock.getTime()) frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *run_start_msg_screen* updates if t >= 0.0 and run_start_msg_screen.status == NOT_STARTED: # keep track of start time/frame for later run_start_msg_screen.tStart = t run_start_msg_screen.frameNStart = frameN # exact frame index run_start_msg_screen.setAutoDraw(True) # *run_start_trigger_key* updates if t >= 0.0 and run_start_trigger_key.status == NOT_STARTED: # keep track of start time/frame for later run_start_trigger_key.tStart = t run_start_trigger_key.frameNStart = frameN # exact frame index run_start_trigger_key.status = STARTED # keyboard checking is just starting event.clearEvents(eventType='keyboard') if run_start_trigger_key.status == STARTED: theseKeys = event.getKeys(keyList=['s']) # check for quit: if "escape" in theseKeys: endExpNow = True if len(theseKeys) > 0: # at least one key was pressed # a response ends the routine continueRoutine = False # 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 run_startComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=["escape"]): core.quit() # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "run_start"------- for thisComponent in run_startComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # the Routine "run_start" was not non-slip safe, so reset the non-slip timer routineTimer.reset() # ------Prepare to start Routine "run_trigger_sync"------- t = 0 run_trigger_syncClock.reset() # clock frameN = -1 continueRoutine = True # update component parameters for each repeat run_trigger_sync_ = event.BuilderKeyResponse() # keep track of which components have finished run_trigger_syncComponents = [run_trigger_sync_, run_start_msg] for thisComponent in run_trigger_syncComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # -------Start Routine "run_trigger_sync"------- while continueRoutine: # get current time print('waiting for scanner trigger....') t = run_trigger_syncClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *run_trigger_sync_* updates if t >= 0.0 and run_trigger_sync_.status == NOT_STARTED: # keep track of start time/frame for later run_trigger_sync_.tStart = t run_trigger_sync_.frameNStart = frameN # exact frame index run_trigger_sync_.status = STARTED # keyboard checking is just starting win.callOnFlip( run_trigger_sync_.clock.reset) # t=0 on next screen flip event.clearEvents(eventType='keyboard') if run_trigger_sync_.status == STARTED: theseKeys = event.getKeys(keyList=['t']) # check for quit: if "escape" in theseKeys: endExpNow = True if len(theseKeys) > 0: # at least one key was pressed run_trigger_sync_.keys = theseKeys[ -1] # just the last key pressed run_trigger_sync_.rt = run_trigger_sync_.clock.getTime() # a response ends the routine continueRoutine = False # *run_start_msg* updates if t >= 0.0 and run_start_msg.status == NOT_STARTED: # keep track of start time/frame for later run_start_msg.tStart = t run_start_msg.frameNStart = frameN # exact frame index run_start_msg.setAutoDraw(True) frameRemains = 0.0 + 5 - win.monitorFramePeriod * 0.75 # most of one frame period left if run_start_msg.status == STARTED and t >= frameRemains: run_start_msg.setAutoDraw(False) # 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 run_trigger_syncComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=["escape"]): core.quit() # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "run_trigger_sync"------- for thisComponent in run_trigger_syncComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # check responses if run_trigger_sync_.keys in ['', [], None]: # No response was made run_trigger_sync_.keys = None thisExp.addData('run_trigger_sync_.keys', run_trigger_sync_.keys) if run_trigger_sync_.keys != None: # we had a response thisExp.addData('run_trigger_sync_.rt', run_trigger_sync_.rt) run_start_timestamp = StartClock.getTime() send_trigger(400) # the Routine "run_trigger_sync" was not non-slip safe, so reset the non-slip timer routineTimer.reset() start_delay = False delay_counter = 0 #print(block_delay) #print(delay_counter) # start movie for whole run (loop over trials) mov = 'movies/mov4.mkv' #print(mov) movie.setMovie(mov) if t >= 0.0 and movie.status == NOT_STARTED: # keep track of start time/frame for later movie.tStart = t movie.frameNStart = frameN # exact frame index movie.setAutoDraw(True) frameRemains = 0.0 + 2 - win.monitorFramePeriod * 0.75 # most of one frame period left # set up handler to look after randomisation of conditions etc trials = data.TrialHandler(nReps=1, method='sequential', extraInfo=expInfo, originPath=-1, trialList=data.importConditions(run_var), 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.keys(): exec(paramName + '= thisTrial.' + paramName) stimuli_played = 0 for thisTrial in trials: currentLoop = trials # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb) if thisTrial != None: for paramName in thisTrial.keys(): exec(paramName + '= thisTrial.' + paramName) # ------Prepare to start Routine "trial"------- t = 0 trialClock.reset() # clock frameN = -1 continueRoutine = True routineTimer.add(2.000000) # update component parameters for each repeat stim_1.setSound(stimuli, secs=2) #read stimuli into dict and set port value abc = stimuli.split('/')[0] trg = trg_dict.get(abc, 100) # keep track of which components have finished trialComponents = [stim_1, fix_1] for thisComponent in trialComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # -------Start Routine "trial"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = trialClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # start/stop stim_1 if t >= 0.0 and stim_1.status == NOT_STARTED: # keep track of start time/frame for later stim_1.tStart = t stim_1.frameNStart = frameN # exact frame index ## TODO reinstate: send_trigger(abc) #print(abc) stim_1.play( ) # start the sound (it finishes automatically) send_trigger(trg) # send block specific trigger # get time for stimuls start thisExp.addData('stimulus_start_global', globalClock.getTime()) thisExp.addData('stimulus_start_routineTimer', routineTimer.getTime()) thisExp.addData('stimulus_start_', frameN) #print(stim_1) stimuli_played += 1 if stimuli_played % 5 == 0: start_delay = True #print('stimuli_nr:'+str(stimuli_played)) frameRemains = 0.0 + 1.5 - win.monitorFramePeriod * 0.75 # most of one frame period left #frameRemainsdelay = 0.0 + 1.5- win.monitorFramePeriod * 0.75 # most of one frame period left if stim_1.status == STARTED and t >= frameRemains: stim_1.stop() # stop the sound (if longer than duration) send_trigger(100) # send sound off trigger # get info on stim end thisExp.addData('stimulus_end_global', globalClock.getTime()) thisExp.addData('stimulus_end_routineTimer', routineTimer.getTime()) # add delay intervall after 5 stimuli if stimuli_played % 5 == 0 and start_delay and delay_counter != 35: send_trigger(200) delay = block_delay[delay_counter] routineTimer.add(block_delay[delay_counter]) #frameRemainsdelay = 0.0 + 1.5 + delay - win.monitorFramePeriod * 0.75 # most of one frame period left #print('delay='+str(delay_counter)) delay_counter += 1 thisExp.addData('delay_counter', block_delay[delay_counter]) thisExp.addData('block_end_global', globalClock.getTime()) start_delay = False if stim_1.status == STARTED and t >= frameRemains: stim_1.stop() # stop the sound (if longer than duration) send_trigger(100) # send sound off trigger # get info on stim end thisExp.addData('stimulus_end_global', globalClock.getTime()) thisExp.addData('stimulus_end_routineTimer', routineTimer.getTime()) # 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 # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=["escape"]): core.quit() # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() stim_1.stop() # ensure sound has stopped at end of routine thisExp.nextEntry() # completed 1 repeats of 'trials' thisExp.nextEntry() # completed 1 repeats of 'block' if stimuli_played == 180: movie.setAutoDraw(False) send_trigger(300) # END RUN thisExp.saveAsWideText(filename + 'run4' + '.csv') thisExp.saveAsPickle(filename + 'run4') logging.flush() # make sure everything is closed down thisExp.abort() # or data files will save again on exit win.close()
u'PartID': u'' } # starget: SSL target. ttarget: ASL target (third stimulus in the triplet) dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName expInfo['Run'] = "1" # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['PartID'], expName, expInfo['Run']) # An ExperimentHandler isn't essential but helps with data saving thisExp = data.ExperimentHandler(name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath=None, 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 # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window( size=(1366, 768),
from psychopy import data, logging from numpy import random logging.console.setLevel(logging.DEBUG) exp = data.ExperimentHandler(name='testExp', version='0.1', extraInfo={ 'participant': 'jwp', 'ori': 45 }, runtimeInfo=None, originPath=None, savePickle=True, saveWideText=True, dataFileName='testExp') #a first loop (like training?) conds = data.createFactorialTrialList({ 'faceExpression': ['happy', 'sad'], 'presTime': [0.2, 0.3] }) training = data.TrialHandler( trialList=conds, nReps=3, name='train', method='random', seed=100) #this will set the global seed - so fixed for whole exp exp.addLoop(training) #run those trials for trial in training: training.addData('training.rt', random.random() * 0.5 + 0.5) if random.random() > 0.5: training.addData('training.key', 'left') else: