Skip to content

Commit

Permalink
Rename subjects to subject, lengths to fixation_history_length, some …
Browse files Browse the repository at this point in the history
…more fixes

Signed-off-by: Matthias Kümmerer <[email protected]>
  • Loading branch information
matthias-k committed Apr 10, 2024
1 parent 404a4d5 commit ff50f41
Show file tree
Hide file tree
Showing 20 changed files with 483 additions and 477 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
Unlike `FixationTrains`, `ScanpathFixations` does not have any attributes that are not derived from the scanpaths.
`FixationTrains` is now a deprecated subclass of `ScanpathFixations` which adds the old properties and constructor
and allows for attributes which are neither scanpath attributes nor scanpath fixation attributes.

* Feature: `VariableLengthArray` for inuititively handling data like scanpaths where each row can have a different length.
`Fixations.x_Hist`, `Fixations.y_hist`, `Scanpaths.xs` etc are now instances of `VariableLengthArray`.
* `Fixations.lengths` has been renamed to `Fixations.scanpath_history_length` to make it clear that it is the length of the scanpath history.
`Fixations.lengths` is now a deprecated alias.
* In general, naming convention for attriutes has been changed to use the plural form if the attribute is a list of values for each
element (i.e., `Scanpaths.xs`) and the singular form if the attribute is a single value (i.e., `Scanpaths.length`, `Fixations.x`). This resulted in
renaming `Fixations.subjects` to `Fixations.subject`. The old name is now a deprecated alias.

* 0.2.22 (dev):
* Enhancement: New [Tutorial](notebooks/Tutorial.ipynb).
Expand Down
123 changes: 64 additions & 59 deletions notebooks/Tutorial.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pysaliency/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Fixations,
FixationTrains,
ScanpathFixations,
Scanpaths,
Stimuli,
FileStimuli,
create_nonfixations,
Expand Down
42 changes: 23 additions & 19 deletions pysaliency/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,36 @@ def create_subset(stimuli, fixations, stimuli_indices):

new_stimuli = stimuli[stimuli_indices]
if isinstance(fixations, FixationTrains):
fix_inds = np.in1d(fixations.scanpaths.n, stimuli_indices)
scanpath_inds = np.in1d(fixations.scanpaths.n, stimuli_indices)

index_list = list(stimuli_indices)
new_pos = {i: index_list.index(i) for i in index_list}

new_image_indices = [new_pos[i] for i in fixations.scanpaths.n[fix_inds]]
new_image_indices = [new_pos[i] for i in fixations.scanpaths.n[scanpath_inds]]

new_scanpaths = fixations.scanpaths[fix_inds]
new_fixations = fixations.filter_fixation_trains(scanpath_inds)
new_fixations.scanpaths.n = np.array(new_image_indices)

new_fixations = FixationTrains(
train_xs=new_scanpaths.xs,
train_ys=new_scanpaths.ys,
train_ts=None, # new_scanpaths.fixation_attributes['ts'],
train_ns=np.array(new_image_indices),
train_subjects=None, # new_scanpaths.scanpath_attributes['subject'],
scanpath_attributes=new_scanpaths.scanpath_attributes,
scanpath_fixation_attributes=new_scanpaths.fixation_attributes,
scanpath_attribute_mapping=new_scanpaths.attribute_mapping
new_fixation_ns = [new_pos[i] for i in new_fixations.n]
new_fixations.n = np.array(new_fixation_ns)

elif isinstance(fixations, ScanpathFixations):
scanpath_inds = np.in1d(fixations.scanpaths.n, stimuli_indices)

index_list = list(stimuli_indices)
new_pos = {i: index_list.index(i) for i in index_list}

new_image_indices = [new_pos[i] for i in fixations.scanpaths.n[scanpath_inds]]

new_scanpaths = fixations.scanpaths[scanpath_inds]

new_fixations = ScanpathFixations(
scanpaths=new_scanpaths,
)

else:
fix_inds = np.in1d(fixations.n, stimuli_indices)
new_fixations = fixations[fix_inds]
scanpath_inds = np.in1d(fixations.n, stimuli_indices)
new_fixations = fixations[scanpath_inds]

index_list = list(stimuli_indices)
new_pos = {i: index_list.index(i) for i in index_list}
Expand All @@ -94,14 +101,11 @@ def concatenate_stimuli(stimuli):
return ObjectStimuli(sum([s.stimulus_objects for s in stimuli], []), attributes=attributes)


#np.testing.assert_allclose(concatenate_attributes([[0], [1, 2, 3]]), [0,1,2,3])
#np.testing.assert_allclose(concatenate_attributes([[[0]], [[1],[2], [3]]]), [[0],[1],[2],[3]])
#np.testing.assert_allclose(concatenate_attributes([[[0.,1.]], [[1.],[2.], [3.]]]), [[0, 1],[1,np.nan],[2,np.nan],[3,np.nan]])


def concatenate_fixations(fixations):
if all(isinstance(f, FixationTrains) for f in fixations):
return FixationTrains.concatenate(fixations)
elif all(isinstance(f, ScanpathFixations) for f in fixations):
return ScanpathFixations.concatenate(fixations)
else:
return Fixations.concatenate(fixations)

Expand Down
Loading

0 comments on commit ff50f41

Please sign in to comment.