<commit_before>__author__ = '<NAME>, <EMAIL>'

""" This example demonstrates how to use the state estimator by using data from
Problem 6.7 in 'Computational Methods for Electric Power Systems' by Mariesa
Crow."""

import sys

from pylon import Case, StateEstimator, Measurement, PF, PT, PG, VM
from pylon.readwrite import ReSTWriter

from cvxopt import matrix

DATA_FILE = "../pylon/test/data/case3bus_P6_6.pkl"

# Load the case file.
case = Case.load(DATA_FILE)

# Specify the measurements.
measurements = [
    Measurement(case.branches[0], PF, 0.12),
    Measurement(case.branches[1], PF, 0.10),
    Measurement(case.branches[2], PT, -0.04),
    Measurement(case.buses[0], PG, 0.58),
    Measurement(case.buses[1], PG, 0.30),
    Measurement(case.buses[2], PG, 0.14),
    Measurement(case.buses[1], VM, 1.04),
    Measurement(case.buses[2], VM, 0.98)
]

# Specify measurement variances (ordered: PF, PT, QF, QT, PG, QG, VM, VA).
sigma = matrix([0.02, 0.02, 0.0, 0.0, 0.015, 0.0, 0.01, 0.0])

# Create a state estimator...
se = StateEstimator(case, measurements, sigma)
# ...and run it.
sol = se.run()

# Write out the power flow solution...
ReSTWriter(case).write(sys.stdout)
# ...and a measurement comparison.
se.output_solution(sys.stdout, sol["z"], sol["z_est"], sol["error_sqrsum"])<commit_msg>Removing ReSTWriter import.<commit_after>__author__ = '<NAME>, <EMAIL>'

""" This example demonstrates how to use the state estimator by using data from
Problem 6.7 in 'Computational Methods for Electric Power Systems' by <NAME>."""

import sys

from pylon import Case, StateEstimator, Measurement, PF, PT, PG, VM

from cvxopt import matrix

DATA_FILE = "../pylon/test/data/case3bus_P6_6.pkl"

# Load the case file.
case = Case.load(DATA_FILE)

# Specify the measurements.
measurements = [
    Measurement(case.branches[0], PF, 0.12),
    Measurement(case.branches[1], PF, 0.10),
    Measurement(case.branches[2], PT, -0.04),
    Measurement(case.buses[0], PG, 0.58),
    Measurement(case.buses[1], PG, 0.30),
    Measurement(case.buses[2], PG, 0.14),
    Measurement(case.buses[1], VM, 1.04),
    Measurement(case.buses[2], VM, 0.98)
]

# Specify measurement variances (ordered: PF, PT, QF, QT, PG, QG, VM, VA).
sigma = matrix([0.02, 0.02, 0.0, 0.0, 0.015, 0.0, 0.01, 0.0])

# Create a state estimator...
se = StateEstimator(case, measurements, sigma)
# ...and run it.
sol = se.run()

# Write out the power flow solution...
case.save_rst(sys.stdout)

# ...and a measurement comparison.
se.output_solution(sys.stdout, sol["z"], sol["z_est"], sol["error_sqrsum"])
{'fraction_non_alphanumeric': 0.15996878657822863, 'fraction_numerical': 0.04525946156847444, 'mean_word_length': 4.158953722334004, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2932591', 'n_tokens_mistral': 1031, 'n_tokens_neox': 924, 'n_words': 262}