TestCenter Reference
TestSupport.HelperFunctions Namespace Reference

Functions

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

Variables

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

Function Documentation

◆ castToNumpy()

def 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 208 of file HelperFunctions.py.

Referenced by TestSupport.HelperFunctions.convertVoxelType().

◆ compareImages3D()

def 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 301 of file HelperFunctions.py.

References TestSupport.Macros.ERROR(), and TestSupport.Macros.INFO().

◆ compareImages6D()

def 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 376 of file HelperFunctions.py.

References TestSupport.Macros.ERROR(), and TestSupport.Macros.INFO().

◆ convertVoxelType()

def 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 229 of file HelperFunctions.py.

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

◆ generateTestDictionary()

def 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 38 of file HelperFunctions.py.

◆ getImage3D()

def 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 248 of file HelperFunctions.py.

References TestSupport.HelperFunctions.getNumComponentsFromImage().

◆ getImage6D()

def 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 275 of file HelperFunctions.py.

References TestSupport.HelperFunctions.getNumComponentsFromImage().

◆ getMinMax()

def 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 91 of file HelperFunctions.py.

◆ getNumComponentsFromImage()

def 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 117 of file HelperFunctions.py.

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

◆ getNumComponentsFromString()

def 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 126 of file HelperFunctions.py.

◆ getNumpyTypeFromImage()

def 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 149 of file HelperFunctions.py.

◆ getNumpyTypeFromString()

def 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 169 of file HelperFunctions.py.

Referenced by TestSupport.HelperFunctions.convertVoxelType().

◆ initModuleFromTemplate()

def 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 58 of file HelperFunctions.py.

References TestSupport.Macros.ASSERT_TRUE().

Variable Documentation

◆ EPSILON

float TestSupport.HelperFunctions.EPSILON = 0.0001

Definition at line 20 of file HelperFunctions.py.

◆ INTTYPES

dictionary 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 22 of file HelperFunctions.py.

◆ LOGONSUCCESS

bool TestSupport.HelperFunctions.LOGONSUCCESS = False

Definition at line 19 of file HelperFunctions.py.

◆ LOGVOXEL

bool TestSupport.HelperFunctions.LOGVOXEL = False

Definition at line 18 of file HelperFunctions.py.