Repository: aeye-lab/pymovements
Pull request #51 (2022-10-30 12:18:03)

Add position property to fixation class
## Description

Fixation detection algorithms may output the position of a fixation. Therefore I added this property to Fixation event class.

## Implemented changes
- Add position property for fixation event class

## Type of change

- [x] New feature (non-breaking change which adds functionality)


dkrako: LGTM
Thank you for your effort

Patch:
diff --git a/src/pymovements/events/base.py b/src/pymovements/events/base.py
index 7ebc625..52d9591 100644
--- a/src/pymovements/events/base.py
+++ b/src/pymovements/events/base.py
@@ -1,6 +1,7 @@
 """
 This module holds all the main Event classes used for event detection.
 """
+from __future__ import annotations
 
 
 class Event:
@@ -24,7 +25,6 @@ class Event:
         Starting index of event (included).
     offset: int
         Ending index of event (excluded).
-
     """
     def __init__(self, name: str, onset: int, offset: int):
         self.name = name
@@ -54,11 +54,25 @@ class Fixation(Event):
         Starting index of event (included).
     offset: int
         Ending index of event (excluded).
+    position: tuple[float, float]
+        (x, y) position of fixation
+
+    Attributes
+    ----------
+    name: str
+        Name of event.
+    onset: int
+        Starting index of event (included).
+    offset: int
+        Ending index of event (excluded).
+    position: tuple[float, float]
+        (x, y) position of fixation
     """
     _name = 'fixation'
 
-    def __init__(self, onset: int, offset: int):
+    def __init__(self, onset: int, offset: int, position: tuple[float, float]):
         super().__init__(name=self._name, onset=onset, offset=offset)
+        self.position = position
 
 
 class Saccade(Event):
@@ -71,6 +85,15 @@ class Saccade(Event):
         Starting index of event (included).
     offset: int
         Ending index of event (excluded).
+
+    Attributes
+    ----------
+    name: str
+        Name of event.
+    onset: int
+        Starting index of event (included).
+    offset: int
+        Ending index of event (excluded).
     """
     _name = 'saccade'
 


Test patch:
diff --git a/tests/events/test_events_base.py b/tests/events/test_events_base.py
index e042535..38afc79 100644
--- a/tests/events/test_events_base.py
+++ b/tests/events/test_events_base.py
@@ -29,8 +29,8 @@ from pymovements.events import Saccade
         ),
         pytest.param(
             Fixation,
-            {'onset': 10, 'offset': 100},
-            {'name': Fixation._name, 'duration': 90},
+            {'onset': 10, 'offset': 100, 'position': (1, 1)},
+            {'name': Fixation._name, 'duration': 90, 'position': (1, 1)},
             id='fixation',
         ),
         pytest.param(
@@ -51,3 +51,8 @@ def test_event_class(event_class: Event, init_params: dict[str, Any], expected:
     assert event.duration == expected['duration'], (
         f'event duration does not match expected value ({event.duration} != {expected["duration"]})'
     )
+    if 'position' in expected.keys():
+        assert event.position == expected['position'], (
+            'fixation event position does not match expected value'
+            f'({event.position} != {expected["position"]})'
+        )