58 targetModuleName, templateModuleName=None, fieldValueOverrides=None, alsoInitNonEditableFields=False
60 context = Base.getTestCaseContext()
62 context.hasModule(targetModuleName),
63 msg=
"Target module {} not found!".format(targetModuleName),
66 if templateModuleName
is None:
67 templateModuleName =
"{}_ParameterTemplate".format(targetModuleName)
70 def ___applyTemplateParameters():
72 context.hasModule(templateModuleName),
73 msg=
"Template module {} not found!".format(templateModuleName),
76 for f
in context.module(templateModuleName).parameterFields():
77 if f.name !=
"instanceName" and f.type !=
"Trigger" and (alsoInitNonEditableFields
or f.isEditable()):
78 value = f.vectorValue()
if "vec" in f.type.lower()
else f.value
79 context.field(
"{}.{}".format(targetModuleName, f.name)).updateValue(value)
82 def ___applyOverrideParameters():
83 targetModule = context.module(targetModuleName)
84 for fieldName, fieldValue
in fieldValueOverrides.items():
86 targetModule.hasField(fieldName),
87 msg=
"Invalid field value override: Field {} does not exist.".format(fieldName),
90 targetModule.field(fieldName).updateValue(fieldValue)
93 ___applyTemplateParameters()
94 if fieldValueOverrides:
95 ___applyOverrideParameters()
162 """Returns a NumPy data type object used with the image."""
164 if MLAB.ML.MLIsStandardType(imageField.image().dataType()):
165 return type(imageField.image().getTile((0, 0, 0), (1, 1, 1))[0][0][0])
169 td = context.addModule(MLAB.moduleLiteral(
"TypeDecomposer64"))
172 'Use parameter "context = ctx" with "getNumpyType()" because the image uses an adv. data type!'
174 td.field(
"input0").connectFrom(imageField)
175 npType = type(td.field(
"output0").image().getTile((0, 0, 0), (1, 1, 1))[0][0][0])
262def getImage3D(imageField, imageStart=(0, 0, 0), imageSize=
None, context=
None):
265 imageSize = imageField.size3D()
270 td = context.addModule(MLAB.moduleLiteral(
"TypeDecomposer64"))
273 'Use parameter "context = ctx" with "getImage3D()" because the image uses an adv. data type!'
276 td.field(
"input0").connectFrom(imageField)
277 for comp
in range(numComp):
278 image.append(td.field(
"output{0}".format(comp)).image().getTile(imageStart, imageSize))
282 image.append(imageField.image().getTile(imageStart, imageSize))
291def getImage6D(imageField, imageStart=(0, 0, 0, 0, 0, 0), imageSize=
None, context=
None):
294 imageSize = imageField.size6D()
299 td = context.addModule(MLAB.moduleLiteral(
"TypeDecomposer64"))
302 'Use parameter "context = ctx" with "getImage6D()" because the image uses an adv. data type!'
305 td.field(
"input0").connectFrom(imageField)
306 for comp
in range(numComp):
307 image.append(td.field(
"output{0}".format(comp)).image().getTile(imageStart, imageSize))
311 image.append(imageField.image().getTile(imageStart, imageSize))
324 numComp = len(expectedImage)
325 expectedSize = [len(expectedImage[0][0][0]), len(expectedImage[0][0]), len(expectedImage[0])]
328 expectedImage = [expectedImage]
329 expectedSize = [len(expectedImage[0][0][0]), len(expectedImage[0][0]), len(expectedImage[0])]
332 resultSize = [len(resultImage[0][0][0]), len(resultImage[0][0]), len(resultImage[0])]
334 resultImage = [resultImage]
335 resultSize = [len(resultImage[0][0][0]), len(resultImage[0][0]), len(resultImage[0])]
337 if resultSize != expectedSize:
339 "Image compare failed: expected and output image are not not of the same size >> "
340 +
"result {0} != expected {1}".format(resultSize, expectedSize)
344 elif numComp != len(resultImage):
346 "Image compare failed: expected and output image have different number of data type components >> "
347 +
"result {0} != expected {1}".format(numComp, len(resultImage))
351 if not numpy.allclose(expectedImage, resultImage, 0, EPSILON)
or LOGONSUCCESS:
352 for z
in range(resultSize[2]):
353 for y
in range(resultSize[1]):
354 for x
in range(resultSize[0]):
355 for comp
in range(numComp):
357 finiteExp = numpy.isfinite(expectedImage[comp][z][y][x])
358 finiteOut = numpy.isfinite(resultImage[comp][z][y][x])
361 finiteExp != finiteOut
362 or (finiteExp, finiteOut) == (
True,
True)
363 and abs(resultImage[comp][z][y][x] - expectedImage[comp][z][y][x]) > EPSILON
367 """Voxel ({0},{1},{2}) of Result and Expected image are not equal (Epsilon = {3}):
368 >> {4} == {5} : False""".format(
373 [resultImage[comp][z][y][x]
for comp
in range(numComp)],
374 [expectedImage[comp][z][y][x]
for comp
in range(numComp)],
381 elif LOGVOXEL
and LOGONSUCCESS
and comp == numComp - 1:
383 """Voxel ({0},{1},{2}) of Result and Expected image are equal (Epsilon = {3}):
384 >> {4} == {5} : True""".format(
389 [resultImage[comp][z][y][x]
for comp
in range(numComp)],
390 [expectedImage[comp][z][y][x]
for comp
in range(numComp)],
395 INFO(
"Image compare passed: expected and out image are equal")
398 "Image compare failed: expected and output image are not equal >> "
399 +
"{0} of {1} voxels are different".format(numErrors, resultSize[0] * resultSize[1] * resultSize[2])
413 numComp = len(expectedImage)
415 len(expectedImage[0][0][0][0][0][0]),
416 len(expectedImage[0][0][0][0][0]),
417 len(expectedImage[0][0][0][0]),
418 len(expectedImage[0][0][0]),
419 len(expectedImage[0][0]),
420 len(expectedImage[0]),
424 expectedImage = [expectedImage]
426 len(expectedImage[0][0][0][0][0][0]),
427 len(expectedImage[0][0][0][0][0]),
428 len(expectedImage[0][0][0][0]),
429 len(expectedImage[0][0][0]),
430 len(expectedImage[0][0]),
431 len(expectedImage[0]),
436 len(resultImage[0][0][0][0][0][0]),
437 len(resultImage[0][0][0][0][0]),
438 len(resultImage[0][0][0][0]),
439 len(resultImage[0][0][0]),
440 len(resultImage[0][0]),
445 resultImage = [resultImage]
447 len(resultImage[0][0][0][0][0][0]),
448 len(resultImage[0][0][0][0][0]),
449 len(resultImage[0][0][0][0]),
450 len(resultImage[0][0][0]),
451 len(resultImage[0][0]),
455 if resultSize != expectedSize:
457 "Image compare failed: expected and output image are not not of the same size >> "
458 +
"result {0} != expected {1}".format(resultSize, expectedSize)
462 elif numComp != len(resultImage):
464 "Image compare failed: expected and output image have different number of data type components >> "
465 +
"result {0} != expected {1}".format(numComp, len(resultImage))
469 if not numpy.allclose(expectedImage, resultImage, 0, EPSILON)
or LOGONSUCCESS:
470 for u
in range(resultSize[5]):
471 for t
in range(resultSize[4]):
472 for c
in range(resultSize[3]):
473 for z
in range(resultSize[2]):
474 for y
in range(resultSize[1]):
475 for x
in range(resultSize[0]):
476 for comp
in range(numComp):
478 finiteExp = numpy.isfinite(expectedImage[comp][u][t][c][z][y][x])
479 finiteOut = numpy.isfinite(resultImage[comp][u][t][c][z][y][x])
482 finiteExp != finiteOut
483 or (finiteExp, finiteOut) == (
True,
True)
485 resultImage[comp][u][t][c][z][y][x] - expectedImage[comp][u][t][c][z][y][x]
491 """Voxel ({0},{1},{2},{3},{4},{5}) of Result and Expected image are not equal (Epsilon = {6}):
492 >> {7} == {8} : False""".format(
500 [resultImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)],
501 [expectedImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)],
508 elif LOGVOXEL
and LOGONSUCCESS
and comp == numComp - 1:
510 """Voxel ({0},{1},{2},{3},{4},{5}) of Result and Expected image are equal (Epsilon = {6}):
511 >> {7} == {8} : True""".format(
519 [resultImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)],
520 [expectedImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)],
525 INFO(
"Image compare passed: expected and out image are equal")
528 "Image compare failed: expected and output image are not equal >> "
529 +
"{0} of {1} voxels are different".format(
530 numErrors, resultSize[0] * resultSize[1] * resultSize[2] * resultSize[3] * resultSize[4] * resultSize[5]
getImage6D(imageField, imageStart=(0, 0, 0, 0, 0, 0), imageSize=None, context=None)
Returns ML image output of given module in 6 dimensions.