|
10 | 10 | { |
11 | 11 | "cell_type": "code", |
12 | 12 | "execution_count": null, |
13 | | - "metadata": {}, |
| 13 | + "metadata": { |
| 14 | + "collapsed": false |
| 15 | + }, |
14 | 16 | "outputs": [], |
15 | 17 | "source": [ |
16 | | - "# The following import commands are modules that have helpful functions. Don't worry about them.\n", |
| 18 | + "# The following import commands are modules that have helpful functions. \n", |
17 | 19 | "import numpy as np\n", |
18 | 20 | "import matplotlib.pyplot as plt\n", |
19 | 21 | "import time\n", |
20 | 22 | "import scipy\n", |
21 | | - "import os" |
| 23 | + "import os\n", |
| 24 | + "print('Modules loaded!')" |
22 | 25 | ] |
23 | 26 | }, |
24 | 27 | { |
25 | 28 | "cell_type": "code", |
26 | 29 | "execution_count": null, |
27 | | - "metadata": {}, |
| 30 | + "metadata": { |
| 31 | + "collapsed": false |
| 32 | + }, |
28 | 33 | "outputs": [], |
29 | 34 | "source": [ |
30 | 35 | "# Load in the data using the program provided by OpenEphys. \n", |
|
49 | 54 | { |
50 | 55 | "cell_type": "code", |
51 | 56 | "execution_count": null, |
52 | | - "metadata": {}, |
| 57 | + "metadata": { |
| 58 | + "collapsed": false |
| 59 | + }, |
53 | 60 | "outputs": [], |
54 | 61 | "source": [ |
55 | 62 | "# Lets check out what we got\n", |
56 | 63 | "print(\"The Sampling rate is :\", data['header']['sampleRate'])\n", |
57 | 64 | "\n", |
58 | | - "# There is a problem. The sampling rate is of type string even though we need it to be a float...\n", |
59 | | - "print(\"Sample rate is type :\", type(data['header']['sampleRate']))\n", |
60 | | - "\n", |
| 65 | + "# There is a problem. The sampling rate is of type string(unicode) even though we need it to be a float...\n", |
| 66 | + "print(\"Sample rate is type :\", type(data['header']['sampleRate']))" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "metadata": { |
| 73 | + "collapsed": false |
| 74 | + }, |
| 75 | + "outputs": [], |
| 76 | + "source": [ |
61 | 77 | "# So lets change it!\n", |
62 | 78 | "sampleRate = float(data['header']['sampleRate'])\n", |
63 | 79 | "print(\"The Sampling rate is still :\", sampleRate)\n", |
64 | 80 | "print(\"But the type is now :\", type(sampleRate))\n", |
65 | | - "print('Notice the precision changed. It\\'s now 30000.0!')\n", |
66 | | - "print('') #Blank line\n", |
67 | | - "\n", |
| 81 | + "print('Notice the precision changed. It\\'s now 30000.0!')" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": null, |
| 87 | + "metadata": { |
| 88 | + "collapsed": false |
| 89 | + }, |
| 90 | + "outputs": [], |
| 91 | + "source": [ |
| 92 | + "# Compare this to an int?\n", |
| 93 | + "sampleRate = int(sampleRate)\n", |
| 94 | + "print('Still the same sampling rate : ', sampleRate)\n", |
| 95 | + "print('But now the type is : ', type(sampleRate))\n", |
| 96 | + "print('And once again the precision has changed!')" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "code", |
| 101 | + "execution_count": null, |
| 102 | + "metadata": { |
| 103 | + "collapsed": false |
| 104 | + }, |
| 105 | + "outputs": [], |
| 106 | + "source": [ |
68 | 107 | "# The data is a little longer so we won't print it out. We can look at how many values are stored though.\n", |
69 | 108 | "print('Number of data points :', len(data['data']))\n", |
70 | 109 | "# The timestamps have a different number of values because there is only 1 timestamp per 1024 data samples.\n", |
71 | 110 | "# This is taken care of for you in the next step so don't worry about it.\n", |
72 | | - "print('Number of timestamps :', len(data['timestamps']))" |
| 111 | + "print('Number of timestamps :', len(data['timestamps']))\n", |
| 112 | + "\n", |
| 113 | + "dataPerTs = len(data['data'])/len(data['timestamps'])\n", |
| 114 | + "print('Number of data samples per timestamp', dataPerTs)" |
73 | 115 | ] |
74 | 116 | }, |
75 | 117 | { |
|
92 | 134 | { |
93 | 135 | "cell_type": "code", |
94 | 136 | "execution_count": null, |
95 | | - "metadata": {}, |
| 137 | + "metadata": { |
| 138 | + "collapsed": true |
| 139 | + }, |
96 | 140 | "outputs": [], |
97 | 141 | "source": [ |
98 | 142 | "class Con:\n", |
|
124 | 168 | { |
125 | 169 | "cell_type": "code", |
126 | 170 | "execution_count": null, |
127 | | - "metadata": {}, |
| 171 | + "metadata": { |
| 172 | + "collapsed": false |
| 173 | + }, |
128 | 174 | "outputs": [], |
129 | 175 | "source": [ |
130 | 176 | "plt.plot(con.ts,con.data, 'r') # This also takes a bit as there is a lot of data.\n", |
131 | | - "# Now you have a plot of every voltage for every sample in the recording." |
| 177 | + "# Now you have a plot of every voltage for every sample in the recording.\n", |
| 178 | + "plt.show()" |
132 | 179 | ] |
133 | 180 | }, |
134 | 181 | { |
135 | 182 | "cell_type": "code", |
136 | 183 | "execution_count": null, |
137 | | - "metadata": {}, |
| 184 | + "metadata": { |
| 185 | + "collapsed": false |
| 186 | + }, |
138 | 187 | "outputs": [], |
139 | 188 | "source": [ |
140 | | - "# Now lets get only the first 2 seconds of data, we'll use the sampling rate we saved before\n", |
| 189 | + "# Now lets get only the first 10 seconds of data, we'll use the sampling rate we saved before\n", |
141 | 190 | "timeElapsed = int(10 * con.fs) # Feel free to change the 1 to as many seconds as you (needs to be an integer for later)\n", |
142 | 191 | "timeStart = int(0 * con.fs) # Where do you want to start (0 is the start, can change to be as many seconds after as you want)\n", |
143 | | - "plt.plot(con.ts[timeStart:timeElapsed], con.data[timeStart:timeElapsed], 'r') # [startIndex:endIndex]" |
| 192 | + "timeEnd = timeElapsed + timeStart # We need what timestamp the end is. It is the start index + how many have elapsed over 10 sec\n", |
| 193 | + "plt.plot(con.ts[timeStart:timeEnd], con.data[timeStart:timeEnd], 'r') # [startIndex:endIndex]\n", |
| 194 | + "plt.show()" |
144 | 195 | ] |
145 | 196 | }, |
146 | 197 | { |
|
157 | 208 | { |
158 | 209 | "cell_type": "code", |
159 | 210 | "execution_count": null, |
160 | | - "metadata": {}, |
| 211 | + "metadata": { |
| 212 | + "collapsed": false |
| 213 | + }, |
161 | 214 | "outputs": [], |
162 | 215 | "source": [ |
163 | | - "timeElapsed = int(2 * con.fs) \n", |
164 | | - "timeStart = int(0 * con.fs)\n", |
165 | | - "\n", |
| 216 | + "timeElapsed = int(10 * con.fs) # Feel free to change the 1 to as many seconds as you (needs to be an integer for later)\n", |
| 217 | + "timeStart = int(0 * con.fs) # Where do you want to start (0 is the start, can change to be as many seconds after as you want)\n", |
| 218 | + "timeEnd = timeElapsed + timeStart # We need what timestamp the end is. It is the start index + how many have elapsed over 10 sec\n", |
166 | 219 | "# Put code here!\n", |
167 | 220 | "# use matplotlib to create a vertical line (hint: use google!)\n", |
168 | 221 | "\n", |
169 | | - "plt.plot(con.ts[timeStart:timeElapsed], con.data[timeStart:timeElapsed], 'r') " |
| 222 | + "plt.plot(con.ts[timeStart:timeEnd], con.data[timeStart:timeEnd], 'r') \n", |
| 223 | + "plt.show()" |
170 | 224 | ] |
171 | 225 | }, |
172 | 226 | { |
|
181 | 235 | { |
182 | 236 | "cell_type": "code", |
183 | 237 | "execution_count": null, |
184 | | - "metadata": {}, |
| 238 | + "metadata": { |
| 239 | + "collapsed": true |
| 240 | + }, |
185 | 241 | "outputs": [], |
186 | 242 | "source": [ |
187 | | - "timeElapsed = int(2 * con.fs) \n", |
188 | | - "timeStart = int(0 * con.fs)\n", |
189 | | - "\n", |
190 | 243 | "# Put code here!\n", |
191 | 244 | "\n", |
192 | | - "plt.plot(con.ts[timeStart:timeElapsed], con.data[timeStart:timeElapsed], 'r') \n", |
193 | | - "# use matplotlib to create a horizontal line (hint: use google!)" |
| 245 | + "plt.plot(con.ts[timeStart:timeEnd], con.data[timeStart:timeEnd], 'r') \n", |
| 246 | + "# use matplotlib to create a horizontal line (hint: use google!)\n", |
| 247 | + "\n", |
| 248 | + "plt.show()" |
194 | 249 | ] |
195 | 250 | }, |
196 | 251 | { |
|
199 | 254 | "source": [ |
200 | 255 | "## Third challenge\n", |
201 | 256 | "\n", |
202 | | - "Use the following imported module (butter) to create a bandpass filter to extract only the theta band (8-12hz)! I recommend writing a few functions to help you this with as well.\n", |
| 257 | + "Use the butter function from scipys signal library to create a bandpass filter to extract only the theta band (4-8hz)! If you want, writing a few functions may help you and be good practice. \n", |
203 | 258 | "\n", |
204 | | - "Use google to understand how to use butter. Also examples are very helpful!" |
| 259 | + "Use google to understand how to use butter. Examples are very helpful!" |
205 | 260 | ] |
206 | 261 | }, |
207 | 262 | { |
208 | 263 | "cell_type": "code", |
209 | 264 | "execution_count": null, |
210 | | - "metadata": {}, |
| 265 | + "metadata": { |
| 266 | + "collapsed": true |
| 267 | + }, |
| 268 | + "outputs": [], |
| 269 | + "source": [ |
| 270 | + "# If you want to use functions write them here." |
| 271 | + ] |
| 272 | + }, |
| 273 | + { |
| 274 | + "cell_type": "code", |
| 275 | + "execution_count": null, |
| 276 | + "metadata": { |
| 277 | + "collapsed": false |
| 278 | + }, |
211 | 279 | "outputs": [], |
212 | 280 | "source": [ |
213 | | - "from scipy.signal import butter, lfilter, sosfilt # You will also need to use either lfilter or sosfilt. \n", |
214 | | - " # There are multiple ways of doing this\n", |
| 281 | + "from scipy import signal \n", |
| 282 | + "# Hints!\n", |
| 283 | + "# butter function can be accessed by signal.butter\n", |
| 284 | + "# You will also need to use lfilter function which is included in the signal library. \n", |
| 285 | + "# Use a filter order of 2\n", |
| 286 | + "# You will also need to normalize your band that you want to extract\n", |
| 287 | + "# by the nyquist frequency\n", |
| 288 | + "\n", |
215 | 289 | "\n", |
216 | 290 | "# Put code here\n", |
217 | 291 | "\n", |
218 | | - "plt.plot(con.ts[timeStart:timeElapsed], filteredData, 'r')" |
| 292 | + "plt.plot(con.ts[timeStart:timeEnd], filteredData[timeStart:timeEnd], 'r')\n", |
| 293 | + "plt.show()" |
219 | 294 | ] |
220 | 295 | } |
221 | 296 | ], |
222 | 297 | "metadata": { |
| 298 | + "anaconda-cloud": {}, |
223 | 299 | "kernelspec": { |
224 | | - "display_name": "Python 3", |
| 300 | + "display_name": "Python [conda root]", |
225 | 301 | "language": "python", |
226 | | - "name": "python3" |
| 302 | + "name": "conda-root-py" |
227 | 303 | }, |
228 | 304 | "language_info": { |
229 | 305 | "codemirror_mode": { |
230 | 306 | "name": "ipython", |
231 | | - "version": 3 |
| 307 | + "version": 2 |
232 | 308 | }, |
233 | 309 | "file_extension": ".py", |
234 | 310 | "mimetype": "text/x-python", |
235 | 311 | "name": "python", |
236 | 312 | "nbconvert_exporter": "python", |
237 | | - "pygments_lexer": "ipython3", |
238 | | - "version": "3.6.8" |
| 313 | + "pygments_lexer": "ipython2", |
| 314 | + "version": "2.7.12" |
239 | 315 | } |
240 | 316 | }, |
241 | 317 | "nbformat": 4, |
|
0 commit comments