示例#1
0
def setup_line_test():
    """Setup a line with 4 wires."""
    from ditto.store import Store
    from ditto.models.line import Line
    from ditto.models.wire import Wire

    m = Store()
    wire_A = Wire(
        m,
        phase="A",
        nameclass="wire_test_phase",
        diameter=5,
        gmr=10,
        ampacity=500,
        emergency_ampacity=1000,
        resistance=5,
    )
    wire_B = Wire(
        m,
        phase="B",
        nameclass="wire_test_phase",
        diameter=5,
        gmr=10,
        ampacity=500,
        emergency_ampacity=1000,
        resistance=5,
    )
    wire_C = Wire(
        m,
        phase="C",
        nameclass="wire_test_phase",
        diameter=5,  # Missing GMR
        ampacity=500,
        emergency_ampacity=1000,
        resistance=5,
    )
    wire_N = Wire(
        m,
        phase="N",
        nameclass="wire_test_neutral",
        diameter=5,
        gmr=10,
        ampacity=500,
        emergency_ampacity=1000,
        resistance=5,
    )
    line = Line(m, name="l1", wires=[wire_A, wire_B, wire_C, wire_N])

    return line
示例#2
0
    def create_switch(self, model, node1, node2):
        switch = Line(model)
        switch.name = node2.replace("node_", "")
        switch.from_element = node1
        switch.to_element = node2
        switch.is_fuse = False
        switch.is_switch = True
        switch.is_banked = False
        switch.is_breaker = False
        switch.is_recloser = False
        switch.is_substation = False
        switch.is_sectionalizer = False
        switch.length = 1  #
        switch.feeder_name = ("" if isinstance(
            self.nxGraph[node1][node2]["feeder"], float) else
                              self.nxGraph[node1][node2]["feeder"])
        switch.substation_name = ("" if isinstance(
            self.nxGraph[node1][node2]["substation"], float) else
                                  self.nxGraph[node1][node2]["substation"])
        phases = self.nxGraph[node1][node2]["phases"]
        phase_list = self.phase_2_index[phases]

        for phase, phase_index in zip(phases, phase_list):
            phase_sw = Wire(model)
            phase_sw.phase = phase
            phase_sw.is_open = (True if self.nxGraph[node1][node2]["state"]
                                == "O" else False)
            # TODO: Fix enabled property for switch
            phase_sw.is_switch = True
            phase_sw.is_fuse = False
            phase_sw.is_recloser = False
            phase_sw.is_breaker = False

            switch.wires.append(phase_sw)

        for node_name in [node1, node2]:
            if "x" in self.nxGraph.node[node_name]:
                node_pos = Position(model)
                node_pos.long = float(self.nxGraph.node[node_name]["x"])
                node_pos.lat = float(self.nxGraph.node[node_name]["y"])
                switch.positions.append(node_pos)
示例#3
0
def test_parse_concentric_neutral_cable():
    """
    Tests the parsing of concentric neutral cables.

    The example used is:

    New CNDATA.250_1/3 k=13 DiaStrand=0.064 Rstrand=2.816666667 epsR=2.3
    ~ InsLayer=0.220 DiaIns=1.06 DiaCable=1.16 Rac=0.076705 GMRac=0.20568 diam=0.573
    ~ Runits=kft Radunits=in GMRunits=in
    """
    from ditto.store import Store
    from ditto.models.wire import Wire
    from ditto.writers.opendss.write import Writer

    m = Store()
    wire = Wire(
        m,
        phase="A",
        nameclass="250_1/3",
        diameter=0.0145542,  # 0.573 inches in meters
        gmr=0.005224272,  # 0.20568 inches in meters
        ampacity=500,
        emergency_ampacity=1000,
        resistance=0.000251656824147,  # 0.076705 ohm/kft in ohm/meter
        concentric_neutral_resistance=
        0.00924103237205,  # 2.816666667 ohm/kft in ohm/meter
        concentric_neutral_diameter=0.0016256,  # 0.064 inches in meters
        concentric_neutral_outside_diameter=0.029464,  # 1.16 inches in meters
        concentric_neutral_nstrand=13,
    )
    output_path = tempfile.gettempdir()
    w = Writer(output_path=output_path)
    parsed_cable = w.parse_cable(wire)
    assert parsed_cable["k"] == 13
    assert parsed_cable["DiaStrand"] == 0.0016256
    assert parsed_cable["Rstrand"] == 0.00924103237205
    assert parsed_cable["Diam"] == 0.0145542
    assert parsed_cable["DiaCable"] == 0.029464
    assert parsed_cable["Rac"] == 0.000251656824147
    assert parsed_cable["GMRac"] == 0.005224272
    assert parsed_cable["Runits"] == "m"
    assert parsed_cable["Radunits"] == "m"
    assert parsed_cable["GMRunits"] == "m"
