|
1 | | -from unittest.mock import Mock |
2 | | - |
3 | 1 | import pandas as pd |
4 | 2 | import pytest |
5 | 3 | from pandas.testing import assert_frame_equal, assert_series_equal |
6 | 4 |
|
7 | | -from prereise.gather.griddata.hifld import const |
8 | 5 | from prereise.gather.griddata.hifld.data_process.transmission import ( |
9 | 6 | add_b2bs_to_dc_lines, |
10 | 7 | add_lines_impedances_ratings, |
|
13 | 10 | augment_line_voltages, |
14 | 11 | create_buses, |
15 | 12 | create_transformers, |
16 | | - estimate_branch_impedance, |
17 | | - estimate_branch_rating, |
18 | 13 | filter_islands_and_connect_with_mst, |
19 | 14 | map_lines_to_substations_using_coords, |
20 | 15 | split_lines_to_ac_and_dc, |
@@ -185,71 +180,49 @@ def test_create_transformers(): |
185 | 180 | }, |
186 | 181 | dtype="float", |
187 | 182 | ) |
188 | | - expected_transformers = pd.DataFrame( |
189 | | - {"from_bus_id": [0, 2, 4, 5], "to_bus_id": [1, 3, 5, 6]} |
190 | | - ) |
191 | | - transformers = create_transformers(bus) |
192 | | - assert_frame_equal(transformers, expected_transformers) |
193 | | - |
194 | | - |
195 | | -def test_estimate_branch_impedance_lines(): |
196 | | - resistance = 0.01 |
197 | | - reactance = 0.1 |
198 | | - fake_lines = [Mock(series_impedance=(resistance + 1j * reactance))] * 3 |
199 | | - branch = pd.DataFrame( |
200 | | - {"VOLTAGE": [69, 70, 345], "type": ["Line"] * 3, "line_object": fake_lines} |
| 183 | + transformer_designs = pd.DataFrame( |
| 184 | + { |
| 185 | + "x": [0.19, 0.07, 0.044, 0.018], |
| 186 | + "r": [0.01, 0.001, 0.001, 5e-4], |
| 187 | + "MVA": [60, 250, 280, 580], |
| 188 | + }, |
| 189 | + index=pd.MultiIndex.from_tuples([(69, 115), (69, 345), (115, 230), (230, 345)]), |
201 | 190 | ) |
202 | | - x = estimate_branch_impedance(branch.iloc[0], pd.Series()) |
203 | | - assert x == reactance / (69**2 / const.s_base) |
204 | | - x = estimate_branch_impedance(branch.iloc[1], pd.Series()) |
205 | | - assert x == reactance / (70**2 / const.s_base) |
206 | | - x = estimate_branch_impedance(branch.iloc[2], pd.Series()) |
207 | | - assert x == reactance / (345**2 / const.s_base) |
208 | | - |
209 | | - |
210 | | -def test_estimate_branch_impedance_transformers(): |
211 | | - transformers = pd.DataFrame( |
212 | | - {"from_bus_id": [0, 1, 2], "to_bus_id": [1, 2, 3], "type": ["Transformer"] * 3} |
| 191 | + lines = pd.DataFrame( |
| 192 | + [ |
| 193 | + # One branch to low-voltage side of buses (0, 1) transformer |
| 194 | + {"from_bus_id": 100, "to_bus_id": 0, "rateA": 75}, |
| 195 | + # Two branches to high-voltage side of buses (0, 1) transformer |
| 196 | + {"from_bus_id": 1, "to_bus_id": 101, "rateA": 100}, |
| 197 | + {"from_bus_id": 1, "to_bus_id": 102, "rateA": 300}, |
| 198 | + # Two branches to low-voltage side of buses (2, 3) transformer |
| 199 | + {"from_bus_id": 103, "to_bus_id": 2, "rateA": 50}, |
| 200 | + {"from_bus_id": 104, "to_bus_id": 2, "rateA": 100}, |
| 201 | + # One branch to high-voltage side of buses (2, 3) transformer |
| 202 | + {"from_bus_id": 3, "to_bus_id": 105, "rateA": 300}, |
| 203 | + # One branch to each side of buses (5, 6) transformer |
| 204 | + # The second of these is also on the high-voltage side of buses (4, 5) xfmr |
| 205 | + {"from_bus_id": 6, "to_bus_id": 106, "rateA": 500}, |
| 206 | + {"from_bus_id": 5, "to_bus_id": 107, "rateA": 250}, |
| 207 | + # One branch connected to no transformers |
| 208 | + {"from_bus_id": 998, "to_bus_id": 999, "rateA": 100e3}, |
| 209 | + ] |
213 | 210 | ) |
214 | | - bus_voltages = pd.Series([69, 230, 350, 500]) |
215 | | - x = estimate_branch_impedance(transformers.iloc[0], bus_voltages) |
216 | | - assert x == const.transformer_reactance[(69, 230)] |
217 | | - x = estimate_branch_impedance(transformers.iloc[1], bus_voltages) |
218 | | - assert x == const.transformer_reactance[(230, 345)] |
219 | | - x = estimate_branch_impedance(transformers.iloc[2], bus_voltages) |
220 | | - assert x == const.transformer_reactance[(345, 500)] |
221 | | - |
222 | | - |
223 | | -def test_estimate_branch_rating_lines(): |
224 | | - fake_ratings = pd.Series([10, 20, 30, 40]) |
225 | | - fake_thermal_ratings = pd.Series([100, 200, 300, 400]) |
226 | | - fake_lines = [Mock(power_rating=i) for i in fake_ratings] |
227 | | - branch = pd.DataFrame( |
| 211 | + # One transformer to (0, 1) (only needs to support the low-voltage power) |
| 212 | + # Three transformer to (2, 3) (low-voltage side requires 3x transformers in total) |
| 213 | + # One transformer to (4, 5) (only needs to support the low-voltage power) |
| 214 | + # One transformer to (5, 6) (only needs to support the low-voltage power) |
| 215 | + expected_transformers = pd.DataFrame( |
228 | 216 | { |
229 | | - "VOLTAGE": [69, 140, 345, 499], |
230 | | - "type": ["Line"] * 4, |
231 | | - "line_object": fake_lines, |
| 217 | + "from_bus_id": [0, 2, 2, 2, 4, 5], |
| 218 | + "to_bus_id": [1, 3, 3, 3, 5, 6], |
| 219 | + "x": [0.07, 0.19, 0.19, 0.19, 0.044, 0.018], |
| 220 | + "r": [0.001, 0.01, 0.01, 0.01, 0.001, 5e-4], |
| 221 | + "rateA": [250.0, 60.0, 60.0, 60.0, 280.0, 580.0], |
232 | 222 | } |
233 | 223 | ) |
234 | | - assert_series_equal( |
235 | | - fake_ratings, |
236 | | - branch.apply(estimate_branch_rating, args=[None, fake_thermal_ratings], axis=1), |
237 | | - ) |
238 | | - |
239 | | - |
240 | | -def test_estimate_branch_rating_transformers(): |
241 | | - thermal_ratings = pd.Series([100, 550, 1655, 2585], index=[69, 230, 345, 500]) |
242 | | - transformers = pd.DataFrame( |
243 | | - {"from_bus_id": [0, 1, 2], "to_bus_id": [1, 2, 3], "type": ["Transformer"] * 3} |
244 | | - ) |
245 | | - bus_voltages = pd.Series([69, 230, 350, 500]) |
246 | | - |
247 | | - rating = estimate_branch_rating(transformers.iloc[0], bus_voltages, thermal_ratings) |
248 | | - assert rating == const.transformer_rating |
249 | | - rating = estimate_branch_rating(transformers.iloc[1], bus_voltages, thermal_ratings) |
250 | | - assert rating == const.transformer_rating * 3 |
251 | | - rating = estimate_branch_rating(transformers.iloc[2], bus_voltages, thermal_ratings) |
252 | | - assert rating == const.transformer_rating * 4 |
| 224 | + transformers = create_transformers(bus, lines, transformer_designs) |
| 225 | + assert_frame_equal(transformers, expected_transformers) |
253 | 226 |
|
254 | 227 |
|
255 | 228 | def test_filter_islands_and_connect_with_mst(): |
|
0 commit comments