Skip to content

Commit

Permalink
adds enmo convinience function
Browse files Browse the repository at this point in the history
  • Loading branch information
Trybnetic committed Sep 6, 2024
1 parent fadedad commit 688b85f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion paat/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def calculate_vector_magnitude(data, minus_one=False, round_negative_to_zero=Fal
round_negative_to_zero : Boolean (optional)
If set to True, round negative values to zero
dtype : np.dtype (optional)
set the data type of the return array. Standard float 16, but can be set to better precision
set the data type of the return array. Standard float 32, but can be set to better precision
Returns
Expand Down Expand Up @@ -78,6 +78,27 @@ def calculate_vector_magnitude(data, minus_one=False, round_negative_to_zero=Fal
return vector_magnitude.reshape(data.shape[0], 1)


def calculate_enmo(data, dtype=np.float32):
"""
Calculate the Euclidean norm minus one from raw acceleration data.
This function is a wrapper of `calculate_vector_magnitude`.
Parameters
----------
data : array_like
numpy array with acceleration data
dtype : np.dtype (optional)
set the data type of the return array. Standard float 32, but can be set to better precision
Returns
-------
vector_magnitude : np.array (acceleration values, 1)(np.float)
numpy array with vector magnitude of the acceleration
"""
if isinstance(data, pd.DataFrame):
data = data[["Y", "X", "Z"]].values

return calculate_vector_magnitude(data, minus_one=True, round_negative_to_zero=True)


def calculate_frequency_features(data, win_len=60, win_step=60, sample_rate=100, nfft=512, nfilt=40):
"""
Calculate frequency features from raw acceleration signal.
Expand Down

0 comments on commit 688b85f

Please sign in to comment.