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)
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)
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)
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)
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()
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()
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()