Ejemplo n.º 1
0
Archivo: data.py Proyecto: iiasa/ixmp
def make_dantzig(mp: Platform,
                 solve: bool = False,
                 quiet: bool = False) -> Scenario:
    """Return :class:`ixmp.Scenario` of Dantzig's canning/transport problem.

    Parameters
    ----------
    mp : .Platform
        Platform on which to create the scenario.
    solve : bool, optional
        If :obj:`True`. then solve the scenario before returning. Default :obj:`False`.
    quiet : bool, optional
        If :obj:`True`, suppress console output when solving.

    Returns
    -------
    .Scenario

    See also
    --------
    .DantzigModel
    """
    # add custom units and region for timeseries data
    try:
        mp.add_unit("USD/km")
    except Exception:
        # Unit already exists. Pending bugfix from zikolach
        pass
    mp.add_region("DantzigLand", "country")

    # Initialize a new Scenario, and use the DantzigModel class' initialize()
    # method to populate it
    annot = "Dantzig's transportation problem for illustration and testing"
    scen = Scenario(
        mp,
        **models["dantzig"],  # type: ignore [arg-type]
        version="new",
        annotation=annot,
        scheme="dantzig",
        with_data=True,
    )

    # commit the scenario
    scen.commit("Import Dantzig's transport problem for testing.")

    # set this new scenario as the default version for the model/scenario name
    scen.set_as_default()

    if solve:
        # Solve the model using the GAMS code provided in the `tests` folder
        scen.solve(model="dantzig", case="transport_standard", quiet=quiet)

    # add timeseries data for testing `clone(keep_solution=False)`
    # and `remove_solution()`
    scen.check_out(timeseries_only=True)
    scen.add_timeseries(HIST_DF, meta=True)
    scen.add_timeseries(INP_DF)
    scen.commit("Import Dantzig's transport problem for testing.")

    return scen
Ejemplo n.º 2
0
def test_timeseries_remove_single_entry(mp):
    args_single = ('Douglas Adams', 'test_remove_single')

    scen = Scenario(mp, *args_single, version='new', annotation='fo')
    scen.add_timeseries(DATA['timeseries'].pivot_table(values='value',
                                                       index=IDX_COLS))
    scen.commit('importing a testing timeseries')

    scen = Scenario(mp, *args_single)
    assert_timeseries(scen, DATA['timeseries'])

    scen.check_out()
    scen.remove_timeseries(DATA['timeseries'][DATA['timeseries'].year == 2010])
    scen.commit('testing for removing a single timeseries data point')

    exp = DATA['timeseries'][DATA['timeseries'].year == 2020]
    assert_timeseries(scen, exp)
Ejemplo n.º 3
0
def test_timeseries_remove_single_entry(mp):
    args_single = ("Douglas Adams", "test_remove_single")

    scen = Scenario(mp, *args_single, version="new", annotation="fo")
    scen.add_timeseries(DATA["timeseries"].pivot_table(values="value",
                                                       index=IDX_COLS))
    scen.commit("importing a testing timeseries")

    scen = Scenario(mp, *args_single)
    assert_timeseries(scen, DATA["timeseries"])

    scen.check_out()
    scen.remove_timeseries(DATA["timeseries"][DATA["timeseries"].year == 2010])
    scen.commit("testing for removing a single timeseries data point")

    exp = DATA["timeseries"][DATA["timeseries"].year == 2020]
    assert_timeseries(scen, exp)
Ejemplo n.º 4
0
def test_timeseries_remove_all_data(mp):
    args_all = ('Douglas Adams', 'test_remove_all')

    scen = Scenario(mp, *args_all, version='new', annotation='fo')
    scen.add_timeseries(DATA['timeseries'].pivot_table(values='value',
                                                       index=IDX_COLS))
    scen.commit('importing a testing timeseries')

    scen = Scenario(mp, *args_all)
    assert_timeseries(scen, DATA['timeseries'])

    exp = DATA['timeseries'].copy()
    exp['variable'] = 'Testing2'

    scen.check_out()
    scen.add_timeseries(exp)
    scen.remove_timeseries(DATA['timeseries'])
    scen.commit('testing for removing a full timeseries row')

    assert scen.timeseries(region='World', variable='Testing').empty
    assert_timeseries(scen, exp)
Ejemplo n.º 5
0
def test_timeseries_remove_all_data(mp):
    args_all = ("Douglas Adams", "test_remove_all")

    scen = Scenario(mp, *args_all, version="new", annotation="fo")
    scen.add_timeseries(DATA["timeseries"].pivot_table(values="value",
                                                       index=IDX_COLS))
    scen.commit("importing a testing timeseries")

    scen = Scenario(mp, *args_all)
    assert_timeseries(scen, DATA["timeseries"])

    exp = DATA["timeseries"].copy()
    exp["variable"] = "Testing2"

    scen.check_out()
    scen.add_timeseries(exp)
    scen.remove_timeseries(DATA["timeseries"])
    scen.commit("testing for removing a full timeseries row")

    assert scen.timeseries(region="World", variable="Testing").empty
    assert_timeseries(scen, exp)