TestCenter Reference
TestSupport.HelperFunctions Namespace Reference

Functions

 generateTestDictionary (function, testDictionaries)
 Concatenates test dictionaries and sets a function that needs to be tested in the final dictionary.
 
 initModuleFromTemplate (targetModuleName, templateModuleName=None, fieldValueOverrides=None, alsoInitNonEditableFields=False)
 Copies all values from a reference module's editable parameter fields to the target ('test') module.
 
 getMinMax (fv1, fv2=None)
 Determines max/min value of given fill value(s).
 
 getNumComponentsFromImage (imageField)
 Returns the number of components of an ML-image data type.
 
 getNumComponentsFromString (dataType)
 Returns the number of components of a data type given as string.
 
 getNumpyTypeFromImage (imageField, context=None)
 Returns the NumPy data type of an ML-Image.
 
 getNumpyTypeFromString (dataType)
 Returns the NumPy data type appropriate to a data type given as string.
 
 castToNumpy (value, numpyType)
 Casts a value to a NumPy type.
 
 convertVoxelType (voxel, oldType, newType)
 Converts a voxel to a new data type.
 
 getImage3D (imageField, imageStart=(0, 0, 0), imageSize=None, context=None)
 Returns ML image output of given module in 3 dimensions.
 
 getImage6D (imageField, imageStart=(0, 0, 0, 0, 0, 0), imageSize=None, context=None)
 Returns ML image output of given module in 6 dimensions.
 
 compareImages3D (resultImage, expectedImage)
 Compares voxels of a result image with an expected image in 3 dimensions.
 
 compareImages6D (resultImage, expectedImage)
 Compares voxels of a result image with an expected image in 6 dimensions.
 

Variables

bool LOGVOXEL = False
 
bool LOGONSUCCESS = False
 
float EPSILON = 0.0001
 
dict INTTYPES
 

Function Documentation

◆ castToNumpy()

TestSupport.HelperFunctions.castToNumpy ( value,
numpyType )

Casts a value to a NumPy type.

A special case is to cast an integer value to (u)int32 which is outside of the data type range. This is not possible with NumPy, so the value needs to be scaled manually before casted, what is the task of this function.

Parameters
valueThe value that needs to be casted.
numpyTypeThe NumPy data type.
Returns
: The casted value.
Returns the value casted to the given NumPy data type.

Definition at line 207 of file HelperFunctions.py.

Referenced by TestSupport.HelperFunctions.convertVoxelType().

◆ compareImages3D()

TestSupport.HelperFunctions.compareImages3D ( resultImage,
expectedImage )

Compares voxels of a result image with an expected image in 3 dimensions.

Parameters
resultImageThe output result for the image. Needs to be in the shape of [z][y][x] or [component][z][y][x] with adv. data types.
expectedImageThe expected result for the image. Needs to be in the shape of [z][y][x] or [component][z][y][x] with adv. data types.
Returns
: A boolean of the comparison result.

Definition at line 300 of file HelperFunctions.py.

◆ compareImages6D()

TestSupport.HelperFunctions.compareImages6D ( resultImage,
expectedImage )

Compares voxels of a result image with an expected image in 6 dimensions.

Parameters
resultImageThe output result for the image. Needs to be in the shape of [u][t][c][z][y][x] or [component][u][t][c][z][y][x] with adv. data types.
expectedImageThe expected result for the image. Needs to be in the shape of [u][t][c][z][y][x] or [component][u][t][c][z][y][x] with adv. data types.
Returns
: A boolean of the comparison result.

Definition at line 375 of file HelperFunctions.py.

◆ convertVoxelType()

TestSupport.HelperFunctions.convertVoxelType ( voxel,
oldType,
newType )

Converts a voxel to a new data type.

Parameters
voxelThe voxel value(s).
oldTypeName of the old data type.
newTypeName of the new data type.
Returns
: The new voxel value(s).
Coverts fill values of any input data type to std output data type.

Definition at line 228 of file HelperFunctions.py.

References TestSupport.HelperFunctions.castToNumpy(), and TestSupport.HelperFunctions.getNumpyTypeFromString().

◆ generateTestDictionary()

TestSupport.HelperFunctions.generateTestDictionary ( function,
testDictionaries )

Concatenates test dictionaries and sets a function that needs to be tested in the final dictionary.

Parameters
functionA string of the function that needs to be tested.
testDictionariesThe test dictionaries that shall be concatenate. Value of a dictionary needs to be a list or tuple with first element an temp value.
Returns
: The test dictionary.

Definition at line 37 of file HelperFunctions.py.

◆ getImage3D()

TestSupport.HelperFunctions.getImage3D ( imageField,
imageStart = (0, 0, 0),
imageSize = None,
context = None )

Returns ML image output of given module in 3 dimensions.

