Skip to content

Commit

Permalink
update clone kwarg from scen to scenario (#133)
Browse files Browse the repository at this point in the history
closes #129, closes #130
  • Loading branch information
gidden authored Nov 27, 2018
1 parent 26cc08f commit 154c581
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# Next Release

- [#131](https://github.com/iiasa/message_ix/pull/131): Update clone function syntax scen to scenario

# v1.1.0

## Warnings
Expand Down
18 changes: 12 additions & 6 deletions message_ix/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def add_horizon(scenario, data):
horizon = data['year']
scenario.add_set("year", horizon)

first = data['firstmodelyear'] if 'firstmodelyear' in data else horizon[0]
first = data['firstmodelyear'] if 'firstmodelyear'\
in data else horizon[0]
scenario.add_cat("year", "firstmodelyear", first, is_unique=True)

def vintage_and_active_years(self, ya_args=None, in_horizon=True):
Expand Down Expand Up @@ -237,15 +238,15 @@ def solve(self, model='MESSAGE', **kwargs):
"""
return super(Scenario, self).solve(model=model, **kwargs)

def clone(self, model=None, scen=None, annotation=None, keep_solution=True,
first_model_year=None, **kwargs):
def clone(self, model=None, scenario=None, annotation=None,
keep_solution=True, first_model_year=None, **kwargs):
"""clone the current scenario and return the new scenario
Parameters
----------
model : string
new model name
scen : string
scenario : string
new scenario name
annotation : string
explanatory comment (optional)
Expand All @@ -261,12 +262,17 @@ def clone(self, model=None, scen=None, annotation=None, keep_solution=True,
'`keep_sol` is deprecated and will be removed in the next' +
' release, please use `keep_solution`')
keep_solution = kwargs.pop('keep_sol')
if 'scen' in kwargs:
warnings.warn(
'`scen` is deprecated and will be removed in the next' +
' release, please use `scenario`')
scenario = kwargs.pop('scen')

self._keep_sol = keep_solution
self._first_model_year = first_model_year or 0
model = self.model if not model else model
scen = self.scenario if not scen else scen
return Scenario(self.platform, model, scen, annotation=annotation,
scenario = self.scenario if not scenario else scenario
return Scenario(self.platform, model, scenario, annotation=annotation,
cache=self._cache, clone=self)

def rename(self, name, mapping, keep=False):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_feature_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def add_addon(s, costs=False, zero_output=False):

# reduce max activity from one canning plant, has to be compensated by addon
def test_addon_tec(test_mp):
scen = Scenario(test_mp, *msg_args).clone(scen='addon',
scen = Scenario(test_mp, *msg_args).clone(scenario='addon',
keep_solution=False)

add_addon(scen, costs=-1)
Expand All @@ -82,7 +82,7 @@ def test_addon_tec(test_mp):

# introduce addon technology with negatove costs, add maximum mitigation
def test_addon_up(test_mp):
scen = Scenario(test_mp, *msg_args).clone(scen='addon_up',
scen = Scenario(test_mp, *msg_args).clone(scenario='addon_up',
keep_solution=False)
add_addon(scen, costs=-1, zero_output=True)

Expand All @@ -99,7 +99,7 @@ def test_addon_up(test_mp):

# introduce addon technology with positive costs, add minimum mitigation
def test_addon_lo(test_mp):
scen = Scenario(test_mp, *msg_args).clone(scen='addon_lo',
scen = Scenario(test_mp, *msg_args).clone(scenario='addon_lo',
keep_solution=False)
add_addon(scen, costs=1, zero_output=True)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_feature_bounds_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def add_data(s, map_df):
'commodity': 'cases',
'level': 'supply'
})
clone = scen.clone(scen='share_mode_list', keep_solution=False)
clone = scen.clone(scenario='share_mode_list', keep_solution=False)
clone.check_out()
add_data(clone, map_df)
clone.commit('foo')
Expand All @@ -175,7 +175,7 @@ def add_data(s, map_df):
'commodity': 'cases',
'level': 'supply'
}, index=[0])
clone2 = scen.clone(scen='share_all_modes', keep_solution=False)
clone2 = scen.clone(scenario='share_all_modes', keep_solution=False)
clone2.check_out()
add_data(clone2, map_df2)
clone2.commit('foo')
Expand Down Expand Up @@ -209,7 +209,7 @@ def calc_share(s):
exp = 1. * calc_share(scen)

# add share constraints
clone = scen.clone(scen='share_commodity_lo', keep_solution=False)
clone = scen.clone(scenario='share_commodity_lo', keep_solution=False)
clone.check_out()
clone.add_cat('technology', 'share', 'transport_from_seattle')
clone.add_cat('technology', 'total', ['transport_from_seattle',
Expand Down Expand Up @@ -268,7 +268,7 @@ def calc_share(s):
exp = 0.95 * calc_share(scen)

# add share constraints
clone = scen.clone(scen='share_mode_up', keep_solution=False)
clone = scen.clone(scenario='share_mode_up', keep_solution=False)
clone.check_out()
clone.add_set('shares', 'test-share')
clone.add_par('share_mode_up',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_init(test_mp):
scen = Scenario(test_mp, *msg_args)
obs = scen.var('OBJ')['lvl']

scen = scen.clone('foo', 'bar', keep_sol=False)
scen = scen.clone('foo', 'bar', keep_solution=False)
scen.check_out()
macro.init(scen)
scen.commit('foo')
Expand Down

0 comments on commit 154c581

Please sign in to comment.