Skip to content

Commit 95ff42f

Browse files
committed
dev
1 parent d361e29 commit 95ff42f

File tree

4 files changed

+56
-34
lines changed

4 files changed

+56
-34
lines changed

devtests.ipynb

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,24 +1223,28 @@
12231223
},
12241224
{
12251225
"cell_type": "code",
1226-
"execution_count": 5,
1226+
"execution_count": 13,
12271227
"metadata": {
12281228
"collapsed": false
12291229
},
12301230
"outputs": [
12311231
{
12321232
"data": {
12331233
"text/plain": [
1234-
"-66"
1234+
"1"
12351235
]
12361236
},
1237-
"execution_count": 5,
1237+
"execution_count": 13,
12381238
"metadata": {},
12391239
"output_type": "execute_result"
12401240
}
12411241
],
12421242
"source": [
1243-
"min(np.diff([1,2,3,4,59,99,33]))"
1243+
"a = np.diff([1,2,3,4,59,99,33])\n",
1244+
"\n",
1245+
"a.dtype == 'int64'\n",
1246+
"\n",
1247+
"a.ndim"
12441248
]
12451249
},
12461250
{
@@ -1265,6 +1269,29 @@
12651269
"min([1,2,3])\n"
12661270
]
12671271
},
1272+
{
1273+
"cell_type": "code",
1274+
"execution_count": 12,
1275+
"metadata": {
1276+
"collapsed": false
1277+
},
1278+
"outputs": [
1279+
{
1280+
"data": {
1281+
"text/plain": [
1282+
"array(['a', 'b', 'c'], \n",
1283+
" dtype='<U1')"
1284+
]
1285+
},
1286+
"execution_count": 12,
1287+
"metadata": {},
1288+
"output_type": "execute_result"
1289+
}
1290+
],
1291+
"source": [
1292+
"b = np.array(['a','b','c"
1293+
]
1294+
},
12681295
{
12691296
"cell_type": "code",
12701297
"execution_count": null,

tests/test_annotations.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class test_rdann():
99
def test_1(self):
1010

1111
# Read data from WFDB python package
12-
annsamp, anntype, subtype, chan, num, aux, annfs = wfdb.rdann(
13-
'sampledata/100', 'atr')
12+
annotation = wfdb.rdann('sampledata/100', 'atr')
13+
14+
1415
# This is not the fault of the script. The annotation file specifies a
1516
# length 3
1617
aux[0] = '(N'
@@ -44,13 +45,12 @@ def test_1(self):
4445
Tchan = Tchan.astype('int')
4546

4647
# Compare
47-
comp = [
48-
np.array_equal(
49-
annsamp, Tannsamp), np.array_equal(
50-
anntype, Tanntype), np.array_equal(
51-
subtype, Tsubtype), np.array_equal(
52-
chan, Tchan), np.array_equal(
53-
num, Tnum), aux == Taux]
48+
comp = [np.array_equal(annotation.annsamp, Tannsamp),
49+
np.array_equal(annotation.anntype, Tanntype),
50+
np.array_equal(annotation.subtype, Tsubtype),
51+
np.array_equal(annotation.chan, Tchan),
52+
np.array_equal(annotation.num, Tnum),
53+
aux == Taux]
5454

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

@@ -59,8 +59,7 @@ def test_1(self):
5959
def test_2(self):
6060

6161
# Read data from WFDB python package
62-
annsamp, anntype, subtype, chan, num, aux, annfs = wfdb.rdann(
63-
'sampledata/12726', 'anI')
62+
annotation = wfdb.rdann('sampledata/12726', 'anI')
6463

6564
# Target data from WFDB software package
6665
lines = tuple(open('tests/targetoutputdata/anntarget2', 'r'))
@@ -88,12 +87,11 @@ def test_2(self):
8887
Tchan = Tchan.astype('int')
8988

9089
# Compare
91-
comp = [
92-
np.array_equal(
93-
annsamp, Tannsamp), np.array_equal(
94-
anntype, Tanntype), np.array_equal(
95-
subtype, Tsubtype), np.array_equal(
96-
chan, Tchan), np.array_equal(
97-
num, Tnum), aux == Taux]
90+
comp = [np.array_equal(annotation.annsamp, Tannsamp),
91+
np.array_equal(annotation.anntype, Tanntype),
92+
np.array_equal(annotation.subtype, Tsubtype),
93+
np.array_equal(annotation.chan, Tchan),
94+
np.array_equal(annotation.num, Tnum),
95+
aux == Taux]
9896

9997
assert (comp == [True] * 6)

wfdb/annotations.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ def checkfield(self, field):
5151
sys.exit('The fs field must be a non-negative number')
5252

5353
else:
54-
# Ensure the field is a list
55-
if type(getattr(self, field)) != list:
56-
print('The ', field, ' field must be a list')
54+
# Ensure the field is a list or 1d numpy array
55+
fielditem = getattr(self, field)
56+
if (type(fielditem) not in [list, np.ndarray]) or
57+
(type(fielditem) == np.ndarray and fielditem.ndim != 1):
58+
print('The ', field, ' field must be a list or a 1d numpy array')
5759
sys.exit()
5860

59-
# Check the field type of the list elements
60-
for fd in getattr(self, field):
61-
if type(fd) not in annfieldtypes[field]:
61+
# Check the data types of the list/array elements
62+
for item in fielditem:
63+
if type(item) not in annfieldtypes[field]:
6264
print('All elements of the ' field, 'field must be one of the following: ', annfieldtypes[field])
6365
sys.exit()
6466

@@ -101,11 +103,6 @@ def wrannfile(self):
101103

102104

103105

104-
105-
106-
107-
108-
109106
## ------------- Reading Annotations ------------- ##
110107

111108
def rdann(recordname, annot, sampfrom=0, sampto=None, anndisp=1):

wfdb/records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# For wrheader(), all fields must be already filled in and cohesive with one another other. The signals field will not be used.
22
# For wrsamp(), the field to use will be d_signals (which is allowed to be empty for 0 channel records).
33
# set_p_features and set_d_features use characteristics of the p_signals or d_signals field to fill in other header fields.
4-
# These are separate from another method 'setdefaults' which the user may call to
4+
# These are separate from another method 'setdefaults' which the user may call to set default header fields
55
# The checkfieldcohesion() function will be called in wrheader which checks all the header fields.
66
# The checksignalcohesion() function will be called in wrsamp in wrdat to check the d_signal against the header fields.
77

0 commit comments

Comments
 (0)