Skip to content

Commit

Permalink
Bugfix: MIT1003 test failed since dataset refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Kümmerer <[email protected]>
  • Loading branch information
matthias-k committed Jun 10, 2024
1 parent 4e69a51 commit 94fe040
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 85 deletions.
54 changes: 54 additions & 0 deletions tests/external_datasets/test_DUT_OMRON.py
Original file line number Diff line number Diff line change
@@ -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))
95 changes: 95 additions & 0 deletions tests/external_datasets/test_MIT.py
Original file line number Diff line number Diff line change
@@ -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
85 changes: 0 additions & 85 deletions tests/test_external_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94fe040

Please sign in to comment.