ClearMap.Utils package

This sub-package provides utility functions used throughout the package

ClearMap.Utils.ParameterTools module

ParameterTools

Provides simple formatting tools to handle / print parameter dictionaries organized as key:value pairs.

getParameter(parameter, key, default=None)[source]

Gets a parameter from a dict, returns default value if not defined

Parameters:
  • parameter (dict) – parameter dictionary
  • key (object) – key
  • default (object) – deault return value if parameter not defined
Returns:

object – parameter value for key

writeParameter(head=None, out=None, **args)[source]

Writes parameter settings in a formatted way

Parameters:
  • head (str or None) – prefix of each line
  • out (object or None) – write to a specific output, if None return string
  • **args – the parameter values as key=value arguments
Returns:

str or None – a formated string with parameter info

joinParameter(*args)[source]

Joins dictionaries in a consitent way

For multiple occurences of a key the value is defined by the first key : value pair.

Parameters:*args – list of parameter dictonaries
Returns:dict – the joined dictionary

ClearMap.Utils.ProcessWriter module

Provides simple formatting tools to print text with parallel process header

class ProcessWriter(process=0)[source]

Bases: object

Class to handle writing from parallel processes

process

int

the process number

writeString(text)[source]

Generate string with process prefix

Parameters:text (str) – the text input
Returns:str – text with [process prefix
write(text)[source]

Write string with process prefix to sys.stdout

Parameters:text (str) – the text input

ClearMap.Utils.Timer module

Provides tools for timing

class Timer(verbose=False)[source]

Bases: object

Class to stop time and print results in formatted way

time

float

the time since the timer was started

start()[source]

Start the timer

reset()[source]

Reset the timer

elapsedTime(head=None, asstring=True)[source]

Calculate elapsed time and return as formated string

Parameters:
  • head (str or None) – prefix to the string
  • asstring (bool) – return as string or float
Returns:

str or float – elapsed time

printElapsedTime(head=None)[source]

Print elapsed time as formated string

Parameters:head (str or None) – prefix to the string
formatElapsedTime(t)[source]

Format time to string

Parameters:t (float) – time in seconds prefix
Returns:str – time as hours:minutes:seconds