Commit 168244d1 authored by Dan Baston's avatar Dan Baston

Merge branch 'master' into forecast-cron

parents 50e416af c454335b
Pipeline #72268547 passed with stages
in 17 minutes and 57 seconds
# Copyright (c) 2019 ISciences, LLC.
# All rights reserved.
# WSIM is licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from wsim_workflow.config_base import ConfigBase
from wsim_workflow.paths import DefaultWorkspace, Static
from wsim_workflow.monthly import monthly_observed
from wsim_workflow.workflow import get_meta_steps
class BasicConfig(ConfigBase):
def historical_years(self):
return range(1948, 2018) # 1948-2017
def result_fit_years(self):
return range(1950, 2010) # 1950-2009
def observed_data(self):
def static_data(self):
return Static('fake')
def workspace(self):
return DefaultWorkspace('tmp')
class TestMonthly(unittest.TestCase):
def setUpClass(cls):
cls.cfg = BasicConfig()
def assertProduced(self, target, steps):
self.assertTrue(any(target in step.targets for step in steps))
def assertNotProduced(self, target, steps):
self.assertTrue(not any(target in step.targets for step in steps))
def test_monthly_observed(self):
meta_steps = get_meta_steps()
ws = self.cfg.workspace()
steps = monthly_observed(config=self.cfg, yearmon='194801', meta_steps=meta_steps)
self.assertProduced(ws.composite_summary(yearmon='194801', window=1), steps)
self.assertNotProduced(ws.composite_summary(yearmon='194801', window=3), steps)
steps = monthly_observed(config=self.cfg, yearmon='194802', meta_steps=meta_steps)
self.assertProduced(ws.composite_summary(yearmon='194802', window=1), steps)
self.assertNotProduced(ws.composite_summary(yearmon='194802', window=3), steps)
steps = monthly_observed(config=self.cfg, yearmon='194803', meta_steps=meta_steps)
self.assertProduced(ws.composite_summary(yearmon='194803', window=1), steps)
self.assertProduced(ws.composite_summary(yearmon='194803', window=3), steps)
self.assertNotProduced(ws.composite_summary(yearmon='194803', window=6), steps)
......@@ -69,7 +69,7 @@ def monthly_observed(config: Config, yearmon: str, meta_steps: Dict[str, Step])
for window in [1] + config.integration_windows():
# Don't write composite steps for a window that extends back too early.
if yearmon > config.historical_yearmons()[window-1]:
if yearmon >= config.historical_yearmons()[window-1]:
composite_indicator_steps = composite_indicators(config.workspace(), window=window, yearmon=yearmon)
steps += composite_indicator_steps
#!/usr/bin/env python3
# Copyright (c) 2018 ISciences, LLC.
# Copyright (c) 2018-2019 ISciences, LLC.
# All rights reserved.
# WSIM is licensed under the Apache License, Version 2.0 (the "License").
......@@ -40,6 +40,21 @@ def find_duplicate_targets(steps: List[Step]) -> List[Step]:
return sorted(list(duplicates))
def get_meta_steps():
return {name: Step.create_meta(name) for name in (
def generate_steps(config: ConfigBase, *,
start: str,
stop: str,
......@@ -52,18 +67,7 @@ def generate_steps(config: ConfigBase, *,
steps += config.global_prep()
meta_steps = {name: Step.create_meta(name) for name in (
meta_steps = get_meta_steps()
if config.should_run_spinup() and not no_spinup:
steps += spinup.spinup(config, meta_steps)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment