Skip to content

Commit 8221e77

Browse files
committed
dev
1 parent e32c895 commit 8221e77

File tree

4 files changed

+167
-133
lines changed

4 files changed

+167
-133
lines changed

devtests.ipynb

Lines changed: 151 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,72 +1181,6 @@
11811181
"a.__dict__"
11821182
]
11831183
},
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-
},
12501184
{
12511185
"cell_type": "code",
12521186
"execution_count": null,
@@ -1278,21 +1212,6 @@
12781212
"a.__dict__\n"
12791213
]
12801214
},
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-
},
12961215
{
12971216
"cell_type": "code",
12981217
"execution_count": null,
@@ -1304,37 +1223,6 @@
13041223
"\n"
13051224
]
13061225
},
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-
},
13381226
{
13391227
"cell_type": "code",
13401228
"execution_count": null,
@@ -1406,18 +1294,60 @@
14061294
},
14071295
"outputs": [],
14081296
"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)"
14101302
]
14111303
},
14121304
{
14131305
"cell_type": "code",
1414-
"execution_count": null,
1306+
"execution_count": 6,
14151307
"metadata": {
14161308
"collapsed": false
14171309
},
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+
],
14191322
"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+
" "
14211351
]
14221352
},
14231353
{
@@ -1429,12 +1359,114 @@
14291359
"outputs": [],
14301360
"source": [
14311361
"import numpy as np\n",
1432-
"inttypes = [int, np.int64, np.int32]\n",
1362+
"import matplotlib.pyplot as plt\n",
14331363
"\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"
14361435
]
14371436
},
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+
},
14381470
{
14391471
"cell_type": "code",
14401472
"execution_count": null,

tests/test_annotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_1(self):
5050
np.array_equal(annotation.subtype, Tsubtype),
5151
np.array_equal(annotation.chan, Tchan),
5252
np.array_equal(annotation.num, Tnum),
53-
aux == Taux]
53+
annotation.aux == Taux]
5454

5555
assert (comp == [True] * 6)
5656

tests/test_records.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def test_1(self):
1616
# Target file created with: rdsamp -r sampledata/100 -f 0.002 -t 30 -s 1 |
1717
# cut -f 2- > target2
1818
def test_2(self):
19-
sig = wfdb.srdsamp('sampledata/100', sampfrom=1,
20-
sampto=10800, channels=[1], physical=0)
19+
record = wfdb.rdsamp('sampledata/100', sampfrom=1,
20+
sampto=10800, channels=[1], physical=False)
21+
sig = record.signals
2122
targetsig = np.genfromtxt('tests/targetoutputdata/target2')
2223
targetsig = targetsig.reshape(len(targetsig), 1)
2324
assert np.array_equal(sig, targetsig)
@@ -26,7 +27,8 @@ def test_2(self):
2627
# Target file created with: rdsamp -r sampledata/test01_00s | cut -f 2- >
2728
# target3
2829
def test_3(self):
29-
sig, fields = wfdb.srdsamp('sampledata/test01_00s', physical=0)
30+
record = wfdb.rdsamp('sampledata/test01_00s', physical=False)
31+
sig = record.signals
3032
targetsig = np.genfromtxt('tests/targetoutputdata/target3')
3133
assert np.array_equal(sig, targetsig)
3234

@@ -44,8 +46,9 @@ def test_4(self):
4446
# Target file created with: rdsamp -r sampledata/a103l -f 80 -s 0 1 | cut
4547
# -f 2- > target5
4648
def test_5(self):
47-
sig, fields = wfdb.srdsamp('sampledata/a103l',
48-
sampfrom=20000, physical=0, channels=[0, 1])
49+
record = wfdb.rdsamp('sampledata/a103l',
50+
sampfrom=20000, channels=[0, 1], physical=False)
51+
sig = record.signals
4952
targetsig = np.genfromtxt('tests/targetoutputdata/target5')
5053
assert np.array_equal(sig, targetsig)
5154

@@ -64,7 +67,8 @@ def test_6(self):
6467
# Target file created with: rdsamp -r sampledata/s0010_re | cut -f 2- >
6568
# target7
6669
def test_7(self):
67-
sig, fields = wfdb.srdsamp('sampledata/s0010_re', physical=0)
70+
record= wfdb.rdsamp('sampledata/s0010_re', physical=False)
71+
sig = record.signals
6872
targetsig = np.genfromtxt('tests/targetoutputdata/target7')
6973
assert np.array_equal(sig, targetsig)
7074

@@ -82,7 +86,8 @@ def test_8(self):
8286
# Target file created with: rdsamp -r sampledata/03700181 | cut -f 2- >
8387
# target9
8488
def test_9(self):
85-
sig, fields = wfdb.srdsamp('sampledata/03700181', physical=0)
89+
record = wfdb.rdsamp('sampledata/03700181', physical=False)
90+
sig = record.signals
8691
# The WFDB library rdsamp does not return the final N samples for all
8792
# channels due to the skew.
8893
sig = sig[:-4, :]
@@ -125,7 +130,8 @@ def test_10(self):
125130
# Target file created with: rdsamp -r sampledata/3000003_0003 -f 0 -t 8.21 | cut -f 2- | wrsamp -o 310derive -O 310
126131
# rdsamp -r 310derive -f 0.007 | cut -f 2- > target13
127132
def test_13(self):
128-
sig, fields = wfdb.srdsamp('sampledata/310derive', sampfrom=2, physical=0)
133+
record = wfdb.rdsamp('sampledata/310derive', sampfrom=2, physical=False)
134+
sig = record.signals
129135
targetsig = np.genfromtxt('tests/targetoutputdata/target13')
130136
assert np.array_equal(sig, targetsig)
131137

0 commit comments

Comments
 (0)