您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import os, sys\n",
  10. "import pandas as pd\n",
  11. "import numpy as np\n",
  12. "import coordsi as csi\n",
  13. "import math\n",
  14. "import time"
  15. ]
  16. },
  17. {
  18. "attachments": {},
  19. "cell_type": "markdown",
  20. "metadata": {},
  21. "source": [
  22. "A brief summary of each original coordinate"
  23. ]
  24. },
  25. {
  26. "cell_type": "code",
  27. "execution_count": 2,
  28. "metadata": {},
  29. "outputs": [
  30. {
  31. "name": "stdout",
  32. "output_type": "stream",
  33. "text": [
  34. "Warning: ./List_Data_Call/21002290020230321/cam1.csv is not exist.\n",
  35. " approx_total_frame x_min x_max y_min \n",
  36. "./List_Data_Call/21004038220221101 478800.0 -3.0 1900.0 -2.0 \\\n",
  37. "./List_Data_Call/21001264420230215 219600.0 -4.0 1901.0 -6.0 \n",
  38. "./List_Data_Call/21001555320230216 349200.0 -5.0 1884.0 -3.0 \n",
  39. "./List_Data_Call/21004030420221004 666000.0 -4.0 1902.0 -3.0 \n",
  40. "./List_Data_Call/21004008220221017 219600.0 -8.0 1883.0 -2.0 \n",
  41. "\n",
  42. " y_max z_min z_max \n",
  43. "./List_Data_Call/21004038220221101 1051.0 0.923129 4.137998 \n",
  44. "./List_Data_Call/21001264420230215 1055.0 0.953854 4.400389 \n",
  45. "./List_Data_Call/21001555320230216 1057.0 0.840809 3.938679 \n",
  46. "./List_Data_Call/21004030420221004 1057.0 0.933506 4.356071 \n",
  47. "./List_Data_Call/21004008220221017 1058.0 0.897373 4.207281 \n"
  48. ]
  49. }
  50. ],
  51. "source": [
  52. "# initialize root path\n",
  53. "root = './List_Data_Call/'\n",
  54. "\n",
  55. "summary_1 = csi.summaryOriginCoord(root, camid=1)\n",
  56. "print(summary_1.head())"
  57. ]
  58. },
  59. {
  60. "cell_type": "code",
  61. "execution_count": 3,
  62. "metadata": {},
  63. "outputs": [
  64. {
  65. "name": "stdout",
  66. "output_type": "stream",
  67. "text": [
  68. "./List_Data_Call/21004038220221101 64.0459258556366\n",
  69. "./List_Data_Call/21001264420230215 34.23401594161987\n",
  70. "./List_Data_Call/21001555320230216 55.52943301200867\n",
  71. "./List_Data_Call/21004030420221004 106.67347645759583\n",
  72. "./List_Data_Call/21004008220221017 31.72646999359131\n",
  73. "./List_Data_Call/21004056620230120 19.501684188842773\n",
  74. "./List_Data_Call/21001057620230126 53.51554536819458\n",
  75. "./List_Data_Call/21003885420220721 76.24831080436707\n",
  76. "./List_Data_Call/21004107920230313 97.09525084495544\n",
  77. "./List_Data_Call/21003975920220723 36.387489318847656\n",
  78. "./List_Data_Call/21004102020230228 31.510535717010498\n",
  79. "./List_Data_Call/21004036420221013 63.18059492111206\n",
  80. "./List_Data_Call/21003962420220712 36.284823179244995\n",
  81. "./List_Data_Call/21004048220221029 50.87060260772705\n",
  82. "./List_Data_Call/21003992420230119 49.36880159378052\n",
  83. "./List_Data_Call/21001418920220921 35.04419279098511\n",
  84. "./List_Data_Call/21004108620230225 94.45536732673645\n",
  85. "./List_Data_Call/21004095420230303 7.877222776412964\n",
  86. "./List_Data_Call/21003655120230207 22.74891757965088\n",
  87. "./List_Data_Call/21003817020230107 24.885369300842285\n",
  88. "./List_Data_Call/21003981020220923 36.27069091796875\n",
  89. "./List_Data_Call/21004033920221007 86.56228399276733\n",
  90. "./List_Data_Call/21004074720230104 37.52795934677124\n",
  91. "./List_Data_Call/21004037520230324 30.00572395324707\n",
  92. "./List_Data_Call/21004040420221103 90.27121639251709\n",
  93. "./List_Data_Call/21004026620221007 69.01991891860962\n",
  94. "./List_Data_Call/21001870620230315 39.85080003738403\n",
  95. "./List_Data_Call/21004068020230102 7.841302871704102\n",
  96. "./List_Data_Call/21004094420230206 100.37451100349426\n",
  97. "./List_Data_Call/21004097420230304 84.17479515075684\n",
  98. "./List_Data_Call/21004047820221028 89.44327425956726\n",
  99. "./List_Data_Call/21004051720230228 9.743078708648682\n",
  100. "./List_Data_Call/21004076520230204 76.26534867286682\n",
  101. "./List_Data_Call/21002591020230218 88.18855333328247\n",
  102. "./List_Data_Call/21004105820230311 59.186476945877075\n",
  103. "./List_Data_Call/21004037520230317 54.6233925819397\n",
  104. "./List_Data_Call/21003993520220917 95.81168413162231\n",
  105. "./List_Data_Call/21003967920220714 36.98200988769531\n",
  106. "./List_Data_Call/21004043620221025 25.73115038871765\n",
  107. "./List_Data_Call/21004097520230208 93.56520891189575\n",
  108. "./List_Data_Call/21004092020230127 89.9213137626648\n",
  109. "./List_Data_Call/21004026220220928 81.38130640983582\n"
  110. ]
  111. },
  112. {
  113. "ename": "ValueError",
  114. "evalue": "Found array with 0 sample(s) (shape=(0,)) while a minimum of 1 is required.",
  115. "output_type": "error",
  116. "traceback": [
  117. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  118. "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
  119. "Cell \u001b[0;32mIn[3], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m start_time \u001b[39m=\u001b[39m time\u001b[39m.\u001b[39mtime()\n\u001b[1;32m 5\u001b[0m df \u001b[39m=\u001b[39m csi\u001b[39m.\u001b[39mreadCam(os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mjoin(index,\u001b[39m'\u001b[39m\u001b[39mcam1.csv\u001b[39m\u001b[39m'\u001b[39m))\n\u001b[0;32m----> 6\u001b[0m df \u001b[39m=\u001b[39m csi\u001b[39m.\u001b[39;49mconvertToSI(df, \u001b[39m3.5\u001b[39;49m, \u001b[39m1.5\u001b[39;49m, \u001b[39m3.4\u001b[39;49m)\n\u001b[1;32m 7\u001b[0m df \u001b[39m=\u001b[39m csi\u001b[39m.\u001b[39mgetVelocity(df)\n\u001b[1;32m 8\u001b[0m df \u001b[39m=\u001b[39m csi\u001b[39m.\u001b[39mgetAcceleration(df)\n",
  120. "File \u001b[0;32m~/workspace/equation20/coordsi.py:62\u001b[0m, in \u001b[0;36mconvertToSI\u001b[0;34m(origin, w, l, h)\u001b[0m\n\u001b[1;32m 60\u001b[0m df \u001b[39m=\u001b[39m origin\u001b[39m.\u001b[39mcopy()\n\u001b[1;32m 61\u001b[0m \u001b[39m#normailze dataframe[0] from -1 to 1\u001b[39;00m\n\u001b[0;32m---> 62\u001b[0m df[\u001b[39m'\u001b[39m\u001b[39mx\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m preprocessing\u001b[39m.\u001b[39;49mminmax_scale(df[\u001b[39m'\u001b[39;49m\u001b[39mx\u001b[39;49m\u001b[39m'\u001b[39;49m], feature_range\u001b[39m=\u001b[39;49m(\u001b[39m-\u001b[39;49m(w\u001b[39m/\u001b[39;49m\u001b[39m2\u001b[39;49m), (w\u001b[39m/\u001b[39;49m\u001b[39m2\u001b[39;49m)), axis\u001b[39m=\u001b[39;49m\u001b[39m0\u001b[39;49m, copy\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n\u001b[1;32m 63\u001b[0m \u001b[39m#normailze dataframe[1] from -0.75 to 0.75\u001b[39;00m\n\u001b[1;32m 64\u001b[0m df[\u001b[39m'\u001b[39m\u001b[39my\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m preprocessing\u001b[39m.\u001b[39mminmax_scale(df[\u001b[39m'\u001b[39m\u001b[39my\u001b[39m\u001b[39m'\u001b[39m], feature_range\u001b[39m=\u001b[39m(\u001b[39m-\u001b[39m(l\u001b[39m/\u001b[39m\u001b[39m2\u001b[39m), (l\u001b[39m/\u001b[39m\u001b[39m2\u001b[39m)), axis\u001b[39m=\u001b[39m\u001b[39m0\u001b[39m, copy\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n",
  121. "File \u001b[0;32m~/.local/lib/python3.8/site-packages/sklearn/preprocessing/_data.py:624\u001b[0m, in \u001b[0;36mminmax_scale\u001b[0;34m(X, feature_range, axis, copy)\u001b[0m\n\u001b[1;32m 550\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Transform features by scaling each feature to a given range.\u001b[39;00m\n\u001b[1;32m 551\u001b[0m \n\u001b[1;32m 552\u001b[0m \u001b[39mThis estimator scales and translates each feature individually such\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 620\u001b[0m \u001b[39m<sphx_glr_auto_examples_preprocessing_plot_all_scaling.py>`.\u001b[39;00m\n\u001b[1;32m 621\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 622\u001b[0m \u001b[39m# Unlike the scaler object, this function allows 1d input.\u001b[39;00m\n\u001b[1;32m 623\u001b[0m \u001b[39m# If copy is required, it will be done inside the scaler object.\u001b[39;00m\n\u001b[0;32m--> 624\u001b[0m X \u001b[39m=\u001b[39m check_array(\n\u001b[1;32m 625\u001b[0m X, copy\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m, ensure_2d\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m, dtype\u001b[39m=\u001b[39;49mFLOAT_DTYPES, force_all_finite\u001b[39m=\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39mallow-nan\u001b[39;49m\u001b[39m\"\u001b[39;49m\n\u001b[1;32m 626\u001b[0m )\n\u001b[1;32m 627\u001b[0m original_ndim \u001b[39m=\u001b[39m X\u001b[39m.\u001b[39mndim\n\u001b[1;32m 629\u001b[0m \u001b[39mif\u001b[39;00m original_ndim \u001b[39m==\u001b[39m \u001b[39m1\u001b[39m:\n",
  122. "File \u001b[0;32m~/.local/lib/python3.8/site-packages/sklearn/utils/validation.py:931\u001b[0m, in \u001b[0;36mcheck_array\u001b[0;34m(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name)\u001b[0m\n\u001b[1;32m 929\u001b[0m n_samples \u001b[39m=\u001b[39m _num_samples(array)\n\u001b[1;32m 930\u001b[0m \u001b[39mif\u001b[39;00m n_samples \u001b[39m<\u001b[39m ensure_min_samples:\n\u001b[0;32m--> 931\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 932\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mFound array with \u001b[39m\u001b[39m%d\u001b[39;00m\u001b[39m sample(s) (shape=\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m) while a\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 933\u001b[0m \u001b[39m\"\u001b[39m\u001b[39m minimum of \u001b[39m\u001b[39m%d\u001b[39;00m\u001b[39m is required\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 934\u001b[0m \u001b[39m%\u001b[39m (n_samples, array\u001b[39m.\u001b[39mshape, ensure_min_samples, context)\n\u001b[1;32m 935\u001b[0m )\n\u001b[1;32m 937\u001b[0m \u001b[39mif\u001b[39;00m ensure_min_features \u001b[39m>\u001b[39m \u001b[39m0\u001b[39m \u001b[39mand\u001b[39;00m array\u001b[39m.\u001b[39mndim \u001b[39m==\u001b[39m \u001b[39m2\u001b[39m:\n\u001b[1;32m 938\u001b[0m n_features \u001b[39m=\u001b[39m array\u001b[39m.\u001b[39mshape[\u001b[39m1\u001b[39m]\n",
  123. "\u001b[0;31mValueError\u001b[0m: Found array with 0 sample(s) (shape=(0,)) while a minimum of 1 is required."
  124. ]
  125. }
  126. ],
  127. "source": [
  128. "#make a loop for each index\n",
  129. "for index, row in summary_1.iterrows():\n",
  130. " timestamp = []\n",
  131. " start_time = time.time()\n",
  132. " df = csi.readCam(os.path.join(index,'cam1.csv'))\n",
  133. " df = csi.convertToSI(df, 3.5, 1.5, 3.4)\n",
  134. " df = csi.getVelocity(df)\n",
  135. " df = csi.getAcceleration(df)\n",
  136. " df = csi.getFullTrace(df,row['approx_total_frame'] )\n",
  137. " df = csi.addValidDetection(df, 25.0)\n",
  138. " df.to_csv(os.path.join('./handletrace/', index[17:]+'.csv'), index=False)\n",
  139. " #save spend time and index of summary_1 in timestamp list \n",
  140. " timestamp.append([index, time.time() - start_time])\n",
  141. "#save timestamp list to csv file\n",
  142. "pd.DataFrame(timestamp, columns=['index', 'time']).to_csv('./handletrace/timestamp.csv', index=False)\n",
  143. "\n"
  144. ]
  145. },
  146. {
  147. "attachments": {},
  148. "cell_type": "markdown",
  149. "metadata": {},
  150. "source": [
  151. "import a origin coord and convert"
  152. ]
  153. },
  154. {
  155. "cell_type": "code",
  156. "execution_count": 3,
  157. "metadata": {},
  158. "outputs": [],
  159. "source": [
  160. "arr_1 = csi.readCam(os.path.join(summary_1.index[0],'cam1.csv'))\n",
  161. "si_1 = csi.convertToSI(arr_1, 3.5, 1.5, 3.4)\n",
  162. "#cartesian coordinate system\n",
  163. "#구면 좌표계로 변경도 해보자...나중에...\n",
  164. "#meter/(1/30)s\n",
  165. "si_1['positionvectorvalue'] = (si_1['x']**2 + si_1['y']**2 + si_1['z']**2)"
  166. ]
  167. },
  168. {
  169. "cell_type": "code",
  170. "execution_count": 4,
  171. "metadata": {},
  172. "outputs": [],
  173. "source": [
  174. "cal_buffer_1, cal_buffer_2 = si_1['positionvectorvalue'].copy(), si_1['positionvectorvalue'].copy()\n",
  175. "#print(cal_buffer_1,'\\n',cal_buffer_2)\n",
  176. "cal_buffer_1, cal_buffer_2= cal_buffer_1.to_frame(), cal_buffer_2.to_frame()\n",
  177. "cal_buffer_1 = list(cal_buffer_1.loc[:, 'positionvectorvalue'])\n",
  178. "cal_buffer_2 = list(cal_buffer_2.loc[:, 'positionvectorvalue'])\n",
  179. "cal_buffer_3 = [0.0]\n",
  180. "for v in range(0, len(cal_buffer_2)-1):\n",
  181. " cal_buffer_3.append(cal_buffer_2[v])\n",
  182. "buffer_a = np.array(cal_buffer_1)\n",
  183. "buffer_b = np.array(cal_buffer_3)"
  184. ]
  185. },
  186. {
  187. "cell_type": "code",
  188. "execution_count": 5,
  189. "metadata": {},
  190. "outputs": [],
  191. "source": [
  192. "velocity = (buffer_a - buffer_b)\n",
  193. "for x in range(0, len(velocity)):\n",
  194. " velocity[x] = math.sqrt(abs(velocity[x]))\n",
  195. "velocity[0]=0.0"
  196. ]
  197. },
  198. {
  199. "cell_type": "code",
  200. "execution_count": 6,
  201. "metadata": {},
  202. "outputs": [],
  203. "source": [
  204. "#merge each list as Series\n",
  205. "si_1['velocity'] = velocity\n",
  206. "#print(si_1)"
  207. ]
  208. },
  209. {
  210. "cell_type": "code",
  211. "execution_count": 7,
  212. "metadata": {},
  213. "outputs": [],
  214. "source": [
  215. "cal_buffer_4, cal_buffer_5 = si_1['velocity'].copy(), si_1['velocity'].copy()\n",
  216. "#print(cal_buffer_1,'\\n',cal_buffer_2)\n",
  217. "cal_buffer_4, cal_buffer_5= cal_buffer_4.to_frame(), cal_buffer_5.to_frame()\n",
  218. "cal_buffer_4 = list(cal_buffer_4.loc[:, 'velocity'])\n",
  219. "cal_buffer_5 = list(cal_buffer_5.loc[:, 'velocity'])\n",
  220. "cal_buffer_6 = [0.0]\n",
  221. "for v in range(0, len(cal_buffer_5)-1):\n",
  222. " cal_buffer_6.append(cal_buffer_5[v])\n",
  223. "buffer_c = np.array(cal_buffer_4)\n",
  224. "buffer_d = np.array(cal_buffer_6)"
  225. ]
  226. },
  227. {
  228. "cell_type": "code",
  229. "execution_count": 8,
  230. "metadata": {},
  231. "outputs": [],
  232. "source": [
  233. "acceleration = buffer_c - buffer_d\n",
  234. "acceleration[1] = 0.0\n",
  235. "#print(acceleration)"
  236. ]
  237. },
  238. {
  239. "cell_type": "code",
  240. "execution_count": 9,
  241. "metadata": {},
  242. "outputs": [],
  243. "source": [
  244. "si_1['acceleration'] = acceleration\n",
  245. "#print(si_1)"
  246. ]
  247. },
  248. {
  249. "attachments": {},
  250. "cell_type": "markdown",
  251. "metadata": {},
  252. "source": [
  253. "Calculate Velocity of all detected objects"
  254. ]
  255. },
  256. {
  257. "attachments": {},
  258. "cell_type": "markdown",
  259. "metadata": {},
  260. "source": [
  261. "\n",
  262. "TODO: approx_total_frame 개수 만큼의 빈 컬럼 생성 (나중에 전체 데이터프레임은 20등분으로 잘릴 예정) -> done\n",
  263. "실제 값이 존재하는 프레임을 찾고, 그 프레임을 인덱스에 맞추어 x,y,z 집어넣기\n",
  264. "존재한다면 (x^2 + y^2 + z^2)^(1/3) 을 계산하여 새 컬럼에 저장\n",
  265. "비 등속 보간 작업을 해야 하는데, 어떤 방식으로 할지 결정하기(piecewise_polynomial?)"
  266. ]
  267. },
  268. {
  269. "cell_type": "code",
  270. "execution_count": 11,
  271. "metadata": {},
  272. "outputs": [
  273. {
  274. "data": {
  275. "text/html": [
  276. "<div>\n",
  277. "<style scoped>\n",
  278. " .dataframe tbody tr th:only-of-type {\n",
  279. " vertical-align: middle;\n",
  280. " }\n",
  281. "\n",
  282. " .dataframe tbody tr th {\n",
  283. " vertical-align: top;\n",
  284. " }\n",
  285. "\n",
  286. " .dataframe thead th {\n",
  287. " text-align: right;\n",
  288. " }\n",
  289. "</style>\n",
  290. "<table border=\"1\" class=\"dataframe\">\n",
  291. " <thead>\n",
  292. " <tr style=\"text-align: right;\">\n",
  293. " <th></th>\n",
  294. " <th>x</th>\n",
  295. " <th>y</th>\n",
  296. " <th>z</th>\n",
  297. " <th>frame</th>\n",
  298. " <th>positionvectorvalue</th>\n",
  299. " <th>velocity</th>\n",
  300. " <th>acceleration</th>\n",
  301. " </tr>\n",
  302. " </thead>\n",
  303. " <tbody>\n",
  304. " <tr>\n",
  305. " <th>count</th>\n",
  306. " <td>62495.000000</td>\n",
  307. " <td>62495.000000</td>\n",
  308. " <td>62495.000000</td>\n",
  309. " <td>62495.000000</td>\n",
  310. " <td>62495.000000</td>\n",
  311. " <td>62495.000000</td>\n",
  312. " <td>62495.000000</td>\n",
  313. " </tr>\n",
  314. " <tr>\n",
  315. " <th>mean</th>\n",
  316. " <td>-0.202211</td>\n",
  317. " <td>-0.207365</td>\n",
  318. " <td>1.601385</td>\n",
  319. " <td>42805.432355</td>\n",
  320. " <td>2.733538</td>\n",
  321. " <td>0.138262</td>\n",
  322. " <td>0.000002</td>\n",
  323. " </tr>\n",
  324. " <tr>\n",
  325. " <th>std</th>\n",
  326. " <td>0.162759</td>\n",
  327. " <td>0.238811</td>\n",
  328. " <td>0.041177</td>\n",
  329. " <td>27211.098449</td>\n",
  330. " <td>0.162993</td>\n",
  331. " <td>0.120752</td>\n",
  332. " <td>0.124054</td>\n",
  333. " </tr>\n",
  334. " <tr>\n",
  335. " <th>min</th>\n",
  336. " <td>-0.750000</td>\n",
  337. " <td>-1.750000</td>\n",
  338. " <td>0.930000</td>\n",
  339. " <td>1.000000</td>\n",
  340. " <td>1.109630</td>\n",
  341. " <td>0.000000</td>\n",
  342. " <td>-1.650274</td>\n",
  343. " </tr>\n",
  344. " <tr>\n",
  345. " <th>25%</th>\n",
  346. " <td>-0.328348</td>\n",
  347. " <td>-0.377956</td>\n",
  348. " <td>1.574043</td>\n",
  349. " <td>19851.500000</td>\n",
  350. " <td>2.637680</td>\n",
  351. " <td>0.067702</td>\n",
  352. " <td>-0.045567</td>\n",
  353. " </tr>\n",
  354. " <tr>\n",
  355. " <th>50%</th>\n",
  356. " <td>-0.183048</td>\n",
  357. " <td>-0.240016</td>\n",
  358. " <td>1.598190</td>\n",
  359. " <td>38725.000000</td>\n",
  360. " <td>2.706999</td>\n",
  361. " <td>0.111651</td>\n",
  362. " <td>0.000205</td>\n",
  363. " </tr>\n",
  364. " <tr>\n",
  365. " <th>75%</th>\n",
  366. " <td>-0.096154</td>\n",
  367. " <td>-0.032186</td>\n",
  368. " <td>1.625495</td>\n",
  369. " <td>69024.500000</td>\n",
  370. " <td>2.793686</td>\n",
  371. " <td>0.168573</td>\n",
  372. " <td>0.045744</td>\n",
  373. " </tr>\n",
  374. " <tr>\n",
  375. " <th>max</th>\n",
  376. " <td>0.750000</td>\n",
  377. " <td>1.750000</td>\n",
  378. " <td>1.800000</td>\n",
  379. " <td>233066.000000</td>\n",
  380. " <td>6.039652</td>\n",
  381. " <td>1.941675</td>\n",
  382. " <td>1.692079</td>\n",
  383. " </tr>\n",
  384. " </tbody>\n",
  385. "</table>\n",
  386. "</div>"
  387. ],
  388. "text/plain": [
  389. " x y z frame \n",
  390. "count 62495.000000 62495.000000 62495.000000 62495.000000 \\\n",
  391. "mean -0.202211 -0.207365 1.601385 42805.432355 \n",
  392. "std 0.162759 0.238811 0.041177 27211.098449 \n",
  393. "min -0.750000 -1.750000 0.930000 1.000000 \n",
  394. "25% -0.328348 -0.377956 1.574043 19851.500000 \n",
  395. "50% -0.183048 -0.240016 1.598190 38725.000000 \n",
  396. "75% -0.096154 -0.032186 1.625495 69024.500000 \n",
  397. "max 0.750000 1.750000 1.800000 233066.000000 \n",
  398. "\n",
  399. " positionvectorvalue velocity acceleration \n",
  400. "count 62495.000000 62495.000000 62495.000000 \n",
  401. "mean 2.733538 0.138262 0.000002 \n",
  402. "std 0.162993 0.120752 0.124054 \n",
  403. "min 1.109630 0.000000 -1.650274 \n",
  404. "25% 2.637680 0.067702 -0.045567 \n",
  405. "50% 2.706999 0.111651 0.000205 \n",
  406. "75% 2.793686 0.168573 0.045744 \n",
  407. "max 6.039652 1.941675 1.692079 "
  408. ]
  409. },
  410. "execution_count": 11,
  411. "metadata": {},
  412. "output_type": "execute_result"
  413. }
  414. ],
  415. "source": [
  416. "si_1.describe()"
  417. ]
  418. },
  419. {
  420. "cell_type": "code",
  421. "execution_count": 12,
  422. "metadata": {},
  423. "outputs": [
  424. {
  425. "name": "stdout",
  426. "output_type": "stream",
  427. "text": [
  428. " x y z frame positionvectorvalue velocity acceleration \n",
  429. "478795 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \\\n",
  430. "478796 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  431. "478797 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  432. "478798 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  433. "478799 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
  434. "\n",
  435. " isValid \n",
  436. "478795 0.0 \n",
  437. "478796 0.0 \n",
  438. "478797 0.0 \n",
  439. "478798 0.0 \n",
  440. "478799 0.0 \n"
  441. ]
  442. }
  443. ],
  444. "source": [
  445. "# create dataframe with 6 columns and create 0 value rows as many as approx_total_frame value in summary_1\n",
  446. "j = 0\n",
  447. "handletrace = pd.DataFrame(columns=['x', 'y', 'z', 'frame', 'positionvectorvalue', 'velocity', 'acceleration', 'isValid'])\n",
  448. "handletrace = pd.concat([handletrace, pd.DataFrame(np.zeros((int(summary_1['approx_total_frame'][j]),8)), columns=['x', 'y', 'z', 'frame', 'positionvectorvalue','velocity', 'acceleration', 'isValid'])], axis=0)\n",
  449. "print(handletrace.tail())"
  450. ]
  451. },
  452. {
  453. "cell_type": "code",
  454. "execution_count": null,
  455. "metadata": {},
  456. "outputs": [],
  457. "source": [
  458. "#print(int(si_1['frame'][2]))\n",
  459. "#print(si_1.loc[2])"
  460. ]
  461. },
  462. {
  463. "cell_type": "code",
  464. "execution_count": 13,
  465. "metadata": {},
  466. "outputs": [],
  467. "source": [
  468. "# frame의 값에 해당하는 것으로 변경\n",
  469. "for x in range(0, len(si_1)):\n",
  470. " handletrace.loc[int(si_1['frame'][x])] = si_1.loc[x]\n",
  471. "handletrace['isValid'] = handletrace['isValid'].fillna(0)"
  472. ]
  473. },
  474. {
  475. "cell_type": "code",
  476. "execution_count": 14,
  477. "metadata": {},
  478. "outputs": [
  479. {
  480. "name": "stdout",
  481. "output_type": "stream",
  482. "text": [
  483. " x y z frame positionvectorvalue velocity \n",
  484. "0 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \\\n",
  485. "1 -0.400997 -0.319101 1.632182 1.0 2.926644 0.000000 \n",
  486. "2 -0.410969 -0.333815 1.629004 2.0 2.933981 0.085661 \n",
  487. "3 -0.412393 -0.352207 1.634730 3.0 2.966459 0.180214 \n",
  488. "4 -0.413818 -0.357725 1.638935 4.0 2.985322 0.137342 \n",
  489. "... ... ... ... ... ... ... \n",
  490. "478795 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  491. "478796 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  492. "478797 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  493. "478798 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  494. "478799 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  495. "\n",
  496. " acceleration isValid \n",
  497. "0 0.000000 0.0 \n",
  498. "1 0.000000 0.0 \n",
  499. "2 0.000000 0.0 \n",
  500. "3 0.094553 0.0 \n",
  501. "4 -0.042873 0.0 \n",
  502. "... ... ... \n",
  503. "478795 0.000000 0.0 \n",
  504. "478796 0.000000 0.0 \n",
  505. "478797 0.000000 0.0 \n",
  506. "478798 0.000000 0.0 \n",
  507. "478799 0.000000 0.0 \n",
  508. "\n",
  509. "[478800 rows x 8 columns]\n"
  510. ]
  511. }
  512. ],
  513. "source": [
  514. "print(handletrace)"
  515. ]
  516. },
  517. {
  518. "cell_type": "code",
  519. "execution_count": null,
  520. "metadata": {},
  521. "outputs": [],
  522. "source": [
  523. "'''import plotly.graph_objects as go\n",
  524. "\n",
  525. "#Create Figure\n",
  526. "fig = go.Figure()\n",
  527. "fig.add_trace(go.Scatter( x=list(handletrace.index), y=list(handletrace['velocity'] * 30)))\n",
  528. "\n",
  529. "#Set Title\n",
  530. "fig.update_layout(title_text='Velocity per second by frame')\n",
  531. "\n",
  532. "#Add range slider\n",
  533. "fig.update_layout(\n",
  534. " xaxis=dict(\n",
  535. " rangeslider=dict(\n",
  536. " visible=True\n",
  537. " )\n",
  538. " )\n",
  539. ")'''"
  540. ]
  541. },
  542. {
  543. "cell_type": "code",
  544. "execution_count": null,
  545. "metadata": {},
  546. "outputs": [],
  547. "source": [
  548. "'''import plotly.graph_objects as go\n",
  549. "\n",
  550. "#Create Figure\n",
  551. "fig = go.Figure()\n",
  552. "fig.add_trace(go.Scatter( x=list(handletrace.index), y=list(handletrace['acceleration']*900)))\n",
  553. "\n",
  554. "#Set Title\n",
  555. "fig.update_layout(title_text='acceleration per second^2 by frame')\n",
  556. "\n",
  557. "#Add range slider\n",
  558. "fig.update_layout(\n",
  559. " xaxis=dict(\n",
  560. " rangeslider=dict(\n",
  561. " visible=True\n",
  562. " )\n",
  563. " )\n",
  564. ")'''"
  565. ]
  566. },
  567. {
  568. "cell_type": "code",
  569. "execution_count": 15,
  570. "metadata": {},
  571. "outputs": [],
  572. "source": [
  573. "#comapre the value of handletrace['acceleration'] and if it is between -25 and 25, then set handletrace['isValid'] to 1\n",
  574. "for x in range(0, len(handletrace)):\n",
  575. " if (-25/900) < handletrace['acceleration'][x] < (25/900):\n",
  576. " handletrace['isValid'][x] = 1\n",
  577. " else:\n",
  578. " handletrace['isValid'][x] = 0"
  579. ]
  580. },
  581. {
  582. "cell_type": "code",
  583. "execution_count": 16,
  584. "metadata": {},
  585. "outputs": [
  586. {
  587. "name": "stdout",
  588. "output_type": "stream",
  589. "text": [
  590. "[1. 0.]\n",
  591. "isValid\n",
  592. "1.0 437730\n",
  593. "0.0 41070\n",
  594. "Name: count, dtype: int64\n"
  595. ]
  596. }
  597. ],
  598. "source": [
  599. "print(handletrace['isValid'].unique())\n",
  600. "print(handletrace['isValid'].value_counts())"
  601. ]
  602. },
  603. {
  604. "cell_type": "code",
  605. "execution_count": 17,
  606. "metadata": {},
  607. "outputs": [
  608. {
  609. "name": "stdout",
  610. "output_type": "stream",
  611. "text": [
  612. " x y z frame positionvectorvalue velocity \n",
  613. "0 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \\\n",
  614. "1 -0.400997 -0.319101 1.632182 1.0 2.926644 0.000000 \n",
  615. "2 -0.410969 -0.333815 1.629004 2.0 2.933981 0.085661 \n",
  616. "3 -0.412393 -0.352207 1.634730 3.0 2.966459 0.180214 \n",
  617. "4 -0.413818 -0.357725 1.638935 4.0 2.985322 0.137342 \n",
  618. "... ... ... ... ... ... ... \n",
  619. "478795 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  620. "478796 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  621. "478797 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  622. "478798 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  623. "478799 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 \n",
  624. "\n",
  625. " acceleration isValid \n",
  626. "0 0.000000 1.0 \n",
  627. "1 0.000000 1.0 \n",
  628. "2 0.000000 1.0 \n",
  629. "3 0.094553 0.0 \n",
  630. "4 -0.042873 0.0 \n",
  631. "... ... ... \n",
  632. "478795 0.000000 1.0 \n",
  633. "478796 0.000000 1.0 \n",
  634. "478797 0.000000 1.0 \n",
  635. "478798 0.000000 1.0 \n",
  636. "478799 0.000000 1.0 \n",
  637. "\n",
  638. "[478800 rows x 8 columns]\n"
  639. ]
  640. }
  641. ],
  642. "source": [
  643. "print(handletrace)"
  644. ]
  645. },
  646. {
  647. "cell_type": "code",
  648. "execution_count": null,
  649. "metadata": {},
  650. "outputs": [],
  651. "source": []
  652. }
  653. ],
  654. "metadata": {
  655. "kernelspec": {
  656. "display_name": "Python 3",
  657. "language": "python",
  658. "name": "python3"
  659. },
  660. "language_info": {
  661. "codemirror_mode": {
  662. "name": "ipython",
  663. "version": 3
  664. },
  665. "file_extension": ".py",
  666. "mimetype": "text/x-python",
  667. "name": "python",
  668. "nbconvert_exporter": "python",
  669. "pygments_lexer": "ipython3",
  670. "version": "3.8.0"
  671. },
  672. "vscode": {
  673. "interpreter": {
  674. "hash": "df0893f56f349688326838aaeea0de204df53a132722cbd565e54b24a8fec5f6"
  675. }
  676. }
  677. },
  678. "nbformat": 4,
  679. "nbformat_minor": 2
  680. }