示例#4
0
    def create_switch(self, model, node1, node2):
        switch = Line(model)
        switch.name = node2.replace('node_', '')
        switch.from_element = node1
        switch.to_element = node2
        switch.is_fuse = False
        switch.is_switch = True
        switch.is_banked = False
        switch.is_breaker = False
        switch.is_recloser = False
        switch.is_substation = False
        switch.is_sectionalizer = False
        switch.length = 1  #
        switch.feeder_name = '' if isinstance(self.nxGraph[node1][node2]['feeder'], float) else \
            self.nxGraph[node1][node2]['feeder']
        switch.substation_name = '' if isinstance(self.nxGraph[node1][node2]['substation'], float) else \
            self.nxGraph[node1][node2]['substation']
        phases = self.nxGraph[node1][node2]['phases']
        phase_list = self.phase_2_index[phases]

        for phase, phase_index in zip(phases, phase_list):
            phase_sw = Wire(model)
            phase_sw.phase = phase
            phase_sw.is_open = True if self.nxGraph[node1][node2][
                'state'] == 'O' else False
            #TODO: Fix enabled property for switch
            phase_sw.is_switch = True
            phase_sw.is_fuse = False
            phase_sw.is_recloser = False
            phase_sw.is_breaker = False

            switch.wires.append(phase_sw)

        for node_name in [node1, node2]:
            if 'x' in self.nxGraph.node[node_name]:
                node_pos = Position(model)
                node_pos.long = float(self.nxGraph.node[node_name]['x'])
                node_pos.lat = float(self.nxGraph.node[node_name]['y'])
                switch.positions.append(node_pos)
示例#5
0
def test_parse_wire():
    from ditto.store import Store
    from ditto.models.wire import Wire
    from ditto.writers.opendss.write import Writer

    m = Store()
    wire_A = Wire(
        m,
        phase="A",
        nameclass="wire_test_phase",
        diameter=5,
        gmr=10,
        ampacity=500,
        emergency_ampacity=1000,
        resistance=5,
    )
    output_path = tempfile.gettempdir()
    w = Writer(output_path=output_path)
    parsed_wire = w.parse_wire(wire_A)
    assert parsed_wire["GMRac"] == 10
    assert parsed_wire["Diam"] == 5
    assert parsed_wire["normamps"] == 500
    assert parsed_wire["emergamps"] == 1000
    assert parsed_wire["Rac"] == 5
