58 alsoInitNonEditableFields=False ):
59 context = Base.getTestCaseContext()
60 ASSERT_TRUE( context.hasModule( targetModuleName ),
61 msg=
"Target module {} not found!".format( targetModuleName ), logOnSuccess=
False )
62 if templateModuleName
is None:
63 templateModuleName =
"{}_ParameterTemplate".format( targetModuleName )
65 def ___applyTemplateParameters():
66 ASSERT_TRUE( context.hasModule( templateModuleName ),
67 msg=
"Template module {} not found!".format( templateModuleName ), logOnSuccess=
False )
68 for f
in context.module( templateModuleName ).parameterFields():
69 if f.name !=
"instanceName" and f.type !=
"Trigger" and ( alsoInitNonEditableFields
or f.isEditable() ):
70 value = f.vectorValue()
if "vec" in f.type.lower()
else f.value
71 context.field(
"{}.{}".format( targetModuleName, f.name ) ).updateValue( value )
73 def ___applyOverrideParameters():
74 targetModule = context.module( targetModuleName )
75 for fieldName, fieldValue
in fieldValueOverrides.items():
76 ASSERT_TRUE( targetModule.hasField( fieldName ),
77 msg =
"Invalid field value override: Field {} does not exist.".format( fieldName ), logOnSuccess=
False )
78 targetModule.field( fieldName ).updateValue( fieldValue )
80 ___applyTemplateParameters()
81 if fieldValueOverrides:
82 ___applyOverrideParameters()
149 """Returns a NumPy data type object used with the image."""
151 if MLAB.ML.MLIsStandardType(imageField.image().dataType()):
152 return type(imageField.image().getTile((0, 0, 0), (1, 1, 1))[0][0][0])
156 td = context.addModule(MLAB.moduleLiteral(
"TypeDecomposer64"))
158 raise Exception(
"Use parameter \"context = ctx\" with \"getNumpyType()\" because the image uses an adv. data type!")
159 td.field(
"input0").connectFrom(imageField)
160 npType = type(td.field(
"output0").image().getTile((0, 0, 0), (1, 1, 1))[0][0][0])
247def getImage3D(imageField, imageStart = (0, 0, 0), imageSize =
None, context =
None):
250 imageSize = imageField.size3D()
255 td = context.addModule(MLAB.moduleLiteral(
"TypeDecomposer64"))
257 raise Exception(
"Use parameter \"context = ctx\" with \"getImage3D()\" because the image uses an adv. data type!")
259 td.field(
"input0").connectFrom(imageField)
260 for comp
in range(numComp):
261 image.append(td.field(
"output{0}".format(comp)).image().getTile(imageStart, imageSize))
265 image.append(imageField.image().getTile(imageStart, imageSize))
274def getImage6D(imageField, imageStart = (0, 0, 0, 0, 0, 0), imageSize =
None, context =
None):
277 imageSize = imageField.size6D()
282 td = context.addModule(MLAB.moduleLiteral(
"TypeDecomposer64"))
284 raise Exception(
"Use parameter \"context = ctx\" with \"getImage6D()\" because the image uses an adv. data type!")
286 td.field(
"input0").connectFrom(imageField)
287 for comp
in range(numComp):
288 image.append(td.field(
"output{0}".format(comp)).image().getTile(imageStart, imageSize))
292 image.append(imageField.image().getTile(imageStart, imageSize))
305 numComp = len(expectedImage)
306 expectedSize = [len(expectedImage[0][0][0]),
307 len(expectedImage[0][0]),
308 len(expectedImage[0])]
311 expectedImage = [expectedImage]
312 expectedSize = [len(expectedImage[0][0][0]),
313 len(expectedImage[0][0]),
314 len(expectedImage[0])]
317 resultSize = [len(resultImage[0][0][0]),
318 len(resultImage[0][0]),
321 resultImage = [resultImage]
322 resultSize = [len(resultImage[0][0][0]),
323 len(resultImage[0][0]),
326 if resultSize != expectedSize:
327 ERROR(
"Image compare failed: expected and output image are not not of the same size >> " \
328 +
"result {0} != expected {1}".format(resultSize, expectedSize))
331 elif numComp != len(resultImage):
332 ERROR(
"Image compare failed: expected and output image have different number of data type components >> " \
333 +
"result {0} != expected {1}".format(numComp, len(resultImage)))
336 if not numpy.allclose(expectedImage, resultImage, 0, EPSILON)
or LOGONSUCCESS:
337 for z
in range(resultSize[2]):
338 for y
in range(resultSize[1]):
339 for x
in range(resultSize[0]):
340 for comp
in range(numComp):
342 finiteExp = numpy.isfinite(expectedImage[comp][z][y][x])
343 finiteOut = numpy.isfinite(resultImage[comp][z][y][x])
345 if finiteExp != finiteOut \
346 or (finiteExp, finiteOut) == (
True,
True) \
347 and abs(resultImage[comp][z][y][x] - expectedImage[comp][z][y][x]) > EPSILON:
349 ERROR(
"""Voxel ({0},{1},{2}) of Result and Expected image are not equal (Epsilon = {3}):
350 >> {4} == {5} : False""".format(x, y, z, EPSILON, \
351 [resultImage[comp][z][y][x]
for comp
in range(numComp)], \
352 [expectedImage[comp][z][y][x]
for comp
in range(numComp)]))
357 elif LOGVOXEL
and LOGONSUCCESS
and comp == numComp-1:
358 INFO(
"""Voxel ({0},{1},{2}) of Result and Expected image are equal (Epsilon = {3}):
359 >> {4} == {5} : True""".format(x, y, z, EPSILON, \
360 [resultImage[comp][z][y][x]
for comp
in range(numComp)], \
361 [expectedImage[comp][z][y][x]
for comp
in range(numComp)]))
364 INFO(
"Image compare passed: expected and out image are equal")
366 ERROR(
"Image compare failed: expected and output image are not equal >> " \
367 +
"{0} of {1} voxels are different".format(numErrors, resultSize[0] * resultSize[1] * resultSize[2]))
380 numComp = len(expectedImage)
381 expectedSize = [len(expectedImage[0][0][0][0][0][0]),
382 len(expectedImage[0][0][0][0][0]),
383 len(expectedImage[0][0][0][0]),
384 len(expectedImage[0][0][0]),
385 len(expectedImage[0][0]),
386 len(expectedImage[0])]
389 expectedImage = [expectedImage]
390 expectedSize = [len(expectedImage[0][0][0][0][0][0]),
391 len(expectedImage[0][0][0][0][0]),
392 len(expectedImage[0][0][0][0]),
393 len(expectedImage[0][0][0]),
394 len(expectedImage[0][0]),
395 len(expectedImage[0])]
398 resultSize = [len(resultImage[0][0][0][0][0][0]),
399 len(resultImage[0][0][0][0][0]),
400 len(resultImage[0][0][0][0]),
401 len(resultImage[0][0][0]),
402 len(resultImage[0][0]),
406 resultImage = [resultImage]
407 resultSize = [len(resultImage[0][0][0][0][0][0]),
408 len(resultImage[0][0][0][0][0]),
409 len(resultImage[0][0][0][0]),
410 len(resultImage[0][0][0]),
411 len(resultImage[0][0]),
414 if resultSize != expectedSize:
415 ERROR(
"Image compare failed: expected and output image are not not of the same size >> " \
416 +
"result {0} != expected {1}".format(resultSize, expectedSize))
419 elif numComp != len(resultImage):
420 ERROR(
"Image compare failed: expected and output image have different number of data type components >> " \
421 +
"result {0} != expected {1}".format(numComp, len(resultImage)))
424 if not numpy.allclose(expectedImage, resultImage, 0, EPSILON)
or LOGONSUCCESS:
425 for u
in range(resultSize[5]):
426 for t
in range(resultSize[4]):
427 for c
in range(resultSize[3]):
428 for z
in range(resultSize[2]):
429 for y
in range(resultSize[1]):
430 for x
in range(resultSize[0]):
431 for comp
in range(numComp):
433 finiteExp = numpy.isfinite(expectedImage[comp][u][t][c][z][y][x])
434 finiteOut = numpy.isfinite(resultImage[comp][u][t][c][z][y][x])
436 if finiteExp != finiteOut \
437 or (finiteExp, finiteOut) == (
True,
True) \
438 and abs(resultImage[comp][u][t][c][z][y][x] - expectedImage[comp][u][t][c][z][y][x]) > EPSILON:
440 ERROR(
"""Voxel ({0},{1},{2},{3},{4},{5}) of Result and Expected image are not equal (Epsilon = {6}):
441 >> {7} == {8} : False""".format(x, y, z, c, t, u, EPSILON, \
442 [resultImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)], \
443 [expectedImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)]))
448 elif LOGVOXEL
and LOGONSUCCESS
and comp == numComp-1:
449 INFO(
"""Voxel ({0},{1},{2},{3},{4},{5}) of Result and Expected image are equal (Epsilon = {6}):
450 >> {7} == {8} : True""".format(x, y, z, c, t, u, EPSILON, \
451 [resultImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)], \
452 [expectedImage[comp][u][t][c][z][y][x]
for comp
in range(numComp)]))
455 INFO(
"Image compare passed: expected and out image are equal")
457 ERROR(
"Image compare failed: expected and output image are not equal >> " \
458 +
"{0} of {1} voxels are different".format(numErrors, resultSize[0] * resultSize[1] * resultSize[2] * resultSize[3] * resultSize[4] * resultSize[5]))