From 94fe0406ec3e779b11f6ca3910cab2490b78ffb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BCmmerer?= Date: Mon, 10 Jun 2024 13:36:43 +0200 Subject: [PATCH] Bugfix: MIT1003 test failed since dataset refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matthias Kümmerer --- tests/external_datasets/test_DUT_OMRON.py | 54 +++++++++++++ tests/external_datasets/test_MIT.py | 95 +++++++++++++++++++++++ tests/test_external_datasets.py | 85 -------------------- 3 files changed, 149 insertions(+), 85 deletions(-) create mode 100644 tests/external_datasets/test_DUT_OMRON.py create mode 100644 tests/external_datasets/test_MIT.py diff --git a/tests/external_datasets/test_DUT_OMRON.py b/tests/external_datasets/test_DUT_OMRON.py new file mode 100644 index 0000000..06aa226 --- /dev/null +++ b/tests/external_datasets/test_DUT_OMRON.py @@ -0,0 +1,54 @@ +import numpy as np +import pytest +from pathlib import Path +from pytest import approx +from scipy.stats import kurtosis, skew + +import pysaliency +import pysaliency.external_datasets +from pysaliency.utils import remove_trailing_nans + +from tests.test_external_datasets import _location, entropy + +@pytest.mark.slow +@pytest.mark.download +def test_DUT_OMRON(location, tmpdir): + real_location = _location(location) + + stimuli, fixations = pysaliency.external_datasets.get_DUT_OMRON(location=real_location) + if location is None: + assert isinstance(stimuli, pysaliency.Stimuli) + assert not isinstance(stimuli, pysaliency.FileStimuli) + else: + assert isinstance(stimuli, pysaliency.FileStimuli) + assert location.join('DUT-OMRON/stimuli.hdf5').check() + assert location.join('DUT-OMRON/fixations.hdf5').check() + + assert len(stimuli.stimuli) == 5168 + + assert len(fixations.x) == 797542 + + assert np.mean(fixations.x) == approx(182.16198519952553) + assert np.mean(fixations.y) == approx(147.622566585835) + assert np.mean(fixations.t) == approx(21.965026293286122) + assert np.mean(fixations.scanpath_history_length) == approx(21.965026293286122) + + assert np.std(fixations.x) == approx(64.01040053828082) + assert np.std(fixations.y) == approx(58.292098903584176) + assert np.std(fixations.t) == approx(17.469479262739807) + assert np.std(fixations.scanpath_history_length) == approx(17.469479262739807) + + assert kurtosis(fixations.x) == approx(-0.0689271960358524) + assert kurtosis(fixations.y) == approx(0.637871926687533) + assert kurtosis(fixations.t) == approx(2.914601085582113) + assert kurtosis(fixations.scanpath_history_length) == approx(2.914601085582113) + + assert skew(fixations.x) == approx(0.23776167825897998) + assert skew(fixations.y) == approx(0.6328497077003701) + assert skew(fixations.t) == approx(1.2911168563657345) + assert skew(fixations.scanpath_history_length) == approx(1.2911168563657345) + + assert entropy(fixations.n) == approx(12.20642017670851) + assert (fixations.n == 0).sum() == 209 + + assert len(fixations) == len(pysaliency.datasets.remove_out_of_stimulus_fixations(stimuli, fixations)) \ No newline at end of file diff --git a/tests/external_datasets/test_MIT.py b/tests/external_datasets/test_MIT.py new file mode 100644 index 0000000..e0e145b --- /dev/null +++ b/tests/external_datasets/test_MIT.py @@ -0,0 +1,95 @@ +import numpy as np +import pytest +from pathlib import Path +from pytest import approx +from scipy.stats import kurtosis, skew + +import pysaliency +import pysaliency.external_datasets +from pysaliency.utils import remove_trailing_nans + + +from tests.test_external_datasets import _location, entropy + + +@pytest.mark.slow +@pytest.mark.download +@pytest.mark.skip_octave +@pytest.mark.matlab +def test_mit1003(location, matlab): + real_location = _location(location) + + stimuli, fixations = pysaliency.external_datasets.get_mit1003(location=real_location) + + if location is None: + assert isinstance(stimuli, pysaliency.Stimuli) + assert not isinstance(stimuli, pysaliency.FileStimuli) + else: + assert isinstance(stimuli, pysaliency.FileStimuli) + assert location.join('MIT1003/stimuli.hdf5').check() + assert location.join('MIT1003/fixations.hdf5').check() + + assert len(stimuli.stimuli) == 1003 + for n in range(len(stimuli.stimuli)): + assert max(stimuli.sizes[n]) == 1024 + + assert len(fixations.x) == 104171 + + assert np.mean(fixations.x) == approx(487.13683496521253) + assert np.mean(fixations.y) == approx(392.72728829760155) + assert np.mean(fixations.t) == approx(1.5039892740461995) + assert np.mean(fixations.scanpath_history_length) == approx(3.3973754691804823) + + assert np.std(fixations.x) == approx(190.0203102093757) + assert np.std(fixations.y) == approx(159.99210430350126) + assert np.std(fixations.t) == approx(0.816414737693668) + assert np.std(fixations.scanpath_history_length) == approx(2.5433689996843354) + + assert kurtosis(fixations.x) == approx(-0.39272472247196033) + assert kurtosis(fixations.y) == approx(0.6983793465837596) + assert kurtosis(fixations.t) == approx(-1.2178525798721818) + assert kurtosis(fixations.scanpath_history_length) == approx(-0.45897225172578704) + + assert skew(fixations.x) == approx(0.2204976032609953) + assert skew(fixations.y) == approx(0.6445191904777621) + assert skew(fixations.t) == approx(0.08125182887100482) + assert skew(fixations.scanpath_history_length) == approx(0.5047182860999948) + + assert entropy(fixations.n) == approx(9.954348058662386) + assert (fixations.n == 0).sum() == 121 + + assert 'duration_hist' in fixations.__attributes__ + assert 'duration' in fixations.__attributes__ + assert len(fixations.duration_hist) == len(fixations.x) + assert len(fixations.duration) == len(fixations.x) + for i in range(len(fixations.x)): + assert len(remove_trailing_nans(fixations.duration_hist[i])) == len(remove_trailing_nans(fixations.x_hist[i])) + + + assert 'durations' in fixations.scanpaths.fixation_attributes + + assert len(fixations) == len(pysaliency.datasets.remove_out_of_stimulus_fixations(stimuli, fixations)) + +@pytest.mark.slow +@pytest.mark.download +@pytest.mark.skip_octave +@pytest.mark.matlab +def test_mit1003_onesize(location, matlab): + real_location = _location(location) + + stimuli, fixations = pysaliency.external_datasets.get_mit1003_onesize(location=real_location) + + if location is None: + assert isinstance(stimuli, pysaliency.Stimuli) + assert not isinstance(stimuli, pysaliency.FileStimuli) + else: + assert isinstance(stimuli, pysaliency.FileStimuli) + assert location.join('MIT1003_onesize/stimuli.hdf5').check() + assert location.join('MIT1003_onesize/fixations.hdf5').check() + + assert len(stimuli.stimuli) == 463 + for n in range(len(stimuli.stimuli)): + assert stimuli.sizes[n] == (768, 1024) + + assert len(fixations.x) == 48771 + assert (fixations.n == 0).sum() == 121 \ No newline at end of file diff --git a/tests/test_external_datasets.py b/tests/test_external_datasets.py index 860c7dc..0939100 100644 --- a/tests/test_external_datasets.py +++ b/tests/test_external_datasets.py @@ -199,91 +199,6 @@ def test_cat2000_test(location): assert np.all(np.array(stimuli.attributes['category'][100:200]) == 1) -@pytest.mark.slow -@pytest.mark.download -@pytest.mark.skip_octave -@pytest.mark.matlab -def test_mit1003(location, matlab): - real_location = _location(location) - - stimuli, fixations = pysaliency.external_datasets.get_mit1003(location=real_location) - - if location is None: - assert isinstance(stimuli, pysaliency.Stimuli) - assert not isinstance(stimuli, pysaliency.FileStimuli) - else: - assert isinstance(stimuli, pysaliency.FileStimuli) - assert location.join('MIT1003/stimuli.hdf5').check() - assert location.join('MIT1003/fixations.hdf5').check() - - assert len(stimuli.stimuli) == 1003 - for n in range(len(stimuli.stimuli)): - assert max(stimuli.sizes[n]) == 1024 - - assert len(fixations.x) == 104171 - - assert np.mean(fixations.x) == approx(487.13683496521253) - assert np.mean(fixations.y) == approx(392.72728829760155) - assert np.mean(fixations.t) == approx(1.5039892740461995) - assert np.mean(fixations.scanpath_history_length) == approx(3.3973754691804823) - - assert np.std(fixations.x) == approx(190.0203102093757) - assert np.std(fixations.y) == approx(159.99210430350126) - assert np.std(fixations.t) == approx(0.816414737693668) - assert np.std(fixations.scanpath_history_length) == approx(2.5433689996843354) - - assert kurtosis(fixations.x) == approx(-0.39272472247196033) - assert kurtosis(fixations.y) == approx(0.6983793465837596) - assert kurtosis(fixations.t) == approx(-1.2178525798721818) - assert kurtosis(fixations.scanpath_history_length) == approx(-0.45897225172578704) - - assert skew(fixations.x) == approx(0.2204976032609953) - assert skew(fixations.y) == approx(0.6445191904777621) - assert skew(fixations.t) == approx(0.08125182887100482) - assert skew(fixations.scanpath_history_length) == approx(0.5047182860999948) - - assert entropy(fixations.n) == approx(9.954348058662386) - assert (fixations.n == 0).sum() == 121 - - assert 'duration_hist' in fixations.__attributes__ - assert 'duration' in fixations.__attributes__ - assert len(fixations.duration_hist) == len(fixations.x) - assert len(fixations.duration) == len(fixations.x) - for i in range(len(fixations.x)): - assert len(remove_trailing_nans(fixations.duration_hist[i])) == len(remove_trailing_nans(fixations.x_hist[i])) - - assert 'durations' in fixations.scanpath_fixation_attributes - assert len(fixations.scanpath_fixation_attributes['durations']) == len(fixations.train_xs) - for i in range(len(fixations.train_xs)): - assert len(remove_trailing_nans(fixations.scanpath_fixation_attributes['durations'][i])) == len(remove_trailing_nans(fixations.train_xs[i])) - - assert len(fixations) == len(pysaliency.datasets.remove_out_of_stimulus_fixations(stimuli, fixations)) - -@pytest.mark.slow -@pytest.mark.download -@pytest.mark.skip_octave -@pytest.mark.matlab -def test_mit1003_onesize(location, matlab): - real_location = _location(location) - - stimuli, fixations = pysaliency.external_datasets.get_mit1003_onesize(location=real_location) - - if location is None: - assert isinstance(stimuli, pysaliency.Stimuli) - assert not isinstance(stimuli, pysaliency.FileStimuli) - else: - assert isinstance(stimuli, pysaliency.FileStimuli) - assert location.join('MIT1003_onesize/stimuli.hdf5').check() - assert location.join('MIT1003_onesize/fixations.hdf5').check() - - assert len(stimuli.stimuli) == 463 - for n in range(len(stimuli.stimuli)): - assert stimuli.sizes[n] == (768, 1024) - - assert len(fixations.x) == 48771 - assert (fixations.n == 0).sum() == 121 - - @pytest.mark.slow @pytest.mark.nonfree @pytest.mark.skip_octave