Skip to content

Commit

Permalink
example for homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
masoudabedinifar committed Aug 14, 2024
1 parent 5f82bd0 commit cab6aa8
Showing 1 changed file with 160 additions and 36 deletions.
196 changes: 160 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,168 @@ classDiagram
```
A recording consists of the motion data from one or more tracking systems, where each tracking system may consist motion data from one or more tracked points. Therefore, the motion data (`KielMATRecording.data`) are organized as a dictionary where the dictionary keys refer to the tracking systems, and the corresponding values the actual (raw) data as a `pandas.DataFrame`. The description of data channels (`KielMATRecording.channels`) is availabe as a dictionary with the same keys, and the values contain the channels description.

#### Example 1: Custom Dataset
You can create a KielMATRecording instance from your own motion data. Suppose you have motion data from your tracking system in a CSV file structured as follows:

```python
>>> from kielmat.datasets import mobilised
>>> file_name = "/mnt/neurogeriatrics_data/Mobilise-D/rawdata/sub-3011/Free-living/data.mat"
>>> recording = mobilised.load_recording(file_name, tracking_systems=["SU", "SU_INDIP"], tracked_points=["LowerBack"])
>>> recording.data
{'SU': LowerBack_ACCEL_x ... LowerBack_BARO_n/a
0 0.967784 ... 1011.628100
1 0.969667 ... 1011.628400
... ... ... ...
993022 0.970579 ... 1012.078703
993023 0.960542 ... 1002.580321

[993024 rows x 10 columns],

'SU_INDIP': LowerBack_ACCEL_x ... LowerBack_MAGN_z
0 0.967986 ... -5.902833
1 0.963671 ... 9.501037
... ... ... ...
993022 0.951656 ... -17.987983
993023 0.955107 ... -18.050600

[993024 rows x 9 columns]
}
timestamp YourTrackedPoint_ACCEL_x YourTrackedPoint_ACCEL_y YourTrackedPoint_ACCEL_z YourTrackedPoint_GYRO_x YourTrackedPoint_GYRO_y YourTrackedPoint_GYRO_z
0 0.00 0.1 0.2 9.8 0.01 0.02 0.03
1 0.01 0.1 0.2 9.8 0.01 0.02 0.03
... ... ... ... ... ... ... ...
```

You can create a `KielMATRecording` as follows:

```python
import pandas as pd
from kielmat.utils.kielmat_dataclass import KielMATRecording

# Load your motion data into a pandas DataFrame
motion_data = pd.read_csv("path_to_your_data.csv")

# Calculate the sampling frequency using the timestamp column
time_diff = motion_data["timestamp"].diff().dropna() # Calculate time differences
sampling_frequency = 1 / time_diff.mean() # Sampling frequency in Hz

# Drop the timestamp column, as it is not needed in the motion data
motion_data = motion_data.drop(columns=["timestamp"])

# Define the tracking system and tracked point names
tracking_system = "YourTrackingSystem"
tracked_point = "YourTrackedPoint"

# Create the data dictionary
data = {tracking_system: motion_data}

# Create the channels DataFrame
channels_info = pd.DataFrame({
"name": [f"{tracked_point}_ACCEL_x", f"{tracked_point}_ACCEL_y",
f"{tracked_point}_ACCEL_z", f"{tracked_point}_GYRO_x",
f"{tracked_point}_GYRO_y", f"{tracked_point}_GYRO_z"],
"type": ["ACCEL", "ACCEL", "ACCEL", "GYRO", "GYRO", "GYRO"],
"component": ["x", "y", "z", "x", "y", "z"],
"tracked_point": [tracked_point] * 6,
"units": ["g", "g", "g", "deg/s", "deg/s", "deg/s"],
"sampling_frequency": [sampling_frequency] * 6
})

# Create the channels dictionary
channels = {tracking_system: channels_info}

# Create a KielMATRecording instance
recording = KielMATRecording(data=data, channels=channels)

# Print data and channels information
print(recording.data)
print(recording.channels)
```
```python
{'YourTrackingSystem': YourTrackedPoint_ACCEL_x YourTrackedPoint_ACCEL_y \
0 0.1 0.2
1 0.1 0.2
... ... ...

YourTrackedPoint_ACCEL_z YourTrackedPoint_GYRO_x YourTrackedPoint_GYRO_y \
0 9.8 0.01 0.02
1 9.8 0.01 0.02
... ... ... ...

YourTrackedPoint_GYRO_z
0 0.03
1 0.03
... ... }

