mad-lab-fau / gaitmap

The Gait and Movement Analysis Package
https://gaitmap.readthedocs.io
Other
38 stars 2 forks source link

Cannot rotate a given dataset #50

Closed rmndrs89 closed 1 year ago

rmndrs89 commented 1 year ago

Hi all,

I am trying to integrate the gaitmap algorithsm in our workflow. Currently I am looking into 9-DOF IMU data from a low back-worn, left foot-worn and right foot-worn IMU that is already time-synchronized. I have prepared the data as a pandas DataFrame with a multi-index column header, and accelerometer data in m/s^2, gyroscope data in deg/s, and magnetometer data in Gauss.

Now, the data for the right foot is not in the gaitmap coordinate system (the +x axis points backwards, the +y axis points to the lateral side, i.e., data needs to be rotated by 180 degrees around the +z axis (that points up)). Therefore I constructed the following dictionary of rotation matrix:

rotation_matrics = {
      "left_foot": np.eye(3),
      "right_foot": np.array([[-1, 0, 0], [0, -1, 0], [0, 0, 1]]),
      "low_back": np.eye(3)
  }

and then I wanted to automatically align the sensor data with the gaitmap coordinate systems:

from gaitmap.utils.rotations import rotate_dataset
rotated_data = rotate_dataset(data, rotation_matrices)

However, this gives me an error: Exception has occurred: AttributeError 'numpy.ndarray' object has no attribute 'apply' File "D:\Projects\Brescia\main.py", line 34, in main rotated_data = rotate_dataset(data, rotation_matrics) File "D:\Projects\Brescia\main.py", line 40, in <module> main() AttributeError: 'numpy.ndarray' object has no attribute 'apply'

Any idea how to resolve this?

Best from Kiel, Robbin

AKuederle commented 1 year ago

Hi Robbin,

Great to here that you want to integrate gaitmap into your workflows!

Regarding your error: The rotations are expected to be scipy.spatial.Rotation objects. You can create them using the from_matrix method (https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.transform.Rotation.from_matrix.html)

Also I would suggest you use flip_dataset instead of rotate_dataset for your case. The input is the same, but the underlying implementation is optimized for 90 and 180 deg rotations, by not actually performing the matrix multiplications, but just changing axis and signs

AKuederle commented 1 year ago

I just realized, that this is indeed not explained correctly in the documentation. Will update this :)

AKuederle commented 1 year ago

Fixed here: https://github.com/mad-lab-fau/gaitmap/commit/993340e9d2be4d3ece5f2a0f16f41fd695153bcb

However, I realized the rotation functions (and likely other methods as well) don't support magnetometer at the moment. This means the mag columns will not be touched and will remain un-rotated

rmndrs89 commented 1 year ago

Hi Arne,

thanks for the quick fix! Yes, with scipy rotations it works.

When I look at the data, the rotated data does not contain the magnetometer columns anymore. For me, this is not a problem, but probably applying the same rotation to the magnetometer columns is an easy fix.

Best regards, Robbin

P.S.: my dataframe also has data from the low_back, these columns indeed do remain untouched (and thus have readings in the original sensor coordinate system, x, y, z)

AKuederle commented 1 year ago

Great! Yes, I think it would make sense to at least rotate the magnetometer columns correctly or at least keep extra columns in the data unrotated.

And yes for the lower back we don't have a standardized coordinate system yet, as we only have algorithms for the feet. So they are not transformed in any type of "body frame".

I will open an issue to track the magnetometer stuff though.

Let me know if you encounter any other issues!