Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predictions #12

Merged
merged 7 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions docs/notebooks/gait/1.preprocess_imu.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"# Automatically reload modules\n",
"%load_ext autoreload\n",
Expand All @@ -50,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -91,7 +82,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -126,40 +117,40 @@
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>31013</th>\n",
" <th>22885</th>\n",
" <td>10.0</td>\n",
" <td>322</td>\n",
" <td>973</td>\n",
" <td>-1681</td>\n",
" <td>51</td>\n",
" <td>-18</td>\n",
" <td>2</td>\n",
" <td>304</td>\n",
" <td>1569</td>\n",
" <td>-1124</td>\n",
" <td>42</td>\n",
" <td>-19</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43503</th>\n",
" <th>46205</th>\n",
" <td>10.0</td>\n",
" <td>1291</td>\n",
" <td>604</td>\n",
" <td>-1394</td>\n",
" <td>168</td>\n",
" <td>80</td>\n",
" <td>-12</td>\n",
" <td>1341</td>\n",
" <td>1097</td>\n",
" <td>-714</td>\n",
" <td>635</td>\n",
" <td>60</td>\n",
" <td>90</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" time acceleration_x acceleration_y acceleration_z rotation_x \\\n",
"31013 10.0 322 973 -1681 51 \n",
"43503 10.0 1291 604 -1394 168 \n",
"22885 10.0 304 1569 -1124 42 \n",
"46205 10.0 1341 1097 -714 635 \n",
"\n",
" rotation_y rotation_z \n",
"31013 -18 2 \n",
"43503 80 -12 "
"22885 -19 3 \n",
"46205 60 90 "
]
},
"execution_count": 24,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -182,7 +173,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -205,8 +196,19 @@
" values_unscaled=np.array(df[list(d_channels_units.keys())]),\n",
" scale_factors=metadata_samples.scale_factors)\n",
"\n",
"# correct for sensor orientation - this subject has watch on right-hand side\n",
"side_watch = 'left'\n",
"df[DataColumns.ACCELERATION_Z] *= -1\n",
"if side_watch == 'right':\n",
" df[DataColumns.ACCELERATION_X] *= -1\n",
"\n",
"for col in [x for x in d_channels_units.keys() if 'acceleration' in x]:\n",
" for result, side_pass in zip(['filt', 'grav'], ['lp', 'hp']):\n",
"\n",
" # change to correct units [g]\n",
" if acceleration_units == 'm/s^2':\n",
" df[col] /= 9.81\n",
"\n",
" for result, side_pass in zip(['filt', 'grav'], ['hp', 'lp']):\n",
" df[f'{result}_{col}'] = dbpd.imu_preprocessing.butterworth_filter(\n",
" config=ppp,\n",
" single_sensor_col=np.array(df[col]),\n",
Expand All @@ -228,7 +230,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down
104 changes: 70 additions & 34 deletions docs/notebooks/gait/2.extract_features_gait.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 52,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -51,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -94,10 +94,46 @@
"l_data_point_level_cols = l_acceleration_cols + l_gravity_cols\n",
"\n",
"# store data\n",
"l_channels = ([f'{x}_{y}' for x in l_gravity_cols for y in ['mean', 'std']] + \n",
" [f'{x}_{y}' for x in l_acceleration_cols for y in ['power_below_gait', 'power_gait', 'power_tremor', 'power_above_tremor']] + \n",
" ['std_norm_acc']\n",
")"
"d_channels_values = {\n",
" 'grav_acceleration_x_mean': 'g',\n",
" 'grav_acceleration_y_mean': 'g',\n",
" 'grav_acceleration_z_mean': 'g',\n",
" 'grav_acceleration_x_std': 'g',\n",
" 'grav_acceleration_y_std': 'g',\n",
" 'grav_acceleration_z_std': 'g',\n",
" 'acceleration_x_power_below_gait': 'X',\n",
" 'acceleration_y_power_below_gait': 'X',\n",
" 'acceleration_z_power_below_gait': 'X',\n",
" 'acceleration_x_power_gait': 'X',\n",
" 'acceleration_y_power_gait': 'X',\n",
" 'acceleration_z_power_gait': 'X',\n",
" 'acceleration_x_power_tremor': 'X',\n",
" 'acceleration_y_power_tremor': 'X',\n",
" 'acceleration_z_power_tremor': 'X',\n",
" 'acceleration_x_power_above_tremor': 'X',\n",
" 'acceleration_y_power_above_tremor': 'X',\n",
" 'acceleration_z_power_above_tremor': 'X',\n",
" 'acceleration_x_dominant_frequency': 'Hz',\n",
" 'acceleration_y_dominant_frequency': 'Hz',\n",
" 'acceleration_z_dominant_frequency': 'Hz',\n",
" 'std_norm_acc': 'X',\n",
" 'cc_1_acc': 'X',\n",
" 'cc_2_acc': 'X',\n",
" 'cc_3_acc': 'X',\n",
" 'cc_4_acc': 'X',\n",
" 'cc_5_acc': 'X',\n",
" 'cc_6_acc': 'X',\n",
" 'cc_7_acc': 'X',\n",
" 'cc_8_acc': 'X',\n",
" 'cc_9_acc': 'X',\n",
" 'cc_10_acc': 'X',\n",
" 'cc_11_acc': 'X',\n",
" 'cc_12_acc': 'X',\n",
" 'cc_13_acc': 'X',\n",
" 'cc_14_acc': 'X',\n",
" 'cc_15_acc': 'X',\n",
" 'cc_16_acc': 'X'\n",
"}"
]
},
{
Expand All @@ -116,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 54,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -153,38 +189,38 @@
" <tr>\n",
" <th>0</th>\n",
" <td>0.00</td>\n",
" <td>-4.159470e-08</td>\n",
" <td>-5.271109</td>\n",
" <td>4.336545e-08</td>\n",
" <td>5.495509</td>\n",
" <td>-2.067087e-08</td>\n",
" <td>-2.619526</td>\n",
" <td>-0.537320</td>\n",
" <td>-4.240030e-09</td>\n",
" <td>0.560195</td>\n",
" <td>4.420535e-09</td>\n",
" <td>0.267026</td>\n",
" <td>2.107122e-09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.01</td>\n",
" <td>-3.711922e-07</td>\n",
" <td>-4.870643</td>\n",
" <td>3.918652e-07</td>\n",
" <td>5.695250</td>\n",
" <td>-1.835777e-07</td>\n",
" <td>-2.307776</td>\n",
" <td>-0.496498</td>\n",
" <td>-3.783814e-08</td>\n",
" <td>0.580556</td>\n",
" <td>3.994549e-08</td>\n",
" <td>0.235247</td>\n",
" <td>1.871333e-08</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" time acceleration_x grav_acceleration_x acceleration_y \\\n",
"0 0.00 -4.159470e-08 -5.271109 4.336545e-08 \n",
"1 0.01 -3.711922e-07 -4.870643 3.918652e-07 \n",
"0 0.00 -0.537320 -4.240030e-09 0.560195 \n",
"1 0.01 -0.496498 -3.783814e-08 0.580556 \n",
"\n",
" grav_acceleration_y acceleration_z grav_acceleration_z \n",
"0 5.495509 -2.067087e-08 -2.619526 \n",
"1 5.695250 -1.835777e-07 -2.307776 "
"0 4.420535e-09 0.267026 2.107122e-09 \n",
"1 3.994549e-08 0.235247 1.871333e-08 "
]
},
"execution_count": 11,
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -208,7 +244,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 55,
"metadata": {},
"outputs": [
{
Expand All @@ -233,7 +269,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 56,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -248,7 +284,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -261,7 +297,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -297,7 +333,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 59,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -323,7 +359,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -341,7 +377,7 @@
},
{
"cell_type": "code",
"execution_count": 88,
"execution_count": 61,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -357,8 +393,8 @@
"metadata_time.__setattr__('file_name', 'gait_time.bin')\n",
"metadata_time.__setattr__('file_dir_path', output_path)\n",
"\n",
"metadata_samples.__setattr__('channels', [x for x in df_windowed.columns if x != 'time'])\n",
"metadata_samples.__setattr__('units', np.concatenate([np.repeat('m/s^2', 7), np.repeat([np.repeat('X', 4).tolist() + ['Hz']], 3), np.repeat('X', 16)]).tolist())\n",
"metadata_samples.__setattr__('channels', list(d_channels_values.keys()))\n",
"metadata_samples.__setattr__('units', list(d_channels_values.values()))\n",
"\n",
"metadata_time.__setattr__('channels', ['time'])\n",
"metadata_time.__setattr__('units', ['s'])\n",
Expand All @@ -367,7 +403,7 @@
},
{
"cell_type": "code",
"execution_count": 89,
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
Expand Down
Loading
Loading