Exemplo n.º 1
0
def test_store_and_load(simple_test_net):
    net = simple_test_net

    n_timesteps = 2
    profiles, ds = create_data_source(n_timesteps)
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"])
    dirname = tempfile.gettempdir()
    ow = OutputWriter(net, output_path=dirname, output_file_type=".json")
    ow.remove_log_variable("res_bus")
    tmp_file = os.path.join(dirname, "net.json")
    pp.to_json(net, tmp_file)
    del net
    del ow
    res_line_file = os.path.join(dirname, "res_line", "loading_percent.json")
    # del result file is one is present
    if os.path.isfile(res_line_file):
        os.remove(res_line_file)
    net = pp.from_json(tmp_file)
    ow = net.output_writer.iat[0, 0]
    assert len(ow.log_variables) == 1
    assert ow.output_path == dirname
    time_steps = range(0, n_timesteps)
    run_timeseries(net, time_steps=time_steps, verbose=False)
    # check if results were written
    assert os.path.isfile(res_line_file)
Exemplo n.º 2
0
def test_remove_variable(simple_test_net):
    net = simple_test_net

    ow = OutputWriter(net)
    # test printing
    logger.info(ow)
    assert len(ow.log_variables) == 2
    assert ow.log_variables[0][0] == "res_bus" and ow.log_variables[0][
        1] == "vm_pu"
    assert ow.log_variables[1][0] == "res_line" and ow.log_variables[1][
        1] == "loading_percent"
    ow.remove_log_variable("res_bus")
    assert ow.log_variables[0][0] == "res_line" and ow.log_variables[0][
        1] == "loading_percent"
    ow.remove_log_variable("res_line", "loading_percent")
    assert len(ow.log_variables) == 0
Exemplo n.º 3
0
def test_output_writer_log(simple_test_net):
    net = simple_test_net

    # timeseries data
    df = pd.DataFrame([[15, 30, 2], [12, 27, 1.5], [7, 29, 2.1]])
    ds = DFData(df)

    # Create gen controller with datasource
    ct.ConstControl(net,
                    element="load",
                    variable="p_mw",
                    element_index=[0, 2],
                    data_source=ds,
                    profile_name=[0, 2])

    # Create, add output and set outputwriter
    ow = OutputWriter(net, output_path=tempfile.gettempdir())
    ow.remove_log_variable("res_bus")
    orig_index = [0, 1]
    ow.log_variable("res_bus", "vm_pu", orig_index)
    ow.log_variable("res_sgen", "p_mw")
    ow.log_variable("res_sgen", "q_mvar")

    # Run timeseries
    run_timeseries(net, time_steps=range(2), verbose=False)

    # --- double logged variables handling
    ow2 = copy.deepcopy(ow)
    new_idx = 2
    ow2.log_variable("res_bus", "vm_pu", new_idx, eval_name="test")
    run_timeseries(net, time_steps=range(2), output_writer=ow2, verbose=False)
    assert all(ow2.output["res_bus.vm_pu"].columns == orig_index + [new_idx])

    # Todo: This test makes no sense if res_bus is logged by default
    # ow3 = copy.deepcopy(ow)
    # new_idx = [2, 3]
    # ow3.log_variable("res_bus", "vm_pu", new_idx)
    # run_timeseries(net, time_steps=range(2), output_writer=ow3)
    # assert all(ow3.output["res_bus.vm_pu"].columns == orig_index + new_idx)

    ow4 = copy.deepcopy(ow)
    new_idx = [2, 4]
    ow4.log_variable("res_bus", "vm_pu", new_idx, eval_name=["test1", "test2"])
    run_timeseries(net, time_steps=range(2), output_writer=ow4, verbose=False)
    assert all(ow4.output["res_bus.vm_pu"].columns == orig_index + new_idx)