/
dicom-ecg-plot
executable file
·68 lines (54 loc) · 2.2 KB
/
dicom-ecg-plot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""ECG Conversion Tool
Usage:
dicom-ecg-plot <inputfile> [--layout=LAYOUT] [--output=FILE|--format=FMT] [--minor-grid] [--interpretation]
dicom-ecg-plot <stu> <ser> <obj> [--layout=LAYOUT] [--output=FILE|--format=FMT] [--minor-grid] [--interpretation]
dicom-ecg-plot --help
Options:
-h, --help This help.
<inputfile> Input dicom file.
<stu> <ser> <obj> studyUID seriesUID objectUID
UIDs for WADO download.
-l LAYOUT --layout=LAYOUT Layout [default: 3x4_1].
-o FILE --output=FILE Output file (format deduced by extension).
-f FMT --format=FMT Output format.
--minor-grid Draw minor axis grid (1mm).
--interpretation Show "Automated ECG interpretation"
Valid layouts are: 3x4_1, 3x4, 12x1
The output format is deduced from the extension of the filename, if present, or
from --format option when filename is not specified.
Valid formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz,
tif, tiff.
"""
from ecg import ECG
from docopt import docopt
from io import BytesIO
import sys
def convert(source, layout, outformat, outputfile,
minor_axis=False, interpretation=False):
ecg = ECG(source)
ecg.draw(layout, 10, minor_axis, interpretation=interpretation)
return ecg.save(outformat=outformat, outputfile=outputfile)
if __name__ == '__main__':
arguments = docopt(__doc__)
inputfile = arguments['<inputfile>']
stu = arguments['<stu>']
ser = arguments['<ser>']
obj = arguments['<obj>']
outputfile = arguments['--output']
outformat = arguments['--format']
layout = arguments['--layout']
minor_axis = arguments['--minor-grid']
interpretation = arguments['--interpretation']
if inputfile:
source = BytesIO(open(inputfile, mode='rb').read())
else:
source = {'stu': stu, 'ser': ser, 'obj': obj}
output = convert(source, layout, outformat, outputfile,
minor_axis, interpretation)
if output:
try:
sys.stdout.buffer.write(output)
except AttributeError:
sys.stdout.write(output)