Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create task_config member variable upon initialization #30

Merged
merged 8 commits into from
Jun 7, 2024
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/wxflow/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,29 @@
"""

# Store the config and arguments as attributes of the object
self.config = AttrDict(config)
self._config = AttrDict(config)

Check warning on line 33 in src/wxflow/task.py

View check run for this annotation

Codecov / codecov/patch

src/wxflow/task.py#L33

Added line #L33 was not covered by tests

for arg in args:
setattr(self, str(arg), arg)

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()

Check warning on line 44 in src/wxflow/task.py

View check run for this annotation

Codecov / codecov/patch

src/wxflow/task.py#L44

Added line #L44 was not covered by tests

# 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.task_config['PDY'], to_timedelta(f"{self.task_config.cyc}H"))
aerorahul marked this conversation as resolved.
Show resolved Hide resolved
logger.debug(f"current cycle: {self.task_config['current_cycle']}")

Check warning on line 51 in src/wxflow/task.py

View check run for this annotation

Codecov / codecov/patch

src/wxflow/task.py#L50-L51

Added lines #L50 - L51 were not covered by tests

# 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']}")

Check warning on line 55 in src/wxflow/task.py

View check run for this annotation

Codecov / codecov/patch

src/wxflow/task.py#L54-L55

Added lines #L54 - L55 were not covered by tests

pass

Expand Down