Parameters
imageFieldThe Module image field. A MLABField* object is needed.
imageStartUsed if image start position is not default.
contextParameter "context = ctx" needed if adv. data types are used.
Returns
: The image in shape [component][z][y][x].

Definition at line 247 of file HelperFunctions.py.

References TestSupport.HelperFunctions.getNumComponentsFromImage().

◆ getImage6D()

TestSupport.HelperFunctions.getImage6D ( imageField,
imageStart = (0, 0, 0, 0, 0, 0),
imageSize = None,
context = None )

Returns ML image output of given module in 6 dimensions.

Parameters
imageFieldThe Module image field. A MLABField* object is needed.
imageStartUsed if image start position is not default.
contextParameter "context = ctx" needed if adv. data types are used.
Returns
: The image in shape [component][u][t][c][z][y][x].

Definition at line 274 of file HelperFunctions.py.

References TestSupport.HelperFunctions.getNumComponentsFromImage().

◆ getMinMax()

TestSupport.HelperFunctions.getMinMax ( fv1,
fv2 = None )

Determines max/min value of given fill value(s).

Implemented especially for adv. data type with several value components.

Parameters
fv1A fill/voxel value. Can be a string or list.
fv2An optional second fill/voxel value. Can be a string or list.
Returns
: The min and max value returned as (min, max).
Determines max/min value of given fill value(s).

Definition at line 90 of file HelperFunctions.py.

◆ getNumComponentsFromImage()

TestSupport.HelperFunctions.getNumComponentsFromImage ( imageField)

Returns the number of components of an ML-image data type.

Parameters
imageFieldThe Module image field. A MLABField* object is needed.
Returns
: Number of components of the data type.
Returns the number of components of the image data type.

Definition at line 116 of file HelperFunctions.py.

Referenced by TestSupport.HelperFunctions.getImage3D(), and TestSupport.HelperFunctions.getImage6D().

◆ getNumComponentsFromString()

TestSupport.HelperFunctions.getNumComponentsFromString ( dataType)

Returns the number of components of a data type given as string.

Parameters
dataTypeName of the data type.
Returns
: Number of components of the data type.

Definition at line 125 of file HelperFunctions.py.

◆ getNumpyTypeFromImage()

TestSupport.HelperFunctions.getNumpyTypeFromImage ( imageField,
context = None )

Returns the NumPy data type of an ML-Image.

Parameters
imageFieldThe Module image field. A MLABField* object is needed.
contextParameter "context = ctx" needed if adv. data types are used.
Returns
: The NumPy type.
Returns a NumPy data type object used with the image.

Definition at line 148 of file HelperFunctions.py.

◆ getNumpyTypeFromString()

TestSupport.HelperFunctions.getNumpyTypeFromString ( dataType)

Returns the NumPy data type appropriate to a data type given as string.

Parameters
mlTypeName of the data type.
Returns
: The NumPy type.

Definition at line 168 of file HelperFunctions.py.

Referenced by TestSupport.HelperFunctions.convertVoxelType().

◆ initModuleFromTemplate()

TestSupport.HelperFunctions.initModuleFromTemplate ( targetModuleName,
templateModuleName = None,
fieldValueOverrides = None,
alsoInitNonEditableFields = False )

Copies all values from a reference module's editable parameter fields to the target ('test') module.

Helpful to reset the test module before running a test function to a fixed, documented state that does not depend on the module's default parameterization (which may change over time).

Parameters
targetModuleNameName of the target module of the assignment
templateModuleNameName of the source module ("template module") of the assignment. If omitted, <targetModuleName>_ParameterTemplate is assumed.
fieldValueOverridesIf selected field shall differ from the template, specify these as a dictionary (use an ordered one, if order matters)
alsoInitNonEditableFieldsIf enabled, also non-editable fields will be overwritten with the template module value

Definition at line 57 of file HelperFunctions.py.

Variable Documentation

◆ EPSILON

float TestSupport.HelperFunctions.EPSILON = 0.0001

Definition at line 19 of file HelperFunctions.py.

◆ INTTYPES

dict TestSupport.HelperFunctions.INTTYPES
Initial value:
1= {
2 "int8": (-128,127),
3 "int16": (-32768,32767),
4 "int32": (-2147483648,2147483647),
5 "int64": (-9223372036854775808,9223372036854775807),
6 "uint8": (0,255),
7 "uint16": (0,65535),
8 "uint32": (0,4294967295),
9 "uint64": (0,18446744073709551615)
10}

Definition at line 21 of file HelperFunctions.py.

◆ LOGONSUCCESS

bool TestSupport.HelperFunctions.LOGONSUCCESS = False

Definition at line 18 of file HelperFunctions.py.

◆ LOGVOXEL

bool TestSupport.HelperFunctions.LOGVOXEL = False

Definition at line 17 of file HelperFunctions.py.