Skip to content

Commit 6d6d1bf

Browse files
committed
fix tests
1 parent 2f04d73 commit 6d6d1bf

File tree

4 files changed

+224
-29
lines changed

4 files changed

+224
-29
lines changed

devtests.ipynb

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,224 @@
285285
"wfdb.dldatabasefiles(pbdb = 'tmpdb', dlbasedir = '/home/chen/Downloads/dbfolder', files = ['test01_00s.hea', 'test01_00s.dat', 'a/A/test02_45s.hea', 'a/A/test01_00s.hea'], keepsubdirs = True, overwrite = False)"
286286
]
287287
},
288+
{
289+
"cell_type": "code",
290+
"execution_count": 1,
291+
"metadata": {
292+
"collapsed": false
293+
},
294+
"outputs": [
295+
{
296+
"data": {
297+
"text/plain": [
298+
"array([[-6., 0.],\n",
299+
" [-7., 0.],\n",
300+
" [-6., 0.],\n",
301+
" [-7., 0.],\n",
302+
" [-7., 0.],\n",
303+
" [-7., 0.],\n",
304+
" [-7., 0.],\n",
305+
" [-7., 0.],\n",
306+
" [-6., 0.],\n",
307+
" [-7., 0.]])"
308+
]
309+
},
310+
"metadata": {},
311+
"output_type": "display_data"
312+
},
313+
{
314+
"data": {
315+
"text/plain": [
316+
"array([[-8., 6.],\n",
317+
" [-8., 6.],\n",
318+
" [-8., 7.],\n",
319+
" [-8., 7.],\n",
320+
" [-8., 7.],\n",
321+
" [-8., 7.],\n",
322+
" [-8., 7.],\n",
323+
" [-7., 6.],\n",
324+
" [-8., 7.],\n",
325+
" [-7., 6.]])"
326+
]
327+
},
328+
"metadata": {},
329+
"output_type": "display_data"
330+
},
331+
{
332+
"name": "stdout",
333+
"output_type": "stream",
334+
"text": [
335+
"\n",
336+
"Target:\n"
337+
]
338+
},
339+
{
340+
"data": {
341+
"text/plain": [
342+
"array([[-6., 0.],\n",
343+
" [-7., 0.],\n",
344+
" [-6., 0.],\n",
345+
" [-7., 0.],\n",
346+
" [-7., 0.],\n",
347+
" [-7., 0.],\n",
348+
" [-7., 0.],\n",
349+
" [-7., 0.],\n",
350+
" [-6., 0.],\n",
351+
" [-7., 0.]])"
352+
]
353+
},
354+
"metadata": {},
355+
"output_type": "display_data"
356+
},
357+
{
358+
"data": {
359+
"text/plain": [
360+
"array([[-8., 6.],\n",
361+
" [-8., 6.],\n",
362+
" [-8., 7.],\n",
363+
" [-8., 7.],\n",
364+
" [-8., 7.],\n",
365+
" [-8., 7.],\n",
366+
" [-8., 7.],\n",
367+
" [-7., 6.],\n",
368+
" [-8., 7.],\n",
369+
" [-7., 6.]])"
370+
]
371+
},
372+
"metadata": {},
373+
"output_type": "display_data"
374+
},
375+
{
376+
"data": {
377+
"text/plain": [
378+
"True"
379+
]
380+
},
381+
"execution_count": 1,
382+
"metadata": {},
383+
"output_type": "execute_result"
384+
}
385+
],
386+
"source": [
387+
"import wfdb\n",
388+
"from IPython.display import display\n",
389+
"import numpy as np\n",
390+
"\n",
391+
"record = wfdb.rdsamp('sampledata/310derive', sampfrom=2, physical=False)\n",
392+
"sig = record.d_signals\n",
393+
"targetsig = np.genfromtxt('tests/targetoutputdata/target13')\n",
394+
"\n",
395+
"\n",
396+
"display(sig[0:10,:])\n",
397+
"display(sig[-10:,:])\n",
398+
"\n",
399+
"print('\\nTarget:')\n",
400+
"display(targetsig[0:10,:])\n",
401+
"display(targetsig[-10:,:])\n",
402+
"\n",
403+
"np.array_equal(sig, targetsig)\n"
404+
]
405+
},
406+
{
407+
"cell_type": "code",
408+
"execution_count": 4,
409+
"metadata": {
410+
"collapsed": false
411+
},
412+
"outputs": [
413+
{
414+
"ename": "SystemExit",
415+
"evalue": "The plotted signal 'record.p_signals' must be a 2d numpy array",
416+
"output_type": "error",
417+
"traceback": [
418+
"An exception has occurred, use %tb to see the full traceback.\n",
419+
"\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m The plotted signal 'record.p_signals' must be a 2d numpy array\n"
420+
]
421+
},
422+
{
423+
"name": "stderr",
424+
"output_type": "stream",
425+
"text": [
426+
"/home/chen/Software/pythonenvs/python3.5/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
427+
" warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
428+
]
429+
}
430+
],
431+
"source": [
432+
"wfdb.plotrec(record)"
433+
]
434+
},
435+
{
436+
"cell_type": "code",
437+
"execution_count": 1,
438+
"metadata": {
439+
"collapsed": false
440+
},
441+
"outputs": [
442+
{
443+
"name": "stdout",
444+
"output_type": "stream",
445+
"text": [
446+
"sigbytes: [246 223 0 ..., 48 242 7]\n",
447+
"2736\n",
448+
"uint64\n",
449+
"float64\n"
450+
]
451+
},
452+
{
453+
"ename": "NameError",
454+
"evalue": "name 'display' is not defined",
455+
"output_type": "error",
456+
"traceback": [
457+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
458+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
459+
"\u001b[0;32m<ipython-input-1-8237e8d15253>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mwfdb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwfdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrdsamp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'sampledata/310derive'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mphysical\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0md_signals\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mdisplay\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mdisplay\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
460+
"\u001b[0;31mNameError\u001b[0m: name 'display' is not defined"
461+
]
462+
}
463+
],
464+
"source": [
465+
"import wfdb\n",
466+
"s = wfdb.rdsamp('sampledata/310derive', physical=False).d_signals\n",
467+
"display(s[0:10,:])\n",
468+
"display(s[-10:,:])"
469+
]
470+
},
471+
{
472+
"cell_type": "code",
473+
"execution_count": 3,
474+
"metadata": {
475+
"collapsed": false
476+
},
477+
"outputs": [],
478+
"source": [
479+
"import numpy as np\n",
480+
"x = np.array([[1,2], [3,4]], dtype = 'uint')"
481+
]
482+
},
483+
{
484+
"cell_type": "code",
485+
"execution_count": 4,
486+
"metadata": {
487+
"collapsed": false
488+
},
489+
"outputs": [
490+
{
491+
"data": {
492+
"text/plain": [
493+
"array([[1, 2],\n",
494+
" [3, 4]], dtype=uint64)"
495+
]
496+
},
497+
"execution_count": 4,
498+
"metadata": {},
499+
"output_type": "execute_result"
500+
}
501+
],
502+
"source": [
503+
"x"
504+
]
505+
},
288506
{
289507
"cell_type": "code",
290508
"execution_count": null,

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Versions should comply with PEP440. For a discussion on single-sourcing
2121
# the version across setup.py and the project code, see
2222
# https://packaging.python.org/en/latest/single_source_version.html
23-
version='0.1.2',
23+
version='0.2.0',
2424

2525
description='The WFDB Python Toolbox',
2626
long_description=long_description,
@@ -56,8 +56,8 @@
5656
'numpy>=1.11.0',
5757
'matplotlib>=1.5.1',
5858
'requests>=2.10.0',
59-
'pandas>=0.19.1',
60-
'ipython>=5.1.0'
59+
'pandas>=0.19.1',
60+
'ipython>=5.1.0',
6161
],
6262

6363
# List additional groups of dependencies here (e.g. development

wfdb/_signals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def processwfdbbytes(filename, dirname, pbdir, fmt, startbyte, readlen, nsig, sa
414414
if tsampsperframe == nsig: # No extra samples/frame
415415
# Turn the bytes into actual samples.
416416
# 1d array of actual samples. Fill the individual triplets.
417+
417418
sig = np.zeros(nsamp)
418419

419420
sig[0::3] = (sigbytes[0::4] >> 1)[0:len(sig[0::3])] + 128 * \
@@ -601,7 +602,7 @@ def getdatbytes(filename, dirname, pbdir, fmt, nsamp, startbyte):
601602

602603
# For special formats that were read as unsigned 1 byte blocks to be further processed,
603604
# convert dtype from uint8 to uint64
604-
if fmt == ['212', '310', '311']:
605+
if fmt in ['212', '310', '311']:
605606
sigbytes = sigbytes.astype('uint')
606607

607608
fp.close()

wfdb/downloads.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def streamdat(filename, pbdir, fmt, bytecount, startbyte, datatypes):
6363

6464
# For special formats that were read as unsigned 1 byte blocks to be further processed,
6565
# convert dtype from uint8 to uint64
66-
if fmt == ['212', '310', '311']:
66+
if fmt in ['212', '310', '311']:
6767
sigbytes = sigbytes.astype('uint')
6868

6969
return sigbytes
@@ -103,30 +103,6 @@ def getdblist():
103103

104104

105105

106-
# Download specific files from a physiobank database
107-
def dldatabasefiles(pbdb, dlbasedir, files, keepsubdirs = True, overwrite = False):
108-
# Full url physiobank database
109-
dburl = os.path.join(dbindexurl, pbdb)
110-
# Check if the database is valid
111-
r = requests.get(dburl)
112-
r.raise_for_status()
113-
114-
# Construct the urls to download
115-
dlinputs = [(os.path.split(file)[1], os.path.split(file)[0], pbdb, dlbasedir, keepsubdirs, overwrite) for file in files]
116-
117-
# Make any required local directories
118-
makelocaldirs(dlbasedir, dlinputs, keepsubdirs)
119-
120-
print('Downloading files...')
121-
# Create multiple processes to download files.
122-
# Limit to 2 connections to avoid overloading the server
123-
pool = multiprocessing.Pool(processes=2)
124-
pool.map(dlpbfile, dlinputs)
125-
print('Finished downloading files')
126-
127-
return
128-
129-
130106
# ---- Helper functions for downloading physiobank files ------- #
131107

132108
def getrecordlist(dburl, records):

0 commit comments

Comments
 (0)