test_switch_nv_state_estimator.py 2.01 KB
Newer Older
Martin Alonso Moraga's avatar
Martin Alonso Moraga committed
1
2
import logging
import numpy as np
Markus Mirz's avatar
Markus Mirz committed
3
4
5
6
7
from pyvolt import network
from pyvolt import nv_powerflow
from pyvolt import nv_state_estimator
from pyvolt import measurement
from pyvolt import results
Martin Alonso Moraga's avatar
Martin Alonso Moraga committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import cimpy
import os

logging.basicConfig(filename='CIGRE.log', level=logging.INFO, filemode='w')

xml_path = r".\sample_data\CIGRE-MV-NoTap-WithBreaker"
xml_files = [xml_path + r"\20191126T1535Z_YYY_EQ_.xml",
             xml_path + r"\20191126T1535Z_XX_YYY_SV_.xml",
             xml_path + r"\20191126T1535Z_XX_YYY_TP_.xml"]

xml_files_abs = []
for file in xml_files:
    xml_files_abs.append(os.path.abspath(file))

# read cim files and create new network.Systen object
Martin Alonso Moraga's avatar
Martin Alonso Moraga committed
23
res, _ = cimpy.cim_import(xml_files_abs, "cgmes_v2_4_15")
Martin Alonso Moraga's avatar
Martin Alonso Moraga committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
system = network.System()
base_apparent_power = 25  # MW
system.load_cim_data(res, base_apparent_power)

#open breaker
system.breakers[-1].open_breaker()
system.Ymatrix_calc()

# Execute power flow analysis
results_pf, num_iter = nv_powerflow.solve(system)

# --- State Estimation ---
""" Write here the percent uncertainties of the measurements"""
V_unc = 0
I_unc = 0
Sinj_unc = 0
S_unc = 0
Pmu_mag_unc = 1
Pmu_phase_unc = 0

# Create measurements data structures
"""use all node voltages as measures"""
measurements_set = measurement.MeasurementSet()
for node in results_pf.nodes:
    measurements_set.create_measurement(node.topology_node, measurement.ElemType.Node, measurement.MeasType.Vpmu_mag,
                                        np.absolute(node.voltage_pu), Pmu_mag_unc)
for node in results_pf.nodes:
    measurements_set.create_measurement(node.topology_node, measurement.ElemType.Node, measurement.MeasType.Vpmu_phase,
                                        np.angle(node.voltage_pu), Pmu_phase_unc)
measurements_set.meas_creation()

# Perform state estimation
state_estimation_results = nv_state_estimator.DsseCall(system, measurements_set)

# print node voltages
print("state_estimation_results.voltages: ")
for node in state_estimation_results.nodes:
    print('{}={}'.format(node.topology_node.name, node.voltage))