def main(arglist): p = cregg.Params("scan") p.set_by_cmdline(arglist) win = cregg.launch_window(p) cregg.WaitText(win, "+", height=2, color="black", advance_keys=[], quit_keys=p.quit_keys).draw()
def main(arglist): mode = arglist.pop(0) p = cregg.Params(mode) p.set_by_cmdline(arglist) data_temp = p.log_base.format(subject=p.subject, run=99) + ".csv" data_temp = data_temp.replace("99", "??") next_run = len(glob(data_temp)) + 1 print("Next run for {} {} is # {}".format(p.subject, mode, next_run))
def main(arglist): p = cregg.Params("scan") p.set_by_cmdline(arglist) win = cregg.launch_window(p) visual.Circle(win, p.array_radius, edges=128, lineColor="white", lineWidth=2).draw() win.flip() event.waitKeys(keyList=p.quit_keys)
def main(arglist): # Load the parameters and launch the window p = cregg.Params("practice") p.set_by_cmdline(arglist) sticks.subject_specific_colors(p) win = cregg.launch_window(p) # Increase the chroma as color is degraded by ffmpeg p.chroma = 45 p.debug = False # Load the stimulus object cue = sticks.PolygonCue(win, p) fix = sticks.Fixation(win, p) array = sticks.StickArray(win, p) array.reset() # Make a movie of two trials for trial in range(2): # Pre-stim fixation for _ in xrange(60): fix.draw() win.flip() win.getMovieFrame() # Orienting cue fix.color = p.fix_stim_color for _ in xrange(43): fix.draw() win.flip() win.getMovieFrame() # Set the cue and stimulus features shape = 4 if trial else 6 cue.set_shape(shape) ps = [.6, .6] if trial else [.4, .4] array.set_feature_probs(*ps) # Show the stimulus for _ in xrange(120): array.update() array.draw() cue.draw() fix.draw() win.flip() win.getMovieFrame() # Post stim fixation fix.color = p.fix_iti_color for _ in xrange(60): fix.draw() win.flip() win.getMovieFrame() win.close() # Write out the image frames dir = mkdtemp() win.saveMovieFrames(dir + "/frame.png") # Convert to mp4 check_output([ "ffmpeg", "-r", "60", "-i", dir + "/frame%03d.png", "-f", "mp4", "-vcodec", "mpeg4", "-b:v", "5000k", "-r", "60", "stim_movie.mp4" ]) # Clean up the temporary directory shutil.rmtree(dir)
def main(arglist): # Get the experiment parameters mode = arglist.pop(0) p = cregg.Params(mode) p.set_by_cmdline(arglist) # Open up the stimulus window win = cregg.launch_window(p) p.win_refresh_hz = win.refresh_hz visual.TextStim(win, "Generating stimuli...", height=p.setup_text_size).draw() win.flip() # Randomize the response mappings consistently by subject counterbalance_feature_response_mapping(p) # Counterbalance the frame - cue mappings consistently by subject counterbalance_cues(p) # Load the subject specific lightness values for the second color subject_specific_colors(p) # Fixation point fix = Fixation(win, p) # The main stimulus arrays array = StickArray(win, p) # Polygon that cues the context for each block cue = PolygonCue(win, p) # The guide text that helps during training and practice guide = LearningGuide(win, p) # Progress bar to show during behavioral breaks progress = ProgressBar(win, p) stims = dict( fix=fix, cue=cue, array=array, guide=guide, progress=progress, ) # Instructions if hasattr(p, "instruct_text"): instruct = cregg.WaitText(win, p.instruct_text, advance_keys=p.wait_keys, quit_keys=p.quit_keys) stims["instruct"] = instruct # Text that allows subjects to take a break between blocks if hasattr(p, "break_text"): take_break = cregg.WaitText(win, p.break_text, advance_keys=p.wait_keys, quit_keys=p.quit_keys) stims["break"] = take_break # Text that alerts subjects to the end of an experimental run if hasattr(p, "finish_text"): finish_run = cregg.WaitText(win, p.finish_text, advance_keys=p.finish_keys, quit_keys=p.quit_keys) stims["finish"] = finish_run # Execute the experiment function globals()[mode](p, win, stims)
def main(arglist): p = cregg.Params("calibrate") p.set_by_cmdline(arglist) # Open up the stimulus window win = cregg.launch_window(p) p.win_refresh_hz = win.refresh_hz # Determine the fixed and moving color parameters fixed_L = p.lightness C = p.chroma fixed_h, moving_h = p.stick_hues # Initialize the stimulus object patches = ColorPatches(win, p) # Initialize the staircase conditions = [{ "stepType": "lin", "nReversals": p.reversals, "nUp": 1, "nDown": 1, "stepSizes": p.step_sizes, "startVal": val, "label": label } for (val, label) in zip(p.start_vals, ["low", "high"])] stairs = MultiStairHandler(nTrials=p.trials, conditions=conditions) # Showt the instructions instruct = cregg.WaitText(win, p.instruct_text, advance_keys=p.wait_keys, quit_keys=p.quit_keys) instruct.draw() # Initialize the clock clock = core.Clock() # Start the log file log_cols = ["staircase", "moving_L", "choice", "time"] p.log_base = p.log_base.format(subject=p.subject, monitor=p.monitor_name) log = cregg.DataLog(p, log_cols) # Initialize a randomizer rs = np.random.RandomState() for moving_L, conditions in stairs: # Randomize the sides that each hue is shown on if rs.rand() < .5: # Show fixed color on the left and moving color on the right colors = (fixed_L, C, fixed_h), (moving_L, C, moving_h) # A "right" response will mean the moving color is brighter # This will be treated as "correct" and will adjust it down trial_resp_keys = p.resp_keys[:] else: # Show fixed color on the right and moving color on the left colors = (moving_L, C, moving_h), (fixed_L, C, fixed_h) # A "left" response will mean the moving color is brighter # This will be treated as "incorrect" and will adjust it up trial_resp_keys = p.resp_keys[::-1] # Update the colors of the patches and draw them patches.set_colors(*colors) patches.draw() win.flip() # Listen for the first valid keypress resp, time = event.waitKeys(keyList=p.resp_keys, timeStamped=clock)[0] resp_code = trial_resp_keys.index(resp) # Update the staircase object stairs.addResponse(resp_code) # Update the log log.add_data( dict(staircase=conditions["label"], moving_L=moving_L, choice=resp_code, time=time)) # Wait for the next trial win.flip() cregg.wait_check_quit(p.iti) # Compute the lightness to use for the moving hue low_reversals = stairs.staircases[0].reversalIntensities[-p.reversals:] high_reversals = stairs.staircases[1].reversalIntensities[-p.reversals:] reversals = np.r_[low_reversals, high_reversals] L = reversals.mean() # Save out a final with the final calibrated L cal_fname = p.color_file.format(subject=p.subject, monitor=p.monitor_name) with open(cal_fname, "w") as fid: json.dump(dict(calibrated_L=L), fid) # Print a summary print("Total trials: {:d}".format(stairs.totalTrials)) print("Final luminance: {:.2f}".format(L)) print("Std. dev. of reversal points: {:.2f}".format(reversals.std()))
def main(arglist): # Load the psychophysics parameters p = cregg.Params("psychophys") p.set_by_cmdline(arglist) # Find data files and combine across runs dfs = [] for run in p.fit_runs: fname = p.log_base.format(subject=p.subject, run=run) + ".csv" df = pd.read_csv(fname).dropna() dfs.append(df) df = pd.concat(dfs, ignore_index=True) # Fit to the whole dataset to get a more robust initial guess initial_guess = FitWeibull(df.context_strength, df.correct).params # Initialize the output data structure stim_strength = dict(hue=dict(), ori=dict()) # Initialize the plot f, axes = plt.subplots(1, 2, figsize=(8, 4), sharey=True) axes = dict(zip(["hue", "ori"], axes)) colors = dict(hue="m", ori="c") xx = np.linspace(0, .25, 100) for context, df_context in df.groupby("context"): # Fit the psychometric function model = FitWeibull(df_context.context_strength, df_context.correct, guess=initial_guess) # Plot the data and model fit ax = axes[context] sns.regplot("context_strength", "correct", data=df_context, fit_reg=False, x_estimator=np.mean, x_ci=68, color=colors[context], ax=ax) ax.plot(xx, model.eval(xx), colors[context], lw=2) ax.set(xlim=(0, .25), ylim=(.4, 1), title=context) for diff in ["easy", "hard"]: # Find the estimated strength values a = p.strength_acc_targets[diff] s = min(model.inverse(a), .25) stim_strength[context][diff] = s # Plot them ax.plot([s, s], [.4, a], c=".5", ls="--") ax.plot([0, s], [a, a], c=".5", ls="--") # Finalize the plot axes["ori"].set(ylabel="") f.tight_layout() png_name = p.strength_file_base.format(subject=p.subject) f.savefig(png_name, filetype="png") # Write out the strength values for the scan json_fname = p.strength_file_base.format(subject=p.subject) + ".json" with open(json_fname, "w") as fid: json.dump(stim_strength, fid) # Open up the image os.system("open {}.png".format(png_name))