Skip to content

Commit a94e069

Browse files
committed
COMP: Remove shadows name from outer scope.
1 parent af9526b commit a94e069

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

Wrapping/Generators/Python/itkExtras.py

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,19 @@ def xarray_from_image(image):
441441
import numpy as np
442442

443443
array_view = itk.array_view_from_image(image)
444-
spacing = itk.spacing(image)
445-
origin = itk.origin(image)
446-
size = itk.size(image)
444+
l_spacing = itk.spacing(image)
445+
l_origin = itk.origin(image)
446+
l_size = itk.size(image)
447447
direction = np.flip(itk.array_from_matrix(image.GetDirection()))
448448
spatial_dimension = image.GetImageDimension()
449449

450450
spatial_dims = ("x", "y", "z")
451451
coords = {}
452-
for index, dim in enumerate(spatial_dims[:spatial_dimension]):
452+
for l_index, dim in enumerate(spatial_dims[:spatial_dimension]):
453453
coords[dim] = np.linspace(
454-
origin[index],
455-
origin[index] + (size[index] - 1) * spacing[index],
456-
size[index],
454+
l_origin[l_index],
455+
l_origin[l_index] + (l_size[l_index] - 1) * l_spacing[l_index],
456+
l_size[l_index],
457457
dtype=np.float64,
458458
)
459459

@@ -491,17 +491,17 @@ def image_from_xarray(data_array):
491491
is_vector = "c" in data_array.dims
492492
itk_image = itk.image_view_from_array(data_array.values, is_vector=is_vector)
493493

494-
origin = [0.0] * spatial_dimension
495-
spacing = [1.0] * spatial_dimension
496-
for index, dim in enumerate(spatial_dims):
494+
l_origin = [0.0] * spatial_dimension
495+
l_spacing = [1.0] * spatial_dimension
496+
for l_index, dim in enumerate(spatial_dims):
497497
coords = data_array.coords[dim]
498498
if coords.shape[0] > 1:
499-
origin[index] = float(coords[0])
500-
spacing[index] = float(coords[1]) - float(coords[0])
501-
spacing.reverse()
502-
itk_image.SetSpacing(spacing)
503-
origin.reverse()
504-
itk_image.SetOrigin(origin)
499+
l_origin[l_index] = float(coords[0])
500+
l_spacing[l_index] = float(coords[1]) - float(coords[0])
501+
l_spacing.reverse()
502+
itk_image.SetSpacing(l_spacing)
503+
l_origin.reverse()
504+
itk_image.SetOrigin(l_origin)
505505
if "direction" in data_array.attrs:
506506
direction = data_array.attrs["direction"]
507507
itk_image.SetDirection(np.flip(direction))
@@ -524,12 +524,12 @@ def vtk_image_from_image(image):
524524
# Always set Scalars for (future?) multi-component volume rendering
525525
vtk_image.GetPointData().SetScalars(data_array)
526526
dim = image.GetImageDimension()
527-
spacing = [1.0,] * 3
528-
spacing[:dim] = image.GetSpacing()
529-
vtk_image.SetSpacing(spacing)
530-
origin = [0.0,] * 3
531-
origin[:dim] = image.GetOrigin()
532-
vtk_image.SetOrigin(origin)
527+
l_spacing = [1.0,] * 3
528+
l_spacing[:dim] = image.GetSpacing()
529+
vtk_image.SetSpacing(l_spacing)
530+
l_origin = [0.0,] * 3
531+
l_origin[:dim] = image.GetOrigin()
532+
vtk_image.SetOrigin(l_origin)
533533
dims = [1,] * 3
534534
dims[:dim] = itk.size(image)
535535
vtk_image.SetDimensions(dims)
@@ -568,12 +568,12 @@ def image_from_vtk_image(vtk_image):
568568
image = itk.image_view_from_array(array, is_vector)
569569

570570
dim = image.GetImageDimension()
571-
spacing = [1.0] * dim
572-
spacing[:dim] = vtk_image.GetSpacing()[:dim]
573-
image.SetSpacing(spacing)
574-
origin = [0.0] * dim
575-
origin[:dim] = vtk_image.GetOrigin()[:dim]
576-
image.SetOrigin(origin)
571+
l_spacing = [1.0] * dim
572+
l_spacing[:dim] = vtk_image.GetSpacing()[:dim]
573+
image.SetSpacing(l_spacing)
574+
l_origin = [0.0] * dim
575+
l_origin[:dim] = vtk_image.GetOrigin()[:dim]
576+
image.SetOrigin(l_origin)
577577
# Todo: Add Direction with VTK 9
578578
return image
579579