示例#6
0
    def create_line(self, model, node1, node2, OHcables, UGcables):
        line = Line(model)
        line.name = node2.replace("node_", "")
        line.from_element = node1
        line.to_element = node2
        line.is_breaker = False
        line.is_recloser = False
        line.is_banked = False
        line.is_fuse = False
        line.is_sectionalizer = False
        line.is_switch = False
        line.length = self.convert_to_meters(
            float(self.nxGraph[node1][node2]["length"]), "ft")
        # line.nominal_voltage = float(self.nxGraph[node1][node2]['kv'])    #TODO: line nominal KV
        line.line_type = self.nxGraph[node1][node2]["type"]
        line.feeder_name = ("" if isinstance(
            self.nxGraph[node1][node2]["feeder"], float) else
                            self.nxGraph[node1][node2]["feeder"])
        line.substation_name = ("" if isinstance(
            self.nxGraph[node1][node2]["substation"], float) else
                                self.nxGraph[node1][node2]["substation"])

        for node_name in [node1, node2]:
            if "x" in self.nxGraph.node[node_name]:
                node_pos = Position(model)
                node_pos.long = float(self.nxGraph.node[node_name]["x"])
                node_pos.lat = float(self.nxGraph.node[node_name]["y"])
                line.positions.append(node_pos)

        phases = self.nxGraph[node1][node2]["phases"]
        phase_list = self.phase_2_index[phases]
        nNeutrals = int(self.nxGraph[node1][node2]["nNeutrals"])
        nertral_list = np.add(range(nNeutrals), 3)
        neutral_phases = "N" * nNeutrals
        if nNeutrals:
            phases += neutral_phases
            phase_list.extend(nertral_list)
        for phase, phase_index in zip(phases, phase_list):
            conductor_name = self.nxGraph[node1][node2]["conductors"][
                phase_index]
            conductor_name = (
                "default_ph_cond" if (phase_index < 3) and
                (isinstance(conductor_name, float)) else "default_nt_cond" if
                (phase_index > 2) and
                (isinstance(conductor_name, float)) else conductor_name)
            phase_wire = Wire(model)
            phase_wire.nameclass = conductor_name.replace(" ", "_").replace(
                ".", "_")
            phase_wire.phase = phase
            phase_wire.is_switch = False
            phase_wire.is_fuse = False
            phase_wire.is_recloser = False
            phase_wire.is_breaker = False
            phase_wire.is_open = False
            phase_wire.X = (-1 if phase is "A" else 1 if phase is "C" else 0
                            )  # TODO: Fix conductor layout later
            phase_wire.Y = 10 if phase is not "N" else 8
            if self.nxGraph[node1][node2]["type"] == "overhead":
                cond_data = OHcables[OHcables["Equipment Identifier"] ==
                                     conductor_name]
                if len(cond_data):
                    phase_wire.gmr = self.convert_to_meters(
                        float(cond_data["Geometric Mean Radius"].iloc[0]),
                        "ft")
                    phase_wire.diameter = self.convert_to_meters(
                        float(cond_data["Diameter"].iloc[0]), "in")
                    phase_wire.ampacity = float(
                        cond_data["Carrying Capacity"].iloc[0])
                    phase_wire.resistance = self.convert_from_meters(
                        float(cond_data["Resistance @ 50"].iloc[0]), "mi")
            if self.nxGraph[node1][node2]["type"] == "underground":
                cond_data = UGcables[UGcables["Equipment Identifier"] ==
                                     conductor_name]
                if len(cond_data):
                    phase_wire.gmr = self.convert_to_meters(
                        float(cond_data["Geometric Mean Radius In Feet"].
                              iloc[0]), "ft")
                    phase_wire.concentric_neutral_gmr = self.convert_to_meters(
                        float(cond_data["GMR (Neutral) In Feed"].iloc[0]),
                        "ft")
                    phase_wire.diameter = self.convert_to_meters(
                        float(cond_data["Diameter of Conductor In Feet"].
                              iloc[0]), "ft")
                    phase_wire.insulation_thickness = self.convert_to_meters(
                        float(cond_data["OD of Cable Insulation In Feet"].
                              iloc[0]), "ft")
                    phase_wire.concentric_neutral_diameter = self.convert_to_meters(
                        float(
                            cond_data["OD of Cable Including Neutral In Fee"].
                            iloc[0]),
                        "ft",
                    )
                    phase_wire.ampacity = float(
                        cond_data["Carrying Capacity In Amps"].iloc[0])
                    phase_wire.resistance = self.convert_from_meters(
                        float(
                            cond_data["Phase Conductor Resistance Ohms/Mile"].
                            iloc[0]),
                        "mi",
                    )
                    phase_wire.concentric_neutral_resistance = self.convert_from_meters(
                        float(cond_data["Concentric Neutral Resist Ohms/Mile"].
                              iloc[0]),
                        "ft",
                    )
            #
            if phase_wire.resistance == None:
                phase_wire.resistance = 0
            if phase_wire.gmr == None or phase_wire.gmr == 0:
                phase_wire.gmr = 1.0

            line.wires.append(phase_wire)

            Dmatrix = np.zeros((len(line.wires), len(line.wires)))
            Phases = []
            GMRs = []
            Rs = []
            for i, wire1 in enumerate(line.wires):
                Phases.append(wire1.phase)
                GMRs.append(wire1.gmr)
                Rs.append(wire1.resistance)
                for j, wire2 in enumerate(line.wires):
                    distance = self.distance([wire1.X, wire1.Y],
                                             [wire2.X, wire2.Y])
                    Dmatrix[i, j] = distance
            if line.wires:
                Z = self.get_primitive_impedance_matrix(Dmatrix, GMRs, Rs)
                if nNeutrals:
                    Z = self.kron_reduction(Z)
                line.impedance_matrix = Z.tolist()
