oopnet.utils package

Subpackages

Submodules

oopnet.utils.oopnet_logging module

oopnet.utils.oopnet_logging.logging_decorator(logger)

Decorates a function to log exceptions.

Parameters:

logger (Logger) – logger to be used for logging

Returns:

decorated function

oopnet.utils.oopnet_logging.start_logger(level=20)

Initializes a RotatingFileHanlder and a StreamHandler for logging.

This function creates a logger with two handlers (RotatingFileHandler and StreamHandler) that can come in handy, if no other logging handlers are being used. The RotatingFileHandler writes it’s output to ‘oopnet.log’ and rotates the file when it reaches a size of 5 MB.

Parameters:

level (Union[int, str]) – logging level (e.g., logging.DEBUG)

Return type:

Logger

Returns:

logger object

oopnet.utils.timer module

oopnet.utils.timer.tic()

Start stopwatch timer.

oopnet.utils.timer.time_it(func)

Decorates a function to measure its execution time.

Parameters:

func – callable to time

Returns:

decorated function

oopnet.utils.timer.toc()

Read elapsed time from stopwatch.

oopnet.utils.utils module

oopnet.utils.utils.copy(network)

This function makes a deepcopy of an OOPNET network object

Parameters:

network – OOPNET network object

Returns:

deepcopy of OOPNET network object

oopnet.utils.utils.make_measurement(report, sensors, precision=None)

This function simulates a measurement in the system at predefined sensorpositions and returns a measurement vector

Parameters:
  • report (SimulationReport) – OOPNET report object

  • sensors (dict) – dict with keys ‘Flow’ and/or ‘Pressure’ containing the node- resp. linkids as list

-> {‘Flow’:[‘flowsensor1’, ‘flowsensor2], ‘Pressure’:[‘sensor1’, ‘sensor2’, ‘sensor3’]}

precision: dict with keys ‘Flow’ and/or ‘Pressure’ and number of decimals -> {‘Flow’:3, ‘Pressure’:2} report: SimulationReport: sensors: dict: precision: Optional[dict]: (Default value = None)

Returns:

numpy vector containing the measurements

oopnet.utils.utils.mkdir(newdir)

Creates a new directory.

  • already exists, silently complete

  • regular file in the way, raise an exception

  • parent directory(ies) does not exist, make them as well

Parameters:

newdir (str) – path to be created

Returns:

Module contents