def test_psydat_filename_collision_overwriting2(self): for count in [1, 10, 20]: trials = data.TrialHandler2([], 1, autoLog=False) for trial in trials: #need to run trials or file won't be saved trials.addData('trialType', 0) base_data_filename = pjoin(self.temp_dir, self.rootName + 'overwrite') trials.saveAsPickle(base_data_filename, fileCollisionMethod='overwrite') # Make sure the file just saved is there data_filename = base_data_filename + '.psydat' assert os.path.exists( data_filename ), "File not found: %s" % os.path.abspath(data_filename) # Make sure the correct number of files for the loop are there. (No overwriting by default). matches = len( glob.glob( os.path.join(self.temp_dir, self.rootName + "*overwrite.psydat"))) assert matches == 1, "Found %d matching files, should be %d" % ( matches, count)
from random import random from psychopy import data # create your list of stimuli # NB as of version 1.62 you could simply import an excel spreadsheet with this # using data.importConditions('someFile.xlsx') stimList = [] for ori in range(90, 180, 30): for sf in [0.5, 1.0, 2.0]: # append a python 'dictionary' to the list stimList.append({'sf': sf, 'ori': ori}) # organize them with the trial handler trials = data.TrialHandler2(stimList, 10, extraInfo={ 'participant': "Nobody", 'session': 1 }) # run the experiment nDone = 0 for thisTrial in trials: # handler can act like a for loop # simulate some data thisReactionTime = random() + float(thisTrial['sf']) / 2.0 thisChoice = round(random()) trials.addData('RT', thisReactionTime) # add the data to our set trials.addData('choice', thisChoice) nDone += 1 # just for a quick reference msg = 'trial %i had position %s in the list (sf=%.1f)' print(msg % (nDone, trials.thisIndex, thisTrial['sf']))
def test_json_dump_to_file(self): t = data.TrialHandler2(self.conditions, nReps=5) t.saveAsJson(fileName=self.temp_dir, fileCollisionMethod='overwrite')
def test_comparison_not_equal_after_iteration(self): t1 = data.TrialHandler2([dict(foo=1)], 2, seed=1) t2 = data.TrialHandler2([dict(foo=1)], 3, seed=1) t1.__next__() t2.__next__() assert t1 != t2
def test_comparison_not_equal(self): t1 = data.TrialHandler2([dict(foo=1)], 2, seed=1) t2 = data.TrialHandler2([dict(foo=1)], 3, seed=1) assert t1 != t2
seconds = datetime.datetime.strftime(datetime.datetime.now(), "%H%M%S") # # logging logfilename = "info_%s_%d_%s.log" % (subjid, run, seconds) logfile = os.path.join(logdir, logfilename) lastLog = logging.LogFile(logfile, level=logging.INFO, filemode='w') logging.log(level=logging.INFO, msg='run %s, loading at epoch %s' % (run, seconds)) logging.flush() # when its okay to write # trial settings and timing sacc_trials = data.TrialHandler2(trialdf.T.to_dict().values(), 1, method='sequential', extraInfo={ 'subjid': subjid, 'epoch': seconds, }) # ## Run calibration if we need it if calEyeScreen: c = showCal(task.win) c.calibrate() # # run saccade trials # blockstarttime=core.getTime() eyetrackingfile = '%s_run%d_%s.txt' % (subjid, run, seconds) task.eyetracking_newfile('%s' % eyetrackingfile) blockstarttime = task.wait_for_scanner(scannerTriggerKeys, run_getReadyMsg) logging.log(level=logging.INFO, msg='scanner trigger recieved at %d' % blockstarttime)
def test_json_dump_to_file(self): _, path = mkstemp(dir=self.temp_dir, suffix='.json') t = data.TrialHandler2(self.conditions, nReps=5) t.saveAsJson(fileName=path, fileCollisionMethod='overwrite')
def test_comparison_equals_after_iteration(self): t1 = data.TrialHandler2([dict(foo=1)], 2, seed=self.random_seed) t2 = data.TrialHandler2([dict(foo=1)], 2, seed=self.random_seed) t1.__next__() t2.__next__() assert t1 == t2
def test_comparison_equals(self): t1 = data.TrialHandler2([dict(foo=1)], 2, seed=self.random_seed) t2 = data.TrialHandler2([dict(foo=1)], 2, seed=self.random_seed) assert t1 == t2
(subjid, tasktype, imgset, timepoint) = getInfoFromDataPath(datadir) trialdf = recallFromPickle(pckl, settings['lastrun'], settings['firstrun'] - 1) # set correct keys and format for trialhandler trialdict = trialdf.reset_index().T.to_dict().values() trialdict = [ dict(x.items() + {'corkeys': response_should_be(x['pos'], accept_keys)}.items()) for x in trialdict ] seconds = datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S") extraInfo = {'subjid': subjid, 'epoch': seconds} recall_trials = data.TrialHandler2(trialdict, 1, extraInfo=extraInfo) # # screen setup win = create_window(settings['fullscreen']) # win settings win.winHandle.activate() # make sure the display window has focus win.mouseVisible = False # and that we dont see the mouse # task class task = mgsTask(win, accept_keys) task.init_recall_side() if settings['instructions']: task.recall_instructions()
# Press 'space' to and the run (will move on to the next run if there is one) event.waitKeys(keyList=('space')) # ===================== # MAIN # # - set up stimuli and runs #sys.exit() #################### MAIN #################### for idx, this_run in enumerate(runs): # 2 runs in total #print(run) #note the the input 'run' has already been raddomized, so it is okay to use 'sequential' here trials = data.TrialHandler2(this_run, 1, extraInfo=run_data) #dataTypes=['stim_onset', 'resp_onset', 'rt', 'resp'], #method='sequential') #pdb.set_trace() nextrun = idx + 1 #print(trials) do_run(nextrun, trials) #print("stopping program here at: " + str(random.randint(0,100))) #sys.exit() win.close() core.quit() #sys.exit()