{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Video Analysis"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import math\n",
"import matplotlib.pyplot as plt\n",
"from scipy.interpolate import interp1d\n",
"import numpy as np\n",
"from glob import glob\n",
"\n",
"# set decimal precision\n",
"pd.set_option('precision', 3)\n",
"\n",
"# set plot parameters\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_formats = ['svg']\n",
"plt.rcParams.update(\n",
" {\n",
" 'axes.grid': True,\n",
" 'axes.spines.bottom': False,\n",
" 'axes.spines.left': False,\n",
" 'axes.spines.right': False,\n",
" 'axes.spines.top': False,\n",
" 'font.family': 'Iosevka sbruder'\n",
" }\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"project = 'chaospendel/coole_bewegung_0'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"tracking_data = pd.read_csv(f'data/{project}.csv')\n",
"# remove all unneeded columns and rename them for easier handling\n",
"tracking_data = tracking_data[['time (s)', 'x (m)', 'y (m)', 'rotation']]\n",
"tracking_data = tracking_data.rename(columns={'time (s)': 't', 'x (m)': 'x', 'y (m)': 'y'})"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# add new columns for distance, velocity and acceleration\n",
"tracking_data['s'] = 0.0 * len(tracking_data)\n",
"tracking_data['v'] = 0.0 * len(tracking_data)\n",
"tracking_data['a'] = 0.0 * len(tracking_data)\n",
"\n",
"# calculate velocities and insert them\n",
"for idx in tracking_data.index[1:]:\n",
" xdelta = tracking_data.loc[idx]['x'] - tracking_data.loc[idx - 1]['x']\n",
" ydelta = tracking_data.loc[idx]['y'] - tracking_data.loc[idx - 1]['y']\n",
" tdelta = tracking_data.loc[idx]['t'] - tracking_data.loc[idx - 1]['t']\n",
" distance = math.sqrt(xdelta**2 + ydelta**2)\n",
" velocity = distance / tdelta\n",
" tracking_data.at[idx, 's'] = distance + tracking_data.loc[idx - 1]['s']\n",
" tracking_data.at[idx, 'v'] = velocity\n",
" \n",
" vdelta = tracking_data.loc[idx]['v'] - tracking_data.loc[idx - 1]['v']\n",
" acceleration = vdelta / tdelta\n",
" tracking_data.at[idx, 'a'] = acceleration\n",
" \n",
" tracking_data.at[idx, 'rotation'] = tracking_data.loc[idx]['rotation'] - 180"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# remove first two rows (too high acceleration)\n",
"tracking_data = tracking_data.drop([0, 1])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"