Beispiel #1
0
def execute_task(task: TaskType, parameters: dict, save_folder: str) -> bool:
    """Execute Task.

    Executes the desired task by setting up the display window and
        data acquisition, then passing on to the start_task function
        which will initialize experiment.

    Input:
        task(str): registered bcipy TaskType
        parameters (dict): parameter dictionary
        save_folder (str): path to save folder
    """
    signal_model = None
    language_model = None
    filename = None

    fake = parameters['fake_data']

    # Init EEG Model, if needed. Calibration Tasks Don't require probabilistic
    # modules to be loaded.
    if not fake and task not in TaskType.calibration_tasks():
        # Try loading in our signal_model and starting a langmodel(if enabled)
        try:
            signal_model, filename = load_signal_model()
        except Exception as e:
            print(f'Cannot load signal model. Exiting. {e}')
            raise e

        # if Language Model enabled init lm
        if parameters['lang_model_enabled']:
            language_model = init_language_model(parameters)

    # Initialize DAQ
    daq, server = init_eeg_acquisition(
        parameters, save_folder, server=fake)

    # Initialize Display Window
    # We have to wait until after the prompt to load the signal model before
    # displaying the window, otherwise in fullscreen mode this throws an error
    display = init_display_window(parameters)
    print_message(display, 'Initializing...')

    # Start Task
    try:
        start_task(
            display, daq, task, parameters, save_folder,
            language_model=language_model,
            signal_model=signal_model, fake=fake, auc_filename=filename)

    # If exception, close all display and acquisition objects
    except Exception as e:
        _clean_up_session(display, daq, server)
        raise e

    return _clean_up_session(display, daq, server)
Beispiel #2
0
    def test_can_use_lsl(self):
        """Test init_eeg_acquisition with LSL device"""

        params = self.parameters
        params['acq_device'] = 'LSL'

        client, server = init_eeg_acquisition(params, self.save, server=True)

        with client:
            time.sleep(0.1)
        client.cleanup()
        server.stop()

        self.assertEqual(client.device_info.name, 'LSL')
        self.assertEqual(client.device_info.fs, 256)
Beispiel #3
0
    def test_default_values(self):
        self.parameters['acq_device'] = 'DSI'

        client, server = init_eeg_acquisition(self.parameters,
                                              self.save,
                                              server=True)

        client.start_acquisition()
        time.sleep(0.1)
        client.stop_acquisition()
        client.cleanup()
        server.stop()

        self.assertEqual(client.device_info.name,
                         self.parameters['acq_device'])
        self.assertEqual(client.device_info.fs, 300)
Beispiel #4
0
    def test_allows_customization(self):
        """Test init_eeg_acquisition with custom values."""

        params = self.parameters
        params['raw_data_name'] = 'foo.csv'
        params['acq_port'] = 9000
        params['acq_device'] = 'DSI'

        client, server = init_eeg_acquisition(params, self.save, server=True)

        with client:
            time.sleep(0.1)
        client.cleanup()
        server.stop()

        self.assertEqual(client.device_info.name, params['acq_device'])
        self.assertEqual(client.device_info.fs, 300)
Beispiel #5
0
    def test_default_values(self):
        print("Testing init_eeg_acquisition with default values.")

        self.parameters['acq_device'] = 'DSI'

        client, server = init_eeg_acquisition(
            self.parameters, self.save, server=True)

        client.start_acquisition()
        time.sleep(0.1)
        client.stop_acquisition()
        client.cleanup()
        server.stop()
        server.join()

        self.assertTrue('raw_data.csv' in client._processor._filename)
        self.assertEqual(client.device_info.name, self.parameters['acq_device'])
        self.assertEqual(client.device_info.fs, 300)