|
1181 | 1181 | "a.__dict__"
|
1182 | 1182 | ]
|
1183 | 1183 | },
|
1184 |
| - { |
1185 |
| - "cell_type": "code", |
1186 |
| - "execution_count": null, |
1187 |
| - "metadata": { |
1188 |
| - "collapsed": false |
1189 |
| - }, |
1190 |
| - "outputs": [], |
1191 |
| - "source": [ |
1192 |
| - "import numpy as np\n", |
1193 |
| - "def givex():\n", |
1194 |
| - " x = np.array([[1,2,3],[1,2,3],[1,2,3]])\n", |
1195 |
| - " return x\n", |
1196 |
| - "\n", |
1197 |
| - "givex()[:,[1,1,0,1]]\n" |
1198 |
| - ] |
1199 |
| - }, |
1200 |
| - { |
1201 |
| - "cell_type": "code", |
1202 |
| - "execution_count": null, |
1203 |
| - "metadata": { |
1204 |
| - "collapsed": false |
1205 |
| - }, |
1206 |
| - "outputs": [], |
1207 |
| - "source": [ |
1208 |
| - "import numpy as np\n", |
1209 |
| - " \n", |
1210 |
| - "np.cumsum([1,2,3,4,5])" |
1211 |
| - ] |
1212 |
| - }, |
1213 |
| - { |
1214 |
| - "cell_type": "code", |
1215 |
| - "execution_count": null, |
1216 |
| - "metadata": { |
1217 |
| - "collapsed": false |
1218 |
| - }, |
1219 |
| - "outputs": [], |
1220 |
| - "source": [ |
1221 |
| - "a = np.diff([1,2,3,4,59,99,33])\n", |
1222 |
| - "\n", |
1223 |
| - "a.dtype == 'int64'\n", |
1224 |
| - "\n", |
1225 |
| - "a.ndim" |
1226 |
| - ] |
1227 |
| - }, |
1228 |
| - { |
1229 |
| - "cell_type": "code", |
1230 |
| - "execution_count": null, |
1231 |
| - "metadata": { |
1232 |
| - "collapsed": false |
1233 |
| - }, |
1234 |
| - "outputs": [], |
1235 |
| - "source": [ |
1236 |
| - "min([1,2,3])\n" |
1237 |
| - ] |
1238 |
| - }, |
1239 |
| - { |
1240 |
| - "cell_type": "code", |
1241 |
| - "execution_count": null, |
1242 |
| - "metadata": { |
1243 |
| - "collapsed": false |
1244 |
| - }, |
1245 |
| - "outputs": [], |
1246 |
| - "source": [ |
1247 |
| - "b = np.array(['a','b','c" |
1248 |
| - ] |
1249 |
| - }, |
1250 | 1184 | {
|
1251 | 1185 | "cell_type": "code",
|
1252 | 1186 | "execution_count": null,
|
|
1278 | 1212 | "a.__dict__\n"
|
1279 | 1213 | ]
|
1280 | 1214 | },
|
1281 |
| - { |
1282 |
| - "cell_type": "code", |
1283 |
| - "execution_count": null, |
1284 |
| - "metadata": { |
1285 |
| - "collapsed": false |
1286 |
| - }, |
1287 |
| - "outputs": [], |
1288 |
| - "source": [ |
1289 |
| - "a.type2aux()\n", |
1290 |
| - "a.__dict__\n", |
1291 |
| - "\n", |
1292 |
| - "\n", |
1293 |
| - "a.wrann()" |
1294 |
| - ] |
1295 |
| - }, |
1296 | 1215 | {
|
1297 | 1216 | "cell_type": "code",
|
1298 | 1217 | "execution_count": null,
|
|
1304 | 1223 | "\n"
|
1305 | 1224 | ]
|
1306 | 1225 | },
|
1307 |
| - { |
1308 |
| - "cell_type": "code", |
1309 |
| - "execution_count": null, |
1310 |
| - "metadata": { |
1311 |
| - "collapsed": false |
1312 |
| - }, |
1313 |
| - "outputs": [], |
1314 |
| - "source": [ |
1315 |
| - "import numpy as np\n", |
1316 |
| - "import timeit\n", |
1317 |
| - "\n", |
1318 |
| - "def fillarray(N):\n", |
1319 |
| - " x = np.empty(N)\n", |
1320 |
| - " for i in range(0, N):\n", |
1321 |
| - " x[i] = i\n", |
1322 |
| - " \n", |
1323 |
| - "def makelist(N):\n", |
1324 |
| - " x = []\n", |
1325 |
| - " for i in range(0, N):\n", |
1326 |
| - " x.append(i)\n", |
1327 |
| - " \n", |
1328 |
| - "def makelistadd(N):\n", |
1329 |
| - " x = []\n", |
1330 |
| - " for i in range(0, N):\n", |
1331 |
| - " x = x+ [i]\n", |
1332 |
| - " \n", |
1333 |
| - "print(timeit.timeit('fillarray(N)', setup=\"from __main__ import fillarray; N= 100000\", number = 100))\n", |
1334 |
| - "print(timeit.timeit('makelist(N)', setup=\"from __main__ import makelist; N= 100000\",number = 100))\n", |
1335 |
| - "#print(timeit.timeit('makelistadd(N)', setup=\"from __main__ import makelistadd; N= 100000\",number = 100))" |
1336 |
| - ] |
1337 |
| - }, |
1338 | 1226 | {
|
1339 | 1227 | "cell_type": "code",
|
1340 | 1228 | "execution_count": null,
|
|
1406 | 1294 | },
|
1407 | 1295 | "outputs": [],
|
1408 | 1296 | "source": [
|
1409 |
| - "type(None) == 'NoneType'" |
| 1297 | + "import numpy as np\n", |
| 1298 | + "inttypes = [int, np.int64, np.int32]\n", |
| 1299 | + "\n", |
| 1300 | + "print(inttypes)\n", |
| 1301 | + "display(inttypes)" |
1410 | 1302 | ]
|
1411 | 1303 | },
|
1412 | 1304 | {
|
1413 | 1305 | "cell_type": "code",
|
1414 |
| - "execution_count": null, |
| 1306 | + "execution_count": 6, |
1415 | 1307 | "metadata": {
|
1416 | 1308 | "collapsed": false
|
1417 | 1309 | },
|
1418 |
| - "outputs": [], |
| 1310 | + "outputs": [ |
| 1311 | + { |
| 1312 | + "name": "stdout", |
| 1313 | + "output_type": "stream", |
| 1314 | + "text": [ |
| 1315 | + "hi\n", |
| 1316 | + "<class '__main__.square'>\n", |
| 1317 | + "<class '__main__.circle'>\n", |
| 1318 | + "<class '__main__.square'>\n" |
| 1319 | + ] |
| 1320 | + } |
| 1321 | + ], |
1419 | 1322 | "source": [
|
1420 |
| - "2**31" |
| 1323 | + "class circle():\n", |
| 1324 | + " \n", |
| 1325 | + " def __init__(self):\n", |
| 1326 | + " self.shape = 'round'\n", |
| 1327 | + " \n", |
| 1328 | + " def circle2square(self):\n", |
| 1329 | + " \n", |
| 1330 | + " return square()\n", |
| 1331 | + " \n", |
| 1332 | + " \n", |
| 1333 | + "class square():\n", |
| 1334 | + " \n", |
| 1335 | + " def __init__(self):\n", |
| 1336 | + " self.shape = 'rectangular'\n", |
| 1337 | + " \n", |
| 1338 | + "\n", |
| 1339 | + "def printandswitch(circle):\n", |
| 1340 | + " print('hi')\n", |
| 1341 | + " circle = circle.circle2square()\n", |
| 1342 | + " print(type(circle))\n", |
| 1343 | + " \n", |
| 1344 | + "myshape = circle()\n", |
| 1345 | + "printandswitch(myshape)\n", |
| 1346 | + "print(type(myshape))\n", |
| 1347 | + "myshape = myshape.circle2square()\n", |
| 1348 | + "print(type(myshape))\n", |
| 1349 | + " \n", |
| 1350 | + " " |
1421 | 1351 | ]
|
1422 | 1352 | },
|
1423 | 1353 | {
|
|
1429 | 1359 | "outputs": [],
|
1430 | 1360 | "source": [
|
1431 | 1361 | "import numpy as np\n",
|
1432 |
| - "inttypes = [int, np.int64, np.int32]\n", |
| 1362 | + "import matplotlib.pyplot as plt\n", |
1433 | 1363 | "\n",
|
1434 |
| - "print(inttypes)\n", |
1435 |
| - "display(inttypes)" |
| 1364 | + "\n", |
| 1365 | + "def plotrec(record=None, signals = None, fields = None, title=None, timeaxis='samples'): \n", |
| 1366 | + " \n", |
| 1367 | + " # Figure out which argument to plot\n", |
| 1368 | + " if record is None:\n", |
| 1369 | + " if signals is None:\n", |
| 1370 | + " sys.exit('Either record or signals must be present. No input signal to plot.')\n", |
| 1371 | + " # Use the signals array\n", |
| 1372 | + " else:\n", |
| 1373 | + " # Use the record object\n", |
| 1374 | + " if signals is None:\n", |
| 1375 | + " \n", |
| 1376 | + " # If it is a MultiRecord, convert it into single\n", |
| 1377 | + " if type(record) == MultiRecord:\n", |
| 1378 | + " record = record.multi_to_single()\n", |
| 1379 | + " \n", |
| 1380 | + " # Need to ensure p_signals is present\n", |
| 1381 | + " if record.p_signals is None:\n", |
| 1382 | + " sys.exit('The p_signals field must be present in the record object to plot')\n", |
| 1383 | + " \n", |
| 1384 | + " signals = record.p_signals\n", |
| 1385 | + " fields = {}\n", |
| 1386 | + " for field in ['fs', 'signame']:\n", |
| 1387 | + " fields[field] = getattr(record, field)\n", |
| 1388 | + " # Both are present\n", |
| 1389 | + " else:\n", |
| 1390 | + " sys.exit(\"Only one of 'record' or 'signals' must be present. Cannot plot both items.\")\n", |
| 1391 | + " \n", |
| 1392 | + " \n", |
| 1393 | + " # Determine x axis resolution\n", |
| 1394 | + " allowedtimes = ['samples, seconds, minutes, hours']\n", |
| 1395 | + " if timeaxis not in allowedtimes:\n", |
| 1396 | + " print(\"The 'timeaxis' field must be one of the following: \", timeaxis)\n", |
| 1397 | + " sys.exit()\n", |
| 1398 | + " if fields['fs'] and \n", |
| 1399 | + " \n", |
| 1400 | + " if (fields[\"fs\"] is None) or (plottime is not True): # x axis is index\n", |
| 1401 | + " plottime=False\n", |
| 1402 | + " t=np.array(range(0,sig.shape[0]))\n", |
| 1403 | + " \n", |
| 1404 | + " else: # x axis is time\n", |
| 1405 | + " t=np.array(range(0,sig.shape[0]))/fields[\"fs\"]\n", |
| 1406 | + " if annsamp!=[]:\n", |
| 1407 | + " annplott=annsamp/fields[\"fs\"]\n", |
| 1408 | + " \n", |
| 1409 | + " f1=plt.figure()\n", |
| 1410 | + " for ch in range(0, sig.shape[1]):\n", |
| 1411 | + " plt.subplot(100*sig.shape[1]+11+ch)\n", |
| 1412 | + " plt.plot(t, sig[:,ch]) # Plot signal channel\n", |
| 1413 | + " if (annsamp!=[]) & (ch in annch): # If there are annotations to plot and the channel is specified\n", |
| 1414 | + " plt.plot(annplott, sig[annsamp, ch], 'r+') # Plot annotations\n", |
| 1415 | + " \n", |
| 1416 | + " if (title!=[])&(ch==0):\n", |
| 1417 | + " plt.title(title)\n", |
| 1418 | + " \n", |
| 1419 | + " # Axis Labels\n", |
| 1420 | + " if plottime:\n", |
| 1421 | + " plt.xlabel('time/s')\n", |
| 1422 | + " else:\n", |
| 1423 | + " plt.xlabel('index/sample')\n", |
| 1424 | + " if fields[\"signame\"][ch]:\n", |
| 1425 | + " chanlabel=fields[\"signame\"][ch]\n", |
| 1426 | + " else:\n", |
| 1427 | + " chanlabel='channel'\n", |
| 1428 | + " if fields[\"units\"][ch]:\n", |
| 1429 | + " unitlabel=fields[\"units\"][ch]\n", |
| 1430 | + " else:\n", |
| 1431 | + " unitlabel='NU'\n", |
| 1432 | + " plt.ylabel(chanlabel+\"/\"+unitlabel)\n", |
| 1433 | + " \n", |
| 1434 | + " plt.show(f1)\n" |
1436 | 1435 | ]
|
1437 | 1436 | },
|
| 1437 | + { |
| 1438 | + "cell_type": "code", |
| 1439 | + "execution_count": 7, |
| 1440 | + "metadata": { |
| 1441 | + "collapsed": true |
| 1442 | + }, |
| 1443 | + "outputs": [], |
| 1444 | + "source": [ |
| 1445 | + "import wfdb\n", |
| 1446 | + "\n", |
| 1447 | + "x = wfdb.Record()\n" |
| 1448 | + ] |
| 1449 | + }, |
| 1450 | + { |
| 1451 | + "cell_type": "code", |
| 1452 | + "execution_count": 9, |
| 1453 | + "metadata": { |
| 1454 | + "collapsed": false |
| 1455 | + }, |
| 1456 | + "outputs": [ |
| 1457 | + { |
| 1458 | + "data": { |
| 1459 | + "text/plain": [ |
| 1460 | + "True" |
| 1461 | + ] |
| 1462 | + }, |
| 1463 | + "execution_count": 9, |
| 1464 | + "metadata": {}, |
| 1465 | + "output_type": "execute_result" |
| 1466 | + } |
| 1467 | + ], |
| 1468 | + "source": [] |
| 1469 | + }, |
1438 | 1470 | {
|
1439 | 1471 | "cell_type": "code",
|
1440 | 1472 | "execution_count": null,
|
|
0 commit comments