forked from ksemmendinger/loslr_regulation_optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
97 lines (65 loc) · 2.9 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
-------------------------------------------------------------------------------
this script contains a template for the `formatDecisionVariables`,
`getReleaseFunctionInputs`, and `releaseFunction` functions
-------------------------------------------------------------------------------
"""
"""
-------------------------------------------------------------------------------
# import libraries
import numpy as np
# import custom function for engineering rounding
import sys
sys.path.append(".")
from functions.utils import round_d
# format raw decision variables from optimization algorithm
def formatDecisionVariables(vars, **args):
# INPUTS
# vars: list of decision variable values returned from the Borg MOEA
# args: dict of optional release function inputs from config["releaseFunction"]
# OUTPUTS
# pars: dict with key value pairs of decision variable names and values
pars = dict()
pars["decisionVariable1"] = vars[0]
pars["decisionVariable2"] = vars[1]
return pars
# extracts timestep inputs for `releaseFunction`
def getReleaseFunctionInputs(data, t, **args):
# INPUTS
# data: dictionary of input time series from main simulation function
# keys are variable names and values are np.arrays of the time series of
# the variable values
# t: timestep from simulation for loop
# args: dict of optional release function inputs from config["releaseFunction"]
# OUTPUTS
# x: dictionary with named key value pairs of hydrologic inputs at the
# timestep of interest, calculated or formatted as needed
x = dict()
x["variable1"] = data["variable1"][t]
x["variable2"] = np.mean(data["variable2"][(t - 48) : (t)])
# code to extract, calculate, or format needed inputs for `releaseFunction`....
return x
# takes in output from formatDecisionVariables and getInputs, outputs release and flow regime
def releaseFunction(x, pars, **args):
# INPUTS
# x: dict that is output from `getReleaseFunctionInputs`
# pars: dict that is output from `formatDecisionVariables`
# args: dict of optional release function inputs from config["releaseFunction"]
# OUTPUTS
# dictionary with named key value pairs "ontFlow" and "ontRegime", "pprFlow", and "rfOutput"
# extract outputs from x
variable1 = x["variable1"]
variable2 = x["variable2"]
# extract decision variables from pars
decisionVariable1 = pars["decisionVariable1"]
decisionVariable2 = pars["decisionVariable2"]
# code for release function here....
# return all the relevant outputs to save in dataframe
outputs = dict()
outputs["rfFlow"] = ontFlow
outputs["rfRegime"] = ontRegime
outputs["pprFlow"] = preproj flow or np.nan
outputs["rfOutput"] = output from release function (could be the same as ontFlow)
return outputs
-------------------------------------------------------------------------------
"""