History of matpower
The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.
[entries] Remove superfluous details of the upstream distribution from the descriptions dc07aa0
The descriptions mentioned incidental details of how the upstream data are made available: the file formats (CSV, JSON, XML, GEXF, SBML, HIF, Pajek, UCINET, ...), file names, where the files were published or obtained from (Zenodo, figshare, Kaggle, the Pajek datasets page, the Internet Archive), and that some networks are only available in the gt format. These are left out; caveats about the data themselves are kept, referring to "the data" instead of "the file". The description of sp_baboons now lists its properties instead of the upstream columns, and says that events without a recipient are left out.
diff --git a/entries/matpower/__init__.py b/entries/matpower/__init__.py
index b52e926..e696b5c 100644
--- a/entries/matpower/__init__.py
+++ b/entries/matpower/__init__.py
@@ -20,18 +20,18 @@ import re
from .. import *
title = "MATPOWER power grid test cases (1962-2025)"
-description = """Electrical power systems distributed as test cases (`case*.m` files) with MATPOWER, the open-source MATLAB package for power flow and optimal power flow computations by Zimmerman, Murillo-Sánchez and Thomas. Nodes are buses (substations or connection points) and directed edges are branches (transmission lines, cables and transformers), directed from the "from" bus to the "to" bus of the branch (for transformers, the tap ratio and phase shift apply at the "from" side). Parallel branches are kept as multiple edges. Generators are not represented as nodes; their data are aggregated at the buses they are connected to. DC lines (present in two cases) are not included.
+description = """Electrical power systems distributed as test cases with MATPOWER, the open-source MATLAB package for power flow and optimal power flow computations by Zimmerman, Murillo-Sánchez and Thomas. Nodes are buses (substations or connection points) and directed edges are branches (transmission lines, cables and transformers), directed from the "from" bus to the "to" bus of the branch (for transformers, the tap ratio and phase shift apply at the "from" side). Parallel branches are kept as multiple edges. Generators are not represented as nodes; their data are aggregated at the buses they are connected to. DC lines (present in two cases) are not included.
-The test cases come from many sources, which are described in each case file. They include:
+The test cases come from many sources, which are described in each test case. They include:
- Classic IEEE test cases and textbook examples: `case4gs`, `case5`, `case6ww`, `case9` (and variants `case9Q`, `case9target`), `case14`, `case24_ieee_rts`, `case30` (and variants `case30Q`, `case30pwl`, `case_ieee30`), `case39` (New England), `case57`, `case59` (Australian), `case60nordic`, `case118`, `case145`, `case300`.
- The Polish transmission system at several dates between 1999 and 2008: `case2383wp`, `case2736sp`, `case2737sop`, `case2746wop`, `case2746wp`, `case3012wp`, `case3120sp`, `case3375wp`.
- Parts of the European high-voltage transmission system from the PEGASE project: `case89pegase`, `case1354pegase`, `case2869pegase`, `case8387pegase`, `case9241pegase`, `case13659pegase` (Fliscounakis et al., 2013; Josz et al., 2016).
- Snapshots of the French transmission system from RTE: `case1888rte`, `case1951rte`, `case2848rte`, `case2868rte`, `case6468rte`, `case6470rte`, `case6495rte`, `case6515rte` (Josz et al., 2016).
- Synthetic grids of the ACTIVSg project, which resemble the grids of US regions without containing real infrastructure data: `case_ACTIVSg200` (Illinois), `case_ACTIVSg500` (South Carolina), `case_ACTIVSg2000` (Texas), `case_ACTIVSg10k` (western US), `case_ACTIVSg25k` (northeastern US), `case_ACTIVSg70k` (eastern US), and `case_SyntheticUSA` (combined US, 82,000 buses) (Birchfield et al., 2017).
-- Radial distribution systems from the literature, e.g. `case10ba`, `case12da`, `case33bw`, `case69`, `case118zh`, `case136ma`, `case141`, `case533mt_hi`, `case533mt_lo`, `case1197`. For these cases, the unit conversions performed by the case files (branch impedances from ohms to per unit, loads from kW to MW, and, for `case141`, loads from kVA using a power factor of 0.85) have been applied.
+- Radial distribution systems from the literature, e.g. `case10ba`, `case12da`, `case33bw`, `case69`, `case118zh`, `case136ma`, `case141`, `case533mt_hi`, `case533mt_lo`, `case1197`. For these cases, the unit conversions performed by the test cases (branch impedances from ohms to per unit, loads from kW to MW, and, for `case141`, loads from kVA using a power factor of 0.85) have been applied.
-The RTS-GMLC test case is not included, since its data use agreement requires reproducing a notice with every copy.
+The RTS-GMLC test case is not included.
The networks have the following properties (in MATPOWER's units: powers in MW and MVAr, voltages in per unit of the base voltage, angles in degrees, impedances in per unit of the system base `base_mva`, a graph property):
[entries] Lay out the spatial networks with hfd_layout() instead of cfd_layout() cc3bcb0
Changed: none
diff --git a/entries/matpower/__init__.py b/entries/matpower/__init__.py
index 3b3280f..b52e926 100644
--- a/entries/matpower/__init__.py
+++ b/entries/matpower/__init__.py
@@ -219,6 +219,6 @@ def parse(alts=None):
def get_pos(g, sbm_fit):
- # Spatial network: laid out with the default parameters of cfd_layout(),
+ # Spatial network: laid out with the default parameters of hfd_layout(),
# without the partition of the SBM fit
- return cfd_layout(g)
+ return hfd_layout(g)
[entries] Add the date when each entry was added, and remove icon_hash beff7c9
The dates are those of the commits that first added the entries' files (2020-08-11 for the entries of the initial commit); renamed entries keep the date of their first name. Changed: none
diff --git a/entries/matpower/__init__.py b/entries/matpower/__init__.py
index e54002d..3b3280f 100644
--- a/entries/matpower/__init__.py
+++ b/entries/matpower/__init__.py
@@ -58,7 +58,7 @@ citation = [('R. D. Zimmerman, C. E. Murillo-Sánchez, R. J. Thomas, "MATPOWER:
('S. Fliscounakis, P. Panciatici, F. Capitanescu, L. Wehenkel, "Contingency Ranking With Respect to Overloads in Very Large Power Systems Taking Into Account Uncertainty, Preventive, and Corrective Actions." IEEE Transactions on Power Systems 28(4), 4909-4917 (2013)', 'https://doi.org/10.1109/TPWRS.2013.2251015'),
('C. Josz, S. Fliscounakis, J. Maeght, P. Panciatici, "AC Power Flow Data in MATPOWER and QCQP Format: iTesla, RTE Snapshots, and PEGASE." arXiv:1603.01533 (2016)', 'https://arxiv.org/abs/1603.01533'),
('A. B. Birchfield, T. Xu, K. M. Gegner, K. S. Shetye, T. J. Overbye, "Grid Structural Characteristics as Validation Criteria for Synthetic Networks." IEEE Transactions on Power Systems 32(4), 3258-3265 (2017)', 'https://doi.org/10.1109/TPWRS.2016.2616385')]
-icon_hash = '56a85c8e26855e083a2f795c'
+date_added = '2026-10-25'
upstream_license = ("Various; see the individual case files (many are CC BY 4.0)",
"https://github.com/MATPOWER/matpower/blob/1a828c7af590714499284e36ee9c81273388c594/LICENSE")
# MATPOWER 8.1 release
[entries] Prefix the properties in the descriptions with (Node), (Edge) or (Graph) bc3dbbd
The lists of properties at the end of the descriptions marked edge properties with "Edge" but left node properties unmarked, or grouped them in "Nodes: `a`, ...; `b`, ..." items, so the kind of a property was often unclear. Every item now starts with (Node), (Edge) or (Graph), followed by the property names, a colon and the explanation, one item per property or group of properties; qualifications (kinds of nodes, networks) follow the names in parentheses. Properties that were only named got a short explanation, and a few items that named the wrong kind of property were corrected.
diff --git a/entries/matpower/__init__.py b/entries/matpower/__init__.py
index 6701f9a..e54002d 100644
--- a/entries/matpower/__init__.py
+++ b/entries/matpower/__init__.py
@@ -35,8 +35,23 @@ The RTS-GMLC test case is not included, since its data use agreement requires re
The networks have the following properties (in MATPOWER's units: powers in MW and MVAr, voltages in per unit of the base voltage, angles in degrees, impedances in per unit of the system base `base_mva`, a graph property):
-- Nodes: `bus_id`, the bus number; `bus_type` (1: PQ (load) bus, 2: PV (generator) bus, 3: reference (slack) bus, 4: isolated bus); `pd` and `qd`, the active and reactive power demand; `gs` and `bs`, the shunt conductance and susceptance (MW and MVAr consumed at 1 p.u. voltage); `area` and `zone`, area and loss zone numbers; `vm` and `va`, the voltage magnitude and angle; `base_kv`, the base voltage (kV); `vmax` and `vmin`, the voltage limits; `n_gen`, the number of in-service generators at the bus; `gen_p`, `gen_q`, `gen_pmax`, `gen_pmin`, `gen_qmax`, `gen_qmin`, the total active and reactive power output and limits of these generators; `name`, the bus name (only for some cases).
-- Edges: `r`, `x` and `b`, the branch resistance, reactance and total line charging susceptance; `rate_a`, `rate_b` and `rate_c`, the long-term, short-term and emergency power ratings (MVA; 0 means unlimited); `ratio`, the transformer tap ratio (0 for lines); `shift`, the transformer phase shift angle; `status`, 1 if in service and 0 otherwise; `angmin` and `angmax`, the limits on the voltage angle difference across the branch."""
+- (Node) `bus_id`: the bus number.
+- (Node) `bus_type` (1: PQ (load) bus, 2: PV (generator) bus, 3: reference (slack) bus, 4: isolated bus).
+- (Node) `pd` and `qd`: the active and reactive power demand.
+- (Node) `gs` and `bs`: the shunt conductance and susceptance (MW and MVAr consumed at 1 p.u. voltage).
+- (Node) `area` and `zone`: area and loss zone numbers.
+- (Node) `vm` and `va`: the voltage magnitude and angle.
+- (Node) `base_kv`: the base voltage (kV).
+- (Node) `vmax` and `vmin`: the voltage limits.
+- (Node) `n_gen`: the number of in-service generators at the bus.
+- (Node) `gen_p`, `gen_q`, `gen_pmax`, `gen_pmin`, `gen_qmax`, `gen_qmin`: the total active and reactive power output and limits of these generators.
+- (Node) `name`: the bus name (only for some cases).
+- (Edge) `r`, `x` and `b`: the branch resistance, reactance and total line charging susceptance.
+- (Edge) `rate_a`, `rate_b` and `rate_c`: the long-term, short-term and emergency power ratings (MVA; 0 means unlimited).
+- (Edge) `ratio`: the transformer tap ratio (0 for lines).
+- (Edge) `shift`: the transformer phase shift angle.
+- (Edge) `status`: 1 if in service and 0 otherwise.
+- (Edge) `angmin` and `angmax`: the limits on the voltage angle difference across the branch."""
tags = ['Technological', 'Power grid', 'Weighted', 'Metadata']
url = 'https://matpower.org'
citation = [('R. D. Zimmerman, C. E. Murillo-Sánchez, R. J. Thomas, "MATPOWER: Steady-State Operations, Planning, and Analysis Tools for Power Systems Research and Education." IEEE Transactions on Power Systems 26(1), 12-19 (2011)', 'https://doi.org/10.1109/TPWRS.2010.2051168'),
[entries] Remove unneeded code from the entries 2c69f19
Unneeded "global files" statements, unused imports and variables, f-strings without placeholders, duplicate keys in foodweb_little_rock (keeping the order and the values used), and the second definition of get_lines() in twitter_higgs. Nothing changes in the networks or descriptions. Changed: none
diff --git a/entries/matpower/__init__.py b/entries/matpower/__init__.py
index aede52b..6701f9a 100644
--- a/entries/matpower/__init__.py
+++ b/entries/matpower/__init__.py
@@ -148,7 +148,6 @@ branch_cols = ["r", "x", "b", "rate_a", "rate_b", "rate_c", "ratio", "shift",
@coerce_props()
@annotate()
def parse(alts=None):
- global files
name = __name__.split(".")[-1]
for fname, alt, fmt in files:
if alts is not None and alt not in alts:
[entries] Lay out spatial networks with cfd_layout() without the SBM partition 9db8d77
Road, power grid, public transport, water and river networks and physical meshes override get_pos() with the default parameters of cfd_layout(), without grouping by the partition of the SBM fit.
diff --git a/entries/matpower/__init__.py b/entries/matpower/__init__.py
index 26a415e..aede52b 100644
--- a/entries/matpower/__init__.py
+++ b/entries/matpower/__init__.py
@@ -202,3 +202,9 @@ def parse(alts=None):
g.add_edge_list([[idx[int(r[0])], idx[int(r[1])]] + list(r[2:13])
for r in branch], eprops=eprops)
yield alt, g
+
+
+def get_pos(g, sbm_fit):
+ # Spatial network: laid out with the default parameters of cfd_layout(),
+ # without the partition of the SBM fit
+ return cfd_layout(g)
[entries] New entry: matpower 38da26b
diff --git a/entries/matpower/__init__.py b/entries/matpower/__init__.py
new file mode 100644
index 0000000..26a415e
--- /dev/null
+++ b/entries/matpower/__init__.py
@@ -0,0 +1,204 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2020-2026 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import re
+from .. import *
+
+title = "MATPOWER power grid test cases (1962-2025)"
+description = """Electrical power systems distributed as test cases (`case*.m` files) with MATPOWER, the open-source MATLAB package for power flow and optimal power flow computations by Zimmerman, Murillo-Sánchez and Thomas. Nodes are buses (substations or connection points) and directed edges are branches (transmission lines, cables and transformers), directed from the "from" bus to the "to" bus of the branch (for transformers, the tap ratio and phase shift apply at the "from" side). Parallel branches are kept as multiple edges. Generators are not represented as nodes; their data are aggregated at the buses they are connected to. DC lines (present in two cases) are not included.
+
+The test cases come from many sources, which are described in each case file. They include:
+
+- Classic IEEE test cases and textbook examples: `case4gs`, `case5`, `case6ww`, `case9` (and variants `case9Q`, `case9target`), `case14`, `case24_ieee_rts`, `case30` (and variants `case30Q`, `case30pwl`, `case_ieee30`), `case39` (New England), `case57`, `case59` (Australian), `case60nordic`, `case118`, `case145`, `case300`.
+- The Polish transmission system at several dates between 1999 and 2008: `case2383wp`, `case2736sp`, `case2737sop`, `case2746wop`, `case2746wp`, `case3012wp`, `case3120sp`, `case3375wp`.
+- Parts of the European high-voltage transmission system from the PEGASE project: `case89pegase`, `case1354pegase`, `case2869pegase`, `case8387pegase`, `case9241pegase`, `case13659pegase` (Fliscounakis et al., 2013; Josz et al., 2016).
+- Snapshots of the French transmission system from RTE: `case1888rte`, `case1951rte`, `case2848rte`, `case2868rte`, `case6468rte`, `case6470rte`, `case6495rte`, `case6515rte` (Josz et al., 2016).
+- Synthetic grids of the ACTIVSg project, which resemble the grids of US regions without containing real infrastructure data: `case_ACTIVSg200` (Illinois), `case_ACTIVSg500` (South Carolina), `case_ACTIVSg2000` (Texas), `case_ACTIVSg10k` (western US), `case_ACTIVSg25k` (northeastern US), `case_ACTIVSg70k` (eastern US), and `case_SyntheticUSA` (combined US, 82,000 buses) (Birchfield et al., 2017).
+- Radial distribution systems from the literature, e.g. `case10ba`, `case12da`, `case33bw`, `case69`, `case118zh`, `case136ma`, `case141`, `case533mt_hi`, `case533mt_lo`, `case1197`. For these cases, the unit conversions performed by the case files (branch impedances from ohms to per unit, loads from kW to MW, and, for `case141`, loads from kVA using a power factor of 0.85) have been applied.
+
+The RTS-GMLC test case is not included, since its data use agreement requires reproducing a notice with every copy.
+
+The networks have the following properties (in MATPOWER's units: powers in MW and MVAr, voltages in per unit of the base voltage, angles in degrees, impedances in per unit of the system base `base_mva`, a graph property):
+
+- Nodes: `bus_id`, the bus number; `bus_type` (1: PQ (load) bus, 2: PV (generator) bus, 3: reference (slack) bus, 4: isolated bus); `pd` and `qd`, the active and reactive power demand; `gs` and `bs`, the shunt conductance and susceptance (MW and MVAr consumed at 1 p.u. voltage); `area` and `zone`, area and loss zone numbers; `vm` and `va`, the voltage magnitude and angle; `base_kv`, the base voltage (kV); `vmax` and `vmin`, the voltage limits; `n_gen`, the number of in-service generators at the bus; `gen_p`, `gen_q`, `gen_pmax`, `gen_pmin`, `gen_qmax`, `gen_qmin`, the total active and reactive power output and limits of these generators; `name`, the bus name (only for some cases).
+- Edges: `r`, `x` and `b`, the branch resistance, reactance and total line charging susceptance; `rate_a`, `rate_b` and `rate_c`, the long-term, short-term and emergency power ratings (MVA; 0 means unlimited); `ratio`, the transformer tap ratio (0 for lines); `shift`, the transformer phase shift angle; `status`, 1 if in service and 0 otherwise; `angmin` and `angmax`, the limits on the voltage angle difference across the branch."""
+tags = ['Technological', 'Power grid', 'Weighted', 'Metadata']
+url = 'https://matpower.org'
+citation = [('R. D. Zimmerman, C. E. Murillo-Sánchez, R. J. Thomas, "MATPOWER: Steady-State Operations, Planning, and Analysis Tools for Power Systems Research and Education." IEEE Transactions on Power Systems 26(1), 12-19 (2011)', 'https://doi.org/10.1109/TPWRS.2010.2051168'),
+ ('S. Fliscounakis, P. Panciatici, F. Capitanescu, L. Wehenkel, "Contingency Ranking With Respect to Overloads in Very Large Power Systems Taking Into Account Uncertainty, Preventive, and Corrective Actions." IEEE Transactions on Power Systems 28(4), 4909-4917 (2013)', 'https://doi.org/10.1109/TPWRS.2013.2251015'),
+ ('C. Josz, S. Fliscounakis, J. Maeght, P. Panciatici, "AC Power Flow Data in MATPOWER and QCQP Format: iTesla, RTE Snapshots, and PEGASE." arXiv:1603.01533 (2016)', 'https://arxiv.org/abs/1603.01533'),
+ ('A. B. Birchfield, T. Xu, K. M. Gegner, K. S. Shetye, T. J. Overbye, "Grid Structural Characteristics as Validation Criteria for Synthetic Networks." IEEE Transactions on Power Systems 32(4), 3258-3265 (2017)', 'https://doi.org/10.1109/TPWRS.2016.2616385')]
+icon_hash = '56a85c8e26855e083a2f795c'
+upstream_license = ("Various; see the individual case files (many are CC BY 4.0)",
+ "https://github.com/MATPOWER/matpower/blob/1a828c7af590714499284e36ee9c81273388c594/LICENSE")
+# MATPOWER 8.1 release
+upstream_prefix = 'https://raw.githubusercontent.com/MATPOWER/matpower/1a828c7af590714499284e36ee9c81273388c594/data'
+
+cases = ["case4gs", "case4_dist", "case5", "case6ww", "case9", "case9Q",
+ "case9target", "case10ba", "case12da", "case14", "case15da",
+ "case15nbr", "case16am", "case16ci", "case17me", "case18",
+ "case18nbr", "case22", "case24_ieee_rts", "case28da", "case30",
+ "case30Q", "case30pwl", "case_ieee30", "case33bw", "case33mg",
+ "case34sa", "case38si", "case39", "case51ga", "case51he", "case57",
+ "case59", "case60nordic", "case69", "case70da", "case74ds", "case85",
+ "case89pegase", "case94pi", "case118", "case118zh", "case136ma",
+ "case141", "case145", "case300", "case533mt_hi", "case533mt_lo",
+ "case1197", "case1354pegase", "case1888rte", "case1951rte",
+ "case2383wp", "case2736sp", "case2737sop", "case2746wop",
+ "case2746wp", "case2848rte", "case2868rte", "case2869pegase",
+ "case3012wp", "case3120sp", "case3375wp", "case6468rte",
+ "case6470rte", "case6495rte", "case6515rte", "case8387pegase",
+ "case9241pegase", "case13659pegase", "case_ACTIVSg200",
+ "case_ACTIVSg500", "case_ACTIVSg2000", "case_ACTIVSg10k",
+ "case_ACTIVSg25k", "case_ACTIVSg70k", "case_SyntheticUSA"]
+files = [(f"{c}.m", c, "matpower") for c in cases]
+
+def fetch_upstream(force=False):
+ return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+ force)
+
+def evalnum(node):
+ "Evaluate a simple arithmetic expression (numbers, + - * / ^, sqrt)."
+ import ast, operator, math
+ ops = {ast.Add: operator.add, ast.Sub: operator.sub,
+ ast.Mult: operator.mul, ast.Div: operator.truediv,
+ ast.Pow: operator.pow, ast.BitXor: operator.pow}
+ if isinstance(node, ast.Expression):
+ return evalnum(node.body)
+ if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)):
+ return float(node.value)
+ if isinstance(node, ast.UnaryOp) and isinstance(node.op, (ast.USub, ast.UAdd)):
+ v = evalnum(node.operand)
+ return -v if isinstance(node.op, ast.USub) else v
+ if isinstance(node, ast.BinOp) and type(node.op) in ops:
+ return ops[type(node.op)](evalnum(node.left), evalnum(node.right))
+ if (isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and
+ node.func.id == "sqrt" and len(node.args) == 1):
+ return math.sqrt(evalnum(node.args[0]))
+ raise ValueError("unsupported expression")
+
+def tonum(x):
+ import ast
+ x = x.strip()
+ if x.lower() in ("inf", "+inf"):
+ return numpy.inf
+ if x.lower() == "-inf":
+ return -numpy.inf
+ if x.lower() == "nan":
+ return numpy.nan
+ try:
+ return float(x)
+ except ValueError:
+ return evalnum(ast.parse(x, mode="eval"))
+
+def read_case(text):
+ """Return the scalar fields, matrix fields and cell arrays of a MATPOWER
+ case file, and the statements outside them."""
+ mats, cells, statements = {}, {}, []
+ lines = [l.split("%", 1)[0].strip() for l in text.splitlines()]
+ i = 0
+ base_mva = None
+ while i < len(lines):
+ s = lines[i]
+ i += 1
+ m = re.match(r"mpc\.(\w+)\s*=\s*([\[\{])(.*)", s)
+ if m:
+ key, br, rest = m.groups()
+ close = "]" if br == "[" else "}"
+ body = [rest]
+ while close not in body[-1]:
+ body.append(lines[i])
+ i += 1
+ body = "\n".join(body).split(close)[0]
+ if br == "[":
+ rows = [r.split() for r in re.split(r"[;\n]", body)]
+ mats[key] = [[tonum(x) for x in r] for r in rows if r]
+ else:
+ cells[key] = re.findall(r"'([^']*)'", body)
+ continue
+ m = re.match(r"mpc\.baseMVA\s*=\s*([^;]+)", s)
+ if m:
+ base_mva = tonum(m.group(1))
+ continue
+ if s and not s.startswith("function") and not s.startswith("mpc.version"):
+ statements.append(s)
+ return base_mva, mats, cells, " ".join(statements)
+
+bus_cols = ["bus_id", "bus_type", "pd", "qd", "gs", "bs", "area", "vm", "va",
+ "base_kv", "zone", "vmax", "vmin"]
+branch_cols = ["r", "x", "b", "rate_a", "rate_b", "rate_c", "ratio", "shift",
+ "status", "angmin", "angmax"]
+
+@cache_network()
+@coerce_props()
+@annotate()
+def parse(alts=None):
+ global files
+ name = __name__.split(".")[-1]
+ for fname, alt, fmt in files:
+ if alts is not None and alt not in alts:
+ continue
+ with open_upstream_file(name, fname, "r", encoding="latin1") as f:
+ base_mva, mats, cells, statements = read_case(f.read())
+ bus = numpy.array([r[:13] for r in mats["bus"]])
+ branch = numpy.array([r[:13] + [numpy.nan] * (13 - len(r[:13]))
+ for r in mats["branch"]])
+ gen = numpy.array([r[:10] for r in mats["gen"]])
+
+ # unit conversions performed by the distribution system case files
+ if "mpc.branch(:, [BR_R BR_X]) = mpc.branch(:, [BR_R BR_X]) / (Vbase^2 / Sbase)" in statements:
+ vbase = bus[0, 9] * 1e3
+ sbase = base_mva * 1e6
+ branch[:, 2:4] /= vbase ** 2 / sbase
+ if "mpc.bus(:, [PD, QD]) = mpc.bus(:, [PD, QD]) / 1e3" in statements:
+ bus[:, 2:4] /= 1e3
+ if "mpc.bus(:, QD) = mpc.bus(:, PD) * sin(acos(pf))" in statements:
+ pf = float(re.search(r"pf = ([\d.]+);", statements).group(1))
+ bus[:, 3] = bus[:, 2] * numpy.sin(numpy.arccos(pf))
+ bus[:, 2] = bus[:, 2] * pf
+
+ idx = {int(b): i for i, b in enumerate(bus[:, 0])}
+ g = Graph(directed=True)
+ g.add_vertex(len(bus))
+ g.gp.base_mva = g.new_gp("double", val=base_mva)
+ for j, c in enumerate(bus_cols):
+ vt = "int" if c in ("bus_id", "bus_type", "area", "zone") else "double"
+ g.vp[c] = g.new_vp(vt, vals=bus[:, j])
+ if "bus_name" in cells:
+ g.vp.name = g.new_vp("string", vals=cells["bus_name"])
+
+ gcols = {"gen_p": 1, "gen_q": 2, "gen_qmax": 3, "gen_qmin": 4,
+ "gen_pmax": 8, "gen_pmin": 9}
+ g.vp.n_gen = g.new_vp("int")
+ for c in gcols:
+ g.vp[c] = g.new_vp("double")
+ for r in gen:
+ if r[7] <= 0: # out of service
+ continue
+ v = idx[int(r[0])]
+ g.vp.n_gen[v] += 1
+ for c, j in gcols.items():
+ g.vp[c][v] += r[j]
+
+ eprops = [g.new_ep("int" if c == "status" else "double")
+ for c in branch_cols]
+ for c, p in zip(branch_cols, eprops):
+ g.ep[c] = p
+ g.add_edge_list([[idx[int(r[0])], idx[int(r[1])]] + list(r[2:13])
+ for r in branch], eprops=eprops)
+ yield alt, g