{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Bus-Branch Transmission Modeling" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating a BusBranchModel" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import all required libraries for data profile, connection parameters, database, and `BusBranchModel`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import cimgraph.data_profile.rc4_2021 as cim\n", "from cimgraph import ConnectionParameters\n", "from cimgraph.databases.blazegraph import BlazegraphConnection\n", "from cimgraph.models import BusBranchModel" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Blazegraph Connection\n", "params = ConnectionParameters(url = \"http://localhost:8889/bigdata/namespace/kb/sparql\",\n", " cim_profile='rc4_2021', iec61970_301=8)\n", "blazegraph = BlazegraphConnection(params)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create CIM EquipmentContainer object:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_mrid = \"1783D2A8-1204-4781-A0B4-7A73A2FA6038\" #IEEE 118 Bus\n", "container = cim.ConnectivityNodeContainer(mRID=model_mrid)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "network = BusBranchModel(connection=blazegraph, container=container, distributed=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "network.get_all_edges(cim.ACLineSegment)\n", "network.pprint(cim.ACLineSegment)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'importlib' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[1], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m cim_profile \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcimhub_2023\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m----> 2\u001b[0m cim \u001b[38;5;241m=\u001b[39m \u001b[43mimportlib\u001b[49m\u001b[38;5;241m.\u001b[39mimport_module(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcimgraph.data_profile.\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m cim_profile)\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# RDFLib File Reader Connection\u001b[39;00m\n\u001b[1;32m 5\u001b[0m params \u001b[38;5;241m=\u001b[39m ConnectionParameters(filename\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../cimgraph/tests/test_models/IEEE118_CIM.xml\u001b[39m\u001b[38;5;124m\"\u001b[39m, cim_profile\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcimhub_2023\u001b[39m\u001b[38;5;124m'\u001b[39m, iec61970_301\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m8\u001b[39m)\n", "\u001b[0;31mNameError\u001b[0m: name 'importlib' is not defined" ] } ], "source": [ "cim_profile = 'cimhub_2023'\n", "cim = importlib.import_module('cimgraph.data_profile.' + cim_profile)\n", "\n", "# RDFLib File Reader Connection\n", "params = ConnectionParameters(filename=\"../cimgraph/tests/test_models/IEEE118_CIM.xml\", cim_profile='cimhub_2023', iec61970_301=8)\n", "rdf = RDFlibConnection(params)\n", "\n", "model_mrid = \"1783D2A8-1204-4781-A0B4-7A73A2FA6038\" #IEEE 118 Bus\"\n", "container = cim.ConnectivityNodeContainer(mRID = model_mrid)\n", "network = BusBranchModel(connection=rdf, container=container, distributed=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "load_nodes = []\n", "gen_nodes = []\n", "cap_nodes = []\n", "inv_nodes = []\n", "\n", "for node in network.graph[cim.ConnectivityNode].values():\n", " print(\"\\n listing equipment for node\", node.name)\n", " for terminal in node.Terminals:\n", " equipment = terminal.ConductingEquipment\n", " # print(equipment.__class__.__name__, equipment.mRID)\n", " type = equipment.__class__.__name__\n", " load_types = ['EnergyConsumer', 'ConformLoad', 'NonConformLoad']\n", " gen_types = ['RotatingMachine', 'SynchronousMachine', 'AsynchronousMachine']\n", " cap_types = ['ShuntCompensator', 'LinearShuntCompensator']\n", " inv_types = ['PowerElectronicsConnection']\n", "\n", "\n", "\n", " if type in load_types:\n", " load_nodes.append(node.mRID)\n", " if type in gen_types:\n", " print('gen node')\n", " if type in \n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "network.get_all_edges(cim.EnergyConsumer)\n", "network.get_all_edges(cim.ConformLoad)\n", "network.get_all_edges(cim.NonConformLoad)\n", "\n", "for load in network.graph[cim.EnergyConsumer].values():\n", " print(f\"name:{load.name}, bus:{load.Terminals[0].ConnectivityNode.name}, p:{float(load.p)/1e6} MW, q:{float(load.q)/1e6} MVAr\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "network.get_all_edges(cim.BaseVoltage)\n", "load_by_voltage = {}\n", "for id in network.graph[cim.BaseVoltage].values():\n", " nomv = id.nominalVoltage\n", " load_by_voltage[id.mRID] = []\n", " for equipment in id.ConductingEquipment:\n", " type = equipment.__class__.__name__\n", " load_types = ['EnergyConsumer', 'ConformLoad', 'NonConformLoad']\n", " if type in load_types:\n", " load_by_voltage[id.mRID].append(equipment)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for id in list(load_by_voltage.keys()):\n", " nomv = network.graph[cim.BaseVoltage][id].nominalVoltage\n", " print(nomv)\n", "\n", " for load in load_by_voltage[id]:\n", " print(load.name, load.p, load.q, load.Terminals[0].ConnectivityNode.name)" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }