Commit cba576ea authored by Cynthia Crowley's avatar Cynthia Crowley

Adapt time_integrate() to deal with forcing variables by passing boolean arg forcing

parent a5354009
......@@ -137,6 +137,7 @@ def run_lsm(workspace: DefaultWorkspace, static: Static, *,
def time_integrate(workspace: DefaultWorkspace,
integrated_stats: Dict[str, List[str]],
forcing: bool,
*,
yearmon: str,
target: Optional[str]=None,
......@@ -154,23 +155,34 @@ def time_integrate(workspace: DefaultWorkspace,
window_observed = months
window_forecast = []
prev_results = [workspace.results(yearmon=x, window=1, basis=basis) for x in window_observed] + \
[workspace.forcing(yearmon=x, window=1) for x in window_observed] + \
[workspace.results(yearmon=yearmon, member=member, target=x, window=1, basis=basis)
for x in window_forecast] + \
[workspace.forcing(yearmon=yearmon, member=member, target=x, window=1) for x in window_forecast]
prev = [workspace.forcing(yearmon=x, window=1) for x in window_observed] + \
[workspace.forcing(yearmon=yearmon,
member=member,
target=x,
window=1) for x in window_forecast] if forcing else [workspace.results(yearmon=x,
window=1,
basis=basis) for x in window_observed] + \
[workspace.results(yearmon=yearmon,
member=member,
target=x,
window=1,
basis=basis) for x in window_forecast]
return [
wsim_integrate(
inputs=[read_vars(f, *set(itertools.chain(*integrated_stats.values()))) for f in prev_results],
inputs=[read_vars(f, *set(itertools.chain(*integrated_stats.values()))) for f in prev],
stats=[stat + '::' + ','.join(varname) for stat, varname in integrated_stats.items()],
attrs=[attrs.integration_window(var='*', months=window)],
output=workspace.results(yearmon=yearmon,
output= workspace.results(yearmon=yearmon,
window=window,
target=target,
member=member,
temporary=False,
basis=basis)
basis=basis) if not forcing else workspace.forcing(yearmon=yearmon,
window=window,
member=member,
target=target)
)
]
......
......@@ -134,6 +134,7 @@ def monthly_observed(config: ConfigBase, yearmon: str, meta_steps: Mapping[str,
config.lsm_integrated_stats(basis=Basis.BASIN),
yearmon=yearmon,
window=window,
forcing=False,
basis=Basis.BASIN)
if yearmon not in config.result_fit_yearmons():
......@@ -185,7 +186,8 @@ def monthly_forecast(config: ConfigBase, yearmon: str, meta_steps: Mapping[str,
target=target,
member=member,
window=window,
basis=Basis.BASIN)
basis=Basis.BASIN,
forcing=False)
steps += compute_basin_loss_factors(config.workspace(), yearmon=yearmon, target=target, member=member)
steps += compute_plant_losses(config.workspace(), yearmon=yearmon, target=target, member=member)
......
......@@ -55,7 +55,8 @@ def monthly_observed(config: Config, yearmon: str, meta_steps: Dict[str, Step])
# Do time integration
for window in config.integration_windows():
steps += time_integrate(config.workspace(), config.all_integrated_stats(), yearmon=yearmon, window=window)
steps += time_integrate(config.workspace(), config.lsm_integrated_stats(), forcing = False, yearmon=yearmon, window=window)
steps += time_integrate(config.workspace(), config.forcing_integrated_stats(), forcing = True, yearmon=yearmon, window=window)
# Compute return periods
for window in [1] + config.integration_windows():
......@@ -140,9 +141,11 @@ def monthly_forecast(config: Config,
for window in config.integration_windows():
# Time integrate the results
steps += time_integrate(config.workspace(), config.lsm_integrated_stats(),
window=window, yearmon=yearmon, target=target,
member=member)
# steps += time_integrate(config.workspace(), config.lsm_integrated_stats(),
# window=window, yearmon=yearmon, target=target,
# member=member)
steps += time_integrate(config.workspace(), config.lsm_integrated_stats(), forcing = False, yearmon=yearmon, window=window, member=member, target=target)
steps += time_integrate(config.workspace(), config.forcing_integrated_stats(), forcing = True, yearmon=yearmon, window=window, member=member, target=target)
# Compute return periods
for window in [1] + config.integration_windows():
......
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