From db65cd2c55a66f76760f1460d3209bcfa0b4df34 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 10 May 2023 15:11:17 +0200 Subject: Moving code into GazeFeatures --- .../DispersionThresholdIdentification.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/argaze/GazeAnalysis/DispersionThresholdIdentification.py b/src/argaze/GazeAnalysis/DispersionThresholdIdentification.py index cb29055..92df6d2 100644 --- a/src/argaze/GazeAnalysis/DispersionThresholdIdentification.py +++ b/src/argaze/GazeAnalysis/DispersionThresholdIdentification.py @@ -18,9 +18,6 @@ SaccadeType = TypeVar('Saccade', bound="Saccade") class Fixation(GazeFeatures.Fixation): """Define dispersion based fixation.""" - centroid: tuple = field(init=False) - """Centroïd of all gaze positions belonging to the fixation.""" - deviation_max: float = field(init=False) """Maximal gaze position distance to the centroïd.""" @@ -28,28 +25,23 @@ class Fixation(GazeFeatures.Fixation): super().__post_init__() - self.update() - - def point_deviation(self, gaze_position) -> float: - """Get distance of a point from the fixation's centroïd.""" - - return numpy.sqrt((self.centroid[0] - gaze_position.value[0])**2 + (self.centroid[1] - gaze_position.value[1])**2) - - def update(self): - """Update fixation's centroïd then maximal gaze positions deviation from this centroïd.""" - points = self.positions.values() points_x, points_y = [p[0] for p in points], [p[1] for p in points] points_array = numpy.column_stack([points_x, points_y]) centroid_array = numpy.array([numpy.mean(points_x), numpy.mean(points_y)]) deviations_array = numpy.sqrt(numpy.sum((points_array - centroid_array)**2, axis=1)) - # Update frozen centroid attribute - object.__setattr__(self, 'centroid', (centroid_array[0], centroid_array[1])) + # Update frozen focus attribute using centroid + object.__setattr__(self, 'focus', (centroid_array[0], centroid_array[1])) # Update frozen deviation_max attribute object.__setattr__(self, 'deviation_max', max(deviations_array)) + def point_deviation(self, gaze_position) -> float: + """Get distance of a point from the fixation's centroïd.""" + + return numpy.sqrt((self.centroid[0] - gaze_position.value[0])**2 + (self.centroid[1] - gaze_position.value[1])**2) + def overlap(self, fixation) -> bool: """Does a gaze position from another fixation having a deviation to this fixation centroïd smaller than maximal deviation?""" -- cgit v1.1