def control_to_cim(pb: PBControl, network_service: NetworkService) -> Optional[Control]: cim = Control(mrid=pb.mrid()) network_service.resolve_or_defer_reference(resolver.remote_control(cim), pb.remoteControlMRID) iopoint_to_cim(pb.ip, cim, network_service) return cim if network_service.add(cim) else None
def basevoltage_to_cim( pb: PBBaseVoltage, network_service: NetworkService) -> Optional[BaseVoltage]: cim = BaseVoltage(mrid=pb.mrid()) cim.nominal_voltage = pb.nominalVoltage identifiedobject_to_cim(pb.io, cim, network_service) return cim if network_service.add(cim) else None
def ratiotapchanger_to_cim( pb: PBRatioTapChanger, network_service: NetworkService) -> Optional[RatioTapChanger]: cim = RatioTapChanger(mrid=pb.mrid(), step_voltage_increment=pb.stepVoltageIncrement) tapchanger_to_cim(pb.tc, cim, network_service) return cim if network_service.add(cim) else None
def pole_to_cim(pb: PBPole, network_service: NetworkService) -> Optional[Pole]: cim = Pole(mrid=pb.mrid(), classification=pb.classification) for mrid in pb.streetlightMRIDs: network_service.resolve_or_defer_reference(resolver.streetlights(cim), mrid) structure_to_cim(pb.st, cim, network_service) return cim if network_service.add(cim) else None
def energysourcephase_to_cim( pb: PBEnergySourcePhase, network_service: NetworkService) -> Optional[EnergySourcePhase]: cim = EnergySourcePhase(mrid=pb.mrid(), phase=phasekind_by_id(pb.phase)) network_service.resolve_or_defer_reference(resolver.energy_source(cim), pb.energySourceMRID) powersystemresource_to_cim(pb.psr, cim, network_service) return cim if network_service.add(cim) else None
def remotesource_to_cim( pb: PBRemoteSource, network_service: NetworkService) -> Optional[RemoteSource]: cim = RemoteSource(mrid=pb.mrid()) network_service.resolve_or_defer_reference(resolver.measurement(cim), pb.measurementMRID) remotepoint_to_cim(pb.rp, cim, network_service) return cim if network_service.add(cim) else None
def streetlight_to_cim( pb: PBStreetlight, network_service: NetworkService) -> Optional[Streetlight]: cim = Streetlight(mrid=pb.mrid(), light_rating=pb.lightRating, lamp_kind=StreetlightLampKind(pb.lampKind)) network_service.resolve_or_defer_reference(resolver.pole(cim), pb.poleMRID) asset_to_cim(pb.at, cim, network_service) return cim if network_service.add(cim) else None
def location_to_cim(pb: PBLocation, network_service: NetworkService) -> Optional[Location]: cim = Location(mrid=pb.mrid(), main_address=streetaddress_to_cim(pb.mainAddress) if pb.HasField('mainAddress') else None) for point in pb.positionPoints: cim.add_point(positionpoint_to_cim(point)) identifiedobject_to_cim(pb.io, cim, network_service) return cim if network_service.add(cim) else None
def aclinesegment_to_cim( pb: PBAcLineSegment, network_service: NetworkService) -> Optional[AcLineSegment]: cim = AcLineSegment(mrid=pb.mrid()) network_service.resolve_or_defer_reference( resolver.per_length_sequence_impedance(cim), pb.perLengthSequenceImpedanceMRID) conductor_to_cim(pb.cd, cim, network_service) return cim if network_service.add(cim) else None
def geographicalregion_to_cim( pb: PBGeographicalRegion, network_service: NetworkService) -> Optional[GeographicalRegion]: cim = GeographicalRegion(mrid=pb.mrid()) for mrid in pb.subGeographicalRegionMRIDs: network_service.resolve_or_defer_reference( resolver.sub_geographical_regions(cim), mrid) identifiedobject_to_cim(pb.io, cim, network_service) return cim if network_service.add(cim) else None
def connectivitynode_to_cim( pb: PBConnectivityNode, network_service: NetworkService) -> Optional[ConnectivityNode]: cim = ConnectivityNode(mrid=pb.mrid()) for mrid in pb.terminalMRIDs: network_service.resolve_or_defer_reference(resolver.cn_terminals(cim), mrid) identifiedobject_to_cim(pb.io, cim, network_service) return cim if network_service.add(cim) else None
def operationalrestriction_to_cim( pb: PBOperationalRestriction, network_service: NetworkService) -> Optional[OperationalRestriction]: cim = OperationalRestriction(mrid=pb.mrid()) for mrid in pb.equipmentMRIDs: network_service.resolve_or_defer_reference(resolver.or_equipment(cim), mrid) document_to_cim(pb.doc, cim, network_service) return cim if network_service.add(cim) else None
def linearshuntcompensator_to_cim( pb: PBLinearShuntCompensator, network_service: NetworkService) -> Optional[LinearShuntCompensator]: cim = LinearShuntCompensator(mrid=pb.mrid(), b0_per_section=pb.b0PerSection, b_per_section=pb.bPerSection, g0_per_section=pb.g0PerSection, g_per_section=pb.gPerSection) shuntcompensator_to_cim(pb.sc, cim, network_service) return cim if network_service.add(cim) else None
def circuit_to_cim(pb: PBCircuit, network_service: NetworkService) -> Optional[Circuit]: cim = Circuit(mrid=pb.mrid()) for mrid in pb.endTerminalMRIDs: network_service.resolve_or_defer_reference(resolver.end_terminal(cim), mrid) for mrid in pb.endSubstationMRIDs: network_service.resolve_or_defer_reference( resolver.end_substation(cim), mrid) line_to_cim(pb.l, cim, network_service) return cim if network_service.add(cim) else None
def powertransformer_to_cim( pb: PBPowerTransformer, network_service: NetworkService) -> Optional[PowerTransformer]: cim = PowerTransformer(mrid=pb.mrid(), vector_group=VectorGroup(pb.vectorGroup), transformer_utilisation=pb.transformerUtilisation) for mrid in pb.powerTransformerEndMRIDs: network_service.resolve_or_defer_reference(resolver.ends(cim), mrid) network_service.resolve_or_defer_reference( resolver.power_transformer_info(cim), pb.asset_info_mrid()) conductingequipment_to_cim(pb.ce, cim, network_service) return cim if network_service.add(cim) else None
def energyconsumerphase_to_cim( pb: PBEnergyConsumerPhase, network_service: NetworkService) -> Optional[EnergyConsumerPhase]: cim = EnergyConsumerPhase(mrid=pb.mrid(), phase=phasekind_by_id(pb.phase), p=pb.p, p_fixed=pb.pFixed, q=pb.q, q_fixed=pb.qFixed) network_service.resolve_or_defer_reference(resolver.energy_consumer(cim), pb.energyConsumerMRID) powersystemresource_to_cim(pb.psr, cim, network_service) return cim if network_service.add(cim) else None
def usagepoint_to_cim(pb: PBUsagePoint, network_service: NetworkService) -> Optional[UsagePoint]: cim = UsagePoint(mrid=pb.mrid()) network_service.resolve_or_defer_reference( resolver.usage_point_location(cim), pb.usagePointLocationMRID) for mrid in pb.equipmentMRIDs: network_service.resolve_or_defer_reference(resolver.up_equipment(cim), mrid) for mrid in pb.endDeviceMRIDs: network_service.resolve_or_defer_reference(resolver.end_devices(cim), mrid) identifiedobject_to_cim(pb.io, cim, network_service) return cim if network_service.add(cim) else None
def terminal_to_cim(pb: PBTerminal, network_service: NetworkService) -> Optional[Terminal]: cim = Terminal(mrid=pb.mrid(), phases=phasecode_by_id(pb.phases), sequence_number=pb.sequenceNumber) network_service.resolve_or_defer_reference( resolver.conducting_equipment(cim), pb.conductingEquipmentMRID) cim.traced_phases._normal_status = pb.tracedPhases.normalStatus cim.traced_phases._current_status = pb.tracedPhases.currentStatus network_service.resolve_or_defer_reference(resolver.connectivity_node(cim), pb.connectivityNodeMRID) acdcterminal_to_cim(pb.ad, cim, network_service) return cim if network_service.add(cim) else None
def feeder_to_cim(pb: PBFeeder, network_service: NetworkService) -> Optional[Feeder]: cim = Feeder(mrid=pb.mrid()) network_service.resolve_or_defer_reference( resolver.normal_head_terminal(cim), pb.normalHeadTerminalMRID) network_service.resolve_or_defer_reference( resolver.normal_energizing_substation(cim), pb.normalEnergizingSubstationMRID) for mrid in pb.currentEquipmentMRIDs: network_service.resolve_or_defer_reference( resolver.current_equipment(cim), mrid) equipmentcontainer_to_cim(pb.ec, cim, network_service) return cim if network_service.add(cim) else None
def loop_to_cim(pb: PBLoop, network_service: NetworkService) -> Optional[Loop]: cim = Loop(mrid=pb.mrid()) for mrid in pb.circuitMRIDs: network_service.resolve_or_defer_reference(resolver.loop_circuits(cim), mrid) for mrid in pb.substationMRIDs: network_service.resolve_or_defer_reference( resolver.loop_substations(cim), mrid) for mrid in pb.normalEnergizingSubstationMRIDs: network_service.resolve_or_defer_reference( resolver.loop_energizing_substations(cim), mrid) identifiedobject_to_cim(pb.io, cim, network_service) return cim if network_service.add(cim) else None
def perlengthsequenceimpedance_to_cim( pb: PBPerLengthSequenceImpedance, network_service: NetworkService ) -> Optional[PerLengthSequenceImpedance]: cim = PerLengthSequenceImpedance(mrid=pb.mrid(), r=pb.r, x=pb.x, r0=pb.r0, x0=pb.x0, bch=pb.bch, gch=pb.gch, b0ch=pb.b0ch, g0ch=pb.g0ch) perlengthimpedance_to_cim(pb.pli, cim, network_service) return cim if network_service.add(cim) else None
def energyconsumer_to_cim( pb: PBEnergyConsumer, network_service: NetworkService) -> Optional[EnergyConsumer]: cim = EnergyConsumer(mrid=pb.mrid(), customer_count=pb.customerCount, grounded=pb.grounded, p=pb.p, p_fixed=pb.pFixed, q=pb.q, q_fixed=pb.qFixed, phase_connection=PhaseShuntConnectionKind( pb.phaseConnection)) for mrid in pb.energyConsumerPhasesMRIDs: network_service.resolve_or_defer_reference(resolver.ec_phases(cim), mrid) energyconnection_to_cim(pb.ec, cim, network_service) return cim if network_service.add(cim) else None
def substation_to_cim(pb: PBSubstation, network_service: NetworkService) -> Optional[Substation]: cim = Substation(mrid=pb.mrid()) network_service.resolve_or_defer_reference( resolver.sub_geographical_region(cim), pb.subGeographicalRegionMRID) for mrid in pb.normalEnergizedFeederMRIDs: network_service.resolve_or_defer_reference( resolver.normal_energizing_feeders(cim), mrid) for mrid in pb.loopMRIDs: network_service.resolve_or_defer_reference(resolver.loops(cim), mrid) for mrid in pb.normalEnergizedLoopMRIDs: network_service.resolve_or_defer_reference( resolver.normal_energized_loops(cim), mrid) for mrid in pb.circuitMRIDs: network_service.resolve_or_defer_reference(resolver.circuits(cim), mrid) equipmentcontainer_to_cim(pb.ec, cim, network_service) return cim if network_service.add(cim) else None
def powertransformerend_to_cim( pb: PBPowerTransformerEnd, network_service: NetworkService) -> Optional[PowerTransformerEnd]: cim = PowerTransformerEnd(mrid=pb.mrid(), rated_s=pb.ratedS, rated_u=pb.ratedU, r=pb.r, r0=pb.r0, x=pb.x, x0=pb.x0, b=pb.b, b0=pb.b0, g=pb.g, g0=pb.g0, connection_kind=WindingConnection( pb.connectionKind), phase_angle_clock=pb.phaseAngleClock) network_service.resolve_or_defer_reference(resolver.power_transformer(cim), pb.powerTransformerMRID) transformerend_to_cim(pb.te, cim, network_service) return cim if network_service.add(cim) else None
def energysource_to_cim( pb: PBEnergySource, network_service: NetworkService) -> Optional[EnergySource]: cim = EnergySource(mrid=pb.mrid(), active_power=pb.activePower, reactive_power=pb.reactivePower, voltage_angle=pb.voltageAngle, voltage_magnitude=pb.voltageMagnitude, r=pb.r, x=pb.x, p_max=pb.pMax, p_min=pb.pMin, r0=pb.r0, rn=pb.rn, x0=pb.x0, xn=pb.xn) for mrid in pb.energySourcePhasesMRIDs: network_service.resolve_or_defer_reference(resolver.es_phases(cim), mrid) energyconnection_to_cim(pb.ec, cim, network_service) return cim if network_service.add(cim) else None
def recloser_to_cim(pb: PBRecloser, network_service: NetworkService) -> Optional[Recloser]: cim = Recloser(mrid=pb.mrid()) protectedswitch_to_cim(pb.sw, cim, network_service) return cim if network_service.add(cim) else None
def disconnector_to_cim( pb: PBDisconnector, network_service: NetworkService) -> Optional[Disconnector]: cim = Disconnector(mrid=pb.mrid()) switch_to_cim(pb.sw, cim, network_service) return cim if network_service.add(cim) else None
def fuse_to_cim(pb: PBFuse, network_service: NetworkService) -> Optional[Fuse]: cim = Fuse(mrid=pb.mrid()) switch_to_cim(pb.sw, cim, network_service) return cim if network_service.add(cim) else None
def junction_to_cim(pb: PBJunction, network_service: NetworkService) -> Optional[Junction]: cim = Junction(mrid=pb.mrid()) connector_to_cim(pb.cn, cim, network_service) return cim if network_service.add(cim) else None
def jumper_to_cim(pb: PBJumper, network_service: NetworkService) -> Optional[Jumper]: cim = Jumper(mrid=pb.mrid()) switch_to_cim(pb.sw, cim, network_service) return cim if network_service.add(cim) else None