|
20 | 20 | "source": [ |
21 | 21 | "# Lab week 3: Data fitting to see if we can detect a pick success y/n\n", |
22 | 22 | "\n", |
23 | | -"Can you use the finger 1 stop time and max value to tell the difference between successful and not?\n", |
| 23 | +"Can you use the finger 1 stop time and max value to tell the difference between a successful and a failed pick?\n", |
24 | 24 | "Lab slides: https://docs.google.com/presentation/d/1NtoXYbl2nq1dkIU0KQE8ogjSCfb22wgLigY3JJpHHGI/edit?usp=sharing\n" |
25 | 25 | ] |
26 | 26 | }, |
|
81 | 81 | "source": [ |
82 | 82 | "## Box plot of fitted lines for all data\n", |
83 | 83 | "\n", |
84 | | -"In the pre-lecture you fitted the line to just one row each of the successful/failed picks. In this lab you'll fit the line to ALL of the picks. For each pick, save the end point (time and y_max value of the motor). You'll be making a box plot of this data to see if it looks different for successful versus failed picks.\n", |
| 84 | +"In the pre-lecture you fit a line to just one row (each) of the successful versus failed picks. In this lab you'll fit the line to ALL of the picks. For each pick, save the end point (time at the y_max value and the y_max value). You'll be making a box plot of this data to see if it looks different for successful versus failed picks.\n", |
85 | 85 | "\n", |
86 | 86 | "Why a box plot? Box plots are better for visually showing multiple distributions in the same plot, where they can be compared side-by-side\n", |
87 | 87 | "\n", |
88 | | -"See lab slides for what this should look like when you're done" |
| 88 | +"See lab slides for what this should look like when you're done." |
89 | 89 | ] |
90 | 90 | }, |
91 | 91 | { |
|
96 | 96 | }, |
97 | 97 | "outputs": [], |
98 | 98 | "source": [ |
99 | | -"# from pre_lecture_3_fitting import fit_line_to_middle_bit\n", |
100 | | -"\n", |
101 | 99 | "...\n", |
102 | 100 | "\n", |
| 101 | +"# TODO: get the fit_line_to_middle_bit function, either by copying it over here, or importing it from a .py file\n", |
| 102 | +"#. Optional (import):\n", |
| 103 | +"# from pre_lecture_3_fitting import fit_line_to_middle_bit\n", |
| 104 | +"# Otherwise, copy function here\n", |
| 105 | +"#\n", |
| 106 | +"# TODO: Check that it works\n", |
| 107 | +"#. - Create t values\n", |
| 108 | +"# - Call fit_line_to_middle_bit with the first row of the successful data and see if your answers\n", |
| 109 | +"#. match the answers from pre-lecture\n", |
| 110 | +"# END PROMPT\"\"\"\n" |
| 111 | +] |
| 112 | +}, |
| 113 | +{ |
| 114 | +"cell_type": "code", |
| 115 | +"execution_count": null, |
| 116 | +"metadata": { |
| 117 | +"tags": [] |
| 118 | +}, |
| 119 | +"outputs": [], |
| 120 | +"source": [ |
| 121 | +"\n", |
| 122 | +"# TODO:\n", |
| 123 | +"# Create a function that computes the \n", |
103 | 124 | "# nx2 arrays of t, y values of end point of fitted line\n", |
104 | 125 | "end_times_successful = ... \n", |
105 | 126 | "end_times_failed = ... \n", |
|
113 | 134 | "cell_type": "code", |
114 | 135 | "execution_count": null, |
115 | 136 | "metadata": { |
| 137 | +"tags": [] |
| 138 | +}, |
| 139 | +"outputs": [], |
| 140 | +"source": [ |
| 141 | +"\n", |
| 142 | +"# TODO:\n", |
| 143 | +"# Create a function that loops over all of the rows of the data and accumulates the start and end times\n", |
| 144 | +"#. in an nx2 array of t (first row) and y (second row)\n", |
| 145 | +"# I'd recommend a function that takes both the t values and the data, so you don't have to keep recomputing\n", |
| 146 | +"#. the t values\n", |
| 147 | +"#. def fit_middle_all(ts, data)\n", |
| 148 | +"#. make numpy array to put data in (nx2)\n", |
| 149 | +"#. for each row in data\n", |
| 150 | +"#. start_pt, end_pt = fit_line_to_middle_bit(ts, current row)\n", |
| 151 | +"# copy end_pt information into appropriate row in nx2 output\n", |
| 152 | +"#. return nx2 numpy array\n", |
| 153 | +"# END PROMPT\"\"\"" |
| 154 | +] |
| 155 | +}, |
| 156 | +{ |
| 157 | +"cell_type": "code", |
| 158 | +"execution_count": null, |
| 159 | +"metadata": { |
| 160 | +"tags": [] |
| 161 | +}, |
| 162 | +"outputs": [], |
| 163 | +"source": [ |
| 164 | +"# Check that it works properly\n", |
| 165 | +"\n", |
| 166 | +"# TODO:\n", |
| 167 | +"# Create the t values\n", |
| 168 | +"#. Call your function twice, once with the successful data, once with the failed\n", |
| 169 | +"end_times_successful = ...\n", |
| 170 | +"end_times_failed = ...\n", |
| 171 | +"# END PROMPT\"\"\"" |
| 172 | +] |
| 173 | +}, |
| 174 | +{ |
| 175 | +"cell_type": "code", |
| 176 | +"execution_count": null, |
| 177 | +"metadata": { |
116 | 178 | "deletable": false, |
117 | 179 | "editable": false |
118 | 180 | }, |
|
129 | 191 | }, |
130 | 192 | "outputs": [], |
131 | 193 | "source": [ |
132 | | -"from pre_lecture_3_fitting import fit_line_to_middle_bit\n", |
133 | | -"\n", |
| 194 | +"# Two plots\n", |
134 | 195 | "n_rows = 1\n", |
135 | 196 | "n_cols = 2\n", |
136 | | -"fig, axs = plt.subplots(n_rows, n_cols)\n", |
| 197 | +"fig, axs = plt.subplots(n_rows, n_cols, figsize=(8, 4))\n", |
137 | 198 | "\n", |
138 | 199 | "...\n", |
139 | 200 | "\n", |
|
147 | 208 | "source": [ |
148 | 209 | "<!-- END QUESTION -->\n", |
149 | 210 | "\n", |
150 | | -"# Part 2: Fitting a curve to the summed wrist force data\n", |
| 211 | +"# Part 2: Fitting a curve to the wrist force data\n", |
151 | 212 | "\n", |
152 | | -"## First step: calculate the data\n", |
| 213 | +"## First step: Getting the data\n", |
153 | 214 | "\n", |
154 | | -"Data to plot: sqrt (sum x,y,z (wrist force data)^2)\n", |
155 | 215 | "\n", |
156 | | -"Read in wrist force data, sum it, and (optional) write it out to two csv files (one for successful, one for failed)\n", |
157 | | -" Feel free to swipe code from Lecture_3_data_analysis.ipynb to do this\n", |
| 216 | +"The wrist force data has three channels (x,y,z). For this assignment, we want to get out the total summed force at the wrist, rather than each channel individually:\n", |
158 | 217 | "\n", |
159 | | -"The data files are also in the directory, so you can read them in if you're having trouble calculating the data yourself.\n" |
| 218 | +"Equation: **sqrt (sum x,y,z (wrist force data)^2)**\n", |
| 219 | +"\n", |
| 220 | +"Just like the last problem, the data has already been extracted from the proxy_pick_data.csv file and output for you (week3_Wrist force_summed_*.csv). \n", |
| 221 | +"\n", |
| 222 | +"Optional: Do this extraction yourself. Read in wrist force data, sum it, and write it out to two csv files (one for successful, one for failed). Feel free to swipe code from Lecture_3_data_analysis.ipynb to do this." |
160 | 223 | ] |
161 | 224 | }, |
162 | 225 | { |
|
168 | 231 | "outputs": [], |
169 | 232 | "source": [ |
170 | 233 | "\n", |
| 234 | +"# TODO: Read in the data from Data/week3_Wrist_force summed*.csv (successful and failed)\n", |
| 235 | +"# TODO: Optional: Read in the pick data and its description file, extract out the rows and columns you\n", |
| 236 | +"#. care about, and write that data out (should be same as the .csv files)\n", |
171 | 237 | "data_wrist_force_successful = ...\n", |
172 | | -"data_wrist_force_failed = ,,,\n", |
| 238 | +"data_wrist_force_failed = ...\n", |
173 | 239 | "# END PROMPT\"\"\"\n" |
174 | 240 | ] |
175 | 241 | }, |
|
191 | 257 | "source": [ |
192 | 258 | "<!-- BEGIN QUESTION -->\n", |
193 | 259 | "\n", |
194 | | -"## Second step: Fit a cubic to the first rows of the successful and failed plots\n", |
| 260 | +"## Second step: Fit a cubic to the wrist force data (18 rows each successful/failed)\n", |
| 261 | +"\n", |
| 262 | +"Split by successful and failed.\n", |
| 263 | +"\n", |
| 264 | +"TODO: See slides for what the final plots should look like. I've handled the for loop and the plot indexing for you.\n", |
| 265 | +"\n", |
| 266 | +"At this point, you should have the data in the form ts, ys for both the successful and the failed data. \n", |
| 267 | +"\n", |
| 268 | +"Where you're headed (pseudo code)\n", |
| 269 | +"\n", |
| 270 | +"for 18 rows of data\n", |
| 271 | +"\n", |
| 272 | +" Fit a cubic polynomial to the data\n", |
| 273 | +" \n", |
| 274 | +" Plot the original data plus the fitted polynomial\n", |
| 275 | +" \n", |
| 276 | +" First three rows: successful, last three rows: failed\n", |
| 277 | +"\n", |
| 278 | +"Implementation steps: You could write a function for doing the polynomial fit, but since there already is one (polynomial.polyval) you probably don't need one.\n", |
195 | 279 | "\n", |
196 | | -"I've copied over the code from Lecture 3 - you just need to fit the polynomial and plot that, too\n", |
| 280 | +"Steps\n", |
| 281 | +"- Fit polynomial for one row of data\n", |
| 282 | +"- Plot it and make sure it looks correct\n", |
| 283 | +"- Copy that code into the for loop, adjusting for which row (p) and which subplot (axs[r, c])\n", |
| 284 | +"- Repeat for the failed data\n", |
197 | 285 | "\n", |
198 | | -"plt.close(fig)" |
| 286 | +"Note: It can take a few seconds to plot." |
199 | 287 | ] |
200 | 288 | }, |
201 | 289 | { |
|
208 | 296 | "source": [ |
209 | 297 | "n_rows = 6\n", |
210 | 298 | "n_cols = 6\n", |
211 | | -"fig, axs = plt.subplots(n_rows, n_rows, figsize=(10, 10))\n", |
| 299 | +"fig, axs = plt.subplots(n_rows, n_rows, figsize=(16, 16))\n", |
212 | 300 | "for p in range(0, (n_rows // 2) * n_cols):\n", |
213 | 301 | " r, c = p // n_cols, p % n_cols\n", |
214 | 302 | " axs[r, c].plot(ts, data_wrist_force_successful[p])\n", |
|
217 | 305 | "\n", |
218 | 306 | "for p in range(0, (n_rows // 2) * n_cols):\n", |
219 | 307 | " r, c = 3 + p // n_cols, p % n_cols\n", |
220 | | -" axs[r, c].plot(ts, data_failed[p])\n", |
| 308 | +" axs[r, c].plot(ts, data_wrist_force_failed[p])\n", |
221 | 309 | " ...\n", |
222 | 310 | " axs[r, c].set_title(f\"{ch_name} summed\" + f\" fail {p}\", fontsize=10)\n", |
223 | 311 | "\n", |
|
282 | 370 | "\n", |
283 | 371 | "Make sure you have run all cells in your notebook in order before running the cell below, so that all images/graphs appear in the output. The cell below will generate a zip file for you to submit. **Please save before exporting!**\n", |
284 | 372 | "\n", |
285 | | -"Submit through gradescope, week 3 lab" |
| 373 | +"Submit through gradescope, week 3 lab. Turn in just the .ipynb file - we will supply the data files." |
286 | 374 | ] |
287 | 375 | }, |
288 | 376 | { |
|
322 | 410 | "name": "python", |
323 | 411 | "nbconvert_exporter": "python", |
324 | 412 | "pygments_lexer": "ipython3", |
325 | | -"version": "3.7.4" |
| 413 | +"version": "3.7.3" |
326 | 414 | }, |
327 | 415 | "otter": { |
328 | 416 | "OK_FORMAT": true, |
|
0 commit comments