powerio.dist

Multiconductor distribution networks in wire coordinates.

Three formats, lossless three way conversion: OpenDSS .dss, PowerModelsDistribution ENGINEERING JSON (pmd-json), and the draft BMOPF task force JSON (bmopf-json). The fidelity rules match the transmission surface: writing back to the source format echoes the retained source text byte for byte, and every cross format write reports each loss in the ~powerio.Conversion warnings instead of dropping it silently.

import powerio.dist as dist

net = dist.parse_file("feeder.dss")
for w in net.warnings:
    print("parse:", w)
conv = net.to_format("pmd-json")
  1"""Multiconductor distribution networks in wire coordinates.
  2
  3Three formats, lossless three way conversion: OpenDSS ``.dss``,
  4PowerModelsDistribution ENGINEERING JSON (``pmd-json``), and the draft BMOPF
  5task force JSON (``bmopf-json``). The fidelity rules match the
  6transmission surface: writing back to the source format echoes the retained
  7source text byte for byte, and every cross format write reports each loss in
  8the :class:`~powerio.Conversion` warnings instead of dropping it silently.
  9
 10    import powerio.dist as dist
 11
 12    net = dist.parse_file("feeder.dss")
 13    for w in net.warnings:
 14        print("parse:", w)
 15    conv = net.to_format("pmd-json")
 16"""
 17
 18from __future__ import annotations
 19
 20from typing import Any, Optional
 21
 22from . import Conversion, _powerio
 23
 24__all__ = [
 25    "DistNetwork",
 26    "MulticonductorNetwork",
 27    "parse_file",
 28    "parse_str",
 29    "convert_file",
 30    "convert_str",
 31]
 32
 33
 34class DistNetwork:
 35    """A parsed multiconductor distribution network.
 36
 37    Buses carry named terminals, lines carry conductor impedance matrices, and
 38    transformers carry per winding connections; nothing is collapsed to
 39    positive sequence. Distinct from :class:`powerio.Network` (the
 40    transmission model); the matrix builders do not accept it.
 41    """
 42
 43    def __init__(self, inner) -> None:
 44        self._inner = inner
 45
 46    @property
 47    def name(self) -> Optional[str]:
 48        """Distribution network name when the source format carries one."""
 49        return self._inner.name()
 50
 51    @property
 52    def source_format(self) -> Optional[str]:
 53        """Format parsed from: ``dss``, ``pmd-json``, or ``bmopf-json``."""
 54        return self._inner.source_format()
 55
 56    @property
 57    def warnings(self) -> "list[str]":
 58        """Parse warnings: everything the reader could not represent or had to assume."""
 59        return self._inner.warnings()
 60
 61    @property
 62    def n_buses(self) -> int:
 63        return self._inner.n_buses()
 64
 65    @property
 66    def n_lines(self) -> int:
 67        return self._inner.n_lines()
 68
 69    @property
 70    def n_transformers(self) -> int:
 71        return self._inner.n_transformers()
 72
 73    @property
 74    def n_loads(self) -> int:
 75        return self._inner.n_loads()
 76
 77    @property
 78    def n_generators(self) -> int:
 79        return self._inner.n_generators()
 80
 81    @property
 82    def n_sources(self) -> int:
 83        return self._inner.n_sources()
 84
 85    def to_format(self, to: str) -> Conversion:
 86        """Serialize to ``to`` (``dss``, ``pmd-json``, ``bmopf-json``).
 87
 88        Writing back to the source format echoes the retained source text byte
 89        for byte; a cross format write regenerates from the typed model and
 90        reports every fidelity loss in the warnings.
 91        """
 92        text, warnings = self._inner.to_format(to)
 93        return Conversion(text, warnings)
 94
 95    def __repr__(self) -> str:
 96        return self._inner.__repr__()
 97
 98
 99# v1 name for the wire coordinate distribution model. ``DistNetwork`` remains
