Quick start¶
This notebook loads a small feeder written in .cimtbl and reads it with the getters in cimhub_core.getters: a line, a transformer, loads, a PV inverter and a terminal. It runs from docs/guide/ in the repository, next to feeder.cimtbl.
The model¶
One source, a 2000 ft line with its own sequence impedance, a 500 kVA transformer to 480 V, three loads and a PV inverter. Units are on the column headers, and CIM holds them as SI.
from pathlib import Path
print(Path('feeder.cimtbl').read_text())
# A small feeder for the quick start: a source, a 4.16 kV to 480 V transformer, a line with its own sequence
# impedance, a PV unit and three loads, one of them on a daily curve. The transformer follows the
# transformer_template shape and the load schedule follows the load_schedule shape, both in cimhub_core/shapes.
# Written for these docs; no external origin.
Profile = cim18v17
Authority = https://github.com/PNNL-CIM-Tools/CIMHub
Model = guide_feeder
Object BasePower: mRID=sbase, basePower (MVA)=10
Object BaseFrequency: mRID=base_freq, frequency (Hz)=60
Object Substation: mRID=sub, name=sub
Object Feeder: mRID=fdr, name=guide_feeder, NormalEnergizingSubstation=sub
Table BaseVoltage: mRID, nominalVoltage (kV)
bv_4p16kv, 4.16
bv_480v, 0.48
Table LoadResponseCharacteristic: mRID, exponentModel, pConstantPower, pConstantCurrent, pConstantImpedance, qConstantPower, qConstantCurrent, qConstantImpedance
zip_pq, false, 1, 0, 0, 1, 0, 0
zip_z, false, 0, 0, 1, 0, 0, 1
Object EnergySource: mRID=src, name=source, node=sourcebus, phases=ABC, nominalVoltage (kV)=4.16, voltageMagnitude (kV)=4.16, voltageAngle (deg)=0, r (ohm)=0.1, x (ohm)=0.4, BaseVoltage=bv_4p16kv, EquipmentContainer=fdr
# The line's own impedance (isTemplate=false), per length in the source's units.
Object PerLengthSequenceImpedance: mRID=ln_trunk_lc, name=trunk, isTemplate=false, calculatedFrequency (Hz)=60, r (ohm/km)=0.35, x (ohm/km)=0.43, r0 (ohm/km)=0.59, x0 (ohm/km)=1.3, bch (nS/km)=3900, b0ch (nS/km)=1700
Object ACLineSegment: mRID=ln_trunk, name=trunk, node1=sourcebus, node2=n1, phases=ABC, length (ft)=2000, PerLengthImpedance=ln_trunk_lc, BaseVoltage=bv_4p16kv, EquipmentContainer=fdr
# A 500 kVA Yn-Yn transformer; the ratings and impedance are in the template (the tank configuration).
Object TransformerTankConfiguration: mRID=xc_xfm1, name=xfm1, percentImpedance=2.2825, percentMagnetizingCurrent=0, noLoadLoss (kW)=0
Table TransformerTankEnd: mRID, endNumber, connectionKind, grounded, rground (ohm), xground (ohm), TankConfiguration=xc_xfm1
xc_xfm1_end_1, 1, Yn, true, 0, 0
xc_xfm1_end_2, 2, Yn, true, 0, 0
Table TransformerWinding: mRID, ratedU (kV), baseU (kV), ratedS (kVA), baseS (kVA), FromTransformerEnd, TankConfiguration=xc_xfm1
xc_xfm1_wdg_1, 4.16, 2.4, 500, 166.667, xc_xfm1_end_1
xc_xfm1_wdg_2, 0.48, 0.277, 500, 166.667, xc_xfm1_end_2
Object TransformerMeshImpedance: mRID=xc_xfm1_mesh_12, FromWinding=xc_xfm1_wdg_1, ToWinding=xc_xfm1_wdg_2, r (percent)=1.1, x (percent)=2.0
Object PowerTransformer: mRID=xf1, name=xf1, EquipmentContainer=fdr
Object TransformerTank: mRID=xf1_tank, PowerTransformer=xf1, TankConfiguration=xc_xfm1, EquipmentContainer=fdr
Table PowerTransformerEnd: mRID, node, phases, endNumber, connectionKind, grounded, BaseVoltage, PowerTransformer=xf1
xf1_1, n1, ABCN, 1, Yn, true, bv_4p16kv
xf1_2, n2, ABCN, 2, Yn, true, bv_480v
# ld_n1 is balanced; ld_n2 is unbalanced, its own p and q on each phase.
Table EnergyConsumer: mRID, name, node, phases, phaseConnection, grounded, p (kW), q (kVAr), LoadResponse, BaseVoltage, EquipmentContainer=fdr
ld_n1, n1, n1, ABC, Y, true, 1155, 660, zip_pq, bv_4p16kv
ld_n2, n2, n2, ABC, Y, true, 400, 290, zip_pq, bv_480v
Update Table EnergyConsumerPhase: mRID, p (kW), q (kVAr)
ld_n2_A, 160, 110
ld_n2_B, 120, 90
ld_n2_C, 120, 90
# A single-phase load on the daily curve of a ConformLoadGroup; its points are in a Parquet sidecar.
Object ConformLoadGroup: mRID=lg_daily, name=daily
Object ConformLoadSchedule: mRID=ls_daily, name=daily, startTime=2009-07-21T00:00:00-04:00, timeStep (s)=3600, value1Unit=none, ConformLoadGroup=lg_daily
Object ConformLoad: mRID=ld_c1, name=c1, node=n1, phases=C, phaseConnection=Y, grounded=true, p (kW)=170, q (kVAr)=80, LoadResponse=zip_z, BaseVoltage=bv_4p16kv, LoadGroup=lg_daily, EquipmentContainer=fdr
Object PowerElectronicsConnection: mRID=pv_p1, name=p1, node=n2, phases=ABC, phaseConnection=Y, ratedS (kVA)=300, ratedU (V)=480, p (kW)=-240, q (kVAr)=0, BaseVoltage=bv_480v, EquipmentContainer=fdr
Object PhotoVoltaicUnit: mRID=pv_p1_unit, maxP (kW)=300, minP (kW)=0, PowerElectronicsConnection=pv_p1, EquipmentContainer=fdr
Load it¶
cimtables.load_model builds a cim-graph FeederModel. It also sets the CIM profile for the whole process, so the load runs inside cim_scope(), which puts the profile back afterwards. The getters work on the loaded objects either way.
import cimprofiles.cim18.cim18v17 as cim
import cimtables
from cimhub_core.cimtbl_testing import cim_scope
with cim_scope():
network = cimtables.load_model('feeder.cimtbl')
print(type(network).__name__, network.base_power.to('MVA'))
FeederModel 10.0
A getter takes a CIM object, so a small helper finds one by mRID.
def find(cim_class, mrid):
return next(obj for obj in network.graph[cim_class].values() if obj.mRID == mrid)
line = find(cim.ACLineSegment, 'ln_trunk')
transformer = find(cim.PowerTransformer, 'xf1')
print(line.mRID, transformer.mRID)
ln_trunk xf1
A line¶
get_line_sequence_impedance reads the whole line's values. This line has no lumped r and x of its own: they come from its PerLengthSequenceImpedance. By default the getter looks only at the lumped values and says so. derive= lets it go one step further.
from cimhub_core.getters.line_impedance import ImpedanceSource, get_line_sequence_impedance
try:
get_line_sequence_impedance(line)
except ValueError as error:
print(error)
ACLineSegment 'ln_trunk': no sequence impedance within derive=LUMPED (lumped r/x: unset, PerLengthImpedance: PerLengthSequenceImpedance, geometry: none)
z = get_line_sequence_impedance(line, 'ohm', derive=ImpedanceSource.PER_LENGTH_SEQ)
print(z)
print(z.r, z.source.name)
SequenceImpedance(r=0.21335999999999997, x=0.26212799999999997, b=2.37744e-06, g=None, r0=0.359664, x0=0.79248, b0=1.03632e-06, g0=None, source=<ImpedanceSource.PER_LENGTH_SEQ: 2>) 0.21335999999999997 PER_LENGTH_SEQ
The same line in per-unit is on its BaseVoltage and the model's base power. Admittance is in siemens. g is None because the line has no conductance, and None is not zero: it says CIM leaves the value unset.
z_pu = get_line_sequence_impedance(line, 'pu', base_power=network.base_power, derive=ImpedanceSource.PER_LENGTH_SEQ)
print(round(z_pu.r, 4), round(z_pu.x, 4), z_pu.g)
0.1233 0.1515 None
The per-length values come in the units you name, here ohm/km and microsiemens/km. They are the numbers the file was written with.
from cimhub_core.getters.line_impedance import get_line_code, get_line_sequence_impedance_per_length
per_length = get_line_sequence_impedance_per_length(line, 'ohm/km', 'uS/km')
print(per_length.r, per_length.x, per_length.b)
print(get_line_code(line).mRID)
0.35 0.43 3.900000000000001 ln_trunk_lc
A transformer¶
A PowerTransformer is read through its units: its tanks, or the transformer itself when it has none. A three-phase transformer here has one tank, and a bank has one per can. get_transformer_model returns the windings and the mesh impedance. The ratings are in the units you name, and the impedance is percent on the power base it reports.
from cimhub_core.getters.transformer import get_transformer_model, get_transformer_units
[unit] = get_transformer_units(transformer)
model = get_transformer_model(unit, 'percent', voltage_unit='kV', power_unit='kVA')
print(model.form.name, model.base_power)
for winding in model.windings:
print(winding.number, winding.connection.value, winding.rated_u, winding.rated_s, winding.grounded)
print(model.mesh)
BY_TANK_ENDS 500.0
1 Yn 4.16 500.0 True
2 Yn 0.48 500.0 True
{(1, 2): MeshImpedance(r=1.1, x=2.0)}
The same impedance on the model's 10 MVA base, as per-unit.
on_system = get_transformer_model(unit, 'pu', base_power=network.base_power, voltage_unit='kV', power_unit='kVA')
print(on_system.base_power, on_system.mesh[(1, 2)])
10000.0 MeshImpedance(r=0.22, x=0.4)
Loads¶
get_phase_loads returns the total and each phase's share. split=True means the loader split the total evenly; False means each phase has its own values.
from cimhub_core.getters.load import get_phase_loads
balanced = get_phase_loads(find(cim.EnergyConsumer, 'ld_n1'), 'kW', 'kVAr')
print(balanced.total, balanced.split)
print({phase.value: power for phase, power in balanced.per_phase.items()})
PhasePower(p=1155.0, q=660.0) True
{'A': PhasePower(p=385.0, q=220.0), 'B': PhasePower(p=385.0, q=220.0), 'C': PhasePower(p=385.0, q=220.0)}
unbalanced = get_phase_loads(find(cim.EnergyConsumer, 'ld_n2'), 'kW', 'kVAr')
print(unbalanced.total, unbalanced.split)
print({phase.value: power for phase, power in unbalanced.per_phase.items()})
PhasePower(p=400.0, q=290.0) False
{'A': PhasePower(p=160.0, q=110.0), 'B': PhasePower(p=120.0, q=90.0), 'C': PhasePower(p=120.0, q=90.0)}
Without unit arguments the getter returns SI, W and VAr. Name the unit.
print(get_phase_loads(find(cim.EnergyConsumer, 'ld_n1')).total)
PhasePower(p=1155000.0, q=660000.0)
Generation and sign¶
CIM's sign is the load's: power into the equipment is positive, so a PV inverter's p is negative. get_der_output makes the caller choose the sign it wants.
from cimhub_core.getters.der import get_der_output
inverter = find(cim.PowerElectronicsConnection, 'pv_p1')
print(get_der_output(inverter, 'kW', 'kVAr', sign='load').total)
print(get_der_output(inverter, 'kW', 'kVAr', sign='generation').total)
PhasePower(p=-240.0, q=0.0) PhasePower(p=240.0, q=0.0)
Terminals and phases¶
A transformer's two ends have terminals on different nodes. get_terminal_phases reads one terminal's conductors, in A, B, C, s1, s2, N order.
from cimhub_core.getters.terminals import get_conductor_phases, get_terminal_nodes, get_terminal_phases
print([node.mRID for node in get_terminal_nodes(line)])
print([phase.value for phase in get_conductor_phases(line)])
for terminal in sorted(transformer.Terminals, key=lambda t: t.sequenceNumber):
print(terminal.sequenceNumber, [phase.value for phase in get_terminal_phases(terminal)])
['sourcebus', 'n1'] ['A', 'B', 'C'] 1 ['A', 'B', 'C', 'N'] 2 ['A', 'B', 'C', 'N']
Unset values and decisions¶
A getter that needs a value CIM leaves unset raises, and one that CIM may legitimately leave unset returns None. A getter that depends on a choice, such as which state of a switch, makes you pass it.
from cimhub_core.getters.in_service import get_in_service
print(get_in_service(line, which='actual'))
try:
get_in_service(line, which='now')
except ValueError as error:
print(error)
None which must be one of ['actual', 'normal'], not 'now'
Next: Using the getters and Units, bases and signs.
<style>
['pre { line-height: 125%; }\ntd.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\nspan.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }\ntd.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\nspan.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }\n.highlight-ipynb .hll { background-color: var(--jp-cell-editor-active-background) }\n.highlight-ipynb { background: var(--jp-cell-editor-background); color: var(--jp-mirror-editor-variable-color) }\n.highlight-ipynb .c { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment */\n.highlight-ipynb .err { color: var(--jp-mirror-editor-error-color) } /* Error */\n.highlight-ipynb .k { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword */\n.highlight-ipynb .o { color: var(--jp-mirror-editor-operator-color); font-weight: bold } /* Operator */\n.highlight-ipynb .p { color: var(--jp-mirror-editor-punctuation-color) } /* Punctuation */\n.highlight-ipynb .ch { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Hashbang */\n.highlight-ipynb .cm { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Multiline */\n.highlight-ipynb .cp { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Preproc */\n.highlight-ipynb .cpf { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.PreprocFile */\n.highlight-ipynb .c1 { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Single */\n.highlight-ipynb .cs { color: var(--jp-mirror-editor-comment-color); font-style: italic } /* Comment.Special */\n.highlight-ipynb .kc { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Constant */\n.highlight-ipynb .kd { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Declaration */\n.highlight-ipynb .kn { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Namespace */\n.highlight-ipynb .kp { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Pseudo */\n.highlight-ipynb .kr { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Reserved */\n.highlight-ipynb .kt { color: var(--jp-mirror-editor-keyword-color); font-weight: bold } /* Keyword.Type */\n.highlight-ipynb .m { color: var(--jp-mirror-editor-number-color) } /* Literal.Number */\n.highlight-ipynb .s { color: var(--jp-mirror-editor-string-color) } /* Literal.String */\n.highlight-ipynb .ow { color: var(--jp-mirror-editor-operator-color); font-weight: bold } /* Operator.Word */\n.highlight-ipynb .pm { color: var(--jp-mirror-editor-punctuation-color) } /* Punctuation.Marker */\n.highlight-ipynb .w { color: var(--jp-mirror-editor-variable-color) } /* Text.Whitespace */\n.highlight-ipynb .mb { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Bin */\n.highlight-ipynb .mf { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Float */\n.highlight-ipynb .mh { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Hex */\n.highlight-ipynb .mi { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Integer */\n.highlight-ipynb .mo { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Oct */\n.highlight-ipynb .sa { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Affix */\n.highlight-ipynb .sb { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Backtick */\n.highlight-ipynb .sc { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Char */\n.highlight-ipynb .dl { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Delimiter */\n.highlight-ipynb .sd { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Doc */\n.highlight-ipynb .s2 { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Double */\n.highlight-ipynb .se { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Escape */\n.highlight-ipynb .sh { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Heredoc */\n.highlight-ipynb .si { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Interpol */\n.highlight-ipynb .sx { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Other */\n.highlight-ipynb .sr { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Regex */\n.highlight-ipynb .s1 { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Single */\n.highlight-ipynb .ss { color: var(--jp-mirror-editor-string-color) } /* Literal.String.Symbol */\n.highlight-ipynb .il { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Integer.Long */']
</style>