Skip to content

Commit

Permalink
STYLE: Run black on all Python examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Mar 12, 2021
1 parent 0175c88 commit 05bd86a
Show file tree
Hide file tree
Showing 67 changed files with 474 additions and 374 deletions.
Expand Up @@ -18,12 +18,13 @@
import itk

from distutils.version import StrictVersion as VS

if VS(itk.Version.GetITKVersion()) < VS("4.10.0"):
print("ITK 4.10.0 is required.")
sys.exit(1)

if len(sys.argv) != 2:
print('Usage: ' + sys.argv[0] + ' <InputFileName>')
print("Usage: " + sys.argv[0] + " <InputFileName>")
sys.exit(1)
imageFileName = sys.argv[1]

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/Code.py
Expand Up @@ -18,7 +18,7 @@
import itk

if len(sys.argv) != 2:
print('Usage: ' + sys.argv[0] + ' <InputFileName>')
print("Usage: " + sys.argv[0] + " <InputFileName>")
sys.exit(1)
imageFileName = sys.argv[1]

Expand Down
Expand Up @@ -19,7 +19,7 @@
import vtk

if len(sys.argv) < 2:
print('Usage: ' + sys.argv[0] + ' <InputFileName>')
print("Usage: " + sys.argv[0] + " <InputFileName>")
sys.exit(1)
imageFileName = sys.argv[1]

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/VtkGlue/ConvertvtkImageDataToAnitkImage/Code.py
Expand Up @@ -19,7 +19,7 @@
import vtk

if len(sys.argv) < 2:
print('Usage: ' + sys.argv[0] + ' <InputFileName>')
print("Usage: " + sys.argv[0] + " <InputFileName>")
sys.exit(1)
imageFileName = sys.argv[1]

Expand Down
1 change: 1 addition & 0 deletions src/Core/Common/AddOffsetToIndex/Code.py
Expand Up @@ -18,6 +18,7 @@
import itk

from distutils.version import StrictVersion as VS

if VS(itk.Version.GetITKVersion()) < VS("4.9.0"):
print("ITK 4.9.0 is required.")
sys.exit(1)
Expand Down
18 changes: 10 additions & 8 deletions src/Core/Common/BoundingBoxOfAPointSet/Code.py
Expand Up @@ -18,12 +18,12 @@
import platform

Dimension = 3
CoordType = itk.ctype('float')
CoordType = itk.ctype("float")
# Windows requires unsigned long long for 64-bit identifiers
if platform.system() == 'Windows':
ElementIdentifierType = itk.ctype('unsigned long long')
if platform.system() == "Windows":
ElementIdentifierType = itk.ctype("unsigned long long")
else:
ElementIdentifierType = itk.ctype('unsigned long')
ElementIdentifierType = itk.ctype("unsigned long")


PointSetType = itk.PointSet[CoordType, Dimension]
Expand All @@ -50,10 +50,12 @@
points.InsertElement(1, p1)
points.InsertElement(2, p2)

VecContType = itk.VectorContainer[ElementIdentifierType,
itk.Point[CoordType, Dimension]]
BoundingBoxType = itk.BoundingBox[ElementIdentifierType,
Dimension, CoordType, VecContType]
VecContType = itk.VectorContainer[
ElementIdentifierType, itk.Point[CoordType, Dimension]
]
BoundingBoxType = itk.BoundingBox[
ElementIdentifierType, Dimension, CoordType, VecContType
]

boundingBox = BoundingBoxType.New()
boundingBox.SetPoints(points)
Expand Down
9 changes: 5 additions & 4 deletions src/Core/Common/ComputeTimeBetweenPoints/Code.py
Expand Up @@ -23,20 +23,21 @@ def LongFunction():
for i in range(int(1e5)):
a = 0.0 # noqa: F841


clock = itk.TimeProbe()

clock.Start()
LongFunction()

clock.Stop()
print('Mean: ' + str(clock.GetMean()))
print('Total: ' + str(clock.GetTotal()))
print("Mean: " + str(clock.GetMean()))
print("Total: " + str(clock.GetTotal()))

clock.Start()
LongFunction()

clock.Stop()
print('Mean: ' + str(clock.GetMean()))
print('Total: ' + str(clock.GetTotal()))
print("Mean: " + str(clock.GetMean()))
print("Total: " + str(clock.GetTotal()))

clock.Report()
2 changes: 1 addition & 1 deletion src/Core/Common/CreateAnImage/Code.py
Expand Up @@ -17,7 +17,7 @@
import itk

Dimension = 3
PixelType = itk.ctype('unsigned char')
PixelType = itk.ctype("unsigned char")
ImageType = itk.Image[PixelType, Dimension]

image = ImageType.New()
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateAnImageOfVectors/Code.py
Expand Up @@ -17,7 +17,7 @@
import itk

Dimension = 3
ComponentType = itk.ctype('float')
ComponentType = itk.ctype("float")
PixelType = itk.Vector[ComponentType, Dimension]
ImageType = itk.Image[PixelType, Dimension]

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/CreateAnRGBImage/Code.py
Expand Up @@ -17,6 +17,6 @@
import itk

Dimension = 2
RGBPixelType = itk.RGBPixel[itk.ctype('unsigned char')]
RGBPixelType = itk.RGBPixel[itk.ctype("unsigned char")]

image = itk.Image[RGBPixelType, Dimension].New()
6 changes: 5 additions & 1 deletion src/Core/Common/CreateDerivativeKernel/Code.py
Expand Up @@ -27,4 +27,8 @@
print(derivativeOperator)

for i in range(9):
print(str(derivativeOperator.GetOffset(i)) + " " + str(derivativeOperator.GetElement(i)))
print(
str(derivativeOperator.GetOffset(i))
+ " "
+ str(derivativeOperator.GetElement(i))
)
10 changes: 8 additions & 2 deletions src/Core/Common/CreateForwardDifferenceKernel/Code.py
Expand Up @@ -17,7 +17,9 @@
import itk

forwardDifferenceOperator = itk.ForwardDifferenceOperator[itk.F, 2]()
forwardDifferenceOperator.SetDirection(0) # Create the operator for the X axis derivative
forwardDifferenceOperator.SetDirection(
0
) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
forwardDifferenceOperator.CreateToRadius(radius)
Expand All @@ -27,4 +29,8 @@
print(forwardDifferenceOperator)

for i in range(9):
print(str(forwardDifferenceOperator.GetOffset(i)) + " " + str(forwardDifferenceOperator.GetElement(i)))
print(
str(forwardDifferenceOperator.GetOffset(i))
+ " "
+ str(forwardDifferenceOperator.GetElement(i))
)
10 changes: 8 additions & 2 deletions src/Core/Common/CreateGaussianDerivativeKernel/Code.py
Expand Up @@ -17,7 +17,9 @@
import itk

gaussianDerivativeOperator = itk.GaussianDerivativeOperator[itk.F, 2]()
gaussianDerivativeOperator.SetDirection(0) # Create the operator for the X axis derivative
gaussianDerivativeOperator.SetDirection(
0
) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
gaussianDerivativeOperator.CreateToRadius(radius)
Expand All @@ -27,4 +29,8 @@
print(gaussianDerivativeOperator)

for i in range(9):
print(str(gaussianDerivativeOperator.GetOffset(i)) + " " + str(gaussianDerivativeOperator.GetElement(i)))
print(
str(gaussianDerivativeOperator.GetOffset(i))
+ " "
+ str(gaussianDerivativeOperator.GetElement(i))
)
4 changes: 3 additions & 1 deletion src/Core/Common/CreateGaussianKernel/Code.py
Expand Up @@ -27,4 +27,6 @@
print(gaussianOperator)

