From 8566ea35a212b7f6b0a48d19b8de9e47831f5466 Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA <134300700+DavidNew-NOAA@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:23:52 -0400 Subject: [PATCH] Create task_config member variable upon initialization (#30) --- src/wxflow/task.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index ee8712b..80ef4a2 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -30,7 +30,7 @@ def __init__(self, config: Dict, *args, **kwargs): """ # Store the config and arguments as attributes of the object - self.config = AttrDict(config) + self._config = AttrDict(config) for arg in args: setattr(self, str(arg), arg) @@ -38,27 +38,21 @@ def __init__(self, config: Dict, *args, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) - # Pull out basic runtime keys values from config into its own runtime config - self.runtime_config = AttrDict() - runtime_keys = ['PDY', 'cyc', 'DATA', 'RUN', 'CDUMP'] # TODO: eliminate CDUMP and use RUN instead - for kk in runtime_keys: - try: - self.runtime_config[kk] = config[kk] - logger.debug(f'Deleting runtime_key {kk} from config') - del self.config[kk] - except KeyError: - raise KeyError(f"Encountered an unreferenced runtime_key {kk} in 'config'") + # Create task_config with everything that is inside _config and whatever the user chooses to + # extend it with when initializing a child subclass of Task. Only task_config should be referenced + # in any application, not _config. + self.task_config = self._config.copy() # Any other composite runtime variables that may be needed for the duration of the task # can be constructed here # Construct the current cycle datetime object - self.runtime_config['current_cycle'] = add_to_datetime(self.runtime_config['PDY'], to_timedelta(f"{self.runtime_config.cyc}H")) - logger.debug(f"current cycle: {self.runtime_config['current_cycle']}") + self.task_config['current_cycle'] = add_to_datetime(self._config['PDY'], to_timedelta(f"{self._config.cyc}H")) + logger.debug(f"current cycle: {self.task_config['current_cycle']}") # Construct the previous cycle datetime object - self.runtime_config['previous_cycle'] = add_to_datetime(self.runtime_config.current_cycle, -to_timedelta(f"{self.config['assim_freq']}H")) - logger.debug(f"previous cycle: {self.runtime_config['previous_cycle']}") + self.task_config['previous_cycle'] = add_to_datetime(self.task_config.current_cycle, -to_timedelta(f"{self._config['assim_freq']}H")) + logger.debug(f"previous cycle: {self.task_config['previous_cycle']}") pass