@@ -23,7 +23,7 @@ def wrann(self):
23
23
# Write the header file using the specified fields
24
24
self .wrannfile ()
25
25
26
- # Check all fields of the annotation object
26
+ # Check the mandatory and set fields of the annotation object
27
27
def checkfields (self ):
28
28
29
29
# Mandatory write fields
@@ -46,16 +46,43 @@ def checkfield(self, field):
46
46
if type (self .fs ) not in annfieldtypes ['fs' ]:
47
47
print ('The fs field must be one of the following types: ' , annfieldtypes ['fs' ])
48
48
sys .exit ()
49
- # Particular condition
49
+ # Field specific check
50
50
if self .fs <= 0 :
51
51
sys .exit ('The fs field must be a non-negative number' )
52
52
53
53
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 ()
58
58
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' )
59
86
60
87
61
88
# Ensure all set annotation fields have the same length
@@ -67,10 +94,7 @@ def checkfieldcohesion(self):
67
94
for field in annfields [1 :- 1 ]:
68
95
if getarr (self , field ) is not None :
69
96
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' )
74
98
75
99
def wrannfile (self ):
76
100
print ('on it' )
0 commit comments