def test_reporter_from_westeros(test_mp): scen = make_westeros(test_mp, emissions=True, solve=True) # Reporter.from_scenario can handle Westeros example model rep = Reporter.from_scenario(scen) # Westeros-specific configuration: '-' is a reserved character in pint configure(units={'replace': {'-': ''}}) # Default target can be calculated rep.get('all') # message default target can be calculated # TODO if df is empty, year is cast to float obs = rep.get('message:default') # all expected reporting exists assert len(obs.data) == 69 # custom values are correct obs = obs.filter(variable='total om*') assert len(obs.data) == 9 assert all( obs['variable'] == # noqa: W504 ['total om cost|coal_ppl'] * 3 + # noqa: W504 ['total om cost|grid'] * 3 + # noqa: W504 ['total om cost|wind_ppl'] * 3 ) assert all(obs['year'] == [700, 710, 720] * 3) obs = obs['value'].values exp = [4832.177734, 8786.515625, 12666.666016, 5555.555664, 8333.333984, 10555.555664, 305.748138, 202.247391, 0.] assert len(obs) == len(exp) assert_allclose(obs, exp)
def test_reporter_from_westeros(test_mp): scen = make_westeros(test_mp, emissions=True, solve=True, quiet=True) # Reporter.from_scenario can handle Westeros example model rep = Reporter.from_scenario(scen) # Westeros-specific configuration: '-' is a reserved character in pint configure(units={"replace": {"-": ""}}) # Default target can be calculated rep.get("all") # message default target can be calculated # TODO if df is empty, year is cast to float obs = rep.get("message:default") # all expected reporting exists assert len(obs.data) == 69 # custom values are correct obs = obs.filter(variable="total om*") assert len(obs.data) == 9 assert all(obs["variable"] == ["total om cost|coal_ppl"] * 3 # noqa: W504 + ["total om cost|grid"] * 3 # noqa: W504 + ["total om cost|wind_ppl"] * 3 # noqa: W504 ) assert all(obs["year"] == [700, 710, 720] * 3) obs = obs.data["value"].values exp = [ 2842.4574905, 5373.0510978, 6933.3333333, 3055.5555555, 4555.5555555, 5777.7777777, 381.57832228, 43.340541129, 0.0, ] assert len(obs) == len(exp) assert_allclose(obs, exp)