def test_ctrl_unconverged(net): output_writer = OutputWriter(net, time_steps=[0, 1]) class DivergentController(Controller): def __init__(self, net): super().__init__(net) def time_step(self, time): self.convergent = True if time % 2 == 0 else False def is_converged(self): return self.convergent DivergentController(net) with pytest.raises(ct.ControllerNotConverged): run_timeseries(net, time_steps=range(0, 3), output_writer=output_writer, max_iter=3) # assert no exceptions but appropriate output in outputwriter run_timeseries(net, time_steps=range(0, 3), output_writer=output_writer, max_iter=3, continue_on_divergence=True) for i, out in enumerate( output_writer.output["Parameters"].controller_unstable): if i % 2 == 0: assert not out else: assert out
def test_const_control(simple_test_net): net = simple_test_net profiles, ds = create_data_source() time_steps = range(0, 10) ow = setup_output_writer(net, time_steps) ConstControl(net, 'load', 'p_mw', element_index=0, data_source=ds, profile_name='load1', scale_factor=0.85) ConstControl(net, 'ext_grid', 'vm_pu', element_index=0, data_source=ds, profile_name='slack_v') run_timeseries(net, time_steps, output_writer=ow, verbose=False) assert np.alltrue(profiles['load1'].values * 0.85 == ow.output['load.p_mw'][0].values) assert np.alltrue( profiles['slack_v'].values == ow.output['res_bus.vm_pu'][0].values)
def run_grid(output_dir, data, datapoints): # 1. create test net #net = simple_test_net() net = nw.create_cigre_network_lv() # 2. create (random) data source n_timesteps = datapoints profiles, ds = load_input(data=data) # profiles, ds = create_data_source(n_timesteps) # n_timesteps # 3. create controllers (to control P values of the load and the sgen) net = create_controllers(net, ds) # time steps to be calculated. Could also be a list with non-consecutive time steps time_steps = range(0, n_timesteps) # 4. the output writer with the desired results to be stored to files. ow = create_output_writer(net, time_steps, output_dir) # 5. the main time series function run_timeseries(net, time_steps) '''Try to clear memory''' # for element in dir(): # if element[0:2] != "__": # del globals()[element] # del element del n_timesteps del profiles del ds del time_steps del ow del net gc.collect()
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)
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)
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)
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"]
def low_load(net, n_time_steps, output_dir): _net = net profiles, ds = create_data_source(_net, mode='Low Load', n_timesteps=n_time_steps) _net = create_controllers(_net, ds) time_steps = range(0, n_time_steps) ow = create_output_writer(_net, time_steps, output_dir) run_timeseries(_net, time_steps, calculate_voltage_angles=True)
def gen_discon_low(net, n_time_steps, output_dir): _net = net _net.sgen.in_service[1] = False profiles, ds = create_data_source(_net, mode='Low Load', n_timesteps=n_time_steps) _net = create_controllers(_net, ds) time_steps = range(0, n_time_steps) ow = create_output_writer(_net, time_steps, output_dir) run_timeseries(_net, time_steps, calculate_voltage_angles=True) _net.sgen.in_service[1] = True
def line_discon_low(net, n_time_steps, output_dir): _net = net index_line_5_6 = pp.get_element_index(_net, 'line', 'Line 5 to 6') _net.line.in_service[index_line_5_6] = False profiles, ds = create_data_source(_net, mode='Low Load', n_timesteps=n_time_steps) _net = create_controllers(_net, ds) time_steps = range(0, n_time_steps) ow = create_output_writer(_net, time_steps, output_dir) run_timeseries(_net, time_steps, calculate_voltage_angles=True) _net.line.in_service[index_line_5_6] = True
def timeseries(output_dir, net): # create (random) data source n_timesteps = n #with less timesteps, the knn algorithm will be less accurate profiles, ds = create_data_source(n_timesteps) # create controllers (to c#ontrol P values of the load and the gen) net = create_controllers(net, ds) # time steps to be calculated. Could also be a list with non-consecutive time steps time_steps = range(0, n_timesteps) # the output writer with the desired results to be stored to files. ow = create_output_writer(net, time_steps, output_dir) # the main time series function run_timeseries(net, time_steps)
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())
def timeseries_example(output_dir): # 1. create test net net = overhead_network() # 2. create (random) data source n_timesteps = 24 profiles, ds = create_data_source(n_timesteps) # 3. create controllers (to control P values of the load and the sgen) create_controllers(net, ds) # time steps to be calculated. Could also be a list with non-consecutive time steps time_steps = range(0, n_timesteps) # 4. the output writer with the desired results to be stored to files. ow = create_output_writer(net, time_steps, output_dir=output_dir) # 5. the main time series function run_timeseries(net, time_steps)
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) 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) run_timeseries(net, time_steps) # 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])
def test_default_output_writer(simple_test_net): net = simple_test_net n_timesteps = 5 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) run_timeseries(net, time_steps, verbose=False) ow = net.output_writer.iloc[0, 0] loading_percent = ow.output["res_line.loading_percent"] vm_pu = ow.output["res_bus.vm_pu"] assert loading_percent.shape[0] == n_timesteps and loading_percent.shape[ 1] == len(net.line) assert vm_pu.shape[0] == n_timesteps and vm_pu.shape[1] == len(net.bus)
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
def test_const_control_write_to_object_attribute(simple_test_net): net = simple_test_net profiles, ds = create_data_source() time_steps = range(0, 10) ow = setup_output_writer(net, time_steps) ContinuousTapControl(net, 0, 1., level=1, check_tap_bounds=False) ConstControl(net, 'load', 'p_mw', element_index=0, data_source=ds, profile_name='load1', scale_factor=0.85) ConstControl(net, 'ext_grid', 'vm_pu', element_index=0, data_source=ds, profile_name='slack_v') ConstControl(net, 'controller', 'object.vm_set_pu', element_index=0, data_source=ds, profile_name='trafo_v') run_timeseries(net, time_steps, output_writer=ow, verbose=False) assert np.alltrue(profiles['load1'].values * 0.85 == ow.output['load.p_mw'][0].values) assert np.alltrue( profiles['slack_v'].values == ow.output['res_bus.vm_pu'][0].values) assert np.allclose( profiles['trafo_v'].values, ow.output['res_bus.vm_pu'][net.trafo.at[0, 'lv_bus']].values, atol=1e-3, rtol=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
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
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)
def feas_chk(net, ow, conn_at_bus, loadorgen, size_p, size_q, prof): """ Initializes the PPnet, Adds additional capacity, applies load/generation profiles on all the grid elements, runs timeseries for the specific case and save the results in the temporary output directory, Checks for violations TODO: Need to check process of how profiles from simbench are actually getting applied to Constcontrol know the fix. Also will lead to finding how profiles from input will be applied on the input grid. TODO: suppress/workaround printing of individual progress bars INPUT net (PP net) - Pandapower net ow (Object) - Output writer object loadorgen (str) - 'sgen' or 'load' for generation or load for additional capacity connected conn_at_bus (int) - Bus at which additional capacity is connected size_p (int) - Size of active power of additional capacity size_q (int) - Size of reactive power of additional capacity prof (str) - Name of the profile. Must be available in the net.profiles of the input grid OUTPUT feas_result (bool) - 'True' for feasible, 'False' for not feasible """ init_all = get_init_all(net) net = add_loadgen(net, loadorgen, conn_at_bus, size_p, size_q, prof) profiles = sb.get_absolute_values(net, profiles_instead_of_study_cases=True) sb.apply_const_controllers( net, profiles) # create timeseries data from profiles and run powerflow run_timeseries(net, time_steps, continue_on_divergence=True, verbose=True) # Run powerflow only over time_steps feas_result = violations(net) net = init_net(net, init_all) return feas_result
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
def test_time_steps(simple_test_net): net = simple_test_net n_timesteps = 11 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"]) # correct run_timeseries(net, time_steps=range(0, n_timesteps), verbose=False) # also correct run_timeseries(net, time_steps=[0, 2, 4, 8, 9], verbose=False) # ok. missing time_step list -> should check the datasource run_timeseries(net, verbose=False) # depricated run_timeseries(net, time_steps=(0, 10), verbose=False)
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 time_series(self, output_dir, mode): profiles, ds = self.create_data_source(mode) self.create_controllers(ds) time_steps = range(0, self.n_time_steps) self.create_output_writer(output_dir) run_timeseries(self.net, time_steps, calculate_voltage_angles=True)
# create (random) data source n_timesteps = 24 profiles, ds = create_data_source(n_timesteps) # create controllers (to control P values of the load and the sgen) create_controllers(net, ds) # time steps to be calculated. Could also be a list with non-consecutive time steps time_steps = range(0, n_timesteps) # the output writer with the desired results to be stored to files. ow = create_output_writer(net, time_steps, output_dir=output_dir) # the main time series function with optimal power flow run_timeseries(net, time_steps, run=pp.runopp) # ------------------------- PLOTS -------------------------------------- # We can see that all of the bus voltages are in the defined constraint range according to the OPF # voltage results (min_vm_pu=0.98, max_vm_pu=1.05) vm_pu_file = os.path.join(output_dir, "res_bus", "vm_pu.xlsx") vm_pu = pd.read_excel(vm_pu_file, index_col=0) vm_pu.plot(label="vm_pu") plt.xlabel("time step") plt.ylabel("voltage mag. [p.u.]") plt.title("Voltage Magnitude") plt.grid() plt.show() # All lines should be inside the range of 80 % maximum load # line loading results
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
with open(read_data_file, 'rb') as f: dic_var = pickle.load(f) profil_mob = dic_var["profil_mob"] dic_param_trajets = dic_var["dic_param_trajets"] dic_nblois = dic_var["dic_nblois"] dic_tranchlois = dic_var["dic_tranchlois"] dic_parklois = dic_var["dic_parklois"] dic_dureelois = dic_var["dic_dureelois"] dic_retourdom = dic_var["dic_retourdom"] ow = create_output_writer(net, time_steps, output_dir=output_dir) # 5. the main time series function run_timeseries(net, time_steps, output_writer=ow) ecart_base = calc_ecart_tension(output_dir, drop = [0,1,2,3]) # line loading results #plot_graph(output_dir, "res_line", "loading_percent.xls", "line loading [%]","Line Loading") # load results exploit_graph.plot_graph(output_dir, "res_bus", "p_mw.csv","P [MW]", "Bus Loads", drop = [0,1,2,3,4,5] ) # voltage results exploit_graph.plot_graph(output_dir, "res_bus", "vm_pu.csv", "voltage mag. [p.u.]","Voltage Magnitude") exploit_graph.plot_graph(output_dir, "res_sgen","q_mvar.csv", "Q [MVAr]", "Prod Reactive Power")
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)