Connection Parameters

The first step in using any of CIMantic Graphs functionalities is to define the connection parameters, which specify the CIM Profile, serialization format, and database to be used. The ConnectionParameters class is used to specify these inputs with the following required and optional arguments:

[2]:
from cimgraph import ConnectionParameters

1. Connection Arguments

Required arguments:

  • cim_profile: This specifies the specific version of CIM to be used, based on the available python data profiles loaded into the library

Optional arguments:

  • namespace: CIM namespace, default is "http://iec.ch/TC57/CIM100#"

  • iec61970-301: Serialization version, default is 7

  • url: URL at which the database can be reached via TCP/IP or other connection

  • host: Database host address

  • port: Database host port

  • database: Database name

  • username: Database username

  • password: Database password

  • filename: Filename for importing CIM models from an XML file

Note that not all parameters are required. Each database connection uses a subset of these arguments depending on the requirements of the database connection driver.

1.1. CIM Namespaces

Each version of the CIM uses a specific namespace, which can typically be found in the first line of the XML file, such as

xmlns:cim="http://iec.ch/TC57/2011/CIM-schema-cim15#"

The default used by CIMantic Graphs is the CIM100 namespace "http://iec.ch/TC57/CIM100#"

To change the namespace used, pass the namespace as a string into the connection parameters. This will then be used in all automated query builders:

[3]:
params = ConnectionParameters(namespace = "http://iec.ch/TC57/2011/CIM-schema-cim15#")

1.2. IEC 61970-301 Serialization Version

Versions 7.0 and older of the IEC 61970-301 standard used the serialization format:

<cim:ClsName rdf:ID="_ABEB635F-729D-24BF-B8A4-E2EF268D8B9E">
  <cim:ClsName.Assoc rdf:resource="#_73C512BD-7249-4F50-50DA-D93849B89C43"/>
</cim:ClsName>

Version 8.0 of the standard has changed the serialization format to specify that the serialization identifier must be a UUID:

<cim:ClsName rdf:about="urn:uuid:abeb635f-729d-24bf-b8a4-e2ef268d8b9e">
  <cim:ClsName.Assoc rdf:resource="urn:uuid:73c512bd-7249-4f50-50da-d93849b89c43"/>
</cim:ClsName>

To enable CIMantic Graphs to handle different serializations dynamically, the serialization version can be passed as an integer argument:

[4]:
params = ConnectionParameters(iec61970_301 = 7) # Use with rdf:ID
[5]:
params = ConnectionParameters(iec61970_301 = 7) # Use with rdf:about:urn:uuid

2. Creating a Connection

CIMantic Graphs currently supports the following data sources:

  • Blazegraph Database

  • GraphDB Database

  • Neo4J Database

  • MySQL Database (in progress)

  • GridAPPS-D Platform

  • AVEVA PI Asset Framework (in progress)

  • RDFLib File Parser

To create the database connection, specify the url / host+port and username/password based on the specific requirements of each database connection driver. Examples of connection parameters for the supported databases are listed below.


3. Blazegraph Database

Blazegraph DB is a ultra high-performance open-source database supporting Blueprints and RDF/SPARQL APIs. It supports up to 50 Billion edges on a single machine.

Docker images preloaded with IEEE test feeders are available from https://hub.docker.com/r/gridappsd/blazegraph/tags.

To connect to Blazegraph, import the BlazegraphConnection class:

[6]:
# Import class from cimgraph databases module
from cimgraph.databases.blazegraph import BlazegraphConnection
# Create connection parameters
params = ConnectionParameters(url = "http://localhost:8889/bigdata/namespace/kb/sparql",
                              cim_profile='rc4_2021', iec61970_301=8)
# Create database connection object
blazegraph = BlazegraphConnection(params)


4. Graph DB Database Connection

GraphDB is a full-featured commercial RDF graph database developed by Ontotext

[7]:
# Import class from cimgraph databases module
from cimgraph.databases.graphdb import GraphDBConnection
# Create connection parameters
params = ConnectionParameters(url = "http://localhost:7200/repositories/cim_test",
                              cim_profile='rc4_2021', iec61970_301=8)
# Create database connection object
graphdb = GraphDBConnection(params)

5. Neo4j Database Connection

[8]:
# Import class from cimgraph databases module
from cimgraph.databases.neo4j import Neo4jConnection
# Create connection parameters

params = ConnectionParameters(url = "neo4j://localhost:7687/neo4j", database="neo4j",
                               cim_profile='rc4_2021', iec61970_301=8)
# Create database connection object
neo4j = Neo4jConnection(params)

6. MySQL-JSON-LD Database Connection

MySQL database with JSON-LD typing generated by the PNNL CIM-Loader library

[ ]:
# Import class from cimgraph databases module
from cimgraph.databases.mysql.mysql import MySQLJSONConnection
# Create connection parameters
params = ConnectionParameters(host= "localhost", database="rc4_2021", username="root", password="password",
                              cim_profile='rc4_2021', namespace="http://iec.ch/TC57/CIM100#")

# Create database connection object
mysql = MySQLJSONConnection(params)

GridAPPS-D Platform Connection

[ ]:
# Import class from cimgraph databases module
from cimgraph.databases.gridappsd import GridAPPSDConnection
# Create connection parameters
params = ConnectionParameters(host= "localhost", port="61613", username="app_user", password="1234App",
                              cim_profile='rc4_2021', namespace="http://iec.ch/TC57/CIM100#")
# Create platform connection object
gapps = GridAPPSDConnection(params)

AVEVA PI Asset Framework (PI-Web-API) Connection

[ ]:
#TODO
[ ]:

Local Connection (No Database)

[ ]:
#TODO
[ ]:

RDFLib File Parser Connection (No Database)

[ ]:
from cimgraph.databases.rdflib.rdflib import RDFlibConnection
# RDFLib File Reader Connection
params = ConnectionParameters(filename="./maple10bus.xml",
                               cim_profile='rc4_2021', iec61970_301=7)
rdf = RDFlibConnection(params)
[ ]: