From 2f3f30d6ba6f83e3e38913274bccb2da6158426f Mon Sep 17 00:00:00 2001 From: matthias-k Date: Sun, 26 May 2024 17:24:42 -0400 Subject: [PATCH] PASCAL-S dataset uses ScanpathFixations (#68) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also the test got recfactored into its own file Signed-off-by: Matthias Kümmerer --- pysaliency/external_datasets/pascal_s.py | 21 ++++++---- tests/external_datasets/test_PASCAL_S.py | 52 ++++++++++++++++++++++++ tests/test_external_datasets.py | 44 -------------------- 3 files changed, 65 insertions(+), 52 deletions(-) create mode 100644 tests/external_datasets/test_PASCAL_S.py diff --git a/pysaliency/external_datasets/pascal_s.py b/pysaliency/external_datasets/pascal_s.py index 56f2014..da28c6e 100644 --- a/pysaliency/external_datasets/pascal_s.py +++ b/pysaliency/external_datasets/pascal_s.py @@ -1,19 +1,18 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function -import zipfile import os +import zipfile -import requests import numpy as np +import requests -from ..datasets import FixationTrains +from ..datasets import ScanpathFixations, Scanpaths from ..utils import ( TemporaryDirectory, - download_and_check, atomic_directory_setup, + download_and_check, ) - -from .utils import create_stimuli, _load +from .utils import _load, create_stimuli def get_PASCAL_S(location=None): @@ -100,7 +99,13 @@ def get_PASCAL_S(location=None): train_ns.append(n) train_subjects.append(subject - 1) # subjects are 1-indexed in matlab - fixations = FixationTrains.from_fixation_trains(train_xs, train_ys, train_ts, train_ns, train_subjects) + fixations = ScanpathFixations(Scanpaths( + xs=train_xs, + ys=train_ys, + ts=train_ts, + n=train_ns, + subject=train_subjects, + )) if location: stimuli.to_hdf5(os.path.join(location, 'stimuli.hdf5')) diff --git a/tests/external_datasets/test_PASCAL_S.py b/tests/external_datasets/test_PASCAL_S.py new file mode 100644 index 0000000..796c4ec --- /dev/null +++ b/tests/external_datasets/test_PASCAL_S.py @@ -0,0 +1,52 @@ +import numpy as np +import pytest +from pytest import approx +from scipy.stats import kurtosis, skew + +import pysaliency +import pysaliency.external_datasets +from tests.test_external_datasets import _location, entropy + + +@pytest.mark.slow +@pytest.mark.download +def test_PASCAL_S(location): + real_location = _location(location) + + stimuli, fixations = pysaliency.external_datasets.get_PASCAL_S(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('PASCAL-S/stimuli.hdf5').check() + assert location.join('PASCAL-S/fixations.hdf5').check() + + assert len(stimuli.stimuli) == 850 + + assert len(fixations.x) == 40314 + + assert np.mean(fixations.x) == approx(240.72756362553952) + assert np.mean(fixations.y) == approx(194.85756809048965) + assert np.mean(fixations.t) == approx(2.7856823932132757) + assert np.mean(fixations.scanpath_history_length) == approx(2.7856823932132757) + + assert np.std(fixations.x) == approx(79.57401169717699) + assert np.std(fixations.y) == approx(65.21296890260112) + assert np.std(fixations.t) == approx(2.1191752645988675) + assert np.std(fixations.scanpath_history_length) == approx(2.1191752645988675) + + assert kurtosis(fixations.x) == approx(0.0009226786675387011) + assert kurtosis(fixations.y) == approx(1.1907544566979986) + assert kurtosis(fixations.t) == approx(-0.540943536495714) + assert kurtosis(fixations.scanpath_history_length) == approx(-0.540943536495714) + + assert skew(fixations.x) == approx(0.2112334873314548) + assert skew(fixations.y) == approx(0.7208733522533084) + assert skew(fixations.t) == approx(0.4800678710338635) + assert skew(fixations.scanpath_history_length) == approx(0.4800678710338635) + + assert entropy(fixations.n) == approx(9.711222735065062) + assert (fixations.n == 0).sum() == 35 + + assert len(fixations) == len(pysaliency.datasets.remove_out_of_stimulus_fixations(stimuli, fixations)) \ No newline at end of file diff --git a/tests/test_external_datasets.py b/tests/test_external_datasets.py index 88dd1f8..3355bf8 100644 --- a/tests/test_external_datasets.py +++ b/tests/test_external_datasets.py @@ -284,50 +284,6 @@ def test_mit1003_onesize(location, matlab): assert (fixations.n == 0).sum() == 121 -@pytest.mark.slow -@pytest.mark.download -def test_PASCAL_S(location): - real_location = _location(location) - - stimuli, fixations = pysaliency.external_datasets.get_PASCAL_S(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('PASCAL-S/stimuli.hdf5').check() - assert location.join('PASCAL-S/fixations.hdf5').check() - - assert len(stimuli.stimuli) == 850 - - assert len(fixations.x) == 40314 - - assert np.mean(fixations.x) == approx(240.72756362553952) - assert np.mean(fixations.y) == approx(194.85756809048965) - assert np.mean(fixations.t) == approx(2.7856823932132757) - assert np.mean(fixations.scanpath_history_length) == approx(2.7856823932132757) - - assert np.std(fixations.x) == approx(79.57401169717699) - assert np.std(fixations.y) == approx(65.21296890260112) - assert np.std(fixations.t) == approx(2.1191752645988675) - assert np.std(fixations.scanpath_history_length) == approx(2.1191752645988675) - - assert kurtosis(fixations.x) == approx(0.0009226786675387011) - assert kurtosis(fixations.y) == approx(1.1907544566979986) - assert kurtosis(fixations.t) == approx(-0.540943536495714) - assert kurtosis(fixations.scanpath_history_length) == approx(-0.540943536495714) - - assert skew(fixations.x) == approx(0.2112334873314548) - assert skew(fixations.y) == approx(0.7208733522533084) - assert skew(fixations.t) == approx(0.4800678710338635) - assert skew(fixations.scanpath_history_length) == approx(0.4800678710338635) - - assert entropy(fixations.n) == approx(9.711222735065062) - assert (fixations.n == 0).sum() == 35 - - assert len(fixations) == len(pysaliency.datasets.remove_out_of_stimulus_fixations(stimuli, fixations)) - - @pytest.mark.slow @pytest.mark.download def test_DUT_OMRON(location, tmpdir):