From 195b3324402ff95796077ee8a03409eae6917ab4 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 26 Mar 2021 21:18:38 +0100 Subject: [PATCH] :wrench: Add default disturbance type to the disturber config --- simzoo/common/disturber.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/simzoo/common/disturber.py b/simzoo/common/disturber.py index 3c6a72e6..9ef94bef 100644 --- a/simzoo/common/disturber.py +++ b/simzoo/common/disturber.py @@ -36,6 +36,8 @@ def periodic_disturbance(time): # See https://rickstaa.github.io/bayesian-learning-control/control/robustness_eval.html # for more information. DISTURBER_CFG = { + # Disturbance type when no type has been given + "default_type": "step_disturbance", # Disturbance applied to environment variables "env_disturbance": { "description": "Lacl mRNA decay rate disturbance", @@ -580,6 +582,27 @@ def init_disturber( self._disturber_cfg = DISTURBER_CFG # Validate disturbance type and/or variant input arguments + if disturbance_type is None: + if "default_type" in self._disturber_cfg.keys(): + print( + colorize( + ( + "INFO: No disturbance type given default type '{}' ".format( + self._disturber_cfg["default_type"] + ) + + "used instead." + ), + "green", + bold=True, + ) + ) + disturbance_type = self._disturber_cfg["default_type"] + else: + raise TypeError( + "init_disturber(): is missing one required positional " + "argument: 'disturbance_type'.", + "disturbance_type", + ) disturbance_type = ( disturbance_type.lower() + "_disturbance" if "_disturbance" not in disturbance_type.lower() @@ -601,8 +624,8 @@ def init_disturber( print( colorize( ( - "INFO: No disturbance variant given default variant (" - + "{}) used instead.".format( + "INFO: No disturbance variant given default variant '" + + "{}' used instead.".format( self._disturber_cfg[disturbance_type][ "default_variant" ] @@ -621,7 +644,8 @@ def init_disturber( "argument: 'disturbance_variant'. This argument is required " f"for disturbance type {disturbance_type}. Please specify a " f"valid disturbance variant " - f"{list(self._disturber_cfg[disturbance_type].keys())}." + f"{list(self._disturber_cfg[disturbance_type].keys())}.", + "disturbance_variant", ) else: disturbance_variant = disturbance_variant.lower()