From 4e69a51cb36ad42dc7a7d3f31b9feb69cdb169cb Mon Sep 17 00:00:00 2001 From: matthias-k Date: Mon, 27 May 2024 14:06:34 +0200 Subject: [PATCH] DUT-OMRON: ScanpathFixations, refactor tests (#70) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matthias Kümmerer --- pysaliency/external_datasets/dut_omrom.py | 23 +++++++----- tests/test_external_datasets.py | 44 ----------------------- 2 files changed, 14 insertions(+), 53 deletions(-) diff --git a/pysaliency/external_datasets/dut_omrom.py b/pysaliency/external_datasets/dut_omrom.py index b4773ef..78b9c08 100644 --- a/pysaliency/external_datasets/dut_omrom.py +++ b/pysaliency/external_datasets/dut_omrom.py @@ -1,24 +1,23 @@ -from __future__ import absolute_import, print_function, division +from __future__ import absolute_import, division, print_function -import zipfile -import os import glob +import os +import zipfile import numpy as np from scipy.io import loadmat from tqdm import tqdm -from ..datasets import FixationTrains +from ..datasets import ScanpathFixations, Scanpaths, Stimuli 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_DUT_OMRON(location=None): +def get_DUT_OMRON(location=None) -> tuple[Stimuli, ScanpathFixations]: """ Loads or downloads the DUT-OMRON fixation dataset. The dataset consists of 5168 natural images with @@ -108,7 +107,13 @@ def get_DUT_OMRON(location=None): train_ns.append(n) train_subjects.append(subject_index) - 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, + )) assert len(fixations) == n_fixations diff --git a/tests/test_external_datasets.py b/tests/test_external_datasets.py index 3355bf8..860c7dc 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_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)) - - @pytest.mark.slow @pytest.mark.nonfree @pytest.mark.skip_octave