1+ from __future__ import unicode_literals , print_function , division , absolute_import
2+ from future import standard_library
3+ standard_library .install_aliases ()
4+ from builtins import int , round , str , range , object
15# -*- coding: utf-8 -*-
26"""ECG (waveform) Dicom module
37
2731OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2832THE SOFTWARE.
2933"""
30-
3134import numpy as np
3235import dicom
3336import struct
3942from matplotlib import pylab as plt
4043from scipy .signal import butter , lfilter
4144
42-
4345try :
4446 from ecgconfig import WADOSERVER , LAYOUT , INSTITUTION
4547except ImportError :
4850 [1 , 4 , 7 , 10 ],
4951 [2 , 5 , 8 , 11 ],
5052 [1 ]],
51- '3x4' : [[0 , 3 , 6 , 9 ],
52- [1 , 4 , 7 , 10 ],
53- [2 , 5 , 8 , 11 ]],
54- '6x2' : [[0 , 6 ],
55- [1 , 7 ],
56- [3 , 8 ],
57- [4 , 9 ],
58- [5 , 10 ],
59- [6 , 11 ]],
60- '12x1' : [[0 ],
61- [1 ],
62- [2 ],
63- [3 ],
64- [4 ],
65- [5 ],
66- [6 ],
67- [7 ],
68- [8 ],
69- [9 ],
70- [10 ],
71- [11 ]]}
53+ '3x4' : [[0 , 3 , 6 , 9 ],
54+ [1 , 4 , 7 , 10 ],
55+ [2 , 5 , 8 , 11 ]],
56+ '6x2' : [[0 , 6 ],
57+ [1 , 7 ],
58+ [3 , 8 ],
59+ [4 , 9 ],
60+ [5 , 10 ],
61+ [6 , 11 ]],
62+ '12x1' : [[0 ],
63+ [1 ],
64+ [2 ],
65+ [3 ],
66+ [4 ],
67+ [5 ],
68+ [6 ],
69+ [7 ],
70+ [8 ],
71+ [9 ],
72+ [10 ],
73+ [11 ]]}
7274
7375 # If INSTITUTION is set to None the value of the tag InstitutionName is
7476 # used
@@ -120,9 +122,9 @@ class ECG(object):
120122
121123 # Normalized in [0, 1]
122124 left = margin_left / paper_w
123- right = left + width / paper_w
125+ right = left + width / paper_w
124126 bottom = margin_bottom / paper_h
125- top = bottom + height / paper_h
127+ top = bottom + height / paper_h
126128
127129 def __init__ (self , source ):
128130 """The ECG class constructor.
@@ -165,7 +167,7 @@ def wadoget(stu, ser, obj):
165167 inputdata = source
166168 else :
167169 # What is it?
168- err ("` source´ must be a path/to/file.ext string\n " +
170+ err ("' source' must be a path/to/file.ext string\n " +
169171 "or a dictionary of stu, ser and obj" )
170172
171173 try :
@@ -176,8 +178,8 @@ def wadoget(stu, ser, obj):
176178
177179 sequence_item = self .dicom .WaveformSequence [0 ]
178180
179- assert (sequence_item .WaveformSampleInterpretation == 'SS' )
180- assert (sequence_item .WaveformBitsAllocated == 16 )
181+ assert (sequence_item .WaveformSampleInterpretation == 'SS' )
182+ assert (sequence_item .WaveformBitsAllocated == 16 )
181183
182184 self .channel_definitions = sequence_item .ChannelDefinitionSequence
183185 self .wavewform_data = sequence_item .WaveformData
@@ -213,7 +215,7 @@ def create_figure(self):
213215 axes .set_ylim ([0 , self .height ])
214216
215217 # We want to plot N points, where N=number of samples
216- axes .set_xlim ([0 , self .samples - 1 ])
218+ axes .set_xlim ([0 , self .samples - 1 ])
217219 return fig , axes
218220
219221 def _signals (self ):
@@ -232,7 +234,7 @@ def _signals(self):
232234 for idx in range (self .channels_no ):
233235 definition = self .channel_definitions [idx ]
234236
235- assert (definition .WaveformBitsStored == 16 )
237+ assert (definition .WaveformBitsStored == 16 )
236238
237239 if definition .get ('ChannelSensitivity' ):
238240 factor [idx ] = (
@@ -252,8 +254,8 @@ def _signals(self):
252254 signals = np .asarray (
253255 unpacked_waveform_data ,
254256 dtype = np .float32 ).reshape (
255- self .samples ,
256- self .channels_no ).transpose ()
257+ self .samples ,
258+ self .channels_no ).transpose ()
257259
258260 for channel in range (self .channels_no ):
259261 signals [channel ] = (
@@ -266,7 +268,6 @@ def _signals(self):
266268 millivolts = {'uV' : 1000.0 , 'mV' : 1.0 }
267269
268270 for i , signal in enumerate (signals ):
269-
270271 signals [i ] = butter_lowpass_filter (
271272 np .asarray (signal ),
272273 high ,
@@ -299,7 +300,6 @@ def draw_grid(self, minor_axis):
299300
300301 for axe in 'x' , 'y' :
301302 for which in 'major' , 'minor' :
302-
303303 self .axis .grid (
304304 which = which ,
305305 axis = axe ,
@@ -335,14 +335,14 @@ def legend(self):
335335 if was .get ('ConceptNameCodeSequence' ):
336336 cncs = was .ConceptNameCodeSequence [0 ]
337337 if cncs .CodeMeaning in (
338- 'QT Interval' ,
339- 'QTc Interval' ,
340- 'RR Interval' ,
341- 'QRS Duration' ,
342- 'QRS Axis' ,
343- 'T Axis' ,
344- 'P Axis' ,
345- 'PR Interval'
338+ 'QT Interval' ,
339+ 'QTc Interval' ,
340+ 'RR Interval' ,
341+ 'QRS Duration' ,
342+ 'QRS Axis' ,
343+ 'T Axis' ,
344+ 'P Axis' ,
345+ 'PR Interval'
346346 ):
347347 ecgdata [cncs .CodeMeaning ] = str (was .NumericValue )
348348
@@ -519,8 +519,8 @@ def plot(self, layoutid, mm_mv):
519519
520520 # Vertical shift of the origin
521521 v_delta = round (
522- self .height * (1.0 - 1.0 / (rows * 2 )) -
523- numrow * (self .height / rows )
522+ self .height * (1.0 - 1.0 / (rows * 2 )) -
523+ numrow * (self .height / rows )
524524 )
525525
526526 # Let's shift the origin on a multiple of 5 mm
@@ -530,7 +530,7 @@ def plot(self, layoutid, mm_mv):
530530 chunk_size = int (self .samples / len (row ))
531531 for numcol , signum in enumerate (row ):
532532 left = numcol * chunk_size
533- right = (1 + numcol ) * chunk_size
533+ right = (1 + numcol ) * chunk_size
534534
535535 # The signal chunk, vertical shifted and
536536 # scaled by mm/mV factor
0 commit comments