100# available in 0.4 because it is the existing handle name.
101MulticonductorNetwork = DistNetwork
102
103
104def parse_file(path: Any, from_: Optional[str] = None) -> MulticonductorNetwork:
105    """Parse a distribution network file.
106
107    The format comes from ``from_`` when given, else from the file itself:
108    ``.dss`` is OpenDSS, and ``.json`` holding the ENGINEERING ``data_model``
109    key is PMD JSON, otherwise BMOPF JSON.
110    """
111    return DistNetwork(_powerio.dist_parse_file(str(path), from_))
112
113
114def parse_str(text: str, format: str) -> MulticonductorNetwork:
115    """Parse an in-memory distribution network of the named ``format``."""
116    return DistNetwork(_powerio.dist_parse_str(text, format))
117
118
119def convert_file(path: Any, to: str, from_: Optional[str] = None) -> Conversion:
120    """Convert a distribution network file to ``to`` in one call.
121
122    The warnings carry both the parse warnings and the writer's fidelity
123    losses (there is no :class:`DistNetwork` to query them from).
124    """
125    text, warnings = _powerio.dist_convert_file(str(path), to, from_)
126    return Conversion(text, warnings)
127
128
129def convert_str(text: str, to: str, format: str) -> Conversion:
130    """Convert an in-memory distribution network of the named ``format`` to ``to``.
131
132    The signature matches :func:`powerio.convert_str`: input, target, source,
133    except ``format`` is required (there is no extension to infer from and no
134    default). The warnings carry both the parse warnings and the writer's
135    fidelity losses (there is no :class:`DistNetwork` to query them from).
136    """
137    text, warnings = _powerio.dist_convert_str(text, to, format)
138    return Conversion(text, warnings)
class DistNetwork:
35class DistNetwork:
36    """A parsed multiconductor distribution network.
37
38    Buses carry named terminals, lines carry conductor impedance matrices, and
39    transformers carry per winding connections; nothing is collapsed to
40    positive sequence. Distinct from :class:`powerio.Network` (the
41    transmission model); the matrix builders do not accept it.
42    """
43
44    def __init__(self, inner) -> None:
45        self._inner = inner
46
47    @property
48    def name(self) -> Optional[str]:
49        """Distribution network name when the source format carries one."""
50        return self._inner.name()
51
52    @property
53    def source_format(self) -> Optional[str]:
54        """Format parsed from: ``dss``, ``pmd-json``, or ``bmopf-json``."""
55        return self._inner.source_format()
56
57    @property
58    def warnings(self) -> "list[str]":
59        """Parse warnings: everything the reader could not represent or had to assume."""
60        return self._inner.warnings()
61
62    @property
63    def n_buses(self) -> int:
64        return self._inner.n_buses()
65
66    @property
67    def n_lines(self) -> int:
68        return self._inner.n_lines()
69
70    @property
71    def n_transformers(self) -> int:
72        return self._inner.n_transformers()
73
74    @property
75    def n_loads(self) -> int:
76        return self._inner.n_loads()
77
78    @property
79    def n_generators(self) -> int:
80        return self._inner.n_generators()
81
82    @property
83    def n_sources(self) -> int:
84        return self._inner.n_sources()
85
86    def to_format(self, to: str) -> Conversion:
87        """Serialize to ``to`` (``dss``, ``pmd-json``, ``bmopf-json``).
88
89        Writing back to the source format echoes the retained source text byte
90        for byte; a cross format write regenerates from the typed model and
91        reports every fidelity loss in the warnings.
92        """
93        text, warnings = self._inner.to_format(to)
94        return Conversion(text, warnings)
95
96    def __repr__(self) -> str:
97        return self._inner.__repr__()

A parsed multiconductor distribution network.

Buses carry named terminals, lines carry conductor impedance matrices, and transformers carry per winding connections; nothing is collapsed to positive sequence. Distinct from powerio.Network (the transmission model); the matrix builders do not accept it.

DistNetwork(inner)
44    def __init__(self, inner) -> None:
45        self._inner = inner
name: Optional[str]
47    @property
48    def name(self) -> Optional[str]:
49        """Distribution network name when the source format carries one."""
50        return self._inner.name()

Distribution network name when the source format carries one.

source_format: Optional[str]
52    @property
53    def source_format(self) -> Optional[str]:
54        """Format parsed from: ``dss``, ``pmd-json``, or ``bmopf-json``."""
55        return self._inner.source_format()