示例#7
0
    def create_device(self, model, node1, node2, Devices):
        device = Line(model)
        device.name = node2.replace("node_", "")
        device.from_element = node1
        device.to_element = node2
        device.is_fuse = True
        device.is_switch = False
        device.is_banked = False
        device.is_breaker = False
        device.is_recloser = False
        device.is_substation = False
        device.is_sectionalizer = False
        device.length = 1  #

        device.feeder_name = (
            "" if not isinstance(self.nxGraph[node1][node2]["feeder"], str)
            else self.nxGraph[node1][node2]["feeder"])
        device.substation_name = (
            "" if not isinstance(self.nxGraph[node1][node2]["substation"], str)
            else self.nxGraph[node1][node2]["substation"])
        phases = self.nxGraph[node1][node2]["phases"]
        phase_list = self.phase_2_index[phases]

        for phase, phase_index in zip(phases, phase_list):
            device_type = self.nxGraph[node1][node2]["equipment"][phase_index]
            device_data = Devices[Devices["Equipment Identifier"] ==
                                  device_type]
            phase_device = Wire(model)
            phase_device.nameclass = device_type.replace(" ", "_")
            phase_device.phase = phase
            phase_device.is_open = bool(
                self.nxGraph[node1][node2]["isClosed"][phase_index])
            # TODO: Fix enabled property for device
            phase_device.is_switch = True
            phase_device.is_fuse = False
            phase_device.is_recloser = False
            phase_device.is_breaker = False
            phase_device.ampacity = float(
                device_data["Current Rating"].iloc[0])
            phase_device.fuse_limit = float(
                device_data["Max Asymmetrical Fault"].iloc[0])
            device.wires.append(phase_device)

        for node_name in [node1, node2]:
            if "x" in self.nxGraph.node[node_name]:
                node_pos = Position(model)
                node_pos.long = float(self.nxGraph.node[node_name]["x"])
                node_pos.lat = float(self.nxGraph.node[node_name]["y"])
                device.positions.append(node_pos)
示例#8
0
def test_ephasor_writer():
    from ditto.writers.ephasor.write import Writer
    from ditto.models.node import Node
    from ditto.models.line import Line
    from ditto.models.load import Load
    from ditto.models.regulator import Regulator
    from ditto.models.wire import Wire
    from ditto.models.capacitor import Capacitor
    from ditto.models.powertransformer import PowerTransformer
    from ditto.models.winding import Winding
    from ditto.models.phase_winding import PhaseWinding
    from ditto.store import Store
    from ditto.models.base import Unicode
    from ditto.models.power_source import PowerSource
    from ditto.models.feeder_metadata import Feeder_metadata

    m = Store()
    src = PowerSource(
        m,
        name="f1_src",
        phases=[Unicode("A"), Unicode("B"),
                Unicode("C")],
        nominal_voltage=12470,
        connecting_element="n1",
        is_sourcebus=True,
    )
    meta = Feeder_metadata(m,
                           name="f1",
                           nominal_voltage=12470,
                           headnode="f1_src",
                           substation="f1_src")
    node1 = Node(m, name="n1", feeder_name="f1")
    node2 = Node(m, name="n2", feeder_name="f1")
    node3 = Node(m, name="n3", feeder_name="f1")
    wirea = Wire(m, gmr=1.3, X=2, Y=20)
    wiren = Wire(m, gmr=1.2, X=2, Y=20)
    line1 = Line(
        m,
        name="l1",
        wires=[wirea, wiren],
        from_element="n1",
        to_element="n2",
        feeder_name="f1",
    )
    load1 = Load(m, name="load1", feeder_name="f1")

    phase_winding = PhaseWinding(m, phase=u"A")

    winding1 = Winding(
        m,
        phase_windings=[phase_winding],
        connection_type="Y",
        nominal_voltage=12.47,
        rated_power=25,
        resistance=10,
    )
    winding2 = Winding(
        m,
        phase_windings=[phase_winding],
        connection_type="Y",
        nominal_voltage=6.16,
        rated_power=25,
        resistance=10,
    )
    transformer1 = PowerTransformer(
        m,
        name="t1",
        from_element="n2",
        to_element="n3",
        windings=[winding1, winding2],
        feeder_name="f1",
    )
    transformer1.reactances.append(6)
    # reg1 = Regulator(m, name='t1_reg', connected_transformer='t1', connected_winding=2, pt_ratio=60, delay=2)
    # cap1 = Capacitor(m, name='cap1', connecting_element='n2', num_phases=3, nominal_voltage=7.2, var=300, connection_type='Y')
    m.set_names()
    t = tempfile.TemporaryDirectory()
    writer = Writer(output_path=t.name, log_path="./")
    writer.write(m)
示例#9
0
def test_opendss_writer():
    from ditto.writers.opendss.write import Writer
    from ditto.models.node import Node
    from ditto.models.line import Line
    from ditto.models.load import Load
    from ditto.models.regulator import Regulator
    from ditto.models.wire import Wire
    from ditto.models.capacitor import Capacitor
    from ditto.models.powertransformer import PowerTransformer
    from ditto.models.winding import Winding

    # from ditto.model import Model
    from ditto.store import Store
    from ditto.models.storage import Storage
    from ditto.models.phase_storage import PhaseStorage
    from ditto.models.base import Unicode
    from ditto.models.base import Float
    from ditto.models.power_source import PowerSource
    from ditto.models.phase_load import PhaseLoad

    m = Store()
    node1 = Node(m, name="n1")
    node2 = Node(m, name="n2")
    node3 = Node(m, name="n3")
    wirea = Wire(m, gmr=1.3, X=2, Y=20)
    wiren = Wire(m, gmr=1.2, X=2, Y=20)
    line1 = Line(m, name="l1", wires=[wirea, wiren])
    phase_load1 = PhaseLoad(m, p=5400, q=2615.3394)
    load1 = Load(m, name="load1", phase_loads=[phase_load1])

    winding1 = Winding(
        m,
        connection_type="W",
        nominal_voltage=12.47,
        rated_power=25,
    )
    winding2 = Winding(
        m,
        connection_type="W",
        nominal_voltage=6.16,
        rated_power=25,
    )
    transformer1 = PowerTransformer(
        m,
        name="t1",
        from_element="n2",
        to_element="n3",
        windings=[winding1, winding2],
        feeder_name="f1",
    )
    transformer1.reactances.append(6)
    reg1 = Regulator(
        m,
        name="t1_reg",
        connected_transformer="t1",
        pt_ratio=60,
        delay=2,
    )
    cap1 = Capacitor(
        m,
        name="cap1",
        nominal_voltage=7.2,
        connection_type="Y",
    )
    print(line1.impedance_matrix)

    # Storage testing
    phase_storage_A = PhaseStorage(m, phase="A", p=15.0, q=5.0)
    phase_storage_B = PhaseStorage(m, phase="B", p=16.0, q=6.0)
    storage = Storage(
        m,
        name="store1",
        connecting_element="n3",
        nominal_voltage=12470.0,
        rated_power=10000.0,
        rated_kWh=100.0,
        stored_kWh=75.5,
        reserve=20.0,
        discharge_rate=25.0,
        charge_rate=18.7,
        charging_efficiency=15.3,
        discharging_efficiency=22.0,
        resistance=20,
        reactance=10,
        model_=1,
        phase_storages=[phase_storage_A, phase_storage_B],
    )

    # PV systems testing
    PV_system = PowerSource(
        m,
        name="PV1",
        is_sourcebus=False,
        nominal_voltage=12470,
        phases=[Unicode("A"), Unicode("C")],
        rated_power=20000.0,
        connection_type="D",
        cutout_percent=30.0,
        cutin_percent=15.3,
        resistance=14.0,
        reactance=5.2,
        v_max_pu=100,
        v_min_pu=60,
        power_factor=0.9,
    )

    t = tempfile.TemporaryDirectory()
    writer = Writer(output_path=t.name)
    # writer.write_wiredata(m)
    # writer.write_linegeometry(m)
    # writer.write_linecodes(m)
    writer.write_storages(m)
    writer.write_PVs(m)
    writer.write_lines(m)
    writer.write_loads(m)
    writer.write_transformers(m)
    writer.write_regulators(m)
    writer.write_capacitors(m)
