Exemplo n.º 1
0
def test_ow_index():
    net = simple_four_bus_system()
    steps = [3, 5, 7]
    p_data = pd.DataFrame(index=steps,
                          columns=["0", "1"],
                          data=[
                              [0.01, 0.02],
                              [0.03, 0.04],
                              [0.05, 0.06],
                          ])
    v_data = pd.DataFrame(index=steps, columns=["0"], data=[1.01, 1.03, 1.02])

    ds_p = DFData(p_data)
    ds_v = DFData(v_data)

    ct.ConstControl(net,
                    element='load',
                    variable='p_mw',
                    element_index=net.load.index.tolist(),
                    data_source=ds_p,
                    profile_name=p_data.columns)
    ct.ConstControl(net,
                    element='ext_grid',
                    variable='vm_pu',
                    element_index=0,
                    data_source=ds_v,
                    profile_name='0')

    ow = OutputWriter(net)
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_line', 'loading_percent')

    run_timeseries(net, time_steps=p_data.index, verbose=False)

    assert np.all(ow.output["res_line.loading_percent"].index == p_data.index)
Exemplo n.º 2
0
def create_output_writer(net, time_steps, output_dir):
    ow = OutputWriter(net,
                      time_steps,
                      output_path=output_dir,
                      output_file_type=".xls",
                      log_variables=list())
    # these variables are saved to the harddisk after / during the time series loop
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_bus', 'va_degree')
    return ow
Exemplo n.º 3
0
    def create_output_writer(self, output_dir):
        ow = OutputWriter(self.net,
                          self.n_time_steps,
                          output_path=output_dir,
                          output_file_type=".xls",
                          log_variables=list())
        # Logging information of the bus voltages and angles
        ow.log_variable('res_bus', 'vm_pu')
        ow.log_variable('res_bus', 'va_degree')

        return ow
Exemplo n.º 4
0
def setup_output_writer(net, time_steps):
    ow = OutputWriter(net, time_steps, output_path=tempfile.gettempdir())
    ow.log_variable('load', 'p_mw')
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_trafo3w', 'p_hv_mw')
    ow.log_variable('res_trafo3w', 'q_hv_mvar')
    return ow
