示例#1
0
 def generate_stimuli(self):
     """Generates the sequences to be presented.
     Returns:
     --------
         tuple(
             samples[list[list[str]]]: list of sequences
             timing(list[list[float]]): list of timings
             color(list(list[str])): list of colors)
     """
     return random_rsvp_calibration_seq_gen(self.alp,
                                            stim_number=self.stim_number,
                                            stim_length=self.stim_length,
                                            timing=self.timing,
                                            is_txt=self.rsvp.is_txt_stim,
                                            color=self.color)
示例#2
0
    def test_random_sequence_gen(self):
        """Test generation of random sequences"""
        alp = [
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            '<', '_'
        ]
        num_sti = 10
        len_sti = 10
        seqs, seq_timings, seq_colors = random_rsvp_calibration_seq_gen(
            alp,
            timing=[0.5, 1, 0.2],
            color=['green', 'red', 'white'],
            num_sti=num_sti,
            len_sti=len_sti,
            is_txt=True)

        self.assertEqual(
            len(seqs), num_sti,
            'Should have produced the correct number of sequences')
        self.assertEqual(len(seq_timings), num_sti)
        self.assertEqual(len(seq_colors), num_sti)

        seq_strings = []
        for seq in seqs:
            self.assertEqual(
                len(seq), len_sti + 2,
                ('Sequence should include the correct number of choices as ',
                 'well as the target and cross.'))
            choices = seq[2:]
            self.assertEqual(len_sti, len(set(choices)),
                             'All choices should be unique')

            # create a string of the options
            seq_strings.append(''.join(choices))

        self.assertEqual(len(seqs), len(set(seq_strings)),
                         'All sequences should be different')
    def execute(self):
        self.logger.debug(f'Starting {self.name()}!')
        run = True

        # Check user input to make sure we should be going
        if not get_user_input(self.rsvp,
                              self.wait_screen_message,
                              self.wait_screen_message_color,
                              first_run=True):
            run = False

        # Begin the Experiment
        while run:

            # Get random sequence information given stimuli parameters
            (stimuli_elements, timing_sti,
             color_sti) = random_rsvp_calibration_seq_gen(
                 self.alp,
                 stim_number=self.stim_number,
                 stim_length=self.stim_length,
                 timing=self.timing,
                 is_txt=self.is_txt_stim,
                 color=self.color)

            import pdb
            pdb.set_trace()

            (task_text, task_color) = get_task_info(self.stim_number,
                                                    self._task.task_info_color)

            # Execute the RSVP sequences
            for sequence_idx in range(len(task_text)):

                # check user input to make sure we should be going
                if not get_user_input(self.rsvp, self.wait_screen_message,
                                      self.wait_screen_message_color):
                    break

                if self.enable_breaks:
                    pause_calibration(self.window, self.rsvp, sequence_idx,
                                      self.parameters)

                # update task state
                self.rsvp.update_task_state(
                    text=task_text[sequence_idx],
                    color_list=task_color[sequence_idx])

                # Draw and flip screen
                self.rsvp.draw_static()
                self.window.flip()

                # Get height
                self.rsvp.sti.height = self.stimuli_height

                # Schedule a sequence
                self.rsvp.stimuli_sequence = stimuli_elements[sequence_idx]

                # check if text stimuli or not for color information
                if self.is_txt_stim:
                    self.rsvp.stimuli_colors = color_sti[sequence_idx]

                self.rsvp.stimuli_timing = timing_sti[sequence_idx]

                # Wait for a time
                core.wait(self._task.buffer_val)

                # Do the sequence
                last_sequence_timing = self.rsvp.do_sequence()

                # Write triggers for the sequence
                _write_triggers_from_sequence_calibration(
                    last_sequence_timing, self._task.trigger_file)

                self.logger.info('[Feedback] Getting Decision')

                position = self._get_feedback_decision(last_sequence_timing)
                self.logger.info(
                    f'[Feedback] Administering feedback position {position}')
                timing = self.visual_feedback.administer(position=position)

                # Wait for a time
                core.wait(self._task.buffer_val)

            # Set run to False to stop looping
            run = False

        # Say Goodbye!
        self.rsvp.text = trial_complete_message(self.window, self.parameters)
        self.rsvp.draw_static()
        self.window.flip()

        # Give the system time to process
        core.wait(self._task.buffer_val)

        if self.daq.is_calibrated:
            _write_triggers_from_sequence_calibration(
                ['offset', self.daq.offset],
                self._task.trigger_file,
                offset=True)

        # Close this sessions trigger file and return some data
        self._task.trigger_file.close()

        # Wait some time before exiting so there is trailing eeg data saved
        core.wait(self._task.eeg_buffer)

        return self.file_save