@@ -623,7 +623,7 @@ def class_(obj):
623623
return obj.__class__
624624

625625

626-
def python_type(obj):
626+
def python_type(object_ref):
627627
"""Returns the Python type name of an object
628628
629629
The Python name corresponding to the given instantiated object is printed.
@@ -651,37 +651,37 @@ def in_itk(name):
651651
else:
652652
return name
653653

654-
def recursive(obj, level):
654+
def recursive(l_obj, level):
655655
try:
656-
T, P = template(obj)
656+
T, P = template(l_obj)
657657
name = in_itk(T.__name__)
658658
parameters = []
659659
for t in P:
660660
parameters.append(recursive(t, level + 1))
661661
return name + "[" + ",".join(parameters) + "]"
662662
except KeyError:
663-
if isinstance(obj, itkCType): # Handles CTypes differently
664-
return "itk." + obj.short_name
665-
elif hasattr(obj, "__name__"):
663+
if isinstance(l_obj, itkCType): # Handles CTypes differently
664+
return "itk." + l_obj.short_name
665+
elif hasattr(l_obj, "__name__"):
666666
# This should be where most ITK types end up.
667-
return in_itk(obj.__name__)
667+
return in_itk(l_obj.__name__)
668668
elif (
669-
not isinstance(obj, type)
670-
and type(obj) != itkTemplate.itkTemplate
669+
not isinstance(l_obj, type)
670+
and type(l_obj) != itkTemplate.itkTemplate
671671
and level != 0
672672
):
673-
# obj should actually be considered a value, not a type,
673+
# l_obj should actually be considered a value, not a type,
674674
# or it is already an itkTemplate type.
675675
# A value can be an integer that is a template parameter.
676676
# This does not happen at the first level of the recursion
677677
# as it is not possible that this object would be a template
678678
# parameter. Checking the level `0` allows e.g. to find the
679679
# type of an object that is a `list` or an `int`.
680-
return str(obj)
680+
return str(l_obj)
681681
else:
682-
return in_itk(type(obj).__name__)
682+
return in_itk(type(l_obj).__name__)
683683

684-
return recursive(obj, 0)
684+
return recursive(object_ref, 0)
685685

686686

687687
def image_intensity_min_max(image_or_filter):
@@ -1107,11 +1107,13 @@ class __templated_class_and_parameters__:
11071107
to instantiate.
11081108
"""
11091109

1110-
def __init__(self, templated_class, template_parameters):
1111-
self.__templated_class__ = templated_class
1112-
self.__template_parameters__ = template_parameters
1113-
if "check_template_parameters" in dir(templated_class.__cls__):
1114-
templated_class.__cls__.check_template_parameters(template_parameters)
1110+
def __init__(self, l_templated_class, l_template_parameters):
1111+
self.__templated_class__ = l_templated_class
1112+
self.__template_parameters__ = l_template_parameters
1113+
if "check_template_parameters" in dir(l_templated_class.__cls__):
1114+
l_templated_class.__cls__.check_template_parameters(
1115+
l_template_parameters
1116+
)
11151117

11161118
def New(self, *args, **kargs):
11171119
"""A New() method to mimic the ITK default behavior, even if the
@@ -1199,7 +1201,7 @@ def clear(self):
11991201
"""
12001202
self.filters = []
12011203

1202-
def GetOutput(self, index=0):
1204+
def GetOutput(self, l_index=0):
12031205
"""Return the output of the pipeline
12041206
12051207
If another output is needed, use
@@ -1212,11 +1214,11 @@ def GetOutput(self, index=0):
12121214
else:
12131215
filter = self.filters[-1]
12141216
if hasattr(filter, "__getitem__"):
1215-
return filter[index]
1217+
return filter[l_index]
12161218
try:
1217-
return filter.GetOutput(index)
1219+
return filter.GetOutput(l_index)
12181220
except Exception:
1219-
if index == 0:
1221+
if l_index == 0:
12201222
return filter.GetOutput()
12211223
else:
12221224
raise ValueError("Index can only be 0 on that object")

0 commit comments

Comments
 (0)