Format parsed from: dss, pmd-json, or bmopf-json.

warnings: list[str]
57    @property
58    def warnings(self) -> "list[str]":
59        """Parse warnings: everything the reader could not represent or had to assume."""
60        return self._inner.warnings()

Parse warnings: everything the reader could not represent or had to assume.

n_buses: int
62    @property
63    def n_buses(self) -> int:
64        return self._inner.n_buses()
n_lines: int
66    @property
67    def n_lines(self) -> int:
68        return self._inner.n_lines()
n_transformers: int
70    @property
71    def n_transformers(self) -> int:
72        return self._inner.n_transformers()
n_loads: int
74    @property
75    def n_loads(self) -> int:
76        return self._inner.n_loads()
n_generators: int
78    @property
79    def n_generators(self) -> int:
80        return self._inner.n_generators()
n_sources: int
82    @property
83    def n_sources(self) -> int:
84        return self._inner.n_sources()
def to_format(self, to: str) -> powerio.Conversion:
86    def to_format(self, to: str) -> Conversion:
87        """Serialize to ``to`` (``dss``, ``pmd-json``, ``bmopf-json``).
88
89        Writing back to the source format echoes the retained source text byte
90        for byte; a cross format write regenerates from the typed model and
91        reports every fidelity loss in the warnings.
92        """
93        text, warnings = self._inner.to_format(to)
94        return Conversion(text, warnings)

Serialize to to (dss, pmd-json, bmopf-json).

Writing back to the source format echoes the retained source text byte for byte; a cross format write regenerates from the typed model and reports every fidelity loss in the warnings.

MulticonductorNetwork = <class 'DistNetwork'>
def parse_file(path: Any, from_: Optional[str] = None) -> DistNetwork:
105def parse_file(path: Any, from_: Optional[str] = None) -> MulticonductorNetwork:
106    """Parse a distribution network file.
107
108    The format comes from ``from_`` when given, else from the file itself:
109    ``.dss`` is OpenDSS, and ``.json`` holding the ENGINEERING ``data_model``
110    key is PMD JSON, otherwise BMOPF JSON.
111    """
112    return DistNetwork(_powerio.dist_parse_file(str(path), from_))

Parse a distribution network file.

The format comes from from_ when given, else from the file itself: .dss is OpenDSS, and .json holding the ENGINEERING data_model key is PMD JSON, otherwise BMOPF JSON.

def parse_str(text: str, format: str) -> DistNetwork:
115def parse_str(text: str, format: str) -> MulticonductorNetwork:
116    """Parse an in-memory distribution network of the named ``format``."""
117    return DistNetwork(_powerio.dist_parse_str(text, format))

Parse an in-memory distribution network of the named format.

def convert_file(path: Any, to: str, from_: Optional[str] = None) -> powerio.Conversion:
120def convert_file(path: Any, to: str, from_: Optional[str] = None) -> Conversion:
121    """Convert a distribution network file to ``to`` in one call.
122
123    The warnings carry both the parse warnings and the writer's fidelity
124    losses (there is no :class:`DistNetwork` to query them from).
125    """
126    text, warnings = _powerio.dist_convert_file(str(path), to, from_)
127    return Conversion(text, warnings)

Convert a distribution network file to to in one call.

The warnings carry both the parse warnings and the writer's fidelity losses (there is no DistNetwork to query them from).

def convert_str(text: str, to: str, format: str) -> powerio.Conversion:
130def convert_str(text: str, to: str, format: str) -> Conversion:
131    """Convert an in-memory distribution network of the named ``format`` to ``to``.
132
133    The signature matches :func:`powerio.convert_str`: input, target, source,
134    except ``format`` is required (there is no extension to infer from and no
135    default). The warnings carry both the parse warnings and the writer's
136    fidelity losses (there is no :class:`DistNetwork` to query them from).
137    """
138    text, warnings = _powerio.dist_convert_str(text, to, format)
139    return Conversion(text, warnings)

Convert an in-memory distribution network of the named format to to.

The signature matches powerio.convert_str(): input, target, source, except format is required (there is no extension to infer from and no default). The warnings carry both the parse warnings and the writer's fidelity losses (there is no DistNetwork to query them from).