示例#10
0
    def create_line(self, model, node1, node2, OHcables, UGcables):
        line = Line(model)
        line.name = node2.replace('node_', '')
        line.from_element = node1
        line.to_element = node2
        line.is_breaker = False
        line.is_recloser = False
        line.is_banked = False
        line.is_fuse = False
        line.is_sectionalizer = False
        line.is_switch = False
        line.length = self.convert_to_meters(
            float(self.nxGraph[node1][node2]['length']), 'ft')
        #line.nominal_voltage = float(self.nxGraph[node1][node2]['kv'])    #TODO: line nominal KV
        line.line_type = self.nxGraph[node1][node2]['type']
        line.feeder_name = '' if isinstance(self.nxGraph[node1][node2]['feeder'], float) else \
                            self.nxGraph[node1][node2]['feeder']
        line.substation_name =  '' if isinstance(self.nxGraph[node1][node2]['substation'], float) else \
                                self.nxGraph[node1][node2]['substation']

        for node_name in [node1, node2]:
            if 'x' in self.nxGraph.node[node_name]:
                node_pos = Position(model)
                node_pos.long = float(self.nxGraph.node[node_name]['x'])
                node_pos.lat = float(self.nxGraph.node[node_name]['y'])
                line.positions.append(node_pos)

        phases = self.nxGraph[node1][node2]['phases']
        phase_list = self.phase_2_index[phases]
        nNeutrals = int(self.nxGraph[node1][node2]['nNeutrals'])
        nertral_list = np.add(range(nNeutrals), 3)
        neutral_phases = 'N' * nNeutrals
        if nNeutrals:
            phases += neutral_phases
            phase_list.extend(nertral_list)
        for phase, phase_index in zip(phases, phase_list):
            conductor_name = self.nxGraph[node1][node2]['conductors'][
                phase_index]
            conductor_name = 'default_ph_cond' if (phase_index < 3) and (isinstance(conductor_name, float)) else \
                             'default_nt_cond' if (phase_index > 2) and (isinstance(conductor_name, float)) else \
                                 conductor_name
            phase_wire = Wire(model)
            phase_wire.nameclass = conductor_name.replace(' ', '_').replace(
                '.', '_')
            phase_wire.phase = phase
            phase_wire.is_switch = False
            phase_wire.is_fuse = False
            phase_wire.is_recloser = False
            phase_wire.is_breaker = False
            phase_wire.is_open = False
            phase_wire.X = -1 if phase is 'A' else 1 if phase is 'C' else 0  #TODO: Fix conductor layout later
            phase_wire.Y = 10 if phase is not 'N' else 8
            if self.nxGraph[node1][node2]['type'] == 'overhead':
                cond_data = OHcables[OHcables['Equipment Identifier'] ==
                                     conductor_name]
                if len(cond_data):
                    phase_wire.gmr = self.convert_to_meters(
                        float(cond_data['Geometric Mean Radius'].iloc[0]),
                        'ft')
                    phase_wire.diameter = self.convert_to_meters(
                        float(cond_data['Diameter'].iloc[0]), 'in')
                    phase_wire.ampacity = float(
                        cond_data['Carrying Capacity'].iloc[0])
                    phase_wire.resistance = self.convert_from_meters(
                        float(cond_data['Resistance @ 50'].iloc[0]), 'mi')
            if self.nxGraph[node1][node2]['type'] == 'underground':
                cond_data = UGcables[UGcables['Equipment Identifier'] ==
                                     conductor_name]
                if len(cond_data):
                    phase_wire.gmr = self.convert_to_meters(
                        float(cond_data['Geometric Mean Radius In Feet'].
                              iloc[0]), 'ft')
                    phase_wire.concentric_neutral_gmr = self.convert_to_meters(
                        float(cond_data['GMR (Neutral) In Feed'].iloc[0]),
                        'ft')
                    phase_wire.diameter = self.convert_to_meters(
                        float(cond_data['Diameter of Conductor In Feet'].
                              iloc[0]), 'ft')
                    phase_wire.insulation_thickness = self.convert_to_meters(
                        float(cond_data['OD of Cable Insulation In Feet'].
                              iloc[0]), 'ft')
                    phase_wire.concentric_neutral_diameter = self.convert_to_meters(
                        float(
                            cond_data['OD of Cable Including Neutral In Fee'].
                            iloc[0]), 'ft')
                    phase_wire.ampacity = float(
                        cond_data['Carrying Capacity In Amps'].iloc[0])
                    phase_wire.resistance = self.convert_from_meters(
                        float(
                            cond_data['Phase Conductor Resistance Ohms/Mile'].
                            iloc[0]), 'mi')
                    phase_wire.concentric_neutral_resistance = self.convert_from_meters(
                        float(cond_data['Concentric Neutral Resist Ohms/Mile'].
                              iloc[0]), 'ft')
