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

Allow custom macro parameter #55

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 16 additions & 1 deletion src/Cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def get_input_specs(cls):
solving the dispatch.""")
time_discr.addSub(InputData.parameterInputFactory('time_variable', contentType=InputTypes.StringType,
descr=r"""name for the \texttt{time} variable used in this simulation. \default{time}"""))
time_discr.addSub(InputData.parameterInputFactory('year_variable', contentType=InputTypes.StringType,
descr=r"""name for the \texttt{year} or \texttt{macro} variable used in this simulation. \default{Year}"""))
time_discr.addSub(InputData.parameterInputFactory('start_time', contentType=InputTypes.FloatType,
descr=r"""value for \texttt{time} variable at which the inner dispatch should begin. \default{0}"""))
time_discr.addSub(InputData.parameterInputFactory('end_time', contentType=InputTypes.FloatType,
Expand Down Expand Up @@ -168,7 +170,8 @@ def __init__(self, run_dir, **kwargs):
self._num_hist = None # number of history steps, hist_len / hist_interval
self._global_econ = {} # global economics settings, as a pass-through
self._increments = {} # stepwise increments for resource balancing
self._time_varname = 'time' # name of the variable throughout simulation
self._time_varname = 'time' # name of the time-variable throughout simulation
self._year_varname = 'Year' # name of the year-variable throughout simulation
self._labels = {} # extra information pertaining to current case

self._time_discretization = None # (start, end, number) for constructing time discretization, same as argument to np.linspace
Expand Down Expand Up @@ -242,6 +245,10 @@ def _read_time_discr(self, node):
var_name = node.findFirst('time_variable')
if var_name is not None:
self._time_varname = var_name.value
# name of year variable
year_name = node.findFirst('year_variable')
if year_name is not None:
self._year_varname = year_name.value
# start
start_node = node.findFirst('start_time')
if start_node is None:
Expand Down Expand Up @@ -403,6 +410,14 @@ def get_time_name(self):
"""
return self._time_varname

def get_year_name(self):
"""
Provides the name of the time variable.
@ In, None
@ Out, time name, string, name of time variable
"""
return self._year_varname

def get_Resample_T(self):
"""
Accessor
Expand Down
6 changes: 3 additions & 3 deletions src/DispatchManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def save_variables(self, raven, dispatch, metrics):
shape = (len(dispatch), len(year_data), len(data))
setattr(raven, var_name, np.empty(shape)) # FIXME could use np.zeros, but slower?
getattr(raven, var_name)[y, c] = data
getattr(raven, '_indexMap')[0][var_name] = ['Year', 'Cluster', 'ClusterTime']
getattr(raven, '_indexMap')[0][var_name] = [self._case.get_year_name(), 'Cluster', 'ClusterTime']
#for component in self._components:
# TODO cheating using the numpy state
# dispatch = cluster_data['dispatch']
Expand Down Expand Up @@ -653,8 +653,8 @@ def _slice_signals(self, all_structure, data):
cluster_index = index_order.index('Cluster')
slicer[cluster_index] = division
# macro time (e.g. cycle, year)
if 'Year' in index_order:
macro_index = index_order.index('Year') # FIXME Macro ID!
if self._case.get_year_name() in index_order:
macro_index = index_order.index(self._case.get_year_name())
slicer[macro_index] = macro
truncated[entry] = raven[entry][slicer]
truncated['_indexMap'][entry] = [time_var] # the only index left should be "time"
Expand Down
2 changes: 1 addition & 1 deletion templates/inner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</Steps>

<VariableGroups>
<Group name='GRO_dispatch' >GRO_dispatch_in, GRO_dispatch_out, ClusterTime, Year, Cluster</Group>
<Group name='GRO_dispatch' >GRO_dispatch_in, GRO_dispatch_out, ClusterTime, Cluster</Group>
<Group name='GRO_dispatch_in' >GRO_dispatch_in_scalar, GRO_dispatch_in_Time</Group>
<Group name='GRO_dispatch_out' >GRO_dispatch_out_Time</Group>
<Group name='GRO_dispatch_in_scalar' >GRO_capacities, scaling</Group>
Expand Down
8 changes: 5 additions & 3 deletions templates/template_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,16 @@ def _modify_inner_time_vars(self, template, case):
@ In, case, HERON Case, defining Case instance
@ Out, None
"""
# Modify GRO_dispatch to contain correct 'Time' variable.
# Modify GRO_dispatch to contain correct 'Time' and 'Year' variable.
var_group = template.find("VariableGroups/Group")
var_group.text += f", {case.get_time_name()}"
var_group.text += f", {case.get_time_name()}, {case.get_year_name()}"
# Modify Data Objects to contain correct index var.
data_objs = template.find('DataObjects')
for index in data_objs.findall("DataSet/Index"):
if index.get('var') == 'Time':
index.set('var', case.get_time_name())
if index.get('var') == 'Year':
index.set('var', case.get_year_name())


def _modify_inner_runinfo(self, template, case):
Expand Down Expand Up @@ -669,7 +671,7 @@ def _add_arma_to_ensemble(self, template, source):
self._create_dataobject(data_objs, 'DataSet', eval_name,
inputs=['scaling'],
outputs=out_vars,
depends={self.__case.get_time_name(): out_vars, 'Year': out_vars}) # TODO user-defined?
depends={self.__case.get_time_name(): out_vars, self.__case.get_year_name(): out_vars}) # TODO user-defined?

# add variables to dispatch input requirements
## before all else fails, use variable groups
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/ARMA/Sine_Hour/Data.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scaling,Year,filename
scaling,YEAR,filename
1,2015,Data_0.csv
Binary file modified tests/integration_tests/ARMA/Sine_Hour/arma.pk
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/integration_tests/ARMA/train_sine_hour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<Output>OutputPlaceHolder</Output>
</PointSet>
<HistorySet name="input">
<Input>scaling, Year</Input>
<Input>scaling, YEAR</Input>
<Output>Signal, Hour</Output>
<options>
<pivotParameter>Hour</pivotParameter>
Expand All @@ -63,7 +63,7 @@
<Input>scaling</Input>
<Output>Signal</Output>
<Index var="Hour">Signal</Index>
<Index var="Year">Signal</Index>
<Index var="YEAR">Signal</Index>
</DataSet>
<DataSet name="meta"/>
</DataObjects>
Expand All @@ -76,7 +76,7 @@
<P>0</P>
<Q>0</Q>
<Segment grouping='interpolate'>
<macroParameter>Year</macroParameter>
<macroParameter>YEAR</macroParameter>
<Classifier class='Models' type='PostProcessor'>classifier</Classifier>
<subspace divisions='1'>Hour</subspace>
</Segment>
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/labels/heron_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<num_arma_samples>10</num_arma_samples>
<time_discretization>
<time_variable>Hour</time_variable>
<year_variable>YEAR</year_variable>
<end_time>2</end_time>
<num_steps>21</num_steps>
</time_discretization>
Expand Down
4 changes: 3 additions & 1 deletion tests/integration_tests/labels/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def flex_price(data, meta):
amount = - 2 * (sine[t] - 0.5)
labels = meta['HERON']['Case'].get_labels()
pivot_id = meta['HERON']['Case'].get_time_name()
year_id = meta['HERON']['Case'].get_year_name()
data = {'reference_price': amount,
'case_labels': labels,
'pivot_id': pivot_id}
'pivot_id': pivot_id,
'year_id': year_id}
return data, meta