예제 #1
0
def execute_task(task_type: dict, parameters: dict, save_folder: str) -> bool:
    """Excecute Task.

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

    Input:
        parameters (dict): parameter dictionary
        task_type (dict): type and mode of experiment
        save_folder (str): path to save folder
    """
    signal_model = None
    language_model = None
    filename = None

    exp_type = ExperimentType(task_type['exp_type'])
    fake = parameters['fake_data']

    # Init EEG Model, if needed. Calibration Tasks Don't require probabilistic
    # modules to be loaded.
    if not fake and exp_type not in ExperimentType.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:
            logging.debug('Cannot load signal model. Exiting')
            raise e

        # if Language Model enabled init lm
        if parameters['languagemodelenabled']:
            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,
                   exp_type,
                   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)
예제 #2
0
    def test_init_display_window_returns_psychopy_window(self):
        """Test display window is created."""

        display_window = init_display_window(self.parameters)

        self.assertIsInstance(display_window, type(self.window))
        self.assertEqual(display_window, self.window)
예제 #3
0
    def test_img_path(self):
        """Test img_path method"""

        parameters = self.parameters
        parameters['window_height'] = 1
        parameters['window_width'] = 1
        parameters['is_txt_stim'] = False
        img_path = 'bcipy/static/images/rsvp_images/'
        parameters['path_to_presentation_images'] = img_path

        fixation = 'bcipy/static/images/bci_main_images/PLUS.png'
        # TODO: can this be mocked?
        display = init_display_window(parameters)
        daq = mock()
        file_save = ""
        signal_model = None
        language_model = None
        fake = True
        auc_filename = ""

        with patch('bcipy.tasks.rsvp.icon_to_icon.open', mock_open()):
            task = RSVPIconToIconTask(display, daq, parameters, file_save,
                                      signal_model, language_model, fake,
                                      False, auc_filename)
            self.assertTrue(len(task.alp) > 0)
            self.assertTrue('PLUS' not in task.alp)

            self.assertEqual('bcipy/static/images/rsvp_images/A.png',
                             task.img_path('A'))
            self.assertEqual('A.png', task.img_path('A.png'))
            self.assertEqual(fixation, task.img_path(fixation))
        display.close()
예제 #4
0
    def setUp(self):
        """Set up needed items for test."""

        parameters_used = 'bcipy/parameters/parameters.json'
        self.window = mock()
        when(psychopy.visual).Window(size=any(),
                                     screen=any(),
                                     allowGUI=False,
                                     useFBO=False,
                                     fullscr=any(bool),
                                     allowStencil=False,
                                     monitor=any(str),
                                     winType='pyglet',
                                     units=any(),
                                     waitBlanking=False,
                                     color=any(str)).thenReturn(self.window)

        self.parameters = load_json_parameters(parameters_used,
                                               value_cast=True)

        self.display_window = init_display_window(self.parameters)
예제 #5
0
            set of variables.
        """
        return self.width, self.height

    def _reset_stimuli(self) -> None:
        """Reset Stimuli.

        Used when redrawing stimuli. Sets the stimuli array and starting
            x positions to their starting values. If using vertical bars
            this should reset the y positions instead.
        """
        # reset stimuli
        self.stimuli = []
        self.position_x = self.parameters['feedback_pos_x']


if __name__ == '__main__':
    from bcipy.helpers.load import load_json_parameters
    from bcipy.display.display_main import init_display_window

    # Load a parameters file
    parameters = load_json_parameters('bcipy/parameters/parameters.json', value_cast=True)
    display = init_display_window(parameters)
    clock = core.Clock()
    feedback = LevelFeedback(display, parameters, clock)

    for index, _ in enumerate(feedback.level_colors):
        # the position argument is based on index starting at 1
        index += 1
        feedback.administer(position=index)
예제 #6
0
def execute_task(task_type: dict, parameters: dict, save_folder: str) -> bool:
    """Excecute Task.

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

    Input:
        parameters (dict): parameter dictionary
        task_type (dict): type and mode of experiment
        save_folder (str): path to save folder
    """

    fake = parameters['fake_data']

    # Init EEG Model, if needed. Calibration Tasks Don't require probalistic
    #   modules to be loaded.
    if task_type['exp_type'] > 1:

        # Try loading in our classifier and starting a langmodel(if enabled)
        try:

            # EEG Model, Load in pre-trained classifier
            if fake:
                classifier = None
            else:
                classifier = load_classifier()

        except Exception as e:
            print("Cannot load EEG classifier. Exiting")
            raise e

        # if Language Model enabled and data not fake, init lm
        if parameters['languagemodelenabled'] == 'true' \
                and not fake:
            try:
                lmodel = init_language_model(parameters)
            except:
                print("Cannot init language model. Setting to None.")
                lmodel = None
        else:
            lmodel = None

    else:
        classifier = None
        lmodel = None

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

    # Initialize Display Window
    display = init_display_window(parameters)

    # Start Task
    try:
        start_task(display,
                   daq,
                   task_type,
                   parameters,
                   save_folder,
                   lmodel=lmodel,
                   classifier=classifier,
                   fake=fake)

    # 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)