Ejemplo n.º 1
0
 def test_psychometric_insufficient_data(self):
     # the psychometric aggregate should return NaN when there is no data for a given contrast
     trials, _ = self._get_trials(sess_dates=['2020-08-25', '2020-08-24', '2020-08-21'])
     trials_all = train.concatenate_trials(trials)
     trials_all['probability_left'] = trials_all['contrastLeft'] * 0 + 80
     psych_nan = train.compute_psychometric(trials_all, block=100)
     assert np.sum(np.isnan(psych_nan)) == 4
Ejemplo n.º 2
0
    def test_concatenate_and_computations(self):
        trials, _ = self._get_trials(sess_dates=['2020-08-25', '2020-08-24', '2020-08-21'])
        trials_total = np.sum([len(trials[k]['contrastRight']) for k in trials.keys()])
        trials_all = train.concatenate_trials(trials)
        assert (len(trials_all['contrastRight']) == trials_total)

        perf_easy = np.array([train.compute_performance_easy(trials[k]) for k in trials.keys()])
        n_trials = np.array([train.compute_n_trials(trials[k]) for k in trials.keys()])
        psych = train.compute_psychometric(trials_all)
        rt = train.compute_median_reaction_time(trials_all, contrast=0)
        np.testing.assert_allclose(perf_easy, [0.91489362, 0.9, 0.90853659])
        np.testing.assert_array_equal(n_trials, [617, 532, 719])
        np.testing.assert_allclose(psych, [4.04487042, 21.6293942, 1.91451396e-02, 1.72669957e-01],
                                   rtol=1e-5)
        assert (np.isclose(rt, 0.83655))
Ejemplo n.º 3
0
def load_combined_trials(sess_paths, one):
    """
    Load and concatenate trials for multiple sessions. Used when we want to concatenate trials for two sessions on the same day
    :param sess_paths: list of paths to sessions
    :param one: ONE instance
    :return:
    """
    trials_dict = {}
    for sess_path in sess_paths:
        trials = load_trials(Path(sess_path), one)
        if trials is not None:
            trials_dict[Path(sess_path).stem] = load_trials(
                Path(sess_path), one)

    return training.concatenate_trials(trials_dict)
Ejemplo n.º 4
0
    def test_concatenate_and_computations(self):
        sess_dates = ['2020-08-25', '2020-08-24', '2020-08-21']
        trials_copy = copy.deepcopy(self.trial_data)
        trials = Bunch(zip(sess_dates, [trials_copy[k] for k in sess_dates]))
        _ = [trials[k].pop('task_protocol') for k in trials.keys()]
        trials_total = np.sum(
            [len(trials[k]['contrastRight']) for k in trials.keys()])

        trials_all = train.concatenate_trials(trials)
        assert (len(trials_all.contrastRight) == trials_total)

        perf_easy = np.array(
            [train.compute_performance_easy(trials[k]) for k in trials.keys()])
        n_trials = np.array(
            [train.compute_n_trials(trials[k]) for k in trials.keys()])
        psych = train.compute_psychometric(trials_all)
        rt = train.compute_median_reaction_time(trials_all)
        np.testing.assert_allclose(perf_easy, [0.91489362, 0.9, 0.90853659])
        np.testing.assert_array_equal(n_trials, [617, 532, 719])
        np.testing.assert_allclose(
            psych, [4.04487042, 21.6293942, 1.91451396e-02, 1.72669957e-01],
            rtol=1e-5)
        assert (np.isclose(rt, 0.83655))