Movement Smoothness Documentation#

smoothness.py is a module contains functions for estimating movement smoothness from different types sensors and different measures.


monalysa.quality.smoothness.dimensionless_jerk(movement: array, fs: float, data_type: str = 'vel', rem_mean: bool = False) float#

Calculates the smoothness metric for the given velocity profile using the dimensionless jerk metric.

Parameters:
  • movement (np.array) – The array containing the movement velocity (acceleration or jerk) profile. This can be multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the different dimensions.

  • fs (float) – The sampling frequency of the data.

  • data_type (string) – The type of movement data provided. This will determine the scaling factor to be used. There are only two possibiliies, {‘vel’, ‘accl’}, corresponding to velocity, and acceleration.

  • rem_mean (booleans) – This indicates if the mean of the given movement data must be removed before comupting the jerk. It must be noted that when the movement data is velocity, this parameter is ignored. This parameter is used only when the movement data is acceleration or jerk.

Returns:

dl – The dimensionless jerk estimate of the given movement’s smoothness.

Return type:

float

Notes

Examples

>>> t = np.arange(-1, 1, 0.01)
>>> move = np.exp(-5*pow(t, 2))
>>> dl = dimensionless_jerk(np.array([move]).T, fs=100.)
>>> print(f'{dl:0.5f}')
'-335.74684'
>>> dl = dimensionless_jerk(np.array([move, move, move]).T, fs=100.)
>>> print(f'{dl:0.5f}')
'-335.74684'
monalysa.quality.smoothness.dimensionless_jerk_factors(movement, fs, data_type: str = 'vel', rem_mean: bool = False) tuple[float, float, float]#

Returns the individual factors of the dimensionless jerk metric.

Parameters:
  • movement (np.array) – The array containing the movement velocity (acceleration or jerk) profile. This can be multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the different dimensions.

  • fs (float) – The sampling frequency of the data.

  • data_type (string) – The type of movement data provided. This will determine the scaling factor to be used. There are only two possibilities, {‘vel’, ‘accl’}, corresponding to velocity, and acceleration.

  • rem_mean (booleans) – This indicates if the mean of the given movement data must be removed before computing the jerk. It must be noted that when the movement data is velocity, this parameter is ignored. This parameter is used only when the movement data is acceleration or jerk.

Returns:

  • T^N (float) – Duration scaling factor.

  • A^M (float) – Amplitude scaling factor.

  • J (float) – Jerk cost.

Notes

Examples

monalysa.quality.smoothness.log_dimensionless_jerk(movement: array, fs: float, data_type: str = 'vel', rem_mean: bool = False) float#

Calculates the smoothness metric for the given movement velocity, acceleration or jerk profile using the log dimensionless jerk metric.

Parameters:
  • movement (np.array) – The array containing the movement velocity (acceleration or jerk) profile. This can be multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the different dimensions.

  • fs (float) – The sampling frequency of the data.

  • data_type (string) – The type of movement data provided. This will determine the scaling factor to be used. There are only two possibiliies, {‘vel’, ‘accl’}, corresponding to velocity, and acceleration.

  • rem_mean (booleans) – This indicates if the mean of the given movement data must be removed before comupting the jerk. It must be noted that when the movement data is velocity, this parameter is ignored. This parameter is used only when the movement data is acceleration or jerk.

Returns:

ldlj – The log dimensionless jerk estimate of the given movement’s smoothness.

Return type:

float

Notes

Examples

>>> t = np.arange(-1, 1, 0.01)
>>> move = np.exp(-5*pow(t, 2))
>>> dl = log_dimensionless_jerk(np.array([move]).T, fs=100.)
>>> print(f'{ldl:0.5f}')
'-5.81636'
>>> dl = log_dimensionless_jerk(np.array([move, move, move]).T, fs=100.)
>>> print(f'{ldl:0.5f}')
'-5.81636'
monalysa.quality.smoothness.log_dimensionless_jerk_factors(movement: array, fs: float, data_type: str = 'vel', rem_mean: bool = False) tuple[float, float, float]#

