def get_batch_outputs(self, net, recycle_options): # read the results in batch from vm, va (ppci values) if isinstance(recycle_options["batch_read"], list) and len(recycle_options["batch_read"]): # vm, va is without out of service elements vm, va = self.output["ppc_bus.vm"], self.output["ppc_bus.va"] _, s_abs, i_abs = v_to_i_s(net, vm, va) results = dict() new_output_list = list() for table, variable in recycle_options["batch_read"]: if table == "res_line" and "res_line" not in results: i_ka, i_from_ka, i_to_ka, loading_percent = get_batch_line_results(net, i_abs) results["res_line"] = dict(i_ka=i_ka, i_from_ka=i_from_ka, i_to_ka=i_to_ka, loading_percent=loading_percent) elif table == "res_trafo" and "res_trafo" not in results: i_ka, i_hv_ka, i_lv_ka, s_mva, loading_percent = get_batch_trafo_results(net, i_abs, s_abs) results["res_trafo"] = dict(i_ka=i_ka, i_hv_ka=i_hv_ka, i_lv_ka=i_lv_ka, loading_percent=loading_percent) elif table == "res_trafo3w": i_h, i_m, i_l, loading_percent = get_batch_trafo3w_results(net, i_abs, s_abs) results["res_trafo3w"] = dict(i_h=i_h, i_m=i_m, i_l=i_l, loading_percent=loading_percent) elif table == "res_bus" and "res_bus" not in results: vm_full, va_full = get_batch_bus_results(net, vm, va) results["res_bus"] = dict(vm_pu=vm_full, va_degree=va_full) else: raise ValueError("Something went wrong") output_name = "%s.%s" % (table, variable) # convert to dataframe self.output[output_name] = pd.DataFrame(data=results[table][variable], index=self.time_steps) new_output_list.append((table, variable)) self.output_list = new_output_list
def test_batch_output_reader(simple_test_net): net = simple_test_net _, ds = create_data_source(n_timesteps) # 1load c = add_const(net, ds, recycle=True) 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') recycle = dict(trafo=False, gen=False, bus_pq=True) only_v = True pp.runpp(net, only_v_results=only_v, recycle=recycle) run_timeseries(net, time_steps, recycle=recycle, only_v_results=only_v, verbose=False) vm, va = ow.output["ppc_bus.vm"], ow.output["ppc_bus.va"] # ppc was removed (set to None) in cleanup() after the timeseries was over. now we have to remake the net._ppc by running the power flow again pp.runpp(net, only_v_results=only_v, recycle=recycle) s, s_abs, i_abs = v_to_i_s(net, vm, va) del net, ow, c net = simple_test_net net.output_writer.drop(index=net.output_writer.index, inplace=True) net.controller.drop(index=net.controller.index, inplace=True) add_const(net, ds, recycle=False) ow = OutputWriter(net, output_path=tempfile.gettempdir(), output_file_type=".json", log_variables=list()) ow.log_variable('res_line', 'i_from_ka') ow.log_variable('res_line', 'loading_percent') ow.log_variable('res_line', 'i_to_ka') ow.log_variable('res_line', 'loading_percent') ow.log_variable('res_trafo', 'loading_percent') ow.log_variable('res_trafo', 'i_hv_ka') ow.log_variable('res_trafo', 'i_lv_ka') ow.log_variable('res_trafo3w', 'loading_percent') ow.log_variable('res_trafo3w', 'i_hv_ka') ow.log_variable('res_trafo3w', 'i_mv_ka') ow.log_variable('res_trafo3w', 'i_lv_ka') ow.log_variable('res_bus', 'vm_pu') ow.log_variable('res_bus', 'va_degree') pp.runpp(net) run_timeseries(net, time_steps, trafo_loading="current", verbose=False) vm_pu, va_degree = ow.output["res_bus.vm_pu"], ow.output[ "res_bus.va_degree"] i_from_ka_normal, i_to_ka_normal = ow.output[ "res_line.i_from_ka"], ow.output["res_line.i_to_ka"] i_hv_ka_normal, i_lv_ka_normal = ow.output["res_trafo.i_hv_ka"], ow.output[ "res_trafo.i_lv_ka"] i3_hv_ka, i3_lm_ka, i3_lv_ka = ow.output["res_trafo3w.i_hv_ka"], ow.output["res_trafo3w.i_mv_ka"], \ ow.output["res_trafo3w.i_lv_ka"] t3_loading_percent_normal = ow.output["res_trafo3w.loading_percent"] loading_percent_normal = ow.output["res_line.loading_percent"] t_loading_percent_normal = ow.output["res_trafo.loading_percent"] v_normal = polar_to_rad(vm_pu, va_degree) v_batch = polar_to_rad(vm, va) i_ka, i_from_ka, i_to_ka, loading_percent = get_batch_line_results( net, i_abs) i_ka, i_hv_ka, i_lv_ka, s_mva, ld_trafo = get_batch_trafo_results( net, i_abs, s_abs) i_h, i_m, i_l, ld3_trafo = get_batch_trafo3w_results(net, i_abs, s_abs) # v batch contains aux buses of trafo3w. we can only compare non aux bus voltages assert np.allclose(v_normal, v_batch[:, :v_normal.shape[1]]) # line loading assert np.allclose(i_from_ka_normal, i_from_ka) assert np.allclose(i_to_ka_normal, i_to_ka) assert np.allclose(loading_percent_normal, loading_percent) # trafo assert np.allclose(i_hv_ka_normal, i_hv_ka) assert np.allclose(i_lv_ka_normal, i_lv_ka) assert np.allclose(t_loading_percent_normal, ld_trafo) # trafo3w assert np.allclose(i3_hv_ka, i_h) assert np.allclose(i3_lm_ka, i_m) assert np.allclose(i3_lv_ka, i_l) assert np.allclose(t3_loading_percent_normal, ld3_trafo)