def start(experiment=None, auto_create_subject_id=None, subject_id=None, skip_ready_screen=False): """Start an experiment. This starts an experiment defined by 'experiment' and asks for the subject number. When the subject number is entered and confirmed by ENTER, a data file is created. Eventually, "Ready" will be shown on the screen and the method waits for ENTER to be pressed. After experiment start the following additional properties are available: * experiment.subject -- the current subject id * experiment.data -- the main data file Parameters ---------- experiment : design.Experiment, optional (DEPRECATED) don't use this parameter, it only exists to keep backward compatibility auto_create_subject_id : bool, optional if True new subject id will be created automatically subject_id : integer, optional start with a specific subject_id; no subject id input mask will be presented; subject_id must be an integer; setting this paramter overrules auto_create_subject_id skip_ready_screen : bool, optional if True ready screen will be skipped (default=False) Returns ------- exp : design.Experiment The started experiment will be returned. """ if experiment is None: experiment = expyriment._active_exp if experiment != expyriment._active_exp: raise Exception("Experiment is not the currently initialized " + "experiment!") if experiment.is_started: raise Exception("Experiment is already started!") if subject_id is not None: if not isinstance(subject_id, int): raise Exception("Subject id must be an integer. " + "{0} is not allowed.".format(type(subject_id))) auto_create_subject_id = True elif auto_create_subject_id is None: auto_create_subject_id = defaults.auto_create_subject_id experiment._is_started = True # temporarily switch off log_level old_logging = experiment.log_level experiment.set_log_level(0) screen_colour = experiment.screen.colour experiment._screen.colour = [0, 0, 0] if subject_id is None: default_number = DataFile.get_next_subject_number() else: default_number = subject_id if not auto_create_subject_id: if android is not None: background_stimulus = stimuli.BlankScreen(colour=(0, 0, 0)) fields = [ stimuli.Circle(radius=100, colour=(70, 70, 70), position=(0, 70), anti_aliasing=10), stimuli.Circle(radius=100, colour=(70, 70, 70), position=(0, -70), anti_aliasing=10), stimuli.Rectangle(size=(50, 50), colour=(70, 70, 70), position=(120, 0)) ] fields[0].scale((0.25, 0.25)) fields[1].scale((0.25, 0.25)) plusminus = [ stimuli.TextLine("Subject Number:", text_size=24, text_colour=constants.C_EXPYRIMENT_PURPLE, position=(-182, 0)), stimuli.FixCross(size=(15, 15), position=(0, 70), colour=(0, 0, 0), line_width=2), stimuli.FixCross(size=(15, 2), position=(0, -70), colour=(0, 0, 0), line_width=2), stimuli.TextLine(text="Go", text_size=18, position=(120, 0), text_colour=(0, 0, 0)) ] subject_id = default_number while True: text = stimuli.TextLine( text="{0}".format(subject_id), text_size=28, text_colour=constants.C_EXPYRIMENT_ORANGE) btn = TouchScreenButtonBox( button_fields=fields, stimuli=plusminus + [text], background_stimulus=background_stimulus) btn.show() key, rt = btn.wait() if key == fields[0]: subject_id += 1 elif key == fields[1]: subject_id -= 1 if subject_id <= 0: subject_id = 0 elif key == fields[2]: break experiment._subject = int(subject_id) else: position = (0, 0) while True: ask_for_subject = TextInput( message="Subject Number:", position=position, message_colour=misc.constants.C_EXPYRIMENT_PURPLE, message_text_size=24, user_text_colour=misc.constants.C_EXPYRIMENT_ORANGE, user_text_size=20, background_colour=(0, 0, 0), frame_colour=(70, 70, 70), ascii_filter=misc.constants.K_ALL_DIGITS) subject_id = ask_for_subject.get(repr(default_number)) try: experiment._subject = int(subject_id) break except: pass else: experiment._subject = default_number experiment.screen.clear() experiment.screen.update() experiment._data = DataFile(additional_suffix=experiment.filename_suffix) experiment.data.add_variable_names(experiment.data_variable_names) for txt in experiment.experiment_info: experiment.data.add_experiment_info(txt) for line in experiment.__str__().splitlines(): experiment.data.add_experiment_info(line) for f in experiment.bws_factor_names: _permuted_bws_factor_condition = \ experiment.get_permuted_bws_factor_condition(f) if isinstance(_permuted_bws_factor_condition, unicode): _permuted_bws_factor_condition = \ unicode2str(_permuted_bws_factor_condition) experiment.data.add_subject_info("{0} = {1}".format( unicode2str(f), _permuted_bws_factor_condition)) if experiment.events is not None: experiment.events._time_stamp = experiment.data._time_stamp experiment.events.rename(experiment.events.standard_file_name) number = defaults.initialize_delay - int(experiment.clock.time / 1000) if number > 0: text = stimuli.TextLine("Initializing, please wait...", text_size=24, text_colour=(160, 70, 250), position=(0, 0)) stimuli._stimulus.Stimulus._id_counter -= 1 text.present() text.present() # for flipping with double buffer text.present() # for flipping with tripple buffer while number > 0: counter = stimuli.TextLine( "{num:02d}".format(num=number), text_font='FreeMono', text_size=18, text_bold=True, text_colour=misc.constants.C_EXPYRIMENT_ORANGE, position=(0, -50), background_colour=(0, 0, 0)) stimuli._stimulus.Stimulus._id_counter -= 1 counter.present(clear=False) number -= 1 key = experiment.keyboard.wait(pygame.K_ESCAPE, duration=1000, check_for_control_keys=False) if key[0] is not None: break position = (0, 0) if not skip_ready_screen: stimuli.TextLine( "Ready", position=position, text_size=24, text_colour=misc.constants.C_EXPYRIMENT_ORANGE).present() stimuli._stimulus.Stimulus._id_counter -= 1 if android is None: experiment.keyboard.wait() else: experiment.mouse.wait_press() experiment.set_log_level(old_logging) experiment._screen.colour = screen_colour experiment.log_design_to_event_file() experiment._event_file_log("Experiment,started") return experiment
def start(experiment=None, auto_create_subject_id=None, subject_id=None, skip_ready_screen=False): """Start an experiment. This starts an experiment defined by 'experiment' and asks for the subject number. When the subject number is entered and confirmed by ENTER, a data file is created. Eventually, "Ready" will be shown on the screen and the method waits for ENTER to be pressed. After experiment start the following additional properties are available: * experiment.subject -- the current subject id * experiment.data -- the main data file Parameters ---------- experiment : design.Experiment, optional (DEPRECATED) don't use this parameter, it only exists to keep backward compatibility auto_create_subject_id : bool, optional if True new subject id will be created automatically subject_id : integer, optional start with a specific subject_id; no subject id input mask will be presented; subject_id must be an integer; setting this paramter overrules auto_create_subject_id skip_ready_screen : bool, optional if True ready screen will be skipped (default=False) Returns ------- exp : design.Experiment The started experiment will be returned. """ if experiment is None: experiment = expyriment._active_exp if experiment != expyriment._active_exp: raise Exception("Experiment is not the currently initialized " + "experiment!") if experiment.is_started: raise Exception("Experiment is already started!") if subject_id is not None: if not isinstance(subject_id, int): raise Exception("Subject id must be an integer. " + "{0} is not allowed.".format(type(subject_id))) auto_create_subject_id = True elif auto_create_subject_id is None: auto_create_subject_id = defaults.auto_create_subject_id experiment._is_started = True # temporarily switch off log_level old_logging = experiment.log_level experiment.set_log_level(0) screen_colour = experiment.screen.colour experiment._screen.colour = [0, 0, 0] if subject_id is None: default_number = DataFile.get_next_subject_number() else: default_number = subject_id if not auto_create_subject_id: if android is not None: background_stimulus = stimuli.BlankScreen(colour=(0, 0, 0)) fields = [stimuli.Circle(radius=100, colour=(70, 70, 70), position=(0, 70), anti_aliasing=10), stimuli.Circle(radius=100, colour=(70, 70, 70), position=(0, -70), anti_aliasing=10), stimuli.Rectangle(size=(50, 50), colour=(70, 70, 70), position=(120, 0))] fields[0].scale((0.25, 0.25)) fields[1].scale((0.25, 0.25)) plusminus = [ stimuli.TextLine("Subject Number:", text_size=24, text_colour=constants.C_EXPYRIMENT_PURPLE, position=(-182, 0)), stimuli.FixCross(size=(15, 15), position=(0, 70), colour=(0, 0, 0), line_width=2), stimuli.FixCross(size=(15, 2), position=(0, -70), colour=(0, 0, 0), line_width=2), stimuli.TextLine(text = "Go", text_size=18, position=(120, 0), text_colour=(0, 0, 0))] subject_id = default_number while True: text = stimuli.TextLine( text="{0}".format(subject_id), text_size=28, text_colour=constants.C_EXPYRIMENT_ORANGE) btn = TouchScreenButtonBox( button_fields=fields, stimuli=plusminus+[text], background_stimulus=background_stimulus) btn.show() key, rt = btn.wait() if key == fields[0]: subject_id += 1 elif key == fields[1]: subject_id -= 1 if subject_id <= 0: subject_id = 0 elif key == fields[2]: break experiment._subject = int(subject_id) else: position = (0, 0) while True: ask_for_subject = TextInput( message="Subject Number:", position=position, message_colour=misc.constants.C_EXPYRIMENT_PURPLE, message_text_size=24, user_text_colour=misc.constants.C_EXPYRIMENT_ORANGE, user_text_size=20, background_colour=(0, 0, 0), frame_colour=(70, 70, 70), ascii_filter=misc.constants.K_ALL_DIGITS) subject_id = ask_for_subject.get(repr(default_number)) try: experiment._subject = int(subject_id) break except: pass else: experiment._subject = default_number experiment.screen.clear() experiment.screen.update() experiment._data = DataFile(additional_suffix=experiment.filename_suffix) experiment.data.add_variable_names(experiment.data_variable_names) for txt in experiment.experiment_info: experiment.data.add_experiment_info(txt) for line in experiment.__str__().splitlines(): experiment.data.add_experiment_info(line) for f in experiment.bws_factor_names: _permuted_bws_factor_condition = \ experiment.get_permuted_bws_factor_condition(f) if isinstance(_permuted_bws_factor_condition, unicode): _permuted_bws_factor_condition = \ unicode2str(_permuted_bws_factor_condition) experiment.data.add_subject_info("{0} = {1}".format( unicode2str(f), _permuted_bws_factor_condition)) if experiment.events is not None: experiment.events._time_stamp = experiment.data._time_stamp experiment.events.rename(experiment.events.standard_file_name) number = defaults.initialize_delay - int(experiment.clock.time / 1000) if number > 0: text = stimuli.TextLine("Initializing, please wait...", text_size=24, text_colour=(160, 70, 250), position=(0, 0)) stimuli._stimulus.Stimulus._id_counter -= 1 text.present() text.present() # for flipping with double buffer text.present() # for flipping with tripple buffer while number > 0: counter = stimuli.TextLine( "{num:02d}".format(num=number), text_font='FreeMono', text_size=18, text_bold=True, text_colour=misc.constants.C_EXPYRIMENT_ORANGE, position=(0, -50), background_colour=(0, 0, 0)) stimuli._stimulus.Stimulus._id_counter -= 1 counter.present(clear=False) number -= 1 key = experiment.keyboard.wait(pygame.K_ESCAPE, duration=1000, check_for_control_keys=False) if key[0] is not None: break position = (0, 0) if not skip_ready_screen: stimuli.TextLine("Ready", position=position, text_size=24, text_colour=misc.constants.C_EXPYRIMENT_ORANGE).present() stimuli._stimulus.Stimulus._id_counter -= 1 if android is None: experiment.keyboard.wait() else: experiment.mouse.wait_press() experiment.set_log_level(old_logging) experiment._screen.colour = screen_colour experiment.log_design_to_event_file() experiment._event_file_log("Experiment,started") return experiment
def start(experiment=None, auto_create_subject_id=None): """Start an experiment. This starts an experiment defined by 'experiment' and asks for the subject number. When the subject number is entered and confirmed by ENTER, a data file is created. Eventually, "Ready" will be shown on the screen and the method waits for ENTER to be pressed. After experiment start the following additional properties are available: * experiment.subject -- the current subject id * experiment.data -- the main data file Parameters ---------- experiment : design.Experiment, optional (DEPRECATED) Don't use this parameter, it only exists to keep backward compatibility. auto_create_subject_id : bool if true new subject id will be created automatically Returns ------- exp : design.Experiment The started experiment will be returned. """ if experiment is None: experiment = expyriment._active_exp if experiment != expyriment._active_exp: raise Exception("Experiment is not the currently initialized " + "experiment!") if experiment.is_started: raise Exception("Experiment is already started!") if auto_create_subject_id is None: auto_create_subject_id = defaults.auto_create_subject_id experiment._is_started = True # temporarily switch off log_level old_logging = experiment.log_level experiment.set_log_level(0) screen_colour = experiment.screen.colour experiment._screen.colour = [0, 0, 0] default_number = DataFile.get_next_subject_number() if not auto_create_subject_id: if android is not None: position = (0, 200) else: position = None while True: ask_for_subject = TextInput(message="Subject Number:", position=position, message_colour=misc.constants.C_EXPYRIMENT_PURPLE, message_text_size=24, user_text_colour=misc.constants.C_EXPYRIMENT_ORANGE, user_text_size=20, background_colour=(0, 0, 0), frame_colour=(70, 70, 70), ascii_filter=misc.constants.K_ALL_DIGITS) subject_id = ask_for_subject.get(repr(default_number)) try: experiment._subject = int(subject_id) break except: pass else: experiment._subject = default_number experiment.screen.clear() experiment.screen.update() experiment._data = DataFile(additional_suffix=experiment.filename_suffix) experiment.data.add_variable_names(experiment.data_variable_names) for txt in experiment.experiment_info: experiment.data.add_experiment_info(txt) for line in experiment.__str__().splitlines(): experiment.data.add_experiment_info(line) for f in experiment.bws_factor_names: experiment.data.add_subject_info("{0} = {1}".format(f, experiment.get_permuted_bws_factor_condition(f))) if experiment.events is not None: experiment.events._time_stamp = experiment.data._time_stamp experiment.events.rename(experiment.events.standard_file_name) number = defaults.initialize_delay - int(experiment.clock.time / 1000) if number > 0: text = stimuli.TextLine("Initializing, please wait...", text_size=24, text_colour=(160, 70, 250), position=(0, 0)) stimuli._stimulus.Stimulus._id_counter -= 1 text.present() text.present() # for flipping with double buffer text.present() # for flipping with tripple buffer while number > 0: counter = stimuli.TextLine("{num:02d}".format(num=number), text_font='Monospace', text_size=18, text_bold=True, text_colour=misc.constants.C_EXPYRIMENT_ORANGE, position=(0, -50), background_colour=(0, 0, 0)) stimuli._stimulus.Stimulus._id_counter -= 1 counter.present(clear=False) number -= 1 key = experiment.keyboard.wait(pygame.K_ESCAPE, duration=1000, check_for_control_keys=False) if key[0] is not None: break stimuli.TextLine("Ready", text_size=24, text_colour=misc.constants.C_EXPYRIMENT_ORANGE).present() stimuli._stimulus.Stimulus._id_counter -= 1 experiment.keyboard.wait() experiment.set_log_level(old_logging) experiment._screen.colour = screen_colour experiment.log_design_to_event_file() experiment._event_file_log("Experiment,started") return experiment