{'YourTrackingSystem': name component type tracked_point units \
0 YourTrackedPoint_ACCEL_x x ACCEL YourTrackedPoint g
1 YourTrackedPoint_ACCEL_y y ACCEL YourTrackedPoint g
2 YourTrackedPoint_ACCEL_z z ACCEL YourTrackedPoint g
3 YourTrackedPoint_GYRO_x x GYRO YourTrackedPoint deg/s
4 YourTrackedPoint_GYRO_y y GYRO YourTrackedPoint deg/s
5 YourTrackedPoint_GYRO_z z GYRO YourTrackedPoint deg/s

sampling_frequency
0 100.0
1 100.0
2 100.0
3 100.0
4 100.0
5 100.0 }
```

#### Example 2: Mobilise-D Dataset
You can also load data from the [`Mobilise-D`](https://neurogeriatricskiel.github.io/KielMAT/datasets/mobilised/) dataset, one of the datasets available in the toolbox. To do this, use the `load_recording()` function in the `kielmat.datasets.mobilised`.

>>> recording.channels
```python
import numpy as np
from pathlib import Path
from kielmat.datasets import mobilised

# Load data from the Mobilise-D dataset
recording = mobilised.load_recording()

# The keys of the recording
recording.__dict__.keys()
dict_keys(['data', 'channels', 'info', 'events', 'events_info'])

# Print the data information
print(recording.data)
{'SU': LowerBack_ACCEL_x LowerBack_ACCEL_y LowerBack_ACCEL_z \
0 0.933334 0.084820 -0.302665
1 0.932675 0.084844 -0.300591
2 0.932350 0.082886 -0.310576
3 0.929716 0.081786 -0.303551
4 0.932825 0.077879 -0.308859
... ... ... ...
693471 -0.192553 -0.016052 -0.984290
693472 -0.189575 -0.016449 -0.988130
693473 -0.191176 -0.017954 -0.983820
693474 -0.189691 -0.014539 -0.986376
693475 -0.192993 -0.015306 -0.989452

LowerBack_GYRO_x LowerBack_GYRO_y LowerBack_GYRO_z \
0 5.600066 1.120697 0.489152
1 5.440734 1.401663 0.279477
2 5.196312 1.168802 0.435765
3 5.553083 1.116346 0.383447
4 5.437505 0.892803 -0.150115
... ... ... ...
693471 -0.225874 0.832856 0.704711
693472 -0.393438 0.598116 0.522755
693473 -0.430749 0.417541 0.282336
693474 -0.279277 0.559122 0.418693
693475 -0.563741 0.478618 0.411295

LowerBack_MAGN_x LowerBack_MAGN_y LowerBack_MAGN_z \
0 -93.972011 -25.023998 44.675028
1 -93.958012 -25.016007 44.610055
2 -93.946010 -25.000014 44.520078
3 -93.938007 -24.980018 44.411097
4 -93.935003 -24.957021 44.287113
... ... ... ...
693471 -50.718928 -36.997006 34.111960
693472 -50.649929 -37.003005 34.072972
693473 -50.579936 -37.008003 34.044986
693474 -50.515946 -37.011000 34.031004
693475 -50.460961 -37.010996 34.035025

LowerBack_BARO_n/a
0 990.394600
1 990.395100
2 990.395600
3 990.396199
4 990.396700
... ...
693471 990.204600
693472 990.204900
693473 990.205200
693474 990.205500
693475 990.205800

[693476 rows x 10 columns]}

# Print the channels information
print(recording.channels)
{'SU':
name type component tracked_point units sampling_frequency
0 LowerBack_ACCEL_x Acc x LowerBack g 100.0
Expand All @@ -96,19 +233,6 @@ classDiagram
7 LowerBack_MAGN_y Mag y LowerBack µT 100.0
8 LowerBack_MAGN_z Mag z LowerBack µT 100.0
9 LowerBack_BARO_n/a Bar n/a LowerBack hPa 100.0,

'SU_INDIP':
name type component tracked_point units sampling_frequency
0 LowerBack_ACCEL_x Acc x LowerBack g 100.0
1 LowerBack_ACCEL_y Acc y LowerBack g 100.0
2 LowerBack_ACCEL_z Acc z LowerBack g 100.0
3 LowerBack_ANGVEL_x Gyr x LowerBack deg/s 100.0
4 LowerBack_ANGVEL_y Gyr y LowerBack deg/s 100.0
5 LowerBack_ANGVEL_z Gyr z LowerBack deg/s 100.0
6 LowerBack_MAGN_x Mag x LowerBack µT 100.0
7 LowerBack_MAGN_y Mag y LowerBack µT 100.0
8 LowerBack_MAGN_z Mag z LowerBack µT 100.0
9 LowerBack_BARO_n/a Bar n/a LowerBack hPa 100.0,
}
```

Expand Down

0 comments on commit cab6aa8

Please sign in to comment.