Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing stimuli with no fixations #42

Merged
merged 3 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pysaliency/filter_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,10 @@ def filter_scanpaths_by_length(scanpaths: FixationTrains, intervals: list):
scanpaths = scanpaths.filter_fixation_trains(indices)

return scanpaths


def remove_stimuli_without_fixations(stimuli: Stimuli, fixations: Fixations):
"""Remove stimuli with no fixations"""

stimuli_indices_with_fixations = list(set(fixations.n))
return create_subset(stimuli, fixations, stimuli_indices_with_fixations)
11 changes: 10 additions & 1 deletion tests/test_filter_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pysaliency
import pysaliency.filter_datasets as filter_datasets
from pysaliency.filter_datasets import filter_fixations_by_attribute, filter_stimuli_by_attribute, filter_scanpaths_by_attribute, filter_scanpaths_by_length, create_subset
from pysaliency.filter_datasets import filter_fixations_by_attribute, filter_stimuli_by_attribute, filter_scanpaths_by_attribute, filter_scanpaths_by_length, create_subset, remove_stimuli_without_fixations
from test_datasets import compare_fixations, compare_scanpaths


Expand Down Expand Up @@ -453,3 +453,12 @@ def test_filter_scanpaths_by_length(fixation_trains, intervals):
inds = [0, 2]
expected_scanpaths = scanpaths.filter_fixation_trains(inds)
compare_scanpaths(filtered_scanpaths, expected_scanpaths)


def test_remove_stimuli_without_fixations(file_stimuli_with_attributes, fixation_trains):
fixations = fixation_trains[:]
filtered_stimuli, filtered_fixations = remove_stimuli_without_fixations(file_stimuli_with_attributes, fixations)
inds = [0, 1]
expected_stimuli, expected_fixations = create_subset(file_stimuli_with_attributes, fixations, inds)
compare_fixations(filtered_fixations, expected_fixations)
assert_stimuli_equal(filtered_stimuli, expected_stimuli)
Loading