for i in range(9):
print(str(gaussianOperator.GetOffset(i)) + " " + str(gaussianOperator.GetElement(i)))
print(
str(gaussianOperator.GetOffset(i)) + " " + str(gaussianOperator.GetElement(i))
)
4 changes: 3 additions & 1 deletion src/Core/Common/CreateLaplacianKernel/Code.py
Expand Up @@ -26,4 +26,6 @@
print(laplacianOperator)

for i in range(laplacianOperator.GetSize()[0] * laplacianOperator.GetSize()[1]):
print(str(laplacianOperator.GetOffset(i)) + " " + str(laplacianOperator.GetElement(i)))
print(
str(laplacianOperator.GetOffset(i)) + " " + str(laplacianOperator.GetElement(i))
)
2 changes: 1 addition & 1 deletion src/Core/Common/GetImageSize/Code.py
Expand Up @@ -19,7 +19,7 @@
import itk

if len(sys.argv) != 2:
print('Usage: ' + sys.argv[0] + ' <inputImageFile>')
print("Usage: " + sys.argv[0] + " <inputImageFile>")
sys.exit(1)

inputImageFile = sys.argv[1]
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Common/ObserveAnEvent/Code.py
Expand Up @@ -31,7 +31,8 @@


def myCommand():
print('Progress: ' + str(source.GetProgress()))
print("Progress: " + str(source.GetProgress()))


source.AddObserver(itk.ProgressEvent(), myCommand)

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Common/ReadWriteVectorImage/Code.py
Expand Up @@ -18,7 +18,7 @@
import itk

if len(sys.argv) != 3:
print('Usage: ' + sys.argv[0] + ' <InputFileName> <OutputFileName>')
print("Usage: " + sys.argv[0] + " <InputFileName> <OutputFileName>")
sys.exit(1)

VectorDimension = 4
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Common/SetDefaultNumberOfThreads/Code.py
Expand Up @@ -17,8 +17,8 @@
import argparse
import itk

parser = argparse.ArgumentParser(description='Set the Default Number Of Threads.')
parser.add_argument('number_of_threads', type=int)
parser = argparse.ArgumentParser(description="Set the Default Number Of Threads.")
parser.add_argument("number_of_threads", type=int)
args = parser.parse_args()

# Create a MultiThreaderBase instance to get access to its static methods
Expand All @@ -30,4 +30,4 @@

print("Filter's default number of threads: {}".format(filter_default_threads))

assert(filter_default_threads == args.number_of_threads)
assert filter_default_threads == args.number_of_threads
2 changes: 1 addition & 1 deletion src/Core/Common/SetPixelValueInOneImage/Code.py
Expand Up @@ -18,7 +18,7 @@
import itk

if len(sys.argv) != 2:
print('Usage: ' + sys.argv[0] + ' <OutputFileName>')
print("Usage: " + sys.argv[0] + " <OutputFileName>")
sys.exit(1)

Dimension = 2
Expand Down
13 changes: 8 additions & 5 deletions src/Core/Common/StreamAPipeline/Code.py
Expand Up @@ -18,12 +18,13 @@
import itk

from distutils.version import StrictVersion as VS

if VS(itk.Version.GetITKVersion()) < VS("4.10.0"):
print("ITK 4.10.0 is required.")
sys.exit(1)

if len(sys.argv) != 2:
print('Usage: ' + sys.argv[0] + ' <NumberOfSplits>')
print("Usage: " + sys.argv[0] + " <NumberOfSplits>")
sys.exit(1)
numberOfSplits = int(sys.argv[1])

Expand All @@ -45,12 +46,14 @@

streamingFilter.Update()

print('The output LargestPossibleRegion is: ' +
str(streamingFilter.GetOutput().GetLargestPossibleRegion()))
print(
"The output LargestPossibleRegion is: "
+ str(streamingFilter.GetOutput().GetLargestPossibleRegion())
)

print('')
print("")

