Angle

angle(df=None, traces=None, per_traces=True)

Angle formed by 3 consecutive points. Computed using formula: 0i = arcos((yi+1-yi,xi+1-xi)*(yi-1-yi,xi-1-xi)/(di+1*di))

Parameters:
  • df (pd.DataFrame) – DataFrame containing required columns.

  • traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.

  • per_traces (bool) – Whether to compute the angle for each trace in the DataFrame. If False, the angle will be computed directly on the DataFrame.

Returns:

A dictionary with keys as (sessionId) and values as lists of DataFrames with the ‘angle’ column.

Return type:

dict

Practical Example

from pywib import angle

 # Calculate the angle
 df_angle = angle(df, per_traces=True)

 # Iterate over traces to obtain angle values
 for session_id, traces in df_angle.items():
     print(f"Session ID: {session_id}")
     for trace in traces:
         print(f"Velocity values:\n{trace['angle']}")

Notes

The method can be either run with either per_traces=True or per_traces=False, the first one segments the data by movement traces, while the second one computes the velocity for the entire DataFrame.

Angular Velocity

angular_velocity(df=None, traces=None, per_traces=True)

Angular velocity computed as the change in angle over time.

Parameters:
  • df (pd.DataFrame) – DataFrame containing required columns.

  • traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.

  • per_traces (bool) – Whether to compute the angular velocity for each trace in the DataFrame. If False, the angular velocity will be computed directly on the DataFrame.

Returns:

A dictionary with keys as (sessionId) and values as lists of DataFrames with the ‘angular_velocity’ column. df: pd.DataFrame: If not per traces, returns the DataFrame with the ‘angular_velocity’ column.

Return type:

dict

Practical Example

from pywib import angular_velocity

 angular_v = angular_velocity(data_frame, per_traces=True)

 for session_id, traces in angular_v.items():
     print(f"Session ID: {session_id}")
     for trace in traces:
         print(f"Velocity values:\n{trace['angular_velocity']}")

Angular Acceleration

angular_acceleration(df=None, traces=None, per_traces=True)

Angular acceleration computed as the change in angular velocity over time.

Parameters:
  • df (pd.DataFrame) – DataFrame containing required columns.

  • traces (dict) – A dictionary with keys as (sessionId) and values as lists of DataFrames. If None, traces will be computed from df.

  • per_traces (bool) – Whether to compute the angular acceleration for each trace in the DataFrame. If False, the angular acceleration will be computed directly on the DataFrame.

Returns:

A dictionary with keys as (sessionId) and values as lists of DataFrames with the ‘angular_acceleration’ column. df: pd.DataFrame: If not per traces, returns the DataFrame with the ‘angular_acceleration’ column.

Return type:

dict

Practical Example

from pywib import angular_acceleration

 angular_v = angular_acceleration(data_frame, per_traces=True)

 for session_id, traces in angular_v.items():
     print(f"Session ID: {session_id}")
     for trace in traces:
         print(f"Velocity values:\n{trace['angular_acceleration']}")