Exemplo n.º 5
0
def test_timeseries_var_func(simple_test_net):
    # This test checks if the output writer works with a user defined function

    # test net
    net = simple_test_net

    n_timesteps = 5
    profiles, ds = create_data_source(n_timesteps)

    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"],
                 scale_factor=0.5)

    time_steps = range(0, n_timesteps)
    ow = OutputWriter(net,
                      time_steps,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_load', 'p_mw', eval_function=np.max)
    ow.log_variable('res_bus', 'vm_pu', eval_function=np.min)
    ow.log_variable('res_bus', 'q_mvar', eval_function=np.sum)

    run_timeseries(net, time_steps, output_writer=ow, verbose=False)
    # asserts if last value of output_writers output is the minimum value
    assert net["res_load"]["p_mw"].max(
    ) == ow.output["res_load.p_mw"].iloc[-1].values
    assert net["res_bus"]["vm_pu"].min() == ow.output["res_bus.vm_pu"].iloc[-1,
                                                                            -1]
    assert net["res_bus"]["q_mvar"].sum(
    ) == ow.output["res_bus.q_mvar"].iloc[-1].values

    # get minimum voltage of all hv busses
    mask = (net.bus.vn_kv > 70.0) & (net.bus.vn_kv < 380.0)
    hv_busses_index = net.bus.loc[mask].index
    mask = (net.bus.vn_kv > 1.0) & (net.bus.vn_kv < 70.0)
    mv_busses_index = net.bus.loc[mask].index
    ow.log_variable('res_bus',
                    'vm_pu',
                    index=hv_busses_index,
                    eval_function=np.min,
                    eval_name="hv_bus_min")
    ow.log_variable('res_bus',
                    'vm_pu',
                    index=mv_busses_index,
                    eval_function=np.min,
                    eval_name="mv_bus_min")
    run_timeseries(net, time_steps, output_writer=ow, verbose=False)
    assert net["res_bus"].loc[hv_busses_index,
                              "vm_pu"].min() == ow.output["res_bus.vm_pu"].loc[
                                  time_steps[-1], "hv_bus_min"]
    assert net["res_bus"].loc[mv_busses_index,
                              "vm_pu"].min() == ow.output["res_bus.vm_pu"].loc[
                                  time_steps[-1], "mv_bus_min"]
Exemplo n.º 6
0
def test_output_writer_eval_simple(simple_test_net):
    net = simple_test_net

    n_timesteps = 1
    profiles, ds = create_data_source(n_timesteps)
    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"])
    time_steps = range(0, n_timesteps)
    ow = OutputWriter(net,
                      time_steps,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_bus', 'vm_pu', eval_function=max, eval_name="max")
    run_timeseries(net, time_steps, verbose=False)
    assert len(ow.output["res_bus.vm_pu"]["max"]) == n_timesteps
Exemplo n.º 7
0
def test_output_writer_without_timesteps_set(simple_test_net):
    net = simple_test_net
    n_timesteps = 5
    profiles, ds = create_data_source(n_timesteps)
    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"])

    time_steps = range(0, n_timesteps)
    ow = OutputWriter(net,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_line', 'i_ka')
    run_timeseries(net, time_steps)
    assert len(ow.output["res_bus.vm_pu"]) == n_timesteps
    assert len(ow.output["res_line.i_ka"]) == n_timesteps
Exemplo n.º 8
0
def test_output_dump_after_time(simple_test_net):
    net = simple_test_net

    n_timesteps = 100
    profiles, ds = create_data_source(n_timesteps)

    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"])

    time_steps = range(0, n_timesteps)
    # write output after 0.1 minutes to disk
    ow = OutputWriter(net,
                      time_steps,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json",
                      write_time=0.05)
    ow.log_variable('res_load', 'p_mw')
    ow.log_variable('res_bus', 'vm_pu')

    ow.log_variable('res_line', 'loading_percent')
    ow.log_variable('res_line', 'i_ka')
    run_timeseries(net, time_steps, output_writer=ow, verbose=False)
Exemplo n.º 9
0
def create_output_writer(net, time_steps, output_dir):
    ow = OutputWriter(net, time_steps, output_path=output_dir, output_file_type=".xlsx", log_variables=list())
    ow.log_variable('res_sgen', 'p_mw')
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_line', 'loading_percent')
    ow.log_variable('res_line', 'i_ka')
    return ow
Exemplo n.º 10
0
def test_ppc_log(simple_test_net):
    net = simple_test_net
    n_timesteps = 5
    profiles, ds = create_data_source(n_timesteps)
    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"],
                 recycle=True)

    time_steps = range(0, n_timesteps)
    ow = OutputWriter(net,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json",
                      log_variables=list())
    ow.log_variable('ppc_bus', 'vm')
    ow.log_variable('ppc_bus', 'va')
    pp.runpp(net,
             only_v_results=True,
             recycle={
                 "bus_pq": True,
                 "gen": False,
                 "trafo": False
             })
    run_timeseries(net,
                   time_steps,
                   recycle={
                       "bus_pq": True,
                       "gen": False,
                       "trafo": False
                   },
                   only_v_results=True,
                   verbose=False)
    assert len(ow.output["ppc_bus.vm"]) == n_timesteps
    assert len(ow.output["ppc_bus.va"]) == n_timesteps
Exemplo n.º 11
0
def test_output_writer_short_data_source(simple_test_net):
    net = simple_test_net
    # outputwriter should fail if data source is shorter than time steps

    n_timesteps = 10
    profiles, ds = create_data_source(5)
    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"])

    time_steps = range(0, n_timesteps)
    ow = OutputWriter(net,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_line', 'i_ka')

    with pytest.raises(KeyError):
        run_timeseries(net, time_steps, verbose=False)
Exemplo n.º 12
0
def test_timeseries_results(simple_test_net):
    # This test compares output writer results with input
    # test net
    net = simple_test_net
    net.user_pf_options = dict()

    n_timesteps = 5
    profiles, ds = create_data_source(n_timesteps)

    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"],
                 scale_factor=0.5)

    time_steps = range(0, n_timesteps)
    ow = OutputWriter(net,
                      time_steps,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_load', 'p_mw')
    ow.log_variable('res_bus', 'vm_pu')

    ow.log_variable('res_line', 'loading_percent')
    ow.log_variable('res_line', 'i_ka')
    run_timeseries(net, time_steps, output_writer=ow, verbose=False)
    assert np.allclose(
        ow.output['res_load.p_mw'].sum().values * 2,
        profiles[["load1", "load2_mv_p", "load3_hv_p"]].sum().values)

    # 3load - @Rieke What is this test for compared to the first one?
    # @Flo in / out of service testen ...
    ow.log_variable('res_load', 'p_mw')
    net.controller.in_service = False  # set the first controller out of service
    ConstControl(net,
                 'load',
                 'p_mw',
                 element_index=0,
                 data_source=ds,
                 profile_name='load1')

    run_timeseries(net, time_steps, output_writer=ow, verbose=False)
    assert np.allclose(ow.output['res_load.p_mw'][0].sum(),
                       profiles["load1"].sum())
Exemplo n.º 13
0
def test_output_writer_without_timesteps_set_repeat(simple_test_net):
    net = simple_test_net
    # the same outputwriter should be able to run repeated time series

    time_steps_to_check = [8, 5, 10]
    profiles, ds = create_data_source(max(time_steps_to_check))
    # 1load
    ConstControl(net,
                 element='load',
                 variable='p_mw',
                 element_index=[0, 1, 2],
                 data_source=ds,
                 profile_name=["load1", "load2_mv_p", "load3_hv_p"])

    ow = OutputWriter(net,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_line', 'i_ka')

    for n_timesteps in time_steps_to_check:
        time_steps = range(0, n_timesteps)
        run_timeseries(net, time_steps, verbose=False)
        assert len(ow.output["res_bus.vm_pu"].index) == n_timesteps
Exemplo n.º 14
0
def create_output_writer(net, time_steps, output_dir):
    ow = OutputWriter(net,
                      time_steps,
                      output_path=output_dir,
                      output_file_type=".xls",
                      log_variables=list())
    # these variables are saved to the harddisk after / during the time series loop
    ow.log_variable('res_load', 'p_mw')
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_line', 'loading_percent')
    ow.log_variable('res_line', 'i_ka')
    return ow
Exemplo n.º 15
0
def define_log(net, time_steps):
    """
    Creates output writer object required for timeseries simulation
    The timeseries module only calculates the values of variables mentioned here for each simulation.
    The temporary data gets stored in the output_dir directory

    OUTPUT
        ow - Output writer object
    """
    ow = OutputWriter(net,
                      time_steps,
                      output_path=output_dir,
                      output_file_type=".json")
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_line', 'loading_percent')
    ow.log_variable('res_trafo', 'loading_percent')
    return ow
Exemplo n.º 16
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)
def simulate_network(scenario, installations_percent, cooperation_percent,
                     installation_buses, cooperating_buses, individual_buses):
    scenario_name = get_scenario_name(scenario)

    full_dir_path = "data/results/{}/03-simulation/{}_installations/{}_cooperative".format(
        scenario_name, installations_percent, cooperation_percent)

    if os.path.exists(full_dir_path) and SKIP_EXISTING:
        if PRINT_SKIPPING_LINES:
            print("[{}] [{}%] [{}%] Simulating network... [skipping]".format(
                scenario_name, installations_percent, cooperation_percent))
        return False

    print("[{}] [{}%] [{}%] Simulating network...".format(
        scenario_name, installations_percent, cooperation_percent))

    net = ieee_european_lv_asymmetric('on_peak_566')

    for index, _ in net.asymmetric_load.iterrows():
        net.asymmetric_load.in_service.at[index] = False

    pandapower.runpp(net)

    for original_index, row in buses.iterrows():
        load_index = pandapower.create_load(net, bus=row.bus, p_mw=0)
        load_profile_raw = pandas.read_csv(
            "data/source/load_profiles/Load_profile_{}.csv".format(
                original_index + 1),
            sep=",",
            decimal=".")
        load_profile_raw['mult'] = load_profile_raw['mult'].apply(
            convertkWToMW).iloc[::10].reset_index(drop=True)
        load_profile = frame_data.DFData(pandas.DataFrame(load_profile_raw))
        load_controller = ConstControl(net,
                                       element='load',
                                       element_index=load_index,
                                       variable='p_mw',
                                       data_source=load_profile,
                                       profile_name='mult',
                                       recycle=False)

    for original_index, row in installation_buses.iterrows():
        if scenario.get('EV') == True:
            ev_index = pandapower.create_load(net, bus=row.bus, p_mw=0)
            ev_profile_raw = pandas.read_csv(
                "data/source/ev_profiles/EV_home_profiles_{}.csv".format(
                    original_index + 1),
                sep=";",
                decimal=",")
            ev_profile_raw['load'] = ev_profile_raw['load'].apply(
                convert10minkWhTokW).apply(convertkWToMW)
            ev_profile = frame_data.DFData(pandas.DataFrame(ev_profile_raw))
            ev_controller = ConstControl(net,
                                         element='load',
                                         element_index=ev_index,
                                         variable='p_mw',
                                         data_source=ev_profile,
                                         profile_name='load',
                                         recycle=False)

        if scenario.get('PV') == True:
            sgen_index = pandapower.create_sgen(net,
                                                bus=row.bus,
                                                p_mw=0,
                                                sn_mva=0,
                                                type='PV')
            pv_profile_raw = pandas.read_csv("data/source/PVProfile1440.csv",
                                             sep=";",
                                             decimal=".")
            pv_profile_raw['pv_output_power_kw'] = pv_profile_raw[
                'pv_output_power_kw'].apply(
                    convertkWToMW).iloc[::10].reset_index(drop=True)
            pv_profile = frame_data.DFData(pandas.DataFrame(pv_profile_raw))
            sgen_controller = ConstControl(net,
                                           element='sgen',
                                           element_index=sgen_index,
                                           variable='p_mw',
                                           data_source=pv_profile,
                                           profile_name='pv_output_power_kw',
                                           recycle=False)

    for original_index, row in cooperating_buses.iterrows():
        storage_index = pandapower.create_storage(
            net,
            bus=row.bus,
            p_mw=0,
            max_e_mwh=BATTERY_ENERGY_MAX / 1000.0,
            soc_percent=(INITIAL_BATTERY_CHARGE / BATTERY_ENERGY_MAX) * 100.0,
            max_p_mw=RATED_P / 1000.0,
            min_p_mw=-RATED_P / 1000.0)
        storage_profile_raw = pandas.read_csv(
            "data/results/{}/02-collective/{}_installations/{}_cooperation/Storage_profile_{}.csv"
            .format(scenario_name, installations_percent, cooperation_percent,
                    original_index + 1),
            sep=",",
            decimal=".")
        storage_profile_raw['power_kW'] = storage_profile_raw[
            'power_kW'].apply(convertkWToMW).apply(convertStorage)
        storage_profile = frame_data.DFData(
            pandas.DataFrame(storage_profile_raw))
        storage_controller = ConstControl(net,
                                          element='storage',
                                          element_index=storage_index,
                                          variable='p_mw',
                                          data_source=storage_profile,
                                          profile_name='power_kW',
                                          recycle=False)

    for original_index, row in individual_buses.iterrows():
        storage_index = pandapower.create_storage(
            net,
            bus=row.bus,
            p_mw=0,
            max_e_mwh=BATTERY_ENERGY_MAX / 1000.0,
            soc_percent=(INITIAL_BATTERY_CHARGE / BATTERY_ENERGY_MAX) * 100.0,
            max_p_mw=RATED_P / 1000.0,
            min_p_mw=-RATED_P / 1000.0)
        storage_profile_raw = pandas.read_csv(
            "data/results/{}/01-individual/storage-profiles/Storage_profile_{}.csv"
            .format(scenario_name, original_index + 1),
            sep=",",
            decimal=".")
        storage_profile_raw['power_kW'] = storage_profile_raw[
            'power_kW'].apply(convertkWToMW).apply(convertStorage)
        storage_profile = frame_data.DFData(
            pandas.DataFrame(storage_profile_raw))
        storage_controller = ConstControl(net,
                                          element='storage',
                                          element_index=storage_index,
                                          variable='p_mw',
                                          data_source=storage_profile,
                                          profile_name='power_kW',
                                          recycle=False)

    time_steps = range(0, T)

    ow = OutputWriter(net,
                      output_path=full_dir_path,
                      output_file_type=".csv",
                      log_variables=[])

    ow.log_variable("load", "p_mw")
    ow.log_variable("res_bus", "vm_pu", index=buses_nodes)
    ow.log_variable("res_line", "p_to_mw", index=line_nodes)
    ow.log_variable("res_trafo", "vm_lv_pu")
    ow.log_variable("res_trafo", "p_lv_mw")

    if scenario.get('PV') == True:
        ow.log_variable("sgen", "p_mw")

    if cooperating_buses.size > 0 or individual_buses.size > 0:
        ow.log_variable("storage", "p_mw")

    run_timeseries(net, time_steps, continue_on_divergence=True, verbose=False)

    return True
Exemplo n.º 18
0
def create_output_writer(net, time_steps, output_dir):
    ow = OutputWriter(net, time_steps, output_path=output_dir, output_file_type=".csv")
    # these variables are saved to the harddisk after / during the time series loop
    ow.log_variable('res_bus', 'p_mw')
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('storage','p_mw')
    ow.log_variable('res_line', 'loading_percent')
    ow.log_variable('res_line', 'i_ka')
    ow.log_variable('storage', 'soc_percent')
    ow.log_variable('storage', 'in_service')
    ow.log_variable('res_line', 'pl_mw')
    ow.log_variable('res_sgen', 'q_mvar')
    return ow
        convertkWToMW).iloc[::10].reset_index(drop=True)

    pv_profile = fd.DFData(pd.DataFrame(pv_profile_raw))

    sgen_controller = ConstControl(
        net, element='sgen', element_index=sgen_index, variable='p_mw',
        data_source=pv_profile, profile_name='pv_output_power_kw',
        recycle=False)

    # initialize storage elements

    storage_index = pp.create_storage(
        net, bus=row.bus, p_mw=0, max_e_mwh=0.0077, soc_percent=50, sn_mva=0.003, max_p_mw=0.003, min_p_mw=-0.003)

    storage_controller = ZeroTargetStorage(
        net, load_index=load_index, storage_index=storage_index, generator_index=sgen_index)


time_steps = range(0, 144)

ow = OutputWriter(net, output_path="./result",
                  output_file_type=".csv")

ow.log_variable("storage", "soc_percent", index=[0])
ow.log_variable("load", "p_mw", index=[0])
ow.log_variable("sgen", "p_mw", index=[0])
ow.log_variable("storage", "p_mw", index=[0])


run_timeseries(net, time_steps, continue_on_divergence=True)
Exemplo n.º 20
0
def create_output_writer(net, time_steps, output_dir):
    ow = OutputWriter(net,
                      time_steps,
                      output_path=output_dir,
                      output_file_type=".xlsx",
                      log_variables=list())  # .csv .xls

    # # create a mask to get the indices of all the hv buses in the grid
    # mask_hv_buses = (net.bus.vn_kv > 70.0) & (net.bus.vn_kv < 380.0)
    # hv_busses_index = net.bus.loc[mask_hv_buses].index
    # # create a mask to get the indices of all the mv buses in the grid
    # mask_mv_buses = (net.bus.vn_kv > 1.0) & (net.bus.vn_kv < 70.0)
    # mv_busses_index = net.bus.loc[mask_mv_buses].index
    # # now define the output writer, so that it gets the indices and specify the evaluation functions
    # # since we want the maximum voltage of all mv buses, we provide the indices of the mv buses and the maximum
    # # function np.max. The variable "eval_name" is free to chose and contains the name of the column in
    # # which the results are saved.
    #pp.create_measurement(net,"p","trafo",0,)
    ow.log_variable('res_trafo', 'loading_percent')  #, index=0 )
    ow.log_variable('res_trafo', 'loading_percent', eval_function=np.max)
    ow.log_variable('res_trafo', 'p_hv_mw')
    ow.log_variable('res_trafo', 'p_lv_mw')
    ow.log_variable('res_trafo', 'q_hv_mvar')
    ow.log_variable('res_trafo', 'q_lv_mvar')
    ow.log_variable('res_trafo', 'pl_mw')
    ow.log_variable('res_trafo', 'ql_mvar')
    ow.log_variable('res_trafo', 'vm_lv_pu')
    ow.log_variable('res_trafo', 'vm_hv_pu')
    ow.log_variable('res_trafo', 'i_lv_ka')
    ow.log_variable('res_trafo', 'i_hv_ka')
    ow.log_variable('res_bus', 'p_mw')
    ow.log_variable('res_bus',
                    'p_mw',
                    eval_function=np.sum,
                    eval_name="lv_bus_sum_p")  #index=[2,12],
    ow.log_variable('res_bus', 'vm_pu')
    ow.log_variable('res_bus',
                    'vm_pu',
                    eval_function=np.max,
                    eval_name="lv_bus_max")
    ow.log_variable('res_line', 'p_to_mw')
    ow.log_variable('res_line', 'i_to_ka')
    ow.log_variable('res_line', 'vm_to_pu')
    ow.log_variable('res_line', 'va_to_degree')
    ow.log_variable('res_line', 'loading_percent')
    return ow
Exemplo n.º 21
0
def test_output_writer_multiple_index_definition(simple_test_net):
    net = simple_test_net

    n_timesteps = 1
    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"])
    time_steps = range(0, n_timesteps)

    ow = OutputWriter(net,
                      time_steps,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_bus', 'vm_pu', net.load.bus[[0, 1]])
    ow.log_variable('res_bus', 'vm_pu', index=[1, 2])
    ow.log_variable('res_bus', 'vm_pu', index=[3, 2, 1])
    ow.log_variable('res_bus', 'vm_pu', net.load.bus)
    ow.log_variable('res_bus', 'vm_pu', index=[3, 4])
    ow.log_variable('res_bus', 'vm_pu', net.bus.index)
    ow.log_variable('res_bus', 'vm_pu', 0)
    run_timeseries(net, time_steps, verbose=False)
    backup_result = copy.deepcopy(
        ow.output["res_bus.vm_pu"].loc[:, net.bus.index])
    del ow

    ow = OutputWriter(net,
                      time_steps,
                      output_path=tempfile.gettempdir(),
                      output_file_type=".json")
    ow.log_variable('res_bus', 'vm_pu', net.bus.index)

    run_timeseries(net, time_steps, verbose=False)
    # assert all are considered
    assert len(ow.output["res_bus.vm_pu"].columns) == len(net.bus.index)
    # assert correct order of values
    assert np.allclose(backup_result,
                       ow.output["res_bus.vm_pu"].loc[:, net.bus.index])