Advertisement
pdb5627

line_design_v_vs_p

Feb 18th, 2023
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.96 KB | Source Code | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from scipy.optimize import curve_fit
  4. from functools import partial
  5. import pandapower
  6. import pandapower.networks as pn
  7. import matplotlib.pyplot as plt
  8.  
  9. """
  10. Code to explore the question raised at
  11. https://electronics.stackexchange.com/questions/654161/what-is-the-relationship-between-a-power-lines-voltage-and-the-amount-of-power/
  12.  
  13. Environment requirements:
  14. matplotlib, numba, numpy, scipy, pandapower
  15. """
  16.  
  17.  
  18. matpower_loader = pandapower.converter.from_mpc
  19.  
  20. """
  21. References for test cases:
  22. https://pandapower.readthedocs.io/en/latest/networks/power_system_test_cases.html
  23.  
  24. https://egriddata.org/group/electric-grid-test-case-repository
  25.  
  26. """
  27.  
  28. # https://egriddata.org/sites/default/files/case_ACTIVSg2000.m
  29. ACTIVSg2000 = partial(matpower_loader, 'case_ACTIVSg2000.m')
  30.  
  31.  
  32. # https://egriddata.org/sites/default/files/case_ACTIVSg70k.m
  33. ACTIVSg70k = partial(matpower_loader, 'case_ACTIVSg70k.m')
  34.  
  35.  
  36. case_loaders = [pn.case2869pegase,
  37.          pn.case3120sp,
  38.          # pn.GBnetwork,  # No rating information
  39.          # pn.iceland,    # No rating information
  40.          ACTIVSg2000,
  41.          ACTIVSg70k]
  42. #case_loaders = [ACTIVSg70k]
  43.          
  44.          
  45. def extract_line_info(net):
  46.     lines_w_ratings = net.line[net.line['max_i_ka'] > 0]
  47.     df = pd.merge(lines_w_ratings, net.bus, left_on='from_bus', right_index=True)
  48.     df = df[['max_i_ka', 'vn_kv']]
  49.     # Some datasets use kA value of 99999 presumably for no info.
  50.     df = df[(df['vn_kv'] > 0) & (df['max_i_ka'] < 99998)]
  51.     df['max_mva'] = df['max_i_ka']*df['vn_kv']*1.732
  52.    
  53.     # Some datasets use MVA value of 9900 presumably for no info.
  54.     df = df[df['max_mva'] < 9000]
  55.    
  56.     print(f"Min KA rating: {df['max_i_ka'].min()}")
  57.     print(f"Max KA rating: {df['max_i_ka'].max()}")
  58.     print(f"Min MVA rating: {df['max_mva'].min()}")
  59.     print(f"Max MVA rating: {df['max_mva'].max()}")
  60.     print(f"Number of lines: {len(df)}")
  61.     return df
  62.    
  63.  
  64. nets = []
  65. for i, loader in enumerate(case_loaders):
  66.     print(f'Loading case {i}')
  67.     nets.append(extract_line_info(loader()))
  68.  
  69. data = pd.concat(nets)
  70.  
  71. plt.plot(data['vn_kv'], data['max_mva'], '.', label='Individual Lines')
  72.  
  73. print('Voltage levels:')
  74. print(np.sort(data['vn_kv'].unique()))
  75.  
  76. data_grouped = data.groupby('vn_kv')
  77.  
  78. print(data_grouped.describe())
  79.  
  80. mean_by_voltage = data_grouped['max_mva'].mean()
  81. plt.plot(mean_by_voltage.index, mean_by_voltage, '*', label='Mean by voltage')
  82.  
  83.  
  84. def power_curve(x, m):
  85.     return x**m
  86.    
  87.  
  88. [m_fit], cov = curve_fit(power_curve, mean_by_voltage.index, mean_by_voltage)
  89.  
  90. print(f'Best fit for power curve: m={m_fit}')
  91.  
  92. plot_xs = np.linspace(mean_by_voltage.index.min(), mean_by_voltage.index.max())
  93.  
  94. plt.plot(plot_xs, power_curve(plot_xs, m_fit), label=f'Power curve, m={m_fit:.2f}')
  95.  
  96.  
  97. """
  98. def exp_curve(x, a, b):
  99.    return a*np.exp(b*x)
  100.    
  101. y1, y2 = mean_by_voltage.iloc[[0, -1]]
  102. x1, x2 = mean_by_voltage.index[[0, -1]]
  103. b = (np.log(y1) - np.log(y2)) / (x1 - x2)
  104. a = (np.log(y1) + np.log(y2) - b*(x1 + x2)) / 2
  105. p0 = (a, b)
  106. params, cov = curve_fit(exp_curve, mean_by_voltage.index, mean_by_voltage, p0=p0)
  107. plt.plot(plot_xs, exp_curve(plot_xs, *params))
  108. """
  109.  
  110. """
  111. def quadratic_curve(x, a, b, c):
  112.    return a*x**2 + b*x + c
  113.    
  114.  
  115. params, cov = curve_fit(quadratic_curve, mean_by_voltage.index, mean_by_voltage)
  116.  
  117. print(f'Best fit for quadratic curve: a={params[0]}, b={params[1]}, c={params[2]}')
  118. plt.plot(plot_xs, quadratic_curve(plot_xs, *params))
  119. """
  120.  
  121. def quadratic_curve2(x, a, b):
  122.     c = 0
  123.     return a*x**2 + b*x + c
  124.    
  125.  
  126. params, cov = curve_fit(quadratic_curve2, mean_by_voltage.index, mean_by_voltage)
  127. (a, b), c = params, 0
  128.  
  129. print(f'Best fit for quadratic curve: a={a}, b={b}, c={c}')
  130. plt.plot(plot_xs, quadratic_curve2(plot_xs, *params), label=f'Quadratic curve, a={a:.3f}, b={b:.2f}, c={c:.2f}')
  131.  
  132. plt.title('Overhead Transmission Lines')
  133. plt.xlabel('Line Voltage (kV)')
  134. plt.ylabel('Line Capacity (MVA)')
  135. plt.grid(True)
  136. plt.legend()
  137. plt.show()
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement