def test_deviation_from_std_type(test_net, diag_params, diag_errors, report_methods): net = copy.deepcopy(test_net) check_function = 'deviation_from_std_type' diag_params = copy.deepcopy(diag_params) report_methods = copy.deepcopy(report_methods) net.line.r_ohm_per_km.loc[0] += 1 net.line.x_ohm_per_km.loc[6] -= 1 net.line.c_nf_per_km.loc[14] *= -1 net.line.max_i_ka.loc[21] = '5' pp.change_std_type(net, 0, element='trafo', name='160 MVA 380/110 kV') net.trafo.vk_percent.loc[0] *= 2 check_result = pp.deviation_from_std_type(net) if check_result: diag_results = {check_function: check_result} else: diag_results = {} assert diag_results[check_function] == \ {'line': {0: {'e_value': 1.1571, 'param': 'r_ohm_per_km', 'std_type_in_lib': True, 'std_type_value': 0.1571}, 6: {'e_value': -0.883, 'param': 'x_ohm_per_km', 'std_type_in_lib': True, 'std_type_value': 0.117}, 14: {'e_value': -264.0, 'param': 'c_nf_per_km', 'std_type_in_lib': True, 'std_type_value': 264}, 21: {'e_value': '5', 'param': 'max_i_ka', 'std_type_in_lib': True, 'std_type_value': 0.105}}, 'trafo': {0: {'e_value': 24.4, 'param': 'vk_percent', 'std_type_in_lib': True, 'std_type_value': 12.2}} } for bool_value in [True, False]: diag_report = DiagnosticReports(net, diag_results, diag_errors, diag_params, compact_report=bool_value) report_check = None try: eval(report_methods[check_function]) report_check = True except: report_check = False assert report_check
def pp2csv_data(net1, export_pp_std_types=False, drop_inactive_elements=True, highest_existing_coordinate_number=-1, round_qLoad_by_voltLvl=False, reserved_aux_node_names=None): """ Internal functionality of pp2csv, but without writing the determined dict to csv files. For parameter explanations, please have a look at the pp2csv() docstring. """ # --- initializations net = deepcopy( net1) # necessary because in net will be changed in converter function csv_data = _init_csv_tables( ['elements', 'profiles', 'types', 'res_elements']) aux_nodes_are_reserved = reserved_aux_node_names is not None # --- net data preparation for converting _extend_pandapower_net_columns(net) if drop_inactive_elements: # attention: trafo3ws are not considered in current version of drop_inactive_elements() pp.drop_inactive_elements(net, respect_switches=False) check_results = pp.deviation_from_std_type(net) if check_results: logger.warning( "There are deviations from standard types in elements: " + str(["%s" % elm for elm in check_results.keys()]) + ". Only the standard " + "type values are converted to csv.") convert_parallel_branches(net) if net.bus.shape[0] and not net.bus_geodata.shape[0] or ( net.bus_geodata.shape[0] != net.bus.shape[0]): logger.info( "Since there are no or incomplete bus_geodata, generic geodata are assumed." ) net.bus_geodata.drop(net.bus_geodata.index, inplace=True) create_generic_coordinates(net) merge_busbar_coordinates(net) move_slack_gens_to_ext_grid(net) scaling_is_not_1 = [] for i in pp.pp_elements(): # prevent elements without name net[i] = ensure_full_column_data_existence(net, i, 'name') avoid_duplicates_in_column(net, i, 'name') # log scaling factor different from 1 if "scaling" in net[i].columns: if not np.allclose(net[i]["scaling"].values, 1): scaling_is_not_1 += [i] if len(scaling_is_not_1): logger.warning("In elements " + str(scaling_is_not_1) + ", the parameter 'scaling' " + "differs from 1, which is not converted.") # log min_e_mwh if not np.allclose(net.storage["min_e_mwh"].dropna().values, 0.): logger.warning( "Storage parameter 'min_e_mwh' is not converted but differs from 0." ) # further preparation provide_subnet_col(net) provide_voltLvl_col(net) provide_substation_cols(net) convert_node_type(net) _add_dspf_calc_type_and_phys_type_columns(net) _add_vm_va_setpoints_to_buses(net) _prepare_res_bus_table(net) reserved_aux_node_names = replace_branch_switches(net, reserved_aux_node_names) _convert_measurement(net) _add_coordID(net, highest_existing_coordinate_number) if not net["trafo"]["autoTapSide"].isnull().all(): net["trafo"]["autoTapSide"] = net["trafo"]["autoTapSide"].str.upper() # --- convert net _pp_profiles_to_csv(net, csv_data) if "loadcases" in net: csv_data["StudyCases"] = net["loadcases"] else: csv_data["StudyCases"] = pd.DataFrame() _pp_types_to_csv1(net, export_pp_std_types) _multi_parameter_determination(net) _convert_elements_and_types(net, csv_data) _pp_types_to_csv2(csv_data) if round_qLoad_by_voltLvl: _round_qLoad_by_voltLvl(csv_data) # --- post_conversion_checks _check_id_voltLvl_subnet(csv_data) if aux_nodes_are_reserved: return csv_data, reserved_aux_node_names else: return csv_data