Returns the individual factors of the dimensionless jerk metric.

Parameters:
  • movement (np.array) – The array containing the movement velocity (acceleration or jerk) profile. This can be multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the different dimensions.

  • fs (float) – The sampling frequency of the data.

  • data_type (string) – The type of movement data provided. This will determine the scaling factor to be used. There are only two possibilities, {‘vel’, ‘accl’}, corresponding to velocity, and acceleration.

  • rem_mean (booleans) – This indicates if the mean of the given movement data must be removed before computing the jerk. It must be noted that when the movement data is velocity, this parameter is ignored. This parameter is used only when the movement data is acceleration or jerk.

Returns:

  • -ln(T^N) (float) – Duration scaling factor.

  • +ln(A^M) (float) – Amplitude scaling factor.

  • -ln(J) (float) – Jerk cost.

Notes

Examples

monalysa.quality.smoothness.log_dimensionless_jerk_imu(accls: array, gyros: array, fs: float) float#

Calculates the smoothness metric for the given IMU data, accelerometer and gyroscope signals, using the log dimensionless jerk metric.

Parameters:
  • accls (np.array) – The array containing the accelerometer profile. This is a multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the x, y, and z components.

  • gyros (np.array) – The array containing the gyroscope profile. This is multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the x, y, and z components.

  • fs (float) – The sampling frequency of the data.

Returns:

ldlj – The log dimensionless jerk estimate of the given movement’s smoothness.

Return type:

float

Notes

Examples

monalysa.quality.smoothness.log_dimensionless_jerk_imu_factors(accls: array, gyros: array, fs: float) tuple[float, float, float]#

Returns the individual factors of the log dimensionless jerk metric used for IMU data.

Parameters:
  • accls (np.array) – The array containing the accelerometer profile. This is a multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the x, y, and z components.

  • gyros (np.array) – The array containing the gyroscope profile. This is multi-dimensional with the rows corresponding to the time samples and the columns corresponding to the x, y, and z components.

  • fs (float) – The sampling frequency of the data.

Returns:

  • -ln(T) (float) – Duration scaling factor.

  • +ln(A) (float) – Amplitude scaling factor.

  • -ln(J) (float) – Jerk cost.

Notes

Examples

monalysa.quality.smoothness.sparc(movement: array, fs: float, padlevel: int = 4, fc: float = 10.0, amp_th: float = 0.05) tuple[float, numpy.array, numpy.array]#

Calcualtes the smoothness of the given speed profile using the modified spectral arc length metric.

Parameters:
  • movement (np.array) – The array containing the movement speed profile.

  • fs (float) – The sampling frequency of the data.

  • padlevel (integer, optional) – Indicates the amount of zero padding to be done to the movement data for estimating the spectral arc length. [default = 4]

  • fc (float, optional) – The max. cut off frequency for calculating the spectral arc length metric. [default = 10.]

  • amp_th (float, optional) – The amplitude threshold to used for determining the cut off frequency upto which the spectral arc length is to be estimated. [default = 0.05]

Returns:

  • sal (float) – The spectral arc length estimate of the given movement’s smoothness.

  • (f, Mf) (tuple of two np.arrays) – This is the frequency(f) and the magntiude spectrum(Mf) of the given movement data. This spectral is from 0. to fs/2.

  • (f_sel, Mf_sel) (tuple of two np.arrays) – This is the portion of the spectrum that is selected for calculating the spectral arc length.

Notes

This is the modfieid spectral arc length metric, which has been tested only for discrete movements.

Examples

>>> t = np.arange(-1, 1, 0.01)
>>> move = np.exp(-5*pow(t, 2))
>>> smooth, _, _ = sparc(move, fs=100.)
>>> print(f'{smooth:0.5f}')
'-1.41403'