#
            if phase_wire.resistance == None:
                phase_wire.resistance = 0
            if phase_wire.gmr == None or phase_wire.gmr == 0:
                phase_wire.gmr = 1.0

            line.wires.append(phase_wire)

            Dmatrix = np.zeros((len(line.wires), len(line.wires)))
            Phases = []
            GMRs = []
            Rs = []
            for i, wire1 in enumerate(line.wires):
                Phases.append(wire1.phase)
                GMRs.append(wire1.gmr)
                Rs.append(wire1.resistance)
                for j, wire2 in enumerate(line.wires):
                    distance = self.distance([wire1.X, wire1.Y],
                                             [wire2.X, wire2.Y])
                    Dmatrix[i, j] = distance
            if line.wires:
                Z = self.get_primitive_impedance_matrix(Dmatrix, GMRs, Rs)
                if nNeutrals:
                    Z = self.kron_reduction(Z)
                line.impedance_matrix = Z.tolist()
示例#11
0
    def create_device(self, model, node1, node2, Devices):
        device = Line(model)
        device.name = node2.replace('node_', '')
        device.from_element = node1
        device.to_element = node2
        device.is_fuse = True
        device.is_switch = False
        device.is_banked = False
        device.is_breaker = False
        device.is_recloser = False
        device.is_substation = False
        device.is_sectionalizer = False
        device.length = 1  #

        device.feeder_name = '' if not isinstance(self.nxGraph[node1][node2]['feeder'], str) else \
            self.nxGraph[node1][node2]['feeder']
        device.substation_name = '' if not isinstance(self.nxGraph[node1][node2]['substation'], str) else \
            self.nxGraph[node1][node2]['substation']
        phases = self.nxGraph[node1][node2]['phases']
        phase_list = self.phase_2_index[phases]

        for phase, phase_index in zip(phases, phase_list):
            device_type = self.nxGraph[node1][node2]['equipment'][phase_index]
            device_data = Devices[Devices['Equipment Identifier'] ==
                                  device_type]
            phase_device = Wire(model)
            phase_device.nameclass = device_type.replace(' ', '_')
            phase_device.phase = phase
            phase_device.is_open = bool(
                self.nxGraph[node1][node2]['isClosed'][phase_index])
            # TODO: Fix enabled property for device
            phase_device.is_switch = True
            phase_device.is_fuse = False
            phase_device.is_recloser = False
            phase_device.is_breaker = False
            phase_device.ampacity = float(
                device_data['Current Rating'].iloc[0])
            phase_device.fuse_limit = float(
                device_data['Max Asymmetrical Fault'].iloc[0])
            device.wires.append(phase_device)

        for node_name in [node1, node2]:
            if 'x' in self.nxGraph.node[node_name]:
                node_pos = Position(model)
                node_pos.long = float(self.nxGraph.node[node_name]['x'])
                node_pos.lat = float(self.nxGraph.node[node_name]['y'])
                device.positions.append(node_pos)
示例#12
0
    def parse_lines(self, model):
        line_types = [
            'ohPrimaryLine', 'ugPrimaryLine', 'ohSecondaryLine',
            'ugSecondaryLine'
        ]
        # self.get_file_content()
        for line_type in line_types:
            lines = self.elements_by_class[line_type]
            for line_name, line_data in lines.items():
                node_from = self.fixStr(line_data['parentSectionID']['@name'])
                node_to = self.fixStr(line_data['sectionID'])
                line = Line(model)

                line.name = self.fixStr(node_from)
                line.from_element = node_from
                line.to_element = node_to
                line.is_breaker = False
                line.is_recloser = False
                line.is_banked = False
                line.is_fuse = False
                line.is_sectionalizer = False
                line.is_switch = False
                line.length = float(line_data['condLength'])
                line.nominal_voltage = float(line_data['operVolt'])
                line.line_type = 'overhead' if 'oh' in line_type else 'underground'
                for xy in line_data['complexLine']['coord']:
                    node_pos = Position(model)
                    node_pos.long = float(xy['X'])
                    node_pos.lat = float(xy['Y'])
                    line.positions.append(node_pos)
                if isinstance(line_data['conductorList'], dict):
                    if not isinstance(line_data['conductorList']['conductor'],
                                      list):
                        conductors = [line_data['conductorList']['conductor']]
                    else:
                        conductors = line_data['conductorList']['conductor']
                    for conductor in conductors:
                        conductor_name = conductor['conductorType']
                        conductor_phase = conductor['phase']
                        phase_wire = Wire(model)
                        phase_wire.nameclass = conductor_name
                        phase_wire.phase = conductor_phase
                        phase_wire.is_switch = False
                        phase_wire.is_fuse = False
                        phase_wire.is_recloser = False
                        phase_wire.is_breaker = False
                        phase_wire.is_open = False
                        phase_wire.X = 0 if conductor_phase == 'A' else 2 if conductor_phase == 'B' else 4
                        phase_wire.Y = 0
                        if conductor_name in self.libraries['OHcables']:
                            conductor_data = self.libraries['OHcables'][
                                conductor_name]
                            phase_wire.nameclass = self.fixStr(
                                conductor['conductorType'])
                            phase_wire.gmr = conductor_data['GMR (feet)']
                            phase_wire.diameter = conductor_data[
                                'Diameter (inches)']
                            phase_wire.ampacity = conductor_data['Ampacity']
                            phase_wire.resistance = conductor_data[
                                'R @ 50 C (ohms/mile)']  # 'R @ 25 C (ohms/mile)'
                        elif conductor_name in self.libraries['UGcables']:
                            conductor_data = self.libraries['UGcables'][
                                conductor_name]
                            phase_wire.nameclass = self.fixStr(
                                conductor['conductorType'])
                            phase_wire.gmr = conductor_data['GMR Phase (feet)']
                            phase_wire.concentric_neutral_gmr = conductor_data[
                                'GMR Neutrl (feet)']
                            phase_wire.diameter = conductor_data[
                                'Cond Dia (feet)']
                            phase_wire.insulation_thickness = conductor_data[
                                'Insul Dia (feet)']
                            phase_wire.concentric_neutral_diameter = conductor_data[
                                'Neutrl Dia (feet)']
                            phase_wire.ampacity = conductor_data['Ampacity']
                            phase_wire.resistance = conductor_data[
                                'R Phase (ohms/1000ft)']
                            phase_wire.concentric_neutral_resistance = conductor_data[
                                'R Ntrl (ohms/1000ft)']
                        else:
                            logger.warning('')
                        if phase_wire.gmr:
                            line.wires.append(phase_wire)

                Dmatrix = np.zeros((len(line.wires), len(line.wires)))
                Phases = []
                GMRs = []
                Rs = []
                for i, wire1 in enumerate(line.wires):
                    Phases.append(wire1.phase)
                    GMRs.append(wire1.gmr)
                    Rs.append(wire1.resistance)
                    for j, wire2 in enumerate(line.wires):
                        distance = self.distance([wire1.X, wire1.Y],
                                                 [wire2.X, wire2.Y])
                        Dmatrix[i, j] = distance

                if line.wires:
                    Z = self.get_primitive_impedance_matrix(Dmatrix, GMRs, Rs)
                    if 'N' in Phases or 'n' in Phases:
                        Z = self.kron_reduction(Z)
                    line.impedance_matrix = Z.tolist()
示例#13
0
    def parse_lines(self, model, **kwargs):
        """Line parser.
        :param model: DiTTo model
        :type model: DiTTo model
        :returns: 1 for success, -1 for failure
        :rtype: int
        """
        for element in self.geojson_content["features"]:
            if 'properties' in element and 'type' in element['properties'] and element['properties']['type'] == 'ElectricalConnector':
                line = Line(model)
                line.name = element['properties']['id']
                if element['properties']['startJunctionId'] in self.substations:
                    line.from_element = 'source'
                else:
                    line.from_element = element['properties']['startJunctionId']
                if element['properties']['endJunctionId'] in self.substations:
                    line.to_element = 'source'
                else:
                    line.to_element = element['properties']['endJunctionId']
                line.length = element['properties']['total_length']*0.3048 #length from feet to meters
                all_wires = []
                for wire_type in element['properties']['wires']:
                    for db_wire in self.equipment_data['wires']:
                        if db_wire['nameclass'] == wire_type:
                            wire = Wire(model)
                            wire.nameclass = wire_type.replace(' ','_').replace('/','-')
                            if 'OH' in wire_type:
                                line.line_type = 'overhead'
                            else:
                                line.line_type = 'underground'
                            if 'S1' in wire_type:
                                wire.phase = 'A'
                            elif 'S2' in wire_type:
                                wire.phase = 'B'
                            else:
                                wire.phase = wire_type.split(' ')[-1] #Currently the convention is that the last element is the phase.
                            wire.ampacity = float(db_wire['ampacity'])
                            wire.gmr = float(db_wire['gmr'])*0.3048
                            wire.resistance = float(db_wire['resistance'])*0.3048
                            wire.diameter = float(db_wire['diameter'])*0.3048
                            wire.X = float(db_wire['x'])*0.3048
                            wire.Y = float(db_wire['height'])*0.3048
                            all_wires.append(wire)
                line.wires = all_wires



        return 1