updatedRequestedRegions = monitorFilter.GetUpdatedRequestedRegions()
print("Updated ApplyAFilterOnlyToASpecifiedImageRegion's:")
for ii in range(len(updatedRequestedRegions)):
print(' ' + str(updatedRequestedRegions[ii]))
print(" " + str(updatedRequestedRegions[ii]))
12 changes: 6 additions & 6 deletions src/Core/Common/VectorDotProduct/Code.py
Expand Up @@ -27,14 +27,14 @@
VectorType = itk.Vector[CoordType, Dimension]

u = VectorType()
u[0] = -1.
u[1] = 1.
u[2] = -1.
u[0] = -1.0
u[1] = 1.0
u[2] = -1.0

v = VectorType()
v[0] = 1.
v[1] = 2.
v[2] = 3.
v[0] = 1.0
v[1] = 2.0
v[2] = 3.0

print("u: " + str(u))
print("v: " + str(v))
Expand Down
13 changes: 9 additions & 4 deletions src/Core/ImageFunction/ResampleSegmentedImage/Code.py
Expand Up @@ -18,7 +18,9 @@
import sys

if len(sys.argv) != 6:
print(f"Usage: {sys.argv[0]} input_image_file spacing_fraction sigma_fraction output_image_file_label_image_interpolator output_image_file_nearest_neighbor_interpolator")
print(
f"Usage: {sys.argv[0]} input_image_file spacing_fraction sigma_fraction output_image_file_label_image_interpolator output_image_file_nearest_neighbor_interpolator"
)
sys.exit(1)

input_image_file = sys.argv[1]
Expand All @@ -36,8 +38,9 @@
resize_filter.SetOutputSpacing(output_spacing)

input_size = itk.size(input_image)
output_size = [int(s * input_spacing[dim] / spacing_fraction) for dim, s in
enumerate(input_size)]
output_size = [
int(s * input_spacing[dim] / spacing_fraction) for dim, s in enumerate(input_size)
]
resize_filter.SetSize(output_size)

gaussian_interpolator = itk.LabelImageGaussianInterpolateImageFunction.New(input_image)
Expand All @@ -48,7 +51,9 @@

itk.imwrite(resize_filter, output_image_file_label_image_interpolator)

nearest_neighbor_interpolator = itk.NearestNeighborInterpolateImageFunction.New(input_image)
nearest_neighbor_interpolator = itk.NearestNeighborInterpolateImageFunction.New(
input_image
)
resize_filter.SetInterpolator(nearest_neighbor_interpolator)

itk.imwrite(resize_filter, output_image_file_nearest_neighbor_interpolator)
Expand Up @@ -18,8 +18,10 @@
import itk

if len(sys.argv) != 6:
print("Usage: " + sys.argv[0] + " <inputImage> <outputImage> "
"<numberOfIterations> <timeStep> <conductance>")
print(
"Usage: " + sys.argv[0] + " <inputImage> <outputImage> "
"<numberOfIterations> <timeStep> <conductance>"
)
sys.exit(1)

inputImage = sys.argv[1]
Expand All @@ -40,16 +42,16 @@
reader.SetFileName(inputImage)

FilterType = itk.CurvatureAnisotropicDiffusionImageFilter[
InputImageType, InputImageType]
InputImageType, InputImageType
]
curvatureAnisotropicDiffusionFilter = FilterType.New()

curvatureAnisotropicDiffusionFilter.SetInput(reader.GetOutput())
curvatureAnisotropicDiffusionFilter.SetNumberOfIterations(numberOfIterations)
curvatureAnisotropicDiffusionFilter.SetTimeStep(timeStep)
curvatureAnisotropicDiffusionFilter.SetConductanceParameter(conductance)

RescaleFilterType = itk.RescaleIntensityImageFilter[
InputImageType, OutputImageType]
RescaleFilterType = itk.RescaleIntensityImageFilter[InputImageType, OutputImageType]
rescaler = RescaleFilterType.New()
rescaler.SetInput(curvatureAnisotropicDiffusionFilter.GetOutput())

Expand Down

0 comments on commit 05bd86a

Please sign in to comment.