Skip to content

Commit d361e29

Browse files
committed
dev
1 parent 30e94f0 commit d361e29

File tree

2 files changed

+96
-13
lines changed

2 files changed

+96
-13
lines changed

devtests.ipynb

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,12 +1199,71 @@
11991199
},
12001200
{
12011201
"cell_type": "code",
1202-
"execution_count": null,
1202+
"execution_count": 4,
12031203
"metadata": {
12041204
"collapsed": false
12051205
},
1206-
"outputs": [],
1207-
"source": []
1206+
"outputs": [
1207+
{
1208+
"data": {
1209+
"text/plain": [
1210+
"array([ 1, 3, 6, 10, 15])"
1211+
]
1212+
},
1213+
"execution_count": 4,
1214+
"metadata": {},
1215+
"output_type": "execute_result"
1216+
}
1217+
],
1218+
"source": [
1219+
"import numpy as np\n",
1220+
" \n",
1221+
"np.cumsum([1,2,3,4,5])"
1222+
]
1223+
},
1224+
{
1225+
"cell_type": "code",
1226+
"execution_count": 5,
1227+
"metadata": {
1228+
"collapsed": false
1229+
},
1230+
"outputs": [
1231+
{
1232+
"data": {
1233+
"text/plain": [
1234+
"-66"
1235+
]
1236+
},
1237+
"execution_count": 5,
1238+
"metadata": {},
1239+
"output_type": "execute_result"
1240+
}
1241+
],
1242+
"source": [
1243+
"min(np.diff([1,2,3,4,59,99,33]))"
1244+
]
1245+
},
1246+
{
1247+
"cell_type": "code",
1248+
"execution_count": 6,
1249+
"metadata": {
1250+
"collapsed": false
1251+
},
1252+
"outputs": [
1253+
{
1254+
"data": {
1255+
"text/plain": [
1256+
"1"
1257+
]
1258+
},
1259+
"execution_count": 6,
1260+
"metadata": {},
1261+
"output_type": "execute_result"
1262+
}
1263+
],
1264+
"source": [
1265+
"min([1,2,3])\n"
1266+
]
12081267
},
12091268
{
12101269
"cell_type": "code",

wfdb/annotations.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def wrann(self):
2323
# Write the header file using the specified fields
2424
self.wrannfile()
2525

26-
# Check all fields of the annotation object
26+
# Check the mandatory and set fields of the annotation object
2727
def checkfields(self):
2828

2929
# Mandatory write fields
@@ -46,16 +46,43 @@ def checkfield(self, field):
4646
if type(self.fs) not in annfieldtypes['fs']:
4747
print('The fs field must be one of the following types: ', annfieldtypes['fs'])
4848
sys.exit()
49-
# Particular condition
49+
# Field specific check
5050
if self.fs <=0:
5151
sys.exit('The fs field must be a non-negative number')
5252

5353
else:
54-
# Ensure the field is an array
55-
56-
# Check the field type of the list elements
57-
54+
# Ensure the field is a list
55+
if type(getattr(self, field)) != list:
56+
print('The ', field, ' field must be a list')
57+
sys.exit()
5858

59+
# Check the field type of the list elements
60+
for fd in getattr(self, field):
61+
if type(fd) not in annfieldtypes[field]:
62+
print('All elements of the ' field, 'field must be one of the following: ', annfieldtypes[field])
63+
sys.exit()
64+
65+
# Field specific checks
66+
if field == 'annsamp':
67+
sampdiffs = np.diff(self.annsamp)
68+
if min(self.annsamp) < 0 :
69+
sys.exit('The annsamp field must only contain non-negative integers')
70+
if min(sampdiffs) < 0 :
71+
sys.exit('The annsamp field must contain monotonically increasing sample numbers')
72+
elif field == 'anntype':
73+
print('to find out...')
74+
elif field == 'num':
75+
if min(self.num) < 0 :
76+
sys.exit('The num field must only contain non-negative integers')
77+
elif field == 'subtype':
78+
if min(self.subtype) < 0 :
79+
sys.exit('The subtype field must only contain non-negative integers')
80+
elif field == 'chan':
81+
if min(self.chan) < 0 :
82+
sys.exit('The chan field must only contain non-negative integers')
83+
elif field == 'aux':
84+
if min(self.aux) < 0 :
85+
sys.exit('The aux field must only contain non-negative integers')
5986

6087

6188
# Ensure all set annotation fields have the same length
@@ -67,10 +94,7 @@ def checkfieldcohesion(self):
6794
for field in annfields[1:-1]:
6895
if getarr(self, field) is not None:
6996
if len(getattr(self, field)) != nannots:
70-
71-
72-
73-
97+
sys.exit('All set annotation fields (aside from fs) must have the same length')
7498

7599
def wrannfile(self):
76100
print('on it')

0 commit comments

Comments
 (0)