Skip to content

Commit ca8a9ba

Browse files
committed
preliminary ann and signame info
1 parent bb7230a commit ca8a9ba

File tree

3 files changed

+63
-37
lines changed

3 files changed

+63
-37
lines changed

wfdb/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .readwrite.records import Record, MultiRecord, rdheader, rdsamp, srdsamp, wrsamp, dldatabase, dldatabasefiles
22
from .readwrite._signals import estres, wrdatfile
3-
from .readwrite._headers import signaltypes
4-
from .readwrite.annotations import Annotation, rdann, wrann, showanncodes
3+
from .readwrite._headers import sigclasses
4+
from .readwrite.annotations import Annotation, rdann, wrann, showanncodes, annclasses
55
from .readwrite.downloads import getdblist
66
from .plot.plots import plotrec, plotann
77
from . import processing

wfdb/readwrite/_headers.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def __init__(self, allowedtypes, delimiter, dependency, write_req, read_def, wri
608608
('siglen', WFDBheaderspecs(inttypes, ' ', 'fs', True, None, None)),
609609
('basetime', WFDBheaderspecs([str], ' ', 'siglen', False, None, '00:00:00')),
610610
('basedate', WFDBheaderspecs([str], ' ', 'basetime', False, None, None))])
611-
611+
612612
# Signal specification fields.
613613
sigfieldspecs = OrderedDict([('filename', WFDBheaderspecs([str], '', None, True, None, None)),
614614
('fmt', WFDBheaderspecs([str], ' ', 'filename', True, None, None)),
@@ -631,15 +631,18 @@ def __init__(self, allowedtypes, delimiter, dependency, write_req, read_def, wri
631631

632632

633633

634-
# For storing WFDB Signal definitions.
634+
# ---------- For storing WFDB Signal definitions ---------- #
635635

636-
# SignalType class with all its parameters
637-
class SignalType(object):
638-
def __init__(self, description, signalnames):
636+
# Signal class with all its parameters
637+
class SignalClass(object):
638+
def __init__(self, abbreviation, description, signalnames):
639+
self.abbreviation = abbreviation
639640
self.description = description
640641
# names that are assigned to this signal type
641642
self.signalnames = signalnames
642-
643+
644+
def __str__(self):
645+
return self.abbreviation
643646

644647
# Unit scales used for default display scales.
645648
unitscale = {
@@ -649,28 +652,24 @@ def __init__(self, description, signalnames):
649652
}
650653

651654
# All signal types. Make sure signal names are in lower case.
652-
# Used for:
653-
# - signal search
654-
# - default waveform display
655-
signaltypes = {
656-
#'ANGLE': SignalType('Angle',None, ['angle, pitch, roll, yaw']),
657-
'BP': SignalType('Blood Pressure', ['bp','abp','pap','cvp',]),
658-
'CO2': SignalType('Carbon Dioxide', ['co2']),
659-
'CO': SignalType('Carbon Monoxide', ['co']),
660-
'ECG': SignalType('Electrocardiogram', ['i','ii','iii','iv','v','avr']),
661-
'EEG': SignalType('Electroencephalogram',['eeg']),
662-
'EMG': SignalType('Electromyograph', ['emg']),
663-
'EOG': SignalType('Electrooculograph', ['eog']),
664-
'HR': SignalType('Heart Rate', ['hr']),
665-
'MMG': SignalType('Magnetomyograph', ['mmg']),
666-
'O2': SignalType('Oxygen', ['o2','sp02']),
667-
'PLETH': SignalType('Plethysmograph', ['pleth']),
668-
'RESP': SignalType('Respiration', ['resp']),
669-
'SCG': SignalType('Seismocardiogram', ['scg']),
670-
'STAT': SignalType('Status', ['stat','status']), # small integers indicating status
671-
'ST': SignalType('ECG ST Segment', ['st']),
672-
'TEMP': SignalType('Temperature', ['temp']),
673-
'UNKNOWN': SignalType('Unknown', []),
674-
}
655+
signalclasses = [
656+
SignalClass('BP', 'Blood Pressure', ['bp','abp','pap','cvp',]),
657+
SignalClass('CO2', 'Carbon Dioxide', ['co2']),
658+
SignalClass('CO', 'Carbon Monoxide', ['co']),
659+
SignalClass('ECG', 'Electrocardiogram', ['i','ii','iii','iv','v','avr']),
660+
SignalClass('EEG', 'Electroencephalogram',['eeg']),
661+
SignalClass('EMG', 'Electromyograph', ['emg']),
662+
SignalClass('EOG', 'Electrooculograph', ['eog']),
663+
SignalClass('HR', 'Heart Rate', ['hr']),
664+
SignalClass('MMG', 'Magnetomyograph', ['mmg']),
665+
SignalClass('O2', 'Oxygen', ['o2','sp02']),
666+
SignalClass('PLETH', 'Plethysmograph', ['pleth']),
667+
SignalClass('RESP', 'Respiration', ['resp']),
668+
SignalClass('SCG', 'Seismocardiogram', ['scg']),
669+
SignalClass('STAT', 'Status', ['stat','status']), # small integers indicating status
670+
SignalClass('ST', 'ECG ST Segment', ['st']),
671+
SignalClass('TEMP', 'Temperature', ['temp']),
672+
SignalClass('UNKNOWN', 'Unknown Class', []),
673+
]
675674

676675

wfdb/readwrite/annotations.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ def checkfield(self, field):
148148
raise ValueError('All custom_anntypes keys must be strings')
149149
if len(key)>1:
150150
raise ValueError('All custom_anntypes keys must be single characters')
151-
# Discourage (but not prevent) using existing codes
152-
if key in annsyms.values():
153-
print('It is discouraged to define the custom annotation code: '+key+' that already has an entry in the wfdb library.')
154-
print('To see existing annotation codes and their meanings, call: showanncodes(). Continuing...')
155151

156152
for value in self.custom_anntypes.values():
157153
if type(key)!= str:
@@ -1095,7 +1091,7 @@ def proc_special_types(annsamp,anntype,num,subtype,chan,aux):
10951091
38: 'PFUS', # fusion of paced and normal beat */
10961092
39: 'WFON', # waveform onset */
10971093
40: 'WFOFF', # waveform end */
1098-
41: 'RONT', # R-on-T premature ventricular contraction */
1094+
41: 'RONT', # R-on-T premature ventricular contraction */
10991095
# 42: '',
11001096
# 43: '',
11011097
# 44: '',
@@ -1106,6 +1102,7 @@ def proc_special_types(annsamp,anntype,num,subtype,chan,aux):
11061102
# 49: ''
11071103
}
11081104

1105+
11091106
# Mapping annotation symbols to the annotation codes
11101107
# For printing/user guidance
11111108
symcodes = pd.DataFrame({'Ann Symbol': list(annsyms.values()), 'Ann Code Meaning': list(anncodes.values())})
@@ -1120,4 +1117,34 @@ def proc_special_types(annsamp,anntype,num,subtype,chan,aux):
11201117
'custom_anntypes': [dict]}
11211118

11221119
# Acceptable numpy integer dtypes
1123-
intdtypes = ['int64', 'uint64', 'int32', 'uint32','int16','uint16']
1120+
intdtypes = ['int64', 'uint64', 'int32', 'uint32','int16','uint16']
1121+
1122+
1123+
1124+
# Classes = extensions
1125+
class AnnotationClass(object):
1126+
def __init__(self, extension, description, isreference):
1127+
self.extension = extension
1128+
self.description = description
1129+
self.isreference = isreference
1130+
1131+
annclasses = [
1132+
AnnotationClass('atr', 'Reference ECG annotations', True),
1133+
AnnotationClass('apn', 'Reference apnea annotations', True),
1134+
AnnotationClass('alarm', 'Machine alarm annotations', False),
1135+
]
1136+
1137+
# Individual annotation labels
1138+
class AnnotationLabel(object):
1139+
def __init__(self, storevalue, symbol, description):
1140+
self.storevalue = storevalue
1141+
self.symbol = symbol
1142+
self.description = description
1143+
1144+
annlabels = [
1145+
AnnotationLabel(0, ' ', 'Not an actual annotation'),
1146+
AnnotationLabel(1, 'N', 'Normal beat'),
1147+
AnnotationLabel(2, 'L', 'Left bundle branch block beat'),
1148+
AnnotationLabel(3, 'R', 'Right bundle branch block beat'),
1149+
AnnotationLabel(4, 'a', 'Aberrated atrial premature beat'),
1150+
]

0 commit comments

Comments
 (0)