Skip to content

Commit

Permalink
refactor(events): Rename position property to location (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrako authored May 26, 2023
1 parent d9a94ef commit 2afecda
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/pymovements/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
pymovements.events.event_properties.dispersion
pymovements.events.event_properties.disposition
pymovements.events.event_properties.peak_velocity
pymovements.events.event_properties.position
pymovements.events.event_properties.location
"""
from pymovements.events.detection.idt import idt
from pymovements.events.detection.ivt import ivt
Expand Down
60 changes: 30 additions & 30 deletions src/pymovements/events/event_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,41 +135,13 @@ def duration() -> pl.Expr:


@register_event_property
def peak_velocity(
*,
velocity_column: str = 'velocity',
n_components: int = 2,
) -> pl.Expr:
"""Peak velocity of an event.
Parameters
----------
velocity_column
The column name of the velocity tuples.
n_components:
Number of positional components. Usually these are the two components yaw and pitch.
Raises
------
ValueError
If number of components is not 2.
"""
_check_has_two_componenents(n_components)

x_velocity = pl.col(velocity_column).arr.get(0)
y_velocity = pl.col(velocity_column).arr.get(1)

return (x_velocity.pow(2) + y_velocity.pow(2)).sqrt().max()


@register_event_property
def position(
def location(
method: str = 'mean',
*,
position_column: str = 'position',
n_components: int = 2,
) -> pl.Expr:
"""Centroid position of an event.
"""Location of an event.
Parameters
----------
Expand Down Expand Up @@ -212,6 +184,34 @@ def position(
return pl.concat_list(component_expressions).first()


@register_event_property
def peak_velocity(
*,
velocity_column: str = 'velocity',
n_components: int = 2,
) -> pl.Expr:
"""Peak velocity of an event.
Parameters
----------
velocity_column
The column name of the velocity tuples.
n_components:
Number of positional components. Usually these are the two components yaw and pitch.
Raises
------
ValueError
If number of components is not 2.
"""
_check_has_two_componenents(n_components)

x_velocity = pl.col(velocity_column).arr.get(0)
y_velocity = pl.col(velocity_column).arr.get(1)

return (x_velocity.pow(2) + y_velocity.pow(2)).sqrt().max()


def _check_has_two_componenents(n_components: int) -> None:
"""Check that number of componenents is two."""
if n_components != 2:
Expand Down
8 changes: 4 additions & 4 deletions tests/dataset/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,12 @@ def test_event_dataframe_add_property_has_expected_height(dataset_configuration,
id='single_event_peak_velocity',
),
pytest.param(
{'event_properties': 'position'},
{'event_properties': 'location'},
{
'subject_id': pl.Int64,
**pm.events.EventDataFrame._minimal_schema,
'duration': pl.Int64,
'position': pl.List(pl.Float64),
'location': pl.List(pl.Float64),
},
id='single_event_position',
),
Expand Down Expand Up @@ -1222,8 +1222,8 @@ def test_event_dataframe_add_property_has_expected_schema(
id='single_event_peak_velocity',
),
pytest.param(
{'event_properties': 'position'},
['position'],
{'event_properties': 'location'},
['location'],
id='single_event_position',
),
],
Expand Down
22 changes: 11 additions & 11 deletions tests/events/event_properties_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
id='peak_velocity_not_2_components_raise_value_error',
),
pytest.param(
event_properties.position,
event_properties.location,
{'method': 'foo'},
ValueError,
('method', 'foo', 'not', 'supported', 'mean', 'median'),
Expand Down Expand Up @@ -352,41 +352,41 @@ def test_property_exceptions(event_property, init_kwargs, input_df, exception, m
id='amplitude_two_samples_xy_move',
),
pytest.param(
event_properties.position,
event_properties.location,
{'method': 'mean'},
pl.DataFrame(
{'position': [[0, 0], [1, 0]]},
schema={'position': pl.List(pl.Float64)},
),
pl.DataFrame(
{'position': [[0.5, 0]]},
schema={'position': pl.List(pl.Float64)},
{'location': [[0.5, 0]]},
schema={'location': pl.List(pl.Float64)},
),
id='position_two_samples_mean',
),
pytest.param(
event_properties.position,
event_properties.location,
{'method': 'mean'},
pl.DataFrame(
{'position': [[0, 0], [0, 1], [0, 3]]},
schema={'position': pl.List(pl.Float64)},
),
pl.DataFrame(
{'position': [[0, 1.3333333333333333]]},
schema={'position': pl.List(pl.Float64)},
{'location': [[0, 1.3333333333333333]]},
schema={'location': pl.List(pl.Float64)},
),
id='position_three_samples_mean',
),
pytest.param(
event_properties.position,
event_properties.location,
{'method': 'median'},
pl.DataFrame(
{'position': [[0, 0], [2, 1], [3, 3]]},
schema={'position': pl.List(pl.Float64)},
),
pl.DataFrame(
{'position': [[2, 1]]},
schema={'position': pl.List(pl.Float64)},
{'location': [[2, 1]]},
schema={'location': pl.List(pl.Float64)},
),
id='position_three_samples_median',
),
Expand All @@ -407,7 +407,7 @@ def test_property_has_expected_result(event_property, init_kwargs, input_df, exp
pytest.param(event_properties.dispersion, 'dispersion', id='dispersion'),
pytest.param(event_properties.amplitude, 'amplitude', id='amplitude'),
pytest.param(event_properties.disposition, 'disposition', id='disposition'),
pytest.param(event_properties.position, 'position', id='position'),
pytest.param(event_properties.location, 'location', id='location'),
],
)
def test_property_registered(property_function, property_function_name):
Expand Down

0 comments on commit 2afecda

Please sign in to comment.