Beispiel #1
0
def test_timeseries_excel(simple_linear_model, filename):
    """Test creation of a DataFrameParameter from external data (e.g. CSV)"""
    model = simple_linear_model

    # create DataFrameParameter from external data
    filename = os.path.join(TEST_FOLDER, filename)
    data = {"url": filename, "column": "Data", "index_col": "Timestamp"}
    if filename.endswith(".csv"):
        data.update({"parse_dates": True, "dayfirst": True})
    ts = DataFrameParameter.load(model, data)

    # model (intentionally not aligned)
    model.timestepper.start = ts.dataframe.index[0] + 5
    model.timestepper.end = ts.dataframe.index[-1] - 12

    # need to assign parameter for it's setup method to be called
    model.nodes["Input"].max_flow = ts

    @assert_rec(model, ts)
    def expected(timestep, scenario_index):
        return ts.dataframe.loc[timestep.datetime]

    model.run()
Beispiel #2
0
def test_timeseries_excel(simple_linear_model, filename):
    """Test creation of a DataFrameParameter from external data (e.g. CSV)"""
    model = simple_linear_model

    # create DataFrameParameter from external data
    filename = os.path.join(TEST_FOLDER, filename)
    data = {"url": filename, "column": "Data", "index_col": "Timestamp"}
    if filename.endswith(".csv"):
        data.update({"parse_dates": True, "dayfirst":True})
    ts = DataFrameParameter.load(model, data)

    # model (intentionally not aligned)
    model.timestepper.start = ts.df.index[0] + 5
    model.timestepper.end = ts.df.index[-1] - 12

    # need to assign parameter for it's setup method to be called
    model.nodes["Input"].max_flow = ts
    model.setup()

    # test accessing a specific value
    timestep = build_timestep(model, '2015-01-15')
    scenario_index = ScenarioIndex(0, np.array([], dtype=np.int32))
    assert(ts.value(timestep, scenario_index) == 28.24)