Skip to content

Commit

Permalink
ENH: py3: Use "six.moves.range()" instead of "xrange()"
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfr committed Feb 14, 2017
1 parent bac8af1 commit 3890702
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions radiomics/glcm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy

from six.moves import range
from tqdm import trange

from radiomics import base, imageoperations
Expand Down Expand Up @@ -147,15 +147,15 @@ def _calculateGLCM(self):
if self.verbose: bar = trange(Ng, desc='calculate GLCM')

# iterate over gray levels for center voxel
for i in xrange(1, Ng + 1):
for i in range(1, Ng + 1):
# give some progress
if self.verbose: bar.update()

# get the indices to all voxels which have the current gray level i
i_indices = numpy.where(self.matrix == i)

# iterate over gray levels for neighbouring voxel
for j in xrange(1, Ng + 1):
for j in range(1, Ng + 1):
# get the indices to all voxels which have the current gray level j
j_indices = set(zip(*numpy.where(self.matrix == j)))

Expand Down
7 changes: 4 additions & 3 deletions radiomics/glrlm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from itertools import chain

import numpy
from six.moves import range

from radiomics import base, imageoperations

Expand Down Expand Up @@ -120,14 +121,14 @@ def _calculateGLRLM(self):
d2 = movingDims[1]
direction = numpy.where(angle < 0, -1, 1)
diags = chain.from_iterable([self.matrix[::direction[0], ::direction[1], ::direction[2]].diagonal(a, d1, d2)
for a in xrange(-self.matrix.shape[d1] + 1, self.matrix.shape[d2])])
for a in range(-self.matrix.shape[d1] + 1, self.matrix.shape[d2])])

else: # movement in 3 dimensions, e.g. angle (1, 1, 1)
diags = []
direction = numpy.where(angle < 0, -1, 1)
for h in [self.matrix[::direction[0], ::direction[1], ::direction[2]].diagonal(a, 0, 1)
for a in xrange(-self.matrix.shape[0] + 1, self.matrix.shape[1])]:
diags.extend([h.diagonal(b, 0, 1) for b in xrange(-h.shape[0] + 1, h.shape[1])])
for a in range(-self.matrix.shape[0] + 1, self.matrix.shape[1])]:
diags.extend([h.diagonal(b, 0, 1) for b in range(-h.shape[0] + 1, h.shape[1])])

matrixDiagonals.append(filter(lambda diag: numpy.nonzero(diag != padVal)[0].size > 0, diags))

Expand Down
3 changes: 2 additions & 1 deletion radiomics/glszm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy
from six.moves import range
from tqdm import trange

from radiomics import base, imageoperations
Expand Down Expand Up @@ -86,7 +87,7 @@ def _calculateGLSZM(self):

if self.verbose: bar = trange(numGrayLevels - 1, desc='calculate GLSZM')

for i in xrange(1, numGrayLevels):
for i in range(1, numGrayLevels):
# give some progress
if self.verbose: bar.update()

Expand Down
7 changes: 4 additions & 3 deletions radiomics/imageoperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pywt
import SimpleITK as sitk
import six
from six.moves import range

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,11 +67,11 @@ def generateAngles(size, maxDistance=1):

angles = []

for z in xrange(1, maxDistance + 1):
for z in range(1, maxDistance + 1):
angles.append((0, 0, z))
for y in xrange(-maxDistance, maxDistance + 1):
for y in range(-maxDistance, maxDistance + 1):
angles.append((0, z, y))
for x in xrange(-maxDistance, maxDistance + 1):
for x in range(-maxDistance, maxDistance + 1):
angles.append((z, y, x))

angles = numpy.array(angles)
Expand Down
7 changes: 4 additions & 3 deletions radiomics/shape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy
import SimpleITK as sitk
from six.moves import range

from radiomics import base

Expand Down Expand Up @@ -55,9 +56,9 @@ def _calculateSurfaceArea(self):

S_A = 0.0
# iterate over all voxels which may border segmentation or are a part of it
for v_z in xrange(minBounds[0] - 1, maxBounds[0] + 1):
for v_y in xrange(minBounds[1] - 1, maxBounds[1] + 1):
for v_x in xrange(minBounds[2] - 1, maxBounds[2] + 1):
for v_z in range(minBounds[0] - 1, maxBounds[0] + 1):
for v_y in range(minBounds[1] - 1, maxBounds[1] + 1):
for v_x in range(minBounds[2] - 1, maxBounds[2] + 1):
# indices to corners of current sampling cube
gridCell = gridAngles + [v_z, v_y, v_x]

Expand Down

0 comments on commit 3890702

Please sign in to comment.