Metadata-Version: 2.5
Name: cim-builder
Version: 0.2.0
Summary: Build CIM power system models from scratch, from single components to full node-breaker substations
Author-email: "A. Anderson" <19935503+AAndersn@users.noreply.github.com>
License-Expression: BSD-3-Clause
License-File: LICENSE
Keywords: cim,power-systems
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.10
Requires-Dist: cim-graph<0.7,>=0.6.1
Requires-Dist: cim-profiles<0.3,>=0.2.0
Requires-Dist: cim-tables<0.3,>=0.2.0
Requires-Dist: pyarrow>=18
Description-Content-Type: text/markdown

# CIM-Builder


![GitHub Tag](https://img.shields.io/github/v/tag/PNNL-CIM-Tools/CIM-Builder)
![GitHub Release Date](https://img.shields.io/github/release-date-pre/PNNL-CIM-Tools/CIM-Builder)
![Tests](https://img.shields.io/github/actions/workflow/status/PNNL-CIM-Tools/CIM-Builder/tests.yml?label=tests)
![Release](https://img.shields.io/github/actions/workflow/status/PNNL-CIM-Tools/CIM-Builder/release.yml?label=release)
![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/PNNL-CIM-Tools/CIM-Builder)

![PyPI - Version](https://img.shields.io/pypi/v/cim-builder)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cim-builder)
![PyPI - Downloads](https://img.shields.io/pypi/dm/cim-builder?label=pypi%20downloads)
![PyPI - Format](https://img.shields.io/pypi/format/cim-builder)

![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/PNNL-CIM-Tools/CIM-Builder)
![GitHub Issues or Pull Requests](https://img.shields.io/github/issues-pr/PNNL-CIM-Tools/CIM-Builder)
![GitHub commit activity](https://img.shields.io/github/commit-activity/t/PNNL-CIM-Tools/CIM-Builder)
![GitHub License](https://img.shields.io/github/license/PNNL-CIM-Tools/CIM-Builder)
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/PNNL-CIM-Tools/CIM-Builder/total?label=git%20downloads)

CIM-Builder is a Python library from Pacific Northwest National Laboratory, for building IEC CIM power 
system models from scratch. Other CIM tooling converts an existing source, such as an OpenDSS, PSS/E or GIS model;
CIM-Builder writes the CIM objects directly, one call per piece of equipment or per substation. It can:

1. create new objects with per-profile builders (`add_connectivity`, `add_electrical`, `add_ssh`, etc.)
2. create new node-breaker substations from API calls,
3. insert existing CIM distribution feeders into those substations,
4. add new equipment and measurements to an existing model, and
5. insert aggregate feeder data into an existing CIM transmission model.

Everything lands in a [CIMantic Graphs](https://pnnl-cim-tools.github.io/CIM-Graph/) model, ready to save as CIM
RDF/XML or JSON-LD.

Documentation: https://pnnl-cim-tools.github.io/CIM-Builder/

## Installation

CIM-Builder needs Python 3.10 or newer. It is installed as `cim-builder` and imported as `cimbuilder`:

```bash
pip install cim-builder
```

or, with [uv](https://docs.astral.sh/uv/), `uv add cim-builder`. It brings in its CIM dependencies,
[cim-tables](https://pnnl-cim-tools.github.io/CIM-Tables/),
[cim-graph](https://pnnl-cim-tools.github.io/CIM-Graph/) and
[cim-profiles](https://github.com/PNNL-CIM-Tools/CIM-Profiles).

## Example

A 115 kV ring bus substation with four sections and a branch on each:

```python
from cimgraph.utils import write_xml
from cimtables.units import Qty

from cimbuilder.network import new_feeder_model
from cimbuilder.object_builder import BaseVoltageBuilder
from cimbuilder.substation_builder import RingBusSubstationBuilder

network = new_feeder_model(authority="https://example.com/models", model="demo", Feeder="fdr_demo")
BaseVoltageBuilder(network, network.container).create(mRID="bv_115kV", nominalVoltage=Qty(115, "kV"))

builder = RingBusSubstationBuilder(network, network.container)
substation = builder.create(mRID="sub_ring", name="Ring bus")
substation, voltage_level = builder.add_voltage_level(substation, mRID="vl_115", BaseVoltage="bv_115kV")
voltage_level, busbars, ring = builder.add_buses(voltage_level, sections=4)
for section in (1, 2, 3, 4):
    builder.add_branch(voltage_level, section=section, node=f"line_{section}")

write_xml(network, "ring_bus.xml")  # 4 busbars, 4 breakers, 12 disconnectors
```

The builder writes every `ConnectivityNode`, `Terminal`, `BusbarSection`, breaker and disconnector of the
layout, with consistent mRIDs, in the right `VoltageLevel` with its `BaseVoltage`.

## What is in the package

### Substation builders: `cimbuilder.substation_builder`

One builder per node-breaker layout. Each has `add_buses` for the busbars and bus ties, and `add_branch`
for the switches between a bus and a branch node:

| Builder | `add_buses` options | `add_branch` connection point |
|---|---|---|
| `SingleBusSubstationBuilder` | | `number` |
| `SectionalizedBusSubstationBuilder` | `sections=2` | `section`, `number` |
| `MainAndTransferSubstationBuilder` | | `number` |
| `DoubleBusSingleBreakerSubstationBuilder` | | `number`, `bus=1` |
| `RingBusSubstationBuilder` | `sections=4` | `section` |
| `BreakerAndHalfSubstationBuilder` | `diameters=2` | `diameter`, `side` |

`add_branch(..., node=...)` creates the branch node if it does not exist yet. Given the head node of a
distribution feeder already loaded into the same graph, it connects the substation to that feeder instead.

### Object builders: `cimbuilder.object_builder`

One builder per CIM class: lines, switches, transformers, regulators and tap changers, loads and shunt
capacitors, sources, generators and inverters, measurements and operational limits. Each builder creates
the object, then fills it in one CIM profile part at a time:

```python
line_builder = ACLineSegmentBuilder(network, container)
line = line_builder.create(mRID="line_1", name="line 1")
line_builder.add_connectivity(
    line, node1="bus_1", node2="bus_2", phases="ABC", length=Qty(1.2, "km"), BaseVoltage="bv_12_47kV"
)
line_builder.add_electrical(line, r=Qty(0.3, "ohm"), x=Qty(0.6, "ohm"))
```

Other objects are referred to by mRID, nodes are created as they are first used, and values can be given
in any unit as a `Qty`.

### Aggregate feeders: `cimbuilder.feeder_builder`

`new_aggregate_feeder` adds a whole distribution feeder to a transmission model as one head breaker, one
aggregate load, aggregate behind-the-meter and front-of-the-meter PV and wind, and the feeder-head
measurements an under-frequency load shedding study reads.

## Development

```bash
git clone https://github.com/PNNL-CIM-Tools/CIM-Builder.git -b develop
cd CIM-Builder
uv sync
uv run pytest
```

See the [developer docs](https://pnnl-cim-tools.github.io/CIM-Builder/developer/) for how the builders are
put together and how to build the documentation, and
[Contributing](https://pnnl-cim-tools.github.io/CIM-Builder/01_overview/1_3_contributing/) before opening a
pull request.

## Attribution and Disclaimer

This software was created under a project sponsored by the U.S. Department of Energy’s Office of Electricity, an agency of the United States Government.  Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any of their employees, nor any jurisdiction or organization that has cooperated in the development of these materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process disclosed, or represents that its use would not infringe privately owned rights.

Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or any agency thereof.

PACIFIC NORTHWEST NATIONAL LABORATORY
operated by
BATTELLE
for the
UNITED STATES DEPARTMENT OF ENERGY
under Contract DE-AC05-76RL01830
