Skip to content

Commit 3e1cb84

Browse files
committed
Added future for python2/3 compatibility
1 parent dd274ec commit 3e1cb84

File tree

7 files changed

+63
-47
lines changed

7 files changed

+63
-47
lines changed

convert.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
Valid formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz,
2626
tif, tiff.
2727
"""
28-
28+
from __future__ import unicode_literals, print_function, division, absolute_import
29+
from future import standard_library
30+
standard_library.install_aliases()
31+
from builtins import open
2932
from ecg import ECG
3033
from docopt import docopt
3134
from io import BytesIO

ecg/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import unicode_literals, print_function, division, absolute_import
2+
from future import standard_library
3+
standard_library.install_aliases()
14
from .ecg import ECG, i18n
25

36
__version__="1.0.1"

ecg/ecg.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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
@@ -27,7 +31,6 @@
2731
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2832
THE SOFTWARE.
2933
"""
30-
3134
import numpy as np
3235
import dicom
3336
import struct
@@ -39,7 +42,6 @@
3942
from matplotlib import pylab as plt
4043
from scipy.signal import butter, lfilter
4144

42-
4345
try:
4446
from ecgconfig import WADOSERVER, LAYOUT, INSTITUTION
4547
except ImportError:
@@ -48,27 +50,27 @@
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

ecg/i18n.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals, print_function, division, absolute_import
3+
from future import standard_library
4+
standard_library.install_aliases()
25
import os
3-
import sys
46
import locale
57
import gettext
68

ecgconfig.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import unicode_literals, print_function, division, absolute_import
2+
from future import standard_library
3+
standard_library.install_aliases()
14
WADOSERVER = "http://example.com/"
25

36
LAYOUT = {'3x4_1': [[0, 3, 6, 9],

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ matplotlib
44
scipy
55
docopt
66
requests
7+
future

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env python
22

33
# Use setuptools if we can
4+
from __future__ import unicode_literals, print_function, division, absolute_import
5+
from future import standard_library
6+
standard_library.install_aliases()
7+
from builtins import open
48
try:
59
from setuptools.core import setup
610
except ImportError:

0 commit comments

Comments
 (0)