def test_throws_error_if_given_incorrect_params_path(self): # try passing a parameters file that does not exist with self.assertRaises(Exception): init_save_data_structure(self.data_save_path, self.user_information, 'does_not_exist.json', self.task, self.experiment)
def test_throws_useful_error_if_given_incorrect_params_path(self): # try passing a parameters file that does not exist with self.assertRaises(Exception): init_save_data_structure( self.data_save_path, 'new_user', 'does_not_exist.json')
def bci_main(parameters: dict, user: str, exp_type: int, mode: str) -> bool: """BCI Main. The BCI main function will initialize a save folder, construct needed information and execute the task. This is the main connection between any UI and running the app. It may also be invoked via tha command line. Ex. `python bci_main.py` this will default parameters, mode, user, and type. You can pass it those attributes with flags, if desired. Ex. `python bci_main.py --user "bci_user" --mode "SHUFFLE"` Input: parameters (dict): parameter dictionary user (str): name of the user exp_type (int): type of experiment. Ex. 1 = calibration mode (str): BCI mode. Ex. RSVP, SHUFFLE, MATRIX """ # Define the parameter and data save location parameter_location = parameters['parameter_location'] data_save_location = parameters['data_save_loc'] # Initialize Save Folder save_folder = init_save_data_structure(data_save_location, user, parameter_location, mode, exp_type) # Register Task Type task_type = {'mode': mode, 'exp_type': exp_type} return execute_task(task_type, parameters, save_folder)
def setUp(self): # set up the needed paths and initial data save structure self.data_save_path = 'data/' self.user_information = 'test_user_002' self.parameters_used = 'bcipy/parameters/parameters.json' self.save_folder_name = init_save_data_structure( self.data_save_path, self.user_information, self.parameters_used)
def bci_main(parameter_location: str, user: str, task: TaskType, experiment: str = DEFAULT_EXPERIMENT_ID) -> bool: """BCI Main. The BCI main function will initialize a save folder, construct needed information and execute the task. This is the main connection between any UI and running the app. It may also be invoked via tha command line. Ex. `python bci_main.py` this will default parameters, mode, user, and type. You can pass it those attributes with flags, if desired. Ex. `python bci_main.py --user "bci_user" --task "RSVP Calibration" --experiment "default" Input: parameter_location (str): location of parameters file to use user (str): name of the user task (TaskType): registered bcipy TaskType experiment_id (str): Name of the experiment. Default name is DEFAULT_EXPERIMENT_ID. """ validate_experiment(experiment) # Load parameters parameters = load_json_parameters(parameter_location, value_cast=True) # Update property to reflect the parameter source parameters['parameter_location'] = parameter_location if parameter_location != DEFAULT_PARAMETERS_PATH: parameters.save() default_params = load_json_parameters(DEFAULT_PARAMETERS_PATH, value_cast=True) if parameters.add_missing_items(default_params): raise Exception('Parameters file out of date.') # update our parameters file with system related information sys_info = get_system_info() # Initialize Save Folder save_folder = init_save_data_structure( parameters['data_save_loc'], user, parameter_location, task=task.label, experiment_id=experiment) # configure bcipy session logging configure_logger(save_folder, log_name=parameters['log_name'], version=sys_info['bcipy_version']) logging.getLogger(__name__).info(sys_info) # Collect experiment field data collect_experiment_field_data(experiment, save_folder) return execute_task(task, parameters, save_folder)
def setUp(self): """set up the needed path for load functions.""" self.parameters_used = 'bcipy/parameters/parameters.json' self.parameters = load_json_parameters(self.parameters_used, value_cast=True) self.data_save_path = 'data/' self.user_information = 'test_user_001' self.save = init_save_data_structure(self.data_save_path, self.user_information, self.parameters_used)
def test_save_structure_adds_experiment_id_when_provided_as_argument(self): experiment_id = 'test' response = init_save_data_structure(self.data_save_path, self.user_information, self.parameters_used, self.task, experiment_id=experiment_id) task = self.task.replace(' ', '_') expected = ( f'{self.data_save_path}{experiment_id}' f'/{self.user_information}/{self.user_information}_{task}_{self.dt}' ) self.assertEqual(response, expected)
def setUp(self): """Set Up.""" # set up the needed data to start a task parameters_used = 'bcipy/parameters/parameters.json' self.parameters = load_json_parameters(parameters_used, value_cast=True) self.parameters['num_sti'] = 1 # Mock the display window self.display_window = mock() self.display_window.size = [1] # Mock the frame rate return when(self.display_window).getActualFrameRate().thenReturn(60) self.text_stim = mock() self.text_stim.height = 2 self.text_stim.boundingBox = [1] # Mock the psychopy text stims and image stims we would expect when(psychopy.visual).TextStim(win=self.display_window, text=any(), font=any()).thenReturn(self.text_stim) when(psychopy.visual).TextStim(win=self.display_window, color=any(str), height=any(), text=any(), font=any(), pos=any(), wrapWidth=any(), colorSpace=any(), opacity=any(), depth=any()).thenReturn(self.text_stim) when(psychopy.visual).ImageStim(self.display_window, image=any(str), size=any(), pos=any(), mask=None, ori=any()).thenReturn(self.text_stim) # save data information self.data_save_path = 'data/' self.user_information = 'test_user_001' self.file_save = init_save_data_structure(self.data_save_path, self.user_information, parameters_used) # Mock the data acquistion self.daq = mock() self.daq.is_calibrated = True self.daq.marker_writer = None
def setUp(self): # set up the needed paths and initial data save structure self.data_save_path = tempfile.mkdtemp() self.user_information = 'test_user_002' self.parameters_used = 'bcipy/parameters/parameters.json' self.task = 'RSVP Calibration' self.experiment = DEFAULT_EXPERIMENT_ID self.save_folder_name = init_save_data_structure( self.data_save_path, self.user_information, self.parameters_used, self.task) self.dt = '10' # mock save modules use of strftime to return an empty string when(save).strftime(any(), any()).thenReturn(self.dt)