CIM power-system models as Python objects¶
cim-graph reads IEC CIM models from CIM XML, JSON-LD or a graph database into an
in-memory knowledge graph of typed CIM objects. You navigate it by following associations, edit it, and write it
back out. The same API works for distribution feeders, node-breaker and bus-branch transmission models, and
distributed areas.
import os
os.environ['CIMG_CIM_PROFILE'] = 'cimhub_2023'
import cimprofiles.cim17.cimhub_2023 as cim
from cimgraph.databases import XMLFile
from cimgraph.models import FeederModel
from cimgraph.utils import write_json_ld
feeder = cim.Feeder(mRID='49AD8E07-3BF9-A4E2-CB8F-C3722F837B62') # IEEE 13-bus
network = FeederModel(connection=XMLFile('ieee13.xml'), container=feeder)
network.get_all_edges(cim.ACLineSegment) # every line's attributes and neighbours
for line in network.graph[cim.ACLineSegment].values():
print(line.name, f"{line.length.to('ft'):.0f} ft")
write_json_ld(network, 'ieee13.jsonld')
To read the model from Blazegraph instead of a file, swap XMLFile(...) for BlazegraphConnection(); nothing
else in the code changes. With a database, get_all_edges is the call that fetches the lines. A file is read
whole, so there it has nothing left to fetch.
-
The profile is the schema
Every CIM class is a Python dataclass generated from the UML: typed attributes, associations with their inverses, and enumerations. Pick a profile with one environment variable, or merge several.
-
One API, many sources
CIM XML, JSON-LD, RDFLib, Blazegraph, GraphDB, Neo4j, MySQL and GridAPPS-D all sit behind the same connection interface.
-
Feeders, substations, buses
FeederModel,NodeBreakerModelandBusBranchModelstart from a container and expand the graph one association at a time. Use them centralized, or split into distributed areas. -
Units, not bare numbers
Physical quantities are
CIMUnits stored in SI:cim.Length(1.2, 'km')in,.to('ft')out. There is no hand-written1e3anywhere. -
Edits you can send
create,modifyanddeletekeep both ends of each association in step and record every change, which you can write out as a CIM difference model. -
Stable identities
An ID that isn't a UUID gets one seeded from the model's authority and name and the object's mRID, so the same source always gives the same UUIDs. The IEC 61970-552 identifier styles are supported, both new and legacy.
Where it fits¶
flowchart LR
uml["<b>CIM UML</b><br/>Enterprise Architect,<br/>CIMTool profiles"] --> profiles["<b>cim-profiles</b><br/>CIM classes and units"]
profiles --> cimgraph["<b>cim-graph</b><br/>the model in memory"]
sources[("<b>CIM XML, JSON-LD,</b><br/>graph databases")] <--> cimgraph
cimgraph --> tables["<b>cim-tables</b><br/>.cimtbl text models"]
cimgraph --> builder["<b>CIM-Builder</b><br/>model builders"]
cimgraph --> hub["<b>CIMHub</b><br/>format converters"]
cim-graph is the hub of the PNNL CIM tools. CIM-Tables writes
models as plain-text tables, CIM-Builder builds them in code, and CIMHub converts them to and from other formats
such as OpenDSS.