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): 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): # Get the experiment parameters mode = arglist.pop(0) p = cregg.Params(mode) p.set_by_cmdline(arglist) # Assign the frame identities randomly over subjects id = p.subject if p.cbid is None else p.cbid state = cregg.subject_specific_state(id) frame_ids = state.permutation(list(letters[:2 * p.frame_per_context])) p.frame_ids = frame_ids.reshape(2, -1).tolist() # Open up the stimulus window win = cregg.launch_window(p) p.win_refresh_hz = win.refresh_hz # Set up the stimulus objects fix = visual.GratingStim(win, tex=None, mask=p.fix_shape, interpolate=True, color=p.fix_iti_color, size=p.fix_size) instruct_text = dedent(p.instruct_text) instruct = cregg.WaitText(win, instruct_text, height=p.instruct_size, advance_keys=p.wait_keys, quit_keys=p.quit_keys) stims = dict(frame=Frame(win, p, fix), dots=Dots(win, p), fix=fix, instruct=instruct, ) if hasattr(p, "break_text"): break_text = dedent(p.break_text) take_break = cregg.WaitText(win, break_text, height=p.break_text_size, advance_keys=p.wait_keys, quit_keys=p.quit_keys) stims["break"] = take_break if hasattr(p, "finish_text"): finish_text = dedent(p.finish_text) finish_run = cregg.WaitText(win, finish_text, height=p.break_text_size, 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): # 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()))