Skip to content

Commit

Permalink
Adjust standard set of reported products (iiasa#220)
Browse files Browse the repository at this point in the history
- rm hist params
- other functions implemented, hanging observed
- reporting now passes without land use
- readd landuse
- remove old assert graph len
- finish adding new products
- Add check for scenario with solution
  • Loading branch information
gidden authored and khaeru committed Aug 1, 2019
1 parent af81ea1 commit 570f798
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
23 changes: 11 additions & 12 deletions message_ix/reporting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,24 @@
PRODUCTS = (
('out',
('output', 'ACT')),
('out_hist',
('output', 'ref_activity')),
('in',
('input', 'ACT')),
('in_hist',
('input', 'ref_activity')),
('rel',
('relation_activity', 'ACT')),
('emi',
('emission_factor', 'ACT')),
('emi_hist',
('emission_factor', 'ref_activity')),
('inv',
('inv_cost', 'CAP_NEW')),
('inv_hist',
('inv_cost', 'ref_new_capacity')),
('fom',
('fix_cost', 'CAP')),
('fom_hist',
('fix_cost', 'ref_capacity')),
('vom',
('var_cost', 'ACT')),
('vom_hist',
('var_cost', 'ref_activity')),
('land_out',
('land_output', 'LAND')),
('land_use_qty', # TODO: better name!
('land_use', 'LAND')),
('land_emi',
('land_emission', 'LAND')),
)

#: Other standard derived quantities.
Expand Down Expand Up @@ -121,6 +117,9 @@ def from_scenario(cls, scenario, **kwargs):
message_ix.reporting.Reporter
A reporter for *scenario*.
"""
if not scenario.has_solution():
raise RuntimeError('Scenario must have a solution to be reported')

# Invoke the ixmp method
rep = super().from_scenario(scenario, **kwargs)

Expand Down
14 changes: 12 additions & 2 deletions tests/test_reporting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from functools import partial
from logging import WARNING
try:
Expand All @@ -18,6 +20,14 @@
from message_ix.testing import make_dantzig, make_westeros


def test_reporter_no_solution(test_mp):
scen = Scenario(test_mp,
'canning problem (MESSAGE scheme)',
'standard')

pytest.raises(RuntimeError, Reporter.from_scenario, scen)


def test_reporter(test_mp):
scen = Scenario(test_mp,
'canning problem (MESSAGE scheme)',
Expand Down Expand Up @@ -61,7 +71,7 @@ def test_reporter(test_mp):
assert len(rep_ix.graph) == 5088

# message_ix.Reporter pre-populated with additional, derived quantities
assert len(rep.graph) == 9615
assert len(rep.graph) == 7975

# Derived quantities have expected dimensions
vom_key = rep.full_key('vom')
Expand All @@ -77,7 +87,7 @@ def test_reporter(test_mp):


def test_reporter_from_dantzig(test_mp):
scen = make_dantzig(test_mp)
scen = make_dantzig(test_mp, solve=True)

# Reporter.from_scenario can handle Dantzig example model
rep = Reporter.from_scenario(scen)
Expand Down

0 comments on commit 570f798

Please sign in to comment.