def test_opendss_to_gridlabd(): ''' Test the OpenDSS to GridlabD conversion. ''' from ditto.readers.opendss.read import Reader from ditto.store import Store from ditto.writers.gridlabd.write import Writer opendss_models = [ f for f in os.listdir( os.path.join(current_directory, 'data/small_cases/opendss/')) if not f.startswith('.') ] for model in opendss_models: m = Store() r = Reader(master_file=os.path.join( current_directory, 'data/small_cases/opendss/{model}/master.dss'.format(model=model)), buscoordinates_file=os.path.join( current_directory, 'data/small_cases/opendss/{model}/buscoord.dss'.format( model=model))) r.parse(m) m.set_names() #TODO: Log properly print('>OpenDSS model {model} red...'.format(model=model)) t = tempfile.TemporaryDirectory() w = Writer(output_path=t.name) w.write(m) #TODO: Log properly print('>...and written to GridLabD.\n')
def test_opendss_to_json(): """Test the JSON writer with OpenDSS models as input.""" from ditto.readers.opendss.read import Reader from ditto.store import Store from ditto.writers.json.write import Writer opendss_models = [ f for f in os.listdir( os.path.join(current_directory, "data/small_cases/opendss/")) if not f.startswith(".") ] for model in opendss_models: m = Store() r = Reader( master_file=os.path.join( current_directory, "data/small_cases/opendss/{model}/master.dss".format( model=model), ), buscoordinates_file=os.path.join( current_directory, "data/small_cases/opendss/{model}/buscoord.dss".format( model=model), ), ) r.parse(m) m.set_names() output_path = tempfile.TemporaryDirectory() w = Writer(output_path=output_path.name) w.write(m)
def test_opendss_to_ephasor(): ''' Test the OpenDSS to Ephasor conversion. ''' from ditto.readers.opendss.read import Reader from ditto.store import Store from ditto.writers.ephasor.write import Writer opendss_models=[f for f in os.listdir(os.path.join(current_directory, 'data/small_cases/opendss/')) if not f.startswith('.')] for model in opendss_models: m = Store() r = Reader( master_file=os.path.join(current_directory, 'data/small_cases/opendss/{model}/master.dss'.format(model=model)), buscoordinates_file=os.path.join(current_directory, 'data/small_cases/opendss/{model}/buscoord.dss'.format(model=model)) ) r.parse(m) m.set_names() m.build_networkx() m.direct_from_source() m.set_node_voltages() #TODO: Log properly print('>OpenDSS model {model} red...'.format(model=model)) output_path = tempfile.TemporaryDirectory() w = Writer(output_path=output_path) w.write(m) #TODO: Log properly print('>...and written to Ephasor.\n')
def test_lines_write(): m = Store() r = Reader( master_file=os.path.join( current_directory, "../../../readers/opendss/Lines/test_linegeometries.dss" ) ) r.parse(m) m.set_names() output_path = tempfile.gettempdir() jw = Json_Writer(output_path=output_path) jw.write(m) w = Writer(output_path=output_path) w.write(m) # Check that the OpenDSS writer created a Master file assert os.path.exists(os.path.join(output_path, "Master.dss")) r_w = Reader(master_file=os.path.join(output_path, "Master.dss")) r_w.parse(m) m.set_names() jw = Json_Writer(output_path="./") jw.write(m) with open(os.path.join(output_path, "Model.json"), "r") as f1: reader_json = json.load(f1) with open("./Model.json", "r") as f2: writer_json = json.load(f2) assert reader_json["model"] == writer_json["model"]
def test_remove_opendss_default_values(): m = Store() r = Reader( master_file=os.path.join(current_directory, "test_default_values.dss"), remove_opendss_default_values_flag=True, ) r.parse(m) m.set_names() assert m["line1"].faultrate == None assert m["line1"].impedance_matrix == None assert m["line1"].capacitance_matrix == None assert m["cap1"].connection_type == None assert m["cap1"].low == None assert m["cap1"].high == None assert m["cap1"].delay == None assert m["cap1"].pt_ratio == None assert m["cap1"].ct_ratio == None assert m["cap1"].pt_phase == None assert m["reg1"].reactances == None assert m["regulator_reg1"].ct_prim == None assert m["regulator_reg1"].delay == None assert m["regulator_reg1"].highstep == None assert m["regulator_reg1"].pt_ratio == None assert m["regulator_reg1"].bandwidth == None assert m["regulator_reg1"].bandcenter == None assert m["load_load1"].connection_type == None assert m["load_load1"].vmin == None assert m["load_load1"].vmax == None
def test_nodes(): from ditto.store import Store from ditto.readers.opendss.read import Reader # test on the test_nodes.dss m = Store() r = Reader( master_file=os.path.join(current_directory, "test_nodes.dss"), buscoordinates_file=os.path.join(current_directory, "buscoord.dss"), ) r.parse(m) m.set_names() assert (m["bus1"].name) == "bus1" assert (m["bus1"].nominal_voltage) == None assert (m["bus1"].positions[0].long) == float(300) assert (m["bus1"].positions[0].lat) == float(400) assert (m["bus1"].positions[0].elevation) == 0 assert (m["bus1"].feeder_name) == "sourcebus_src" assert (m["sourcebus"].name) == "sourcebus" assert (m["sourcebus"].nominal_voltage) == None assert (m["sourcebus"].positions[0].long) == float(1674346.56814483) assert (m["sourcebus"].positions[0].lat) == float(12272927.0644858) assert (m["sourcebus"].positions[0].elevation) == 0 assert (m["sourcebus"].feeder_name) == "sourcebus_src" assert (m["b1"].name) == "b1" assert (m["b1"].nominal_voltage) == None assert (m["b1"].positions[0].long) == float(1578139) assert (m["b1"].positions[0].lat) == float(14291312) assert (m["b1"].positions[0].elevation) == 0 assert (m["b1"].feeder_name) == "sourcebus_src"
def create_output_dir(tests_dir): """Reading the input from every reader for each test case and creating the Opendss output.""" # Creating output directory current_dir = os.path.realpath(os.path.dirname(__file__)) validation_dir = os.path.join(current_dir, "validation_outputs") if os.path.exists(validation_dir): shutil.rmtree(validation_dir) for each in os.listdir(tests_dir): if each == "cim" or each == "demo": continue for dirname in os.listdir(os.path.join(tests_dir, each)): if dirname == "storage_test": continue output_dir = os.path.join(validation_dir, dirname, each + "_output") test_path = os.path.join(tests_dir, each, dirname) m = Store() if each == "opendss": r1 = OpenDSS_Reader( master_file=os.path.join(test_path, "master.dss")) elif each == "synergi": if dirname == "ieee_4node": r1 = Synergi_Reader( input_file=os.path.join(test_path, "network.mdb")) elif each == "cyme": r1 = Cyme_Reader(data_folder_path=os.path.join(test_path)) elif each == "gridlabd": r1 = Gridlabd_Reader( input_file=os.path.join(test_path, "node.glm")) r1.parse(m) w1 = OpenDSS_Writer(output_path=output_dir) w1.write(m, separate_feeders=True) return validation_dir
def dssToGridLab(args): ''' Convert dss file to gridlab. ''' m = Store() reader = OReader(master_file=args.infile, buscoordinates_file=args.buscoords) writer = Writer(output_path='.') reader.parse(m) writer.write(m) print ("GRIDLAB-D FILE WRITTEN")
def test_load_p_and_q(): m = Store() r = Reader(master_file=os.path.join(current_directory, "test_load_p_and_q.dss")) r.parse(m) m.set_names() # P and Q values should be equally divided accross phase loads # Here we sum P and Q and check that the obtained values match the values in the DSS file # precision = 0.001 assert len(m["load_load1"].phase_loads) == 3 # Load1 is a three phase load assert sum( [phase_load.p for phase_load in m["load_load1"].phase_loads] ) == pytest.approx(5400 * 10 ** 3, precision) assert sum( [phase_load.q for phase_load in m["load_load1"].phase_loads] ) == pytest.approx(4285 * 10 ** 3, precision) assert len(m["load_load2"].phase_loads) == 3 # Load2 is a three phase load assert sum( [phase_load.p for phase_load in m["load_load2"].phase_loads] ) == pytest.approx(3466 * 10 ** 3, precision) assert sum( [phase_load.q for phase_load in m["load_load2"].phase_loads] ) == pytest.approx(3466.0 * math.sqrt(1.0 / 0.9 ** 2 - 1) * 10 ** 3, precision) assert len(m["load_load3"].phase_loads) == 2 # Load3 is a two phase load assert sum( [phase_load.p for phase_load in m["load_load3"].phase_loads] ) == pytest.approx(1600 * 10 ** 3, precision) assert sum( [phase_load.q for phase_load in m["load_load3"].phase_loads] ) == pytest.approx(980 * 10 ** 3, precision) assert len(m["load_load4"].phase_loads) == 2 # Load4 is a two phase load assert sum( [phase_load.p for phase_load in m["load_load4"].phase_loads] ) == pytest.approx(1555 * 10 ** 3, precision) assert sum( [phase_load.q for phase_load in m["load_load4"].phase_loads] ) == pytest.approx(1555.0 * math.sqrt(1.0 / 0.95 ** 2 - 1) * 10 ** 3, precision) assert len(m["load_load5"].phase_loads) == 1 # Load5 is a one phase load assert sum( [phase_load.p for phase_load in m["load_load5"].phase_loads] ) == pytest.approx(650 * 10 ** 3, precision) assert sum( [phase_load.q for phase_load in m["load_load5"].phase_loads] ) == pytest.approx(500.5 * 10 ** 3, precision) assert len(m["load_load6"].phase_loads) == 1 # Load6 is a one phase load assert sum( [phase_load.p for phase_load in m["load_load6"].phase_loads] ) == pytest.approx(623.21 * 10 ** 3, precision) assert sum( [phase_load.q for phase_load in m["load_load6"].phase_loads] ) == pytest.approx(623.21 * math.sqrt(1.0 / 0.85 ** 2 - 1) * 10 ** 3, precision)
def test_metric_extraction(): """ This test reads all small OpenDSS test cases, set the nominal voltages using a system_structure_modifier object and compute all metrics using a network analyzer object. Finally, it exports the metrics to excel and Json formats. """ from ditto.readers.opendss.read import Reader from ditto.store import Store from ditto.modify.system_structure import system_structure_modifier from ditto.metrics.network_analysis import NetworkAnalyzer as network_analyzer opendss_models = [ f for f in os.listdir( os.path.join(current_directory, "data/small_cases/opendss/")) if not f.startswith(".") ] opendss_models.remove("storage_test") for model in opendss_models: m = Store() r = Reader( master_file=os.path.join( current_directory, "data/small_cases/opendss/{model}/master.dss".format( model=model), ), buscoordinates_file=os.path.join( current_directory, "data/small_cases/opendss/{model}/buscoord.dss".format( model=model), ), ) r.parse(m) m.set_names() # Create a modifier object modifier = system_structure_modifier(m) # And set the nominal voltages of the elements since we don't have it from OpenDSS modifier.set_nominal_voltages_recur() modifier.set_nominal_voltages_recur_line() # Create a Network analyszer object with the modified model net = network_analyzer(modifier.model, True, "sourcebus") net.model.set_names() # Compute all the available metrics net.compute_all_metrics() output_path = tempfile.gettempdir() # Export them to excel net.export(os.path.join(output_path, "metrics.xlsx")) # Export them to JSON net.export_json(os.path.join(output_path, "metrics.json"))
def test_linegeometries(): m = Store() r = Reader(master_file=os.path.join(current_directory, "test_linegeometries.dss")) r.parse(m) m.set_names() # Number of wires assert len(m["line1"].wires) == 4 # Line1 should have 4 wires # Phases of the different wires assert set([w.phase for w in m["line1"].wires]) == set(["A", "B", "C", "N"]) phased_wires = {} for wire in m["line1"].wires: phased_wires[wire.phase] = wire # Nameclass for p in ["A", "B", "C"]: assert phased_wires[p].nameclass == "ACSR336" assert phased_wires["N"].nameclass == "ACSR1/0" # Positions of the wires assert (phased_wires["A"].X, phased_wires["A"].Y) == (-1.2909, 13.716) assert (phased_wires["B"].X, phased_wires["B"].Y) == ( -0.1530096 * 0.3048, 4.1806368 * 0.3048, ) assert (phased_wires["C"].X, phased_wires["C"].Y) == (0.5737, 13.716) assert (phased_wires["N"].X, phased_wires["N"].Y) == (0.0, 14.648) # GMR for p in ["A", "B", "C"]: assert phased_wires[p].gmr == 0.0255 * 0.3048 assert phased_wires["N"].gmr == 0.00446 * 0.3048 # Diameter for p in ["A", "B", "C"]: assert phased_wires[p].diameter == 0.741 * 0.0254 assert phased_wires["N"].diameter == 0.398 * 0.0254 # Resistance # TODO: Change this once the resistance of a Wire object will no longer be the total # resistance, but the per meter resistance... # for p in ["A", "B", "C"]: assert phased_wires[p].resistance == pytest.approx( 0.306 * 0.000621371 * 300 * 0.3048, 0.00001 ) assert phased_wires["N"].resistance == pytest.approx( 1.12 * 0.000621371 * 300 * 0.3048, 0.00001 )
def test_default_values(): m = Store() r = Reader( master_file=os.path.join(current_directory, "test_default_values.dss"), default_values_file=os.path.join(current_directory, "test_default_values.json"), ) r.parse(m) m.set_names() assert m["line1"].faultrate == 0.2 assert m["line1"].impedance_matrix == [ [(0.00113148 + 0.000884886j), (0.000142066 + 0.000366115j)], [(0.000142066 + 0.000366115j), (0.00113362 + 0.000882239j)], ] assert m["line1"].capacitance_matrix == [ [(0.00733718 + 0j), (-0.00239809 + 0j)], [(-0.00239809 + 0j), (0.00733718 + 0j)], ] phased_wires = {} for wire in m["line1"].wires: phased_wires[wire.phase] = wire # Ampacity for p in ["A", "B", "C"]: assert phased_wires[p].ampacity == 200 assert phased_wires[p].emergency_ampacity == 400 assert m["cap1"].connection_type == "Y" assert m["cap1"].low == 114 assert m["cap1"].high == 125 assert m["cap1"].delay == 10 assert m["cap1"].pt_ratio == 50 assert m["cap1"].ct_ratio == 50 assert m["cap1"].pt_phase == "A" assert m["reg1"].reactances == [6] assert m["regulator_reg1"].ct_prim == 300 assert m["regulator_reg1"].delay == 16 assert m["regulator_reg1"].highstep == 15 assert m["regulator_reg1"].pt_ratio == 60 assert m["regulator_reg1"].bandwidth == 3 assert m["regulator_reg1"].bandcenter == 130 assert m["load_load1"].connection_type == "Y" assert m["load_load1"].vmin == 0.95 assert m["load_load1"].vmax == 1.05
def test_opendss_transformer(): opendss_test_data = """ Clear new circuit.IEEE13 ~ basekv=4.16 pu=1.0000 phases=3 bus1=SourceBus ~ Angle=0 ~ MVAsc3=200000 MVASC1=200000 ! stiffen the source to approximate inf source New Transformer.reg Phases=3 Windings=2 XHL=0.01 ~ wdg=1 bus=Sourcebus.1.2.3.0 conn=Wye kv=4.16 kva=5000 %r=0.000498 XHT=.00498 ~ wdg=2 bus=651.1.2.3 conn=Wye kv=4.16 kva=5000 %r=0.000498 XLT=.00498 New Transformer.XFM1 Phases=3 Windings=2 XHL=2 ~ wdg=1 bus=633.1.2.3.0 conn=Wye kv=4.16 kva=500 %r=.55 XHT=1 ~ wdg=2 bus=634.1.2.3 conn=Wye kv=0.480 kva=500 %r=.55 XLT=1 """ master_file = os.path.join(tempfile.gettempdir(), os.urandom(24).hex()) # TODO: figure out why named temporary file doesn't work as expected on windows # master_file = tempfile.NamedTemporaryFile(mode="w") with open(master_file, "w") as f: f.write(opendss_test_data) m = Store() r = Reader(master_file=master_file, ) r.parse(m) m.set_names() for t in m.iter_models(type=PowerTransformer): assert len(t.windings) == 2 assert t.windings[0].is_grounded is True assert t.windings[1].is_grounded is False output_path = tempfile.TemporaryDirectory() w = Writer(output_path=output_path.name) w.write(m) with open(os.path.join(output_path.name, "Transformers.dss")) as f: string = f.read() assert "sourcebus.1.2.3.0" in string assert "651.1.2.3.0" not in string assert "651.1.2.3" in string assert "633.1.2.3.0" in string assert "634.1.2.3.0" not in string assert "634.1.2.3" in string
def test_opendss_center_transformer(): opendss_test_data = """ Clear new circuit.IEEE13 ~ basekv=4.16 pu=1.0000 phases=3 bus1=SourceBus ~ Angle=0 ~ MVAsc3=200000 MVASC1=200000 ! stiffen the source to approximate inf source New Transformer.Example1-ph phases=1 Windings=3 ~ Xhl=2.04 Xht=2.04 Xlt=1.36 %noloadloss=.2 ~ Buses=[bus1.1.2 bus2.1.0 bus2.0.2] ! mid-point of secondary is grounded ~ kVs=[12.47 .12 .12] ! ratings of windings ~ kVAs=[25 25 25] ~ %Rs = [0.6 1.2 1.2] ~ conns=[delta wye wye] """ master_file = os.path.join(tempfile.gettempdir(), os.urandom(24).hex()) # TODO: figure out why named temporary file doesn't work as expected on windows # master_file = tempfile.NamedTemporaryFile(mode="w") with open(master_file, "w") as f: f.write(opendss_test_data) m = Store() r = Reader(master_file=master_file) r.parse(m) m.set_names() for t in m.iter_models(type=PowerTransformer): assert len(t.windings) == 3 assert t.windings[0].is_grounded is False assert t.windings[1].is_grounded is False assert t.windings[2].is_grounded is False output_path = tempfile.TemporaryDirectory() w = Writer(output_path=output_path.name) w.write(m) with open(os.path.join(output_path.name, "Transformers.dss")) as f: string = f.read() assert "bus1.1.2 " in string assert "bus2.1.0 " in string assert "bus2.0.2 " in string
def test_json_serialize_deserialize(): """Write a model to JSON, read it back in, and test that both models match.""" from ditto.readers.opendss.read import Reader from ditto.store import Store from ditto.writers.json.write import Writer from ditto.readers.json.read import Reader as json_reader opendss_models = [ f for f in os.listdir( os.path.join(current_directory, "data/small_cases/opendss/")) if not f.startswith(".") ] opendss_models.remove("storage_test") for model in opendss_models: m = Store() r = Reader( master_file=os.path.join( current_directory, "data/small_cases/opendss/{model}/master.dss".format( model=model), ), buscoordinates_file=os.path.join( current_directory, "data/small_cases/opendss/{model}/buscoord.dss".format( model=model), ), ) r.parse(m) m.set_names() w = Writer(output_path="./") w.write(m) jr = json_reader(input_file="./Model.json") jr.parse(m) jr.model.set_names() for obj in m.models: if hasattr(obj, "name"): json_obj = jr.model[obj.name] assert compare(obj, json_obj) for json_obj in jr.model.models: if hasattr(json_obj, "name"): obj = m[json_obj.name] assert compare(json_obj, obj) os.remove("./Model.json")
def main(): ''' Conversion example of a relatively large test system: the EPRI J1 feeder. OpenDSS ---> CYME example. This example uses the dss files located in tests/data/big_cases/opendss/epri_j1 ''' #Path settings (assuming it is run from examples folder) #Change this if you wish to use another system path = '../tests/data/big_cases/opendss/epri_j1' ############################### # STEP 1: READ FROM OPENDSS # ############################### # #Create a Store object print('>>> Creating empty model...') model = Store() #Instanciate a Reader object r = Reader(master_file=os.path.join(path, 'master.dss'), buscoordinates_file=os.path.join(path, 'buscoords.dss')) #Parse (can take some time for large systems...) print('>>> Reading from OpenDSS...') start = time.time() #basic timer r.parse(model) end = time.time() print('...Done (in {} seconds'.format(end - start)) ########################### # STEP 2: WRITE TO CYME # ########################### # #Instanciate a Writer object w = Writer(output_path='./') #Write to CYME (can also take some time for large systems...) print('>>> Writing to CYME...') start = time.time() #basic timer w.write(model) end = time.time() print('...Done (in {} seconds'.format(end - start))
def test_capacitor_kvar(): m = Store() r = Reader( master_file=os.path.join(current_directory, "test_capacitor_kvar.dss")) r.parse(m) m.set_names() assert len( m["cap1"].phase_capacitors) == 3 # Cap1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["cap1"].phase_capacitors ]) == pytest.approx(600 * 10**3, 0.0001) assert len( m["cap2"].phase_capacitors) == 1 # Cap2 is a one phase capacitor assert m["cap2"].phase_capacitors[0].var == 100 * 10**3 assert len( m["cap3"].phase_capacitors) == 1 # Cap3 is a one phase capacitor assert m["cap3"].phase_capacitors[0].var == 200.37 * 10**3
def test_cyme_to_json(): """Test the JSON writer with CYME models as input.""" from ditto.readers.cyme.read import Reader from ditto.store import Store from ditto.writers.json.write import Writer cyme_models = [ f for f in os.listdir( os.path.join(current_directory, "data/small_cases/cyme/")) if not f.startswith(".") ] for model in cyme_models: m = Store() r = Reader(data_folder_path=os.path.join( current_directory, "data/small_cases/cyme", model)) r.parse(m) m.set_names() output_path = tempfile.TemporaryDirectory() w = Writer(output_path=output_path.name) w.write(m)
def test_transformer_kv(): m = Store() r = Reader(master_file=os.path.join(current_directory, "test_transformer_kv.dss")) r.parse(m) m.set_names() # Substation is a 115kV/4.16kV step-down two windings transformer assert ( len(m["substation"].windings) == 2 ) # Transformer substation should have 2 Windings assert m["substation"].windings[0].nominal_voltage == 115 * 10 ** 3 assert m["substation"].windings[1].nominal_voltage == 4.16 * 10 ** 3 # reg1 is a 4.16kV/4.16kV two windings regulator assert len(m["reg1"].windings) == 2 # Transformer reg1 should have 2 Windings assert m["reg1"].windings[0].nominal_voltage == 4.16 * 10 ** 3 assert m["reg1"].windings[1].nominal_voltage == 4.16 * 10 ** 3 # xfm1 is a 4.16kV/0.48kV two windings distribution transformer assert len(m["xfm1"].windings) == 2 # Transformer xfm1 should have 2 Windings assert m["xfm1"].windings[0].nominal_voltage == 4.16 * 10 ** 3 assert m["xfm1"].windings[1].nominal_voltage == 0.48 * 10 ** 3
def test_loads(): m = Store() r = Reader(master_file=os.path.join(current_directory, "test_loads.dss")) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", )) parsed_values = d_v.parse() precision = 0.001 assert m["load_zipv"].name == "load_zipv" assert m["load_zipv"].connection_type == parsed_values["Load"][ "connection_type"] assert m["load_zipv"].vmin == 0.0 assert m["load_zipv"].vmax == 1.2 assert m["load_zipv"].connecting_element == "load" assert m["load_zipv"].nominal_voltage == 1 * 10**3 assert m["load_zipv"].feeder_name == "src_src" assert m["load_zipv"].peak_coincident_p == None assert m["load_zipv"].peak_coincident_q == None assert len(m["load_zipv"].phase_loads) == 1 # Load is a one phase load assert m["load_zipv"].phase_loads[0].phase == "A" assert m["load_zipv"].phase_loads[0].p == 1 * 10**3 assert m["load_zipv"].phase_loads[0].q == pytest.approx( 1.0 * math.sqrt(1.0 / 0.88**2 - 1) * 10**3, precision) assert m["load_zipv"].phase_loads[0].model == 8 assert m["load_zipv"].phase_loads[0].use_zip == 1 assert m["load_zipv"].phase_loads[0].ppercentcurrent == -0.9855 * 100 assert m["load_zipv"].phase_loads[0].qpercentcurrent == -2.963 * 100 assert m["load_zipv"].phase_loads[0].ppercentpower == 1.1305 * 100 assert m["load_zipv"].phase_loads[0].qpercentpower == 1.404 * 100 assert m["load_zipv"].phase_loads[0].ppercentimpedance == 0.855 * 100 assert m["load_zipv"].phase_loads[0].qpercentimpedance == 2.559 * 100
def test_line_connectivity(): from ditto.store import Store from ditto.readers.opendss.read import Reader # test on the test_line_connectivity.dss m = Store() r = Reader( master_file=os.path.join(current_directory, "test_line_connectivity.dss") ) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", ) ) parsed_values = d_v.parse() # Line1 connects sourcebus to bus1 and should have 3 wires: A, B, C assert len(m["line1"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line1"].wires]) == set(["A", "B", "C"]) assert m["line1"].name == "line1" assert m["line1"].nominal_voltage == float(4.16) * 10 ** 3 assert m["line1"].line_type is None assert m["line1"].length == 100 assert m["line1"].from_element == "sourcebus" assert m["line1"].to_element == "bus1" assert m["line1"].is_fuse is None assert m["line1"].is_switch is None assert m["line1"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"] ) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"] ) # r0,x0 taken from default values diag = (2 * z1 + z0) / 3 diag = round(diag.real, 8) + round(diag.imag, 4) * 1j rem = (z0 - z1) / 3 rem = round(rem.real, 8) + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line1"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = (2 * c1 + c0) / 3 c_diag = round(c_diag.real, 4) + c_diag.imag * 1j c_rem = (c0 - c1) / 3 c_rem = round(c_rem.real, 4) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line1"].capacitance_matrix == cap_matrix assert m["line1"].feeder_name == "sourcebus_src" assert m["line1"].is_recloser is None assert m["line1"].is_breaker is None assert m["line1"].nameclass == "" for w in m["line1"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"]["emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line2 connects bus1 to bus2 and should have 3 wires: A, B, C assert len(m["line2"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line2"].wires]) == set(["A", "B", "C"]) assert m["line2"].name == "line2" assert m["line2"].nominal_voltage == float(4.16) * 10 ** 3 assert m["line2"].line_type is None assert m["line2"].length == 200 assert m["line2"].from_element == "bus1" assert m["line2"].to_element == "bus2" assert m["line2"].is_fuse is None assert m["line2"].is_switch is None assert m["line2"].faultrate == parsed_values["Line"]["faultrate"] assert ( m["line2"].impedance_matrix == imp_matrix ) # Copying the matrix from Line1 as it has 3 wires assert ( m["line2"].capacitance_matrix == cap_matrix ) # Copying the matrix from Line1 as it has 3 wires assert m["line2"].feeder_name == "sourcebus_src" assert m["line2"].is_recloser is None assert m["line2"].is_breaker is None assert m["line2"].nameclass == "" for w in m["line2"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"]["emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line3 connects bus2 to bus3 and should have 2 wires: A, B assert len(m["line3"].wires) == 2 # Phases of the different wires assert set([w.phase for w in m["line3"].wires]) == set(["A", "B"]) assert m["line3"].name == "line3" assert m["line3"].nominal_voltage == float(4.16) * 10 ** 3 assert m["line3"].line_type is None assert m["line3"].length == 50 assert m["line3"].from_element == "bus2" assert m["line3"].to_element == "bus3" assert m["line3"].is_fuse is None assert m["line3"].is_switch is None assert m["line3"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"] ) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"] ) # r0,x0 taken from default values diag = (2 * z1 + z0) / 3 diag = round(diag.real, 8) + round(diag.imag, 4) * 1j rem = (z0 - z1) / 3 rem = round(rem.real, 8) + rem.imag * 1j imp_matrix = np.zeros((2, 2), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line3"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = (2 * c1 + c0) / 3 c_diag = round(c_diag.real, 4) + c_diag.imag * 1j c_rem = (c0 - c1) / 3 c_rem = round(c_rem.real, 4) + c_rem.imag * 1j cap_matrix = np.zeros((2, 2), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line3"].capacitance_matrix == cap_matrix assert m["line3"].feeder_name == "sourcebus_src" assert m["line3"].is_recloser is None assert m["line3"].is_breaker is None assert m["line3"].nameclass == "" for w in m["line3"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"]["emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line4 connects bus3 to bus4 and should have 1 wire: B assert len(m["line4"].wires) == 1 # Phases of the different wires assert set([w.phase for w in m["line4"].wires]) == set(["B"]) assert m["line4"].name == "line4" assert m["line4"].nominal_voltage == float(4.16) * 10 ** 3 assert m["line4"].line_type is None assert m["line4"].length == 25 assert m["line4"].from_element == "bus3" assert m["line4"].to_element == "bus4" assert m["line4"].is_fuse is None assert m["line4"].is_switch is None assert m["line4"].faultrate == parsed_values["Line"]["faultrate"] imp_matrix = complex(parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) imp_matrix = round(imp_matrix.real, 9) + imp_matrix.imag * 1j assert m["line4"].impedance_matrix == [[imp_matrix]] cap_matrix = complex(parsed_values["Line"]["C1"], 0) assert m["line4"].capacitance_matrix == [[cap_matrix]] assert m["line4"].feeder_name == "sourcebus_src" assert m["line4"].is_recloser is None assert m["line4"].is_breaker is None assert m["line4"].nameclass == "" for w in m["line4"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"]["emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line5 connects bus1 to bus5 and should have 2 wires: A, C assert len(m["line5"].wires) == 2 # Phases of the different wires assert set(w.phase for w in m["line5"].wires) == set(["A", "C"]) assert m["line5"].name == "line5" assert m["line5"].nominal_voltage == float(4.16) * 10 ** 3 assert m["line5"].line_type is None assert m["line5"].length == float(1500 * 0.3048) # units = ft assert m["line5"].from_element == "bus1" assert m["line5"].to_element == "bus5" assert m["line5"].is_fuse is None assert m["line5"].is_switch is None assert m["line5"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"] ) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"] ) # r0,x0 taken from default values # import pdb;pdb.set_trace() diag = ((2 * z1 + z0) / 3) / 0.3048 # Units = ft diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) / 0.3048 # Units = ft rem = round(rem.real, 11) + rem.imag * 1j imp_matrix = np.zeros((2, 2), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() # assert m["line5"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) / 0.3048 # Units = ft c_diag = c_diag.real + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) / 0.3048 # Units = ft c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((2, 2), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() np.testing.assert_array_almost_equal(m["line5"].capacitance_matrix, cap_matrix) assert m["line5"].feeder_name == "sourcebus_src" assert m["line5"].is_recloser is None assert m["line5"].is_breaker is None assert m["line5"].nameclass == "" for w in m["line5"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"]["emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line6 connects bus4 to bus6 and should have 2 wires: B, C assert len(m["line6"].wires) == 2 # Phases of the different wires assert set([w.phase for w in m["line6"].wires]) == set(["B", "C"]) assert m["line6"].name == "line6" assert m["line6"].nominal_voltage == float(4.16) * 10 ** 3 assert m["line6"].line_type is None assert m["line6"].length == 110 assert m["line6"].from_element == "bus4" assert m["line6"].to_element == "bus6" assert m["line6"].is_fuse is None assert m["line6"].is_switch is None assert m["line6"].faultrate == parsed_values["Line"]["faultrate"] assert m["line6"].impedance_matrix == [ [(0.09813333 + 0.2153j), (0.04013333 + 0.0947j)], [(0.04013333 + 0.0947j), (0.09813333 + 0.2153j)], ] assert m["line6"].capacitance_matrix == [ [(2.8 + 0j), (-0.6 + 0j)], [(-0.6 + 0j), (2.8 + 0j)], ] assert m["line6"].feeder_name == "sourcebus_src" assert m["line6"].is_recloser is None assert m["line6"].is_breaker is None assert m["line6"].nameclass == "" for w in m["line6"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"]["emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line7 assert len(m["line7"].wires) == 2 # Phases of the different wires assert set([w.phase for w in m["line7"].wires]) == set(["B", "C"]) assert m["line7"].name == "line7" assert m["line7"].nominal_voltage == float(4.16) * 10 ** 3 assert m["line7"].line_type is None assert m["line7"].length == 100 assert m["line7"].from_element == "bus1" assert m["line7"].to_element == "bus2" assert m["line7"].is_fuse is None assert m["line7"].is_switch is None assert m["line7"].faultrate == parsed_values["Line"]["faultrate"] assert m["line7"].impedance_matrix == [ [(0.09813333 + 0.2153j), (0.04013333 + 0.0947j)], [(0.04013333 + 0.0947j), (0.09813333 + 0.2153j)], ] assert m["line7"].capacitance_matrix == [ [(2.8 + 0j), (-0.6 + 0j)], [(-0.6 + 0j), (2.8 + 0j)], ] assert m["line7"].feeder_name == "sourcebus_src" assert m["line7"].is_recloser is None assert m["line7"].is_breaker is None assert m["line7"].nameclass == "" for w in m["line7"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"]["emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None
def test_line_length(): from ditto.store import Store from ditto.readers.opendss.read import Reader from ditto.readers.json.read import Reader as json_reader from ditto.default_values.default_values_json import Default_Values m = Store() r = Reader( master_file=os.path.join(current_directory, "test_line_length.dss")) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", )) parsed_values = d_v.parse() # Line 1 is a 100 meters 3 phase line assert len(m["line1"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line1"].wires]) == set(["A", "B", "C"]) assert m["line1"].name == "line1" assert m["line1"].nominal_voltage == float(4.16) * 10**3 assert m["line1"].line_type == None assert m["line1"].length == float(100) # Units = meters assert m["line1"].from_element == "sourcebus" assert m["line1"].to_element == "bus1" assert m["line1"].is_fuse is None assert m["line1"].is_switch is None assert m["line1"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = (2 * z1 + z0) / 3 diag = round(diag.real, 8) + round(diag.imag, 4) * 1j rem = (z0 - z1) / 3 rem = round(rem.real, 8) + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line1"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = (2 * c1 + c0) / 3 c_diag = round(c_diag.real, 10) + c_diag.imag * 1j c_rem = (c0 - c1) / 3 c_rem = round(c_rem.real, 10) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line1"].capacitance_matrix == cap_matrix assert m["line1"].feeder_name == "sourcebus_src" assert m["line1"].is_recloser is None assert m["line1"].is_breaker is None assert m["line1"].nameclass == "" for w in m["line1"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 2 is a 83.47 kilo-feet 3 phase line assert len(m["line2"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line2"].wires]) == set(["A", "B", "C"]) assert m["line2"].name == "line2" assert m["line2"].nominal_voltage == float(4.16) * 10**3 assert m["line2"].line_type == None assert m["line2"].length == float(83.47 * 304.8) # units = kft assert m["line2"].from_element == "bus1" assert m["line2"].to_element == "bus2" assert m["line2"].is_fuse is None assert m["line2"].is_switch is None assert m["line2"].faultrate == parsed_values["Line"]["faultrate"] diag = ((2 * z1 + z0) / 3) / 304.8 # Units = kft diag = diag.real + diag.imag * 1j rem = ((z0 - z1) / 3) / 304.8 # Units = kft rem = rem.real + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() # assert m["line2"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) / 304.8 # Units = kft c_diag = c_diag.real + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) / 304.8 # Units = kft c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() # assert m["line2"].capacitance_matrix == cap_matrix assert m["line2"].feeder_name == "sourcebus_src" assert m["line2"].is_recloser is None assert m["line2"].is_breaker is None assert m["line2"].nameclass == "" for w in m["line2"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 3 is a 200 feet 2 phases line assert len(m["line3"].wires) == 2 # Phases of the different wires assert set([w.phase for w in m["line3"].wires]) == set(["A", "C"]) assert m["line3"].name == "line3" assert m["line3"].nominal_voltage == float(4.16) * 10**3 assert m["line3"].line_type == None assert m["line3"].length == float(200 * 0.3048) # units = ft assert m["line3"].from_element == "bus2" assert m["line3"].to_element == "bus3" assert m["line3"].is_fuse is None assert m["line3"].is_switch is None assert m["line3"].faultrate == parsed_values["Line"]["faultrate"] diag = ((2 * z1 + z0) / 3) / 0.3048 # Units = ft diag = diag.real + diag.imag * 1j rem = ((z0 - z1) / 3) / 0.3048 # Units = ft rem = rem.real + rem.imag * 1j imp_matrix = np.zeros((2, 2), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() # assert m["line3"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) / 0.3048 # Units = ft c_diag = c_diag.real + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) / 0.3048 # Units = ft c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((2, 2), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() # assert m["line3"].capacitance_matrix == cap_matrix assert m["line3"].feeder_name == "sourcebus_src" assert m["line3"].is_recloser is None assert m["line3"].is_breaker is None assert m["line3"].nameclass == "" for w in m["line3"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 4 is a 1.01 miles 1 phase line assert len(m["line4"].wires) == 1 # Phases of the different wires assert m["line4"].wires[0].phase == "B" assert m["line4"].name == "line4" assert m["line4"].nominal_voltage == float(4.16) * 10**3 assert m["line4"].line_type == None assert m["line4"].length == float(1.01 * 1609.34) # units = mi assert m["line4"].from_element == "bus2" assert m["line4"].to_element == "bus4" assert m["line4"].is_fuse is None assert m["line4"].is_switch is None assert m["line4"].faultrate == parsed_values["Line"]["faultrate"] imp_matrix = ( complex(parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) / 1609.34) # Units = mi imp_matrix = imp_matrix.real + imp_matrix.imag * 1j assert m["line4"].impedance_matrix == [[imp_matrix]] cap_matrix = complex(parsed_values["Line"]["C1"], 0) / 1609.34 # Units = mi assert m["line4"].capacitance_matrix == [[cap_matrix]] assert m["line4"].feeder_name == "sourcebus_src" assert m["line4"].is_recloser is None assert m["line4"].is_breaker is None assert m["line4"].nameclass == "" for w in m["line4"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 5 is a 2040.12 centimeters 3 phase line assert len(m["line5"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line5"].wires]) == set(["A", "B", "C"]) assert m["line5"].name == "line5" assert m["line5"].nominal_voltage == float(4.16) * 10**3 assert m["line5"].line_type == None assert m["line5"].length == float(2040.12 * 0.01) # units = cm assert m["line5"].from_element == "bus2" assert m["line5"].to_element == "bus5" assert m["line5"].is_fuse is None assert m["line5"].is_switch is None assert m["line5"].faultrate == parsed_values["Line"]["faultrate"] diag = ((2 * z1 + z0) / 3) / 0.01 # Units = cm diag = round(diag.real, 6) + diag.imag * 1j rem = ((z0 - z1) / 3) / 0.01 # Units = cm rem = round(rem.real, 6) + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() # assert m["line5"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) / 0.01 # Units = cm c_diag = c_diag.real + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) / 0.01 # Units = cm c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() # assert m["line5"].capacitance_matrix == cap_matrix assert m["line5"].feeder_name == "sourcebus_src" assert m["line5"].is_recloser is None assert m["line5"].is_breaker is None assert m["line5"].nameclass == "" for w in m["line5"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 6 is a 1666.87 inches 1 phase line assert len(m["line6"].wires) == 1 # Phases of the different wires assert m["line6"].wires[0].phase == "A" assert m["line6"].name == "line6" assert m["line6"].nominal_voltage == float(4.16) * 10**3 assert m["line6"].line_type == None assert m["line6"].length == float(1666.87 * 0.0254) # units = in assert m["line6"].from_element == "bus2" assert m["line6"].to_element == "bus6" assert m["line6"].is_fuse is None assert m["line6"].is_switch is None assert m["line6"].faultrate == parsed_values["Line"]["faultrate"] imp_matrix = ( complex(parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) / 0.0254) # Units = in imp_matrix = imp_matrix.real + imp_matrix.imag * 1j assert m["line6"].impedance_matrix == [[imp_matrix]] cap_matrix = complex(parsed_values["Line"]["C1"], 0) / 0.0254 # Units = in assert m["line6"].capacitance_matrix == [[cap_matrix]] assert m["line6"].feeder_name == "sourcebus_src" assert m["line6"].is_recloser is None assert m["line6"].is_breaker is None assert m["line6"].nameclass == "" for w in m["line6"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["line9"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line9"].wires]) == set(["A", "B", "C"]) assert m["line9"].name == "line9" assert m["line9"].nominal_voltage == float(4.16) * 10**3 assert m["line9"].line_type == None assert m["line9"].length == 1.01 * 1609.34 # units = mi assert m["line9"].from_element == "bus2" assert m["line9"].to_element == "bus9" assert m["line9"].is_fuse is None assert m["line9"].is_switch is None assert m["line9"].faultrate == 0 z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) / 1609.34 # Units = mi diag = diag.real + diag.imag * 1j rem = ((z0 - z1) / 3) / 1609.34 # Units = mi rem = rem.real + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() # assert m["line9"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) / 1609.34 # Units = mi c_diag = round(c_diag.real, 18) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) / 1609.34 # Units = mi c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line9"].capacitance_matrix == cap_matrix assert m["line9"].feeder_name == "sourcebus_src" assert m["line9"].is_recloser is None assert m["line9"].is_breaker is None assert m["line9"].nameclass == "" for w in m["line9"].wires: assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["line10"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line1"].wires]) == set(["A", "B", "C"]) assert m["line10"].name == "line10" assert m["line10"].nominal_voltage == float(4.16) * 10**3 assert m["line10"].line_type == None assert m["line10"].length == 1.01 * 1609.34 # units = mi assert m["line10"].from_element == "bus2" assert m["line10"].to_element == "bus10" assert m["line10"].is_fuse is None assert m["line10"].is_switch is None assert m["line10"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) / 1609.34 # Units = mi diag = diag.real + diag.imag * 1j rem = ((z0 - z1) / 3) / 1609.34 # Units = mi rem = rem.real + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() # assert m["line10"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) / 1609.34 # Units = mi c_diag = round(c_diag.real, 18) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) / 1609.34 # Units = mi c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line10"].capacitance_matrix == cap_matrix assert m["line10"].feeder_name == "sourcebus_src" assert m["line10"].is_recloser is None assert m["line10"].is_breaker is None assert m["line10"].nameclass == "" for w in m["line10"].wires: assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["line11"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line1"].wires]) == set(["A", "B", "C"]) assert m["line11"].name == "line11" assert m["line11"].nominal_voltage == float(4.16) * 10**3 assert m["line11"].line_type == None assert m["line11"].length == 1.01 * 1609.34 # units = mi assert m["line11"].from_element == "bus2" assert m["line11"].to_element == "bus11" assert m["line11"].is_fuse is None assert m["line11"].is_switch is None assert m["line11"].faultrate == 1.0 z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) / 1609.34 # Units = mi diag = diag.real + diag.imag * 1j rem = ((z0 - z1) / 3) / 1609.34 # Units = mi rem = rem.real + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() # assert m["line11"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) / 1609.34 # Units = mi c_diag = round(c_diag.real, 18) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) / 1609.34 # Units = mi c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line11"].capacitance_matrix == cap_matrix assert m["line11"].feeder_name == "sourcebus_src" assert m["line11"].is_recloser is None assert m["line11"].is_breaker is None assert m["line11"].nameclass == "" for w in m["line11"].wires: assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None
def test_linegeometries(): m = Store() r = Reader(master_file=os.path.join(current_directory, "test_linegeometries.dss")) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", ) ) parsed_values = d_v.parse() # Number of wires assert len(m["line1"].wires) == 4 # Line1 should have 4 wires # Phases of the different wires assert set([w.phase for w in m["line1"].wires]) == set(["A", "B", "C", "N"]) assert m["line1"].name == "line1" assert m["line1"].nominal_voltage == float(4.8) * 10 ** 3 assert m["line1"].line_type == "overhead" assert m["line1"].length == 300 * 0.3048 # units = ft assert m["line1"].from_element == "bus1" assert m["line1"].to_element == "bus2" assert m["line1"].is_fuse is None assert m["line1"].is_switch is None z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"] ) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"] ) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + rem.imag * 1j imp_matrix = np.zeros((4, 4), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line1"].faultrate == parsed_values["Line"]["faultrate"] np.testing.assert_array_almost_equal( m["line1"].impedance_matrix, [ [ (0.00024738133202099736 + 0.0008769514435695538j), (5.810587270341207e-05 + 0.00031932618110236215j), (5.723612204724409e-05 + 0.0004637522965879265j), (5.717280183727034e-05 + 0.0004757309711286089j), ], [ (5.810587270341207e-05 + 0.00031932618110236215j), (0.0002491671587926509 + 0.0008750521653543306j), (5.810603674540682e-05 + 0.0003196077099737533j), (5.803946850393701e-05 + 0.0003143254593175853j), ], [ (5.723612204724409e-05 + 0.0004637522965879265j), (5.810603674540682e-05 + 0.0003196077099737533j), (0.00024738133202099736 + 0.0008769514435695538j), (5.717296587926509e-05 + 0.0005039963910761155j), ], [ (5.717280183727034e-05 + 0.0004757309711286089j), (5.803946850393701e-05 + 0.0003143254593175853j), (5.717296587926509e-05 + 0.0005039963910761155j), (0.0007530643044619422 + 0.0010085508530183727j), ], ], ) np.testing.assert_array_almost_equal( m["line1"].capacitance_matrix, [ [ (0.008384708005249344 + 0j), (-0.0001470299868766404 + 0j), (-0.0019942040682414696 + 0j), (-0.0020357719816272964 + 0j), ], [ (-0.0001470299868766404 + 0j), (0.00994426837270341 + 0j), (-0.00014228366141732281 + 0j), (-9.78384186351706e-05 + 0j), ], [ (-0.0019942040682414696 + 0j), (-0.00014228366141732281 + 0j), (0.008713290682414698 + 0j), (-0.002607346128608924 + 0j), ], [ (-0.0020357719816272964 + 0j), (-9.78384186351706e-05 + 0j), (-0.002607346128608924 + 0j), (0.008078645013123359 + 0j), ], ], ) assert m["line1"].feeder_name == "sourcebus_src" assert m["line1"].is_recloser is None assert m["line1"].is_breaker is None assert m["line1"].nameclass == "" for w in m["line1"].wires: assert w.emergency_ampacity == 795 assert w.insulation_thickness == parsed_values["Wire"]["insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None phased_wires = {} for wire in m["line1"].wires: phased_wires[wire.phase] = wire # Nameclass for p in ["A", "B", "C"]: assert phased_wires[p].ampacity == 530 assert phased_wires[p].nameclass == "wire1" assert phased_wires["N"].ampacity == 230 assert phased_wires["N"].nameclass == "wire2" # Positions of the wires assert (phased_wires["A"].X, phased_wires["A"].Y) == (-1.2909, 13.716) assert (phased_wires["B"].X, phased_wires["B"].Y) == ( -0.1530096 * 0.3048, 4.1806368 * 0.3048, ) assert (phased_wires["C"].X, phased_wires["C"].Y) == (0.5737, 13.716) assert (phased_wires["N"].X, phased_wires["N"].Y) == (0.0, 14.648) # GMR for p in ["A", "B", "C"]: assert phased_wires[p].gmr == 0.0255 * 0.3048 assert phased_wires["N"].gmr == 0.00446 * 0.3048 # Diameter for p in ["A", "B", "C"]: assert phased_wires[p].diameter == 0.741 * 0.0254 assert phased_wires["N"].diameter == 0.398 * 0.0254 # Resistance # TODO: Change this once the resistance of a Wire object will no longer be the total # resistance, but the per meter resistance... # for p in ["A", "B", "C"]: assert phased_wires[p].resistance == pytest.approx( 0.306 * 0.000621371 * 300 * 0.3048, 0.00001 ) assert phased_wires["N"].resistance == pytest.approx( 1.12 * 0.000621371 * 300 * 0.3048, 0.00001 ) # Number of wires assert len(m["line2"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line2"].wires]) == set(["A", "B", "C"]) assert m["line2"].name == "line2" assert m["line2"].nominal_voltage == float(4.8) * 10 ** 3 assert m["line2"].line_type == "underground" assert m["line2"].length == 1 * 1609.34 # units = mi assert m["line2"].from_element == "bus2" assert m["line2"].to_element == "bus3" assert m["line2"].is_fuse is None assert m["line2"].is_switch is None assert m["line2"].faultrate == parsed_values["Line"]["faultrate"] np.testing.assert_array_almost_equal( m["line2"].impedance_matrix, [ [ (0.0005010314787428386 + 0.00026819845402463124j), (0.00020170349335752545 + 1.1288596567537003e-05j), (0.00017933407483813242 - 1.766354530428623e-05j), ], [ (0.00020170349335752545 + 1.1288596567537003e-05j), (0.0004946492350901612 + 0.00024160345234692485j), (0.00020170349335752545 + 1.1288596567537003e-05j), ], [ (0.00017933407483813242 - 1.766354530428623e-05j), (0.00020170349335752545 + 1.1288596567537003e-05j), (0.0005010314787428386 + 0.00026819845402463124j), ], ], ) np.testing.assert_array_almost_equal( m["line2"].capacitance_matrix, [ [(0.23857494376576735 + 0j), 0j, 0j], [0j, (0.23857494376576735 + 0j), 0j], [0j, 0j, (0.23857494376576735 + 0j)], ], ) assert m["line2"].feeder_name == "sourcebus_src" assert m["line2"].is_recloser is None assert m["line2"].is_breaker is None assert m["line2"].nameclass == "" for w in m["line2"].wires: assert w.emergency_ampacity is None assert w.insulation_thickness == 0.005588 assert w.is_open is None assert w.concentric_neutral_gmr == 0.0508 assert w.concentric_neutral_resistance == 858.5200001016 assert w.concentric_neutral_diameter == 0.0016256 assert w.concentric_neutral_outside_diameter == 0.029463999999999997 assert w.concentric_neutral_nstrand == 13 phased_wires = {} for wire in m["line2"].wires: phased_wires[wire.phase] = wire # Nameclass for p in ["A", "B", "C"]: assert phased_wires[p].ampacity is None assert phased_wires[p].nameclass == "cndata1" # Positions of the wires assert (phased_wires["A"].X, phased_wires["A"].Y) == (-0.5 * 0.3048, -4 * 0.3048) assert (phased_wires["B"].X, phased_wires["B"].Y) == (0, -4 * 0.3048) assert (phased_wires["C"].X, phased_wires["C"].Y) == (0.5 * 0.3048, -4 * 0.3048) # GMR for p in ["A", "B", "C"]: assert phased_wires[p].gmr == 0.20568 * 0.0254 # Diameter for p in ["A", "B", "C"]: assert phased_wires[p].diameter == 0.573 * 0.0254 for p in ["A", "B", "C"]: assert phased_wires[p].resistance == pytest.approx( 0.076705 * 1609.34 * 0.00328084, 0.00001 )
def test_capacitor_connectivity(): m = Store() r = Reader(master_file=os.path.join(current_directory, "test_capacitor_connectivity.dss")) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", )) parsed_values = d_v.parse() # Capacitor Cap1 should be a three phase capacitor (3 PhaseCapacitor objects) connected to bus1 assert len( m["cap1"].phase_capacitors) == 3 # Cap1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["cap1"].phase_capacitors ]) == pytest.approx(600 * 10**3, 0.0001) assert m["cap1"].name == "cap1" assert m["cap1"].nominal_voltage == float(4.16) * 10**3 assert m["cap1"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap1"].delay is None assert m["cap1"].mode is None assert m["cap1"].low is None assert m["cap1"].high is None assert m["cap1"].resistance == 0.0 assert m["cap1"].reactance == 0.0 assert m["cap1"].susceptance is None assert m["cap1"].conductance is None assert m["cap1"].pt_ratio is None assert m["cap1"].ct_ratio is None assert m["cap1"].pt_phase is None assert m["cap1"].connecting_element == "bus1" assert m["cap1"].measuring_element is None assert m["cap1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["cap1"].phase_capacitors]) == set(["A", "B", "C"]) # Capacitor Cap2 should be a one phase capacitor (1 PhaseCapacitor object) connected to bus2 on phase C assert len( m["cap2"].phase_capacitors) == 1 # Cap2 is a one phase capacitor assert m["cap2"].phase_capacitors[0].var == 100 * 10**3 assert m["cap2"].name == "cap2" assert m["cap2"].nominal_voltage == float(2.4) * 10**3 assert m["cap2"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap2"].delay is None assert m["cap2"].mode is None assert m["cap2"].low is None assert m["cap2"].high is None assert m["cap2"].resistance == 0.0 assert m["cap2"].reactance == 0.0 assert m["cap2"].susceptance is None assert m["cap2"].conductance is None assert m["cap2"].pt_ratio is None assert m["cap2"].ct_ratio is None assert m["cap2"].pt_phase is None assert m["cap2"].connecting_element == "bus2" assert m["cap2"].measuring_element is None assert m["cap2"].feeder_name == "sourcebus_src" assert m["cap2"].phase_capacitors[0].phase == "C" # Capacitor Cap3 should be a one phase capacitor (1 PhaseCapacitor object) connected to bus3 on phase A assert len( m["cap3"].phase_capacitors) == 1 # Cap3 is a one phase capacitor assert m["cap3"].phase_capacitors[0].var == 200.37 * 10**3 assert m["cap3"].name == "cap3" assert m["cap3"].nominal_voltage == float(2.4) * 10**3 assert m["cap3"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap3"].delay is None assert m["cap3"].mode is None assert m["cap3"].low is None assert m["cap3"].high is None assert m["cap3"].resistance == 0.0 assert m["cap3"].reactance == 0.0 assert m["cap3"].susceptance is None assert m["cap3"].conductance is None assert m["cap3"].pt_ratio is None assert m["cap3"].ct_ratio is None assert m["cap3"].pt_phase is None assert m["cap3"].connecting_element == "bus3" assert m["cap3"].measuring_element is None assert m["cap3"].feeder_name == "sourcebus_src" assert m["cap3"].phase_capacitors[0].phase == "A" # Capacitor Cap4 should be a two phase capacitor (2 PhaseCapacitor objects) connected to bus4 on phase A and C assert len( m["cap4"].phase_capacitors) == 2 # Cap4 is a two phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["cap4"].phase_capacitors ]) == pytest.approx(400 * 10**3, 0.0001) assert m["cap4"].name == "cap4" assert m["cap4"].nominal_voltage == float(2.4) * 10**3 assert m["cap4"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap4"].delay is None assert m["cap4"].mode is None assert m["cap4"].low is None assert m["cap4"].high is None assert m["cap4"].resistance == 0.0 assert m["cap4"].reactance == 0.0 assert m["cap4"].susceptance is None assert m["cap4"].conductance is None assert m["cap4"].pt_ratio is None assert m["cap4"].ct_ratio is None assert m["cap4"].pt_phase is None assert m["cap4"].connecting_element == "bus4" assert m["cap4"].measuring_element is None assert m["cap4"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["cap4"].phase_capacitors]) == set(["A", "C"]) # Capacitors from epri_j1 assert len(m["b4909-1"].phase_capacitors ) == 3 # b4909-1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b4909-1"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["b4909-1"].name == "b4909-1" assert m["b4909-1"].nominal_voltage == float(12.47) * 10**3 assert m["b4909-1"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["b4909-1"].delay == 30 assert m["b4909-1"].mode == "voltage" assert m["b4909-1"].low == parsed_values["Capacitor"]["low"] assert m["b4909-1"].high == parsed_values["Capacitor"]["high"] assert m["b4909-1"].resistance == 0.0 assert m["b4909-1"].reactance == 0.0 assert m["b4909-1"].susceptance is None assert m["b4909-1"].conductance is None assert m["b4909-1"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b4909-1"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b4909-1"].pt_phase == "B" assert m["b4909-1"].connecting_element == "b4909" assert m["b4909-1"].measuring_element == "Line.OH_B4904" assert m["b4909-1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b4909-1"].phase_capacitors ]) == set(["A", "B", "C"]) assert len(m["b4909-2"].phase_capacitors ) == 3 # b4909-2 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b4909-2"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["b4909-2"].name == "b4909-2" assert m["b4909-2"].nominal_voltage == float(12.47) * 10**3 assert m["b4909-2"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["b4909-2"].delay == 30 assert m["b4909-2"].mode == "voltage" assert m["b4909-2"].low == 120.5 assert m["b4909-2"].high == 125 assert m["b4909-2"].resistance == 0.0 assert m["b4909-2"].reactance == 0.0 assert m["b4909-2"].susceptance is None assert m["b4909-2"].conductance is None assert m["b4909-2"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b4909-2"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b4909-2"].pt_phase == "B" assert m["b4909-2"].connecting_element == "b4909" assert m["b4909-2"].measuring_element == "Line.OH_B4904" assert m["b4909-2"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b4909-2"].phase_capacitors ]) == set(["A", "B", "C"]) # oh_b4904 assert len(m["oh_b4904"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["oh_b4904"].wires]) == set(["A", "B", "C"]) assert m["oh_b4904"].name == "oh_b4904" assert (m["oh_b4904"].nameclass == "OH-3X_477AAC_4/0AAACN" ) # Linecode is OH-3X_477AAC_4/0AAACN assert m["oh_b4904"].line_type == None assert m["oh_b4904"].from_element == "b4909" assert m["oh_b4904"].to_element == "b4904" assert m["oh_b4904"].length == pytest.approx(161.84879) assert m["oh_b4904"].nominal_voltage == float(4.16) * 10**3 assert m["oh_b4904"].is_fuse is None assert m["oh_b4904"].is_switch is None assert m["oh_b4904"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex(0.12241009, 0.39494091) # Specified in the dss input z0 = complex(0.33466485, 1.2742766) # Specified in the dss input diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 10) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units =km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["oh_b4904"].impedance_matrix == imp_matrix c1 = complex(11.1973, 0) # Specified in the dss input c0 = complex(4.8089, 0) # Specified in the dss input c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 9) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 9) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["oh_b4904"].capacitance_matrix == cap_matrix assert m["oh_b4904"].feeder_name == "sourcebus_src" assert m["oh_b4904"].is_recloser is None assert m["oh_b4904"].is_breaker is None for w in m["oh_b4904"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(732) assert w.emergency_ampacity == float(871) assert w.resistance is None assert w.insulation_thickness == 0.0 assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert (len(m["b18944-1"].phase_capacitors) == 3 ) # b18944-1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b18944-1"].phase_capacitors ]) == pytest.approx(1200 * 10**3, 0.0001) assert m["b18944-1"].name == "b18944-1" assert m["b18944-1"].nominal_voltage == float(12.47) * 10**3 assert (m["b18944-1"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["b18944-1"].delay == 31 assert m["b18944-1"].mode == "voltage" assert m["b18944-1"].low == parsed_values["Capacitor"]["low"] assert m["b18944-1"].high == parsed_values["Capacitor"]["high"] assert m["b18944-1"].resistance == 0.0 assert m["b18944-1"].reactance == 0.0 assert m["b18944-1"].susceptance is None assert m["b18944-1"].conductance is None assert m["b18944-1"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b18944-1"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b18944-1"].pt_phase == "A" assert m["b18944-1"].connecting_element == "b18941" assert m["b18944-1"].measuring_element == "Line.OH_B18944" assert m["b18944-1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b18944-1"].phase_capacitors ]) == set(["A", "B", "C"]) assert (len(m["b18944-2"].phase_capacitors) == 3 ) # b18944-2 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b18944-2"].phase_capacitors ]) == pytest.approx(1200 * 10**3, 0.0001) assert m["b18944-2"].name == "b18944-2" assert m["b18944-2"].nominal_voltage == float(12.47) * 10**3 assert (m["b18944-2"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["b18944-2"].delay == 31 assert m["b18944-2"].mode == "voltage" assert m["b18944-2"].low == 118 assert m["b18944-2"].high == 124 assert m["b18944-2"].resistance == 0.0 assert m["b18944-2"].reactance == 0.0 assert m["b18944-2"].susceptance is None assert m["b18944-2"].conductance is None assert m["b18944-2"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b18944-2"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b18944-2"].pt_phase == "A" assert m["b18944-2"].connecting_element == "b18941" assert m["b18944-2"].measuring_element == "Line.OH_B18944" assert m["b18944-2"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b18944-2"].phase_capacitors ]) == set(["A", "B", "C"]) # oh_b18944 assert len(m["oh_b18944"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["oh_b18944"].wires]) == set(["A", "B", "C"]) assert m["oh_b18944"].name == "oh_b18944" assert m[ "oh_b18944"].nameclass == "OH-3X_4CU_4CUN" # Linecode is OH-3X_4CU_4CUN assert m["oh_b18944"].line_type == None assert m["oh_b18944"].from_element == "b18941" assert m["oh_b18944"].to_element == "b18944" assert m["oh_b18944"].length == pytest.approx(141.1224) assert m["oh_b18944"].nominal_voltage == float(4.16) * 10**3 assert m["oh_b18944"].is_fuse is None assert m["oh_b18944"].is_switch is None assert m["oh_b18944"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex(0.85376372, 0.49484991) # Specified in the dss input z0 = complex(1.2302027, 1.5569817) # Specified in the dss input diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 10) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units =km rem = round(rem.real, 10) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["oh_b18944"].impedance_matrix == imp_matrix c1 = complex(8.7903, 0) # Specified in the dss input c0 = complex(4.2476, 0) # Specified in the dss input c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 9) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 9) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["oh_b18944"].capacitance_matrix == cap_matrix assert m["oh_b18944"].feeder_name == "sourcebus_src" assert m["oh_b18944"].is_recloser is None assert m["oh_b18944"].is_breaker is None for w in m["oh_b18944"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(142) assert w.emergency_ampacity == float(142) assert w.resistance is None assert w.insulation_thickness == 0.0 assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Capacitors from ieee 8500-node test feeder assert (len(m["capbank0a"].phase_capacitors) == 1 ) # capbank0a is a single phase capacitor assert m["capbank0a"].phase_capacitors[0].var == 400 * 10**3 assert m["capbank0a"].name == "capbank0a" assert m["capbank0a"].nominal_voltage == float(7.2) * 10**3 assert (m["capbank0a"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank0a"].delay == None assert m["capbank0a"].mode == None assert m["capbank0a"].low is None assert m["capbank0a"].high is None assert m["capbank0a"].resistance == 0.0 assert m["capbank0a"].reactance == 0.0 assert m["capbank0a"].susceptance is None assert m["capbank0a"].conductance is None assert m["capbank0a"].pt_ratio == None assert m["capbank0a"].ct_ratio is None assert m["capbank0a"].pt_phase == None assert m["capbank0a"].connecting_element == "r42246" assert m["capbank0a"].measuring_element == None assert m["capbank0a"].feeder_name == "sourcebus_src" assert m["capbank0a"].phase_capacitors[0].phase == "A" assert (len(m["capbank0b"].phase_capacitors) == 1 ) # capbank0b is a single phase capacitor assert m["capbank0b"].phase_capacitors[0].var == 400 * 10**3 assert m["capbank0b"].name == "capbank0b" assert m["capbank0b"].nominal_voltage == float(7.2) * 10**3 assert (m["capbank0b"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank0b"].delay == None assert m["capbank0b"].mode == None assert m["capbank0b"].low is None assert m["capbank0b"].high is None assert m["capbank0b"].resistance == 0.0 assert m["capbank0b"].reactance == 0.0 assert m["capbank0b"].susceptance is None assert m["capbank0b"].conductance is None assert m["capbank0b"].pt_ratio == None assert m["capbank0b"].ct_ratio is None assert m["capbank0b"].pt_phase == None assert m["capbank0b"].connecting_element == "r42246" assert m["capbank0b"].measuring_element == None assert m["capbank0b"].feeder_name == "sourcebus_src" assert m["capbank0b"].phase_capacitors[0].phase == "B" assert (len(m["capbank0c"].phase_capacitors) == 1 ) # capbank0c is a single phase capacitor assert m["capbank0c"].phase_capacitors[0].var == 400 * 10**3 assert m["capbank0c"].name == "capbank0c" assert m["capbank0c"].nominal_voltage == float(7.2) * 10**3 assert (m["capbank0c"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank0c"].delay == None assert m["capbank0c"].mode == None assert m["capbank0c"].low is None assert m["capbank0c"].high is None assert m["capbank0c"].resistance == 0.0 assert m["capbank0c"].reactance == 0.0 assert m["capbank0c"].susceptance is None assert m["capbank0c"].conductance is None assert m["capbank0c"].pt_ratio == None assert m["capbank0c"].ct_ratio is None assert m["capbank0c"].pt_phase == None assert m["capbank0c"].connecting_element == "r42246" assert m["capbank0c"].measuring_element == None assert m["capbank0c"].feeder_name == "sourcebus_src" assert m["capbank0c"].phase_capacitors[0].phase == "C" # This is a 3-phase capacitor bank assert (len(m["capbank3"].phase_capacitors) == 3 ) # capbank3 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["capbank3"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["capbank3"].name == "capbank3" assert m["capbank3"].nominal_voltage == float(12.47112) * 10**3 assert (m["capbank3"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank3"].delay == None assert m["capbank3"].mode == None assert m["capbank3"].low is None assert m["capbank3"].high is None assert m["capbank3"].resistance == 0.0 assert m["capbank3"].reactance == 0.0 assert m["capbank3"].susceptance is None assert m["capbank3"].conductance is None assert m["capbank3"].pt_ratio == None assert m["capbank3"].ct_ratio is None assert m["capbank3"].pt_phase == None assert m["capbank3"].connecting_element == "r18242" assert m["capbank3"].measuring_element == None assert m["capbank3"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["capbank3"].phase_capacitors ]) == set(["A", "B", "C"]) # 3-phase capacitor with number of phases mentioned assert (len(m["capbank3-1"].phase_capacitors) == 3 ) # capbank3-1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["capbank3-1"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["capbank3-1"].nominal_voltage == float(12.47112) * 10**3 assert m["capbank3-1"].name == "capbank3-1" assert (m["capbank3-1"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank3-1"].delay == None assert m["capbank3-1"].mode == None assert m["capbank3-1"].low is None assert m["capbank3-1"].high is None assert m["capbank3-1"].resistance == 0.0 assert m["capbank3-1"].reactance == 0.0 assert m["capbank3-1"].susceptance is None assert m["capbank3-1"].conductance is None assert m["capbank3-1"].pt_ratio == None assert m["capbank3-1"].ct_ratio is None assert m["capbank3-1"].pt_phase == None assert m["capbank3-1"].connecting_element == "r18242" assert m["capbank3-1"].measuring_element == None assert m["capbank3-1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["capbank3-1"].phase_capacitors ]) == set(["A", "B", "C"])
def test_linecodes(): """Tests if linecodes are read correctly.""" from ditto.store import Store from ditto.readers.opendss.read import Reader # test on the test_linecodes.dss m = Store() r = Reader( master_file=os.path.join(current_directory, "test_linecodes.dss")) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", )) parsed_values = d_v.parse() # Line 1 assert len(m["line1"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line1"].wires]) == set(["A", "B", "C"]) assert m[ "line1"].nameclass == "3-1/0C_2/0CN_T" # Linecode is 3-1/0C_2/0CN_T assert m["line1"].line_type == None assert m["line1"].from_element == "bus1" assert m["line1"].to_element == "bus2" assert m["line1"].length == 10 assert m["line1"].nominal_voltage == float(12.47) * 10**3 assert m["line1"].is_fuse is None assert m["line1"].is_switch is None assert m["line1"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex(0.3489, 0.426198) # r1,x1 values from linecode z0 = complex(0.588811, 1.29612) # r0,x0 values from linecode diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 10) + diag.imag * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line1"].impedance_matrix == imp_matrix c1 = complex(10.4308823411236, 0) # Value in Linecode c0 = complex(4.48501282215346, 0) # Value in Linecode c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 9) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 9) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line1"].capacitance_matrix == cap_matrix assert m["line1"].feeder_name == "sourcebus_src" assert m["line1"].is_recloser is None assert m["line1"].is_breaker is None for w in m["line1"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(310) assert w.emergency_ampacity == float(310) assert w.resistance is None assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 2 assert len(m["line2"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["line2"].wires]) == set(["C", "N"]) assert m["line2"].nameclass == "1P_#8CU_#8N" # Linecode is 1P_#8CU_#8N assert m["line2"].line_type == None assert m["line2"].from_element == "bus2" assert m["line2"].to_element == "bus3" assert m["line2"].length == 10 assert m["line2"].nominal_voltage == float(12.47) * 10**3 assert m["line2"].is_fuse is None assert m["line2"].is_switch is None assert m["line2"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex(2.15622, 0.539412) # r1,x1 values from linecode z0 = complex(2.5511, 1.78041) # r0,x0 values from linecode diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 9) + diag.imag * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 10) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line2"].impedance_matrix == imp_matrix c1 = complex(8.05740467479414, 0) # Value in Linecode c0 = complex(4.52209592389387, 0) # Value in Linecode c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 9) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 9) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line2"].capacitance_matrix == cap_matrix assert m["line2"].feeder_name == "sourcebus_src" assert m["line2"].is_recloser is None assert m["line2"].is_breaker is None for w in m["line2"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(1) assert w.emergency_ampacity == float(1) assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 3 assert len(m["line3"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line3"].wires]) == set(["A", "B", "C"]) assert (m["line3"].nameclass == "3P_3#500_AL_EPR_CD" ) # Linecode is 3P_3#500_AL_EPR_CD assert m["line3"].line_type == None assert m["line3"].from_element == "bus2" assert m["line3"].to_element == "bus4" assert m["line3"].length == 10 assert m["line3"].nominal_voltage == float(12.47) * 10**3 assert m["line3"].is_fuse is None assert m["line3"].is_switch is None assert m["line3"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex(0.072514, 0.001056) # r1,x1 values from linecode z0 = complex(0.140678, -0.043807) # r0,x0 values from linecode diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 11) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 11) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line3"].impedance_matrix == imp_matrix assert m["line3"].capacitance_matrix == [[0j, 0j, 0j], [0j, 0j, 0j], [0j, 0j, 0j]] assert m["line3"].feeder_name == "sourcebus_src" assert m["line3"].is_recloser is None assert m["line3"].is_breaker is None for w in m["line3"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(1110) assert w.emergency_ampacity == float(1110) assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 4 assert len(m["line4"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line4"].wires]) == set(["A", "B", "C"]) assert (m["line4"].nameclass == "3ph_h-397_acsr397_acsr397_acsr2/0_acsr" ) # Linecode is 3ph_h-397_acsr397_acsr397_acsr2/0_acsr assert m["line4"].line_type == None assert m["line4"].from_element == "bus4" assert m["line4"].to_element == "bus5" assert m["line4"].length == 10 assert m["line4"].nominal_voltage == float(12.47) * 10**3 assert m["line4"].is_fuse is None assert m["line4"].is_switch is None assert m["line4"].faultrate == parsed_values["Line"]["faultrate"] actual_impedance_matrix = [ [ (0.000270019 + 0.000695974j), (0.000109951 + 0.00033351j), (0.000113538 + 0.000308271j), ], [ (0.000109951 + 0.00033351j), (0.000264634 + 0.000708729j), (0.000110747 + 0.000350259j), ], [ (0.000113538 + 0.000308271j), (0.000110747 + 0.000350259j), (0.000271698 + 0.000692021j), ], ] assert m["line4"].impedance_matrix == actual_impedance_matrix assert m["line4"].capacitance_matrix == [ [(0.00913606 + 0j), (-0.00266777 + 0j), (-0.00217646 + 0j)], [(-0.00266777 + 0j), (0.00962226 + 0j), (-0.00315664 + 0j)], [(-0.00217646 + 0j), (-0.00315664 + 0j), (0.00943197 + 0j)], ] assert m["line4"].feeder_name == "sourcebus_src" assert m["line4"].is_recloser is None assert m["line4"].is_breaker is None for w in m["line4"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 5 assert len(m["line5"].wires) == 1 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line5"].wires]) == set(["B"]) assert (m["line5"].nameclass == "1ph-2_acsrxx4_acsr" ) # Linecode is 1ph-2_acsrxx4_acsr assert m["line5"].line_type == None assert m["line5"].from_element == "bus5" assert m["line5"].to_element == "bus6" assert m["line5"].length == 10 assert m["line5"].nominal_voltage == float(12.47) * 10**3 assert m["line5"].is_fuse is None assert m["line5"].is_switch is None assert m["line5"].faultrate == parsed_values["Line"]["faultrate"] actual_impedance_matrix = [[(0.00112339 + 0.000937794j)]] assert m["line5"].impedance_matrix == actual_impedance_matrix assert m["line5"].capacitance_matrix == [[(0.00649582 + 0j)]] assert m["line5"].feeder_name == "sourcebus_src" assert m["line5"].is_recloser is None assert m["line5"].is_breaker is None for w in m["line5"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 6 assert len(m["line6"].wires) == 2 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line6"].wires]) == set(["A", "C"]) assert (m["line6"].nameclass == "2ph_h-2_acsrx2_acsr2_acsr" ) # Linecode is 2ph_h-2_acsrx2_acsr2_acsr assert m["line6"].line_type == None assert m["line6"].from_element == "bus5" assert m["line6"].to_element == "bus7" assert m["line6"].length == 10 assert m["line6"].nominal_voltage == float(12.47) * 10**3 assert m["line6"].is_fuse is None assert m["line6"].is_switch is None assert m["line6"].faultrate == parsed_values["Line"]["faultrate"] actual_impedance_matrix = [ [(0.00113148 + 0.000884886j), (0.000142066 + 0.000366115j)], [(0.000142066 + 0.000366115j), (0.00113362 + 0.000882239j)], ] assert m["line6"].impedance_matrix == actual_impedance_matrix assert m["line6"].capacitance_matrix == [ [(0.00733718 + 0j), (-0.00239809 + 0j)], [(-0.00239809 + 0j), (0.00733718 + 0j)], ] assert m["line6"].feeder_name == "sourcebus_src" assert m["line6"].is_recloser is None assert m["line6"].is_breaker is None for w in m["line6"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.interrupting_rating is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 7 assert len(m["line7"].wires) == 2 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line7"].wires]) == set(["A", "B"]) assert m["line7"].nameclass == "750_Triplex" # Linecode is 750_Triplex assert m["line7"].line_type == None assert m["line7"].from_element == "bus5" assert m["line7"].to_element == "bus8" assert m["line7"].length == 10 assert m["line7"].nominal_voltage == float(12.47) * 10**3 assert m["line7"].is_fuse is None assert m["line7"].is_switch is None assert m["line7"].faultrate == parsed_values["Line"]["faultrate"] actual_impedance_matrix = [ [(0.000163213 + 9.128727e-05j), (7.684242e-05 + 2.19643e-05j)], [(7.684242e-05 + 2.19643e-05j), (0.000163213 + 9.128727e-05j)], ] # Converted from meters to kft assert m["line7"].impedance_matrix == actual_impedance_matrix assert m["line7"].capacitance_matrix == [ [(0.00984252 + 0j), (-0.007874016 + 0j)], [(-0.007874016 + 0j), (0.00984252 + 0j)], ] # Converted from meters to kft assert m["line7"].feeder_name == "sourcebus_src" assert m["line7"].is_recloser is None assert m["line7"].is_breaker is None for w in m["line7"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(580) assert w.emergency_ampacity == float(580 * 1.25) assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.interrupting_rating is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 8 assert len(m["line8"].wires) == 2 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line8"].wires]) == set(["B", "C"]) assert m["line8"].nameclass == "4/0Triplex" # Linecode is 4/0Triplex assert m["line8"].line_type == None assert m["line8"].from_element == "bus5" assert m["line8"].to_element == "bus9" assert m["line8"].length == 10 assert m["line8"].nominal_voltage == float(12.47) * 10**3 assert m["line8"].is_fuse is None assert m["line8"].is_switch is None assert m["line8"].faultrate == parsed_values["Line"]["faultrate"] actual_impedance_matrix = [ [(0.001344984 + 0.0005473038j), (0.0003874511 + 0.0004186106j)], [(0.0003874511 + 0.0004186106j), (0.001344984 + 0.0005473038j)], ] # Converted from meters to kft assert m["line8"].impedance_matrix == actual_impedance_matrix assert m["line8"].capacitance_matrix == [ [(0.00984252 + 0j), (-0.007874016 + 0j)], [(-0.007874016 + 0j), (0.00984252 + 0j)], ] # Converted from meters to kft assert m["line8"].feeder_name == "sourcebus_src" assert m["line8"].is_recloser is None assert m["line8"].is_breaker is None for w in m["line8"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(156) assert w.emergency_ampacity == float(156 * 1.25) assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 9 assert len(m["line9"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line9"].wires]) == set(["A", "B", "C"]) assert m["line9"].nameclass == "empty" # Linecode is empty assert m["line9"].line_type == None assert m["line9"].from_element == "bus4" assert m["line9"].to_element == "bus10" assert m["line9"].length == 10 assert m["line9"].nominal_voltage == float(12.47) * 10**3 assert m["line9"].is_fuse is None assert m["line9"].is_switch is None assert m["line9"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line9"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 10) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 10) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line9"].capacitance_matrix == cap_matrix assert m["line9"].feeder_name == "sourcebus_src" assert m["line9"].is_recloser is None assert m["line9"].is_breaker is None for w in m["line9"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 10 assert len(m["line10"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line10"].wires]) == set(["A", "B", "C"]) assert m["line10"].nameclass == "r1_only" # Linecode is r1_only assert m["line10"].line_type == None assert m["line10"].from_element == "bus10" assert m["line10"].to_element == "bus11" assert m["line10"].length == 10 assert m["line10"].nominal_voltage == float(12.47) * 10**3 assert m["line10"].is_fuse is None assert m["line10"].is_switch is None assert m["line10"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( 0.3489, parsed_values["Line"] ["X1"]) # r1 taken from linecode, x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 10) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line10"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 10) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 10) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line10"].capacitance_matrix == cap_matrix assert m["line10"].feeder_name == "sourcebus_src" assert m["line10"].is_recloser is None assert m["line10"].is_breaker is None for w in m["line10"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 11 assert len(m["line11"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line11"].wires]) == set(["A", "B", "C"]) assert m["line11"].nameclass == "r0_only" # Linecode is r0_only assert m["line11"].line_type == None assert m["line11"].from_element == "bus11" assert m["line11"].to_element == "bus12" assert m["line11"].length == 10 assert m["line11"].nominal_voltage == float(12.47) * 10**3 assert m["line11"].is_fuse is None assert m["line11"].is_switch is None assert m["line11"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex(0.588811, parsed_values["Line"] ["X0"]) # r0 taken from linecode,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 10) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line11"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 10) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 10) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line11"].capacitance_matrix == cap_matrix assert m["line11"].feeder_name == "sourcebus_src" assert m["line11"].is_recloser is None assert m["line11"].is_breaker is None for w in m["line11"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 12 assert len(m["line12"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line12"].wires]) == set(["A", "B", "C"]) assert m["line12"].nameclass == "x1_only" # Linecode is x1_only assert m["line12"].line_type == None assert m["line12"].from_element == "bus12" assert m["line12"].to_element == "bus13" assert m["line12"].length == 10 assert m["line12"].nominal_voltage == float(12.47) * 10**3 assert m["line12"].is_fuse is None assert m["line12"].is_switch is None assert m["line12"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], 0.426198) # r1 taken from default values, x1 taken from linecode z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line12"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 10) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 10) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line12"].capacitance_matrix == cap_matrix assert m["line12"].feeder_name == "sourcebus_src" assert m["line12"].is_recloser is None assert m["line12"].is_breaker is None for w in m["line12"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 13 assert len(m["line13"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line13"].wires]) == set(["A", "B", "C"]) assert m["line13"].nameclass == "x0_only" # Linecode is x0_only assert m["line13"].line_type == None assert m["line13"].from_element == "bus13" assert m["line13"].to_element == "bus14" assert m["line13"].length == 10 assert m["line13"].nominal_voltage == float(12.47) * 10**3 assert m["line13"].is_fuse is None assert m["line13"].is_switch is None assert m["line13"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], 1.29612) # r0 taken from default values, x0 taken from linecode diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line13"].impedance_matrix == imp_matrix assert m["line13"].capacitance_matrix == cap_matrix assert m["line13"].feeder_name == "sourcebus_src" assert m["line13"].is_recloser is None assert m["line13"].is_breaker is None for w in m["line13"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 14 assert len(m["line14"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line14"].wires]) == set(["A", "B", "C"]) assert m["line14"].nameclass == "c1_only" # Linecode is c1_only assert m["line14"].line_type == None assert m["line14"].from_element == "bus14" assert m["line14"].to_element == "bus15" assert m["line14"].length == 10 assert m["line14"].nominal_voltage == float(12.47) * 10**3 assert m["line14"].is_fuse is None assert m["line14"].is_switch is None assert m["line14"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line14"].impedance_matrix == imp_matrix c1 = complex(10.4308823411236, 0) # c1 taken from linecode c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 9) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 9) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line14"].capacitance_matrix == cap_matrix assert m["line14"].feeder_name == "sourcebus_src" assert m["line14"].is_recloser is None assert m["line14"].is_breaker is None for w in m["line14"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Line 15 assert len(m["line15"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["line15"].wires]) == set(["A", "B", "C"]) assert m["line15"].nameclass == "c0_only" # Linecode is c0_only assert m["line15"].line_type == None assert m["line15"].from_element == "bus15" assert m["line15"].to_element == "bus16" assert m["line15"].length == 10 assert m["line15"].nominal_voltage == float(12.47) * 10**3 assert m["line15"].is_fuse is None assert m["line15"].is_switch is None assert m["line15"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + round(rem.imag, 10) * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["line15"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(4.38501282215346, 0) # c0 taken from linecode c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 9) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 10) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["line15"].capacitance_matrix == cap_matrix assert m["line15"].feeder_name == "sourcebus_src" assert m["line15"].is_recloser is None assert m["line15"].is_breaker is None for w in m["line15"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None
def main(): ''' Conversion example of the IEEE 123 node system. Gridlab-D ---> OpenDSS example. This example uses the glm file located in tests/data/big_cases/gridlabd/ieee_123node ''' #Path settings (assuming it is run from examples folder) #Change this if you wish to use another system path = r'C:\Users\rjain\Desktop\BoxSync\NMG\ditto_ODO\ditto\tests\IEEE_13_nodes_origin' ################################# # STEP 1: READ FROM GRIDLAB-D # ################################# # #Create a Store object # print('>>> Creating empty model...') # model = Store() # # #Instanciate a GridLab-D Reader object # r = Reader_glab(input_file = os.path.join(path, 'The-1069-node-system.glm')) # # #Parse (can take some time for large systems...) # print('>>> Reading from Gridlab-D...') # start = time.time() #basic timer # r.parse(model) # end = time.time() # print('...Done (in {} seconds'.format(end-start)) # # ############################## # # STEP 2: WRITE TO OpenDSS # # ############################## # # # #Instanciate a Writer object # #w = Writer(output_path = './') # # #Write to OpenDSS (can also take some time for large systems...) # w = Writer_dss(output_path = './tests/IEEE_13_nodes_out/glab_out') # # print('>>> Writing to OpenDSS...') # start = time.time() #basic timer # w.write(model) # end = time.time() # print('...Done (in {} seconds'.format(end-start)) #Create a Store object print('>>> Creating empty model...') m = Store() #Instanciate a OpenDSS Reader object r_dss = Reader_dss( master_file='./tests/IEEE_13_nodes_out/glab_out/Master.dss', bus_coordinates_file='./IEEE_13_nodes_origin/ReducedModel/BusCoords.dss' ) print('>>> Reading from OpenDSS...') start = time.time() #basic timer r_dss.parse(m, verbose=True) end = time.time() print('...Done (in {} seconds'.format(end - start)) print('>>> Writing to ODO...') start = time.time() #basic timer baseMVA = 10 basekV = 13.8 odo_writer = Writer_odo(linecodes_flag=True, output_path='./IEEE_13_nodes_out', basekV=basekV, baseMVA=baseMVA) network = odo_writer.write(m, verbose=True) # network = odo_writer.write(model, verbose=True) end = time.time() #network['baseKV'] = 4.16 #network['baseMVA'] = 10.0 network['baseKV'] = basekV network['baseMVA'] = baseMVA network['per_unit'] = bool(1) network['multinetwork'] = bool(0) with open('network_glabd.json', 'w') as f: f.write( json_tricks.dumps(network, allow_nan=True, sort_keys=True, indent=4)) Modeldss = OpenDSS.OpenDSS() Modeldss.disable_forms( ) # Turns off the window dialog boxes for progress bars and errors # compile and solve the given model file Modeldss.compile( r'C:\Users\rjain\Desktop\BoxSync\NMG\ditto_ODO\ditto\tests\IEEE_13_nodes_origin\master.dss' ) #Modeldss.compile(r'C:\Users\rjain\Desktop\BoxSync\NMG\ditto_ODO\ditto\tests\IEEE_13_nodes_origin\ReducedModel\Master.DSS') Modeldss.solve() # Get the bus dictionary from OpenDSS_function busV = Modeldss.get_buses() ## Parsing the bus voltages into a usable format busV_dict = {} for bus in range(len(busV)): bus_id = busV[bus]["name"] nodes = busV[bus]["nodes"] voltages = busV[bus]["voltages"] puVmag = busV[bus]["puVmag"] busV_dict[bus_id] = {} temp_varr = [0, 0, 0] temp_thetaarr = [0, 0, 0] temp_vminarr = [-1, -1, -1] theta = [] # Calculate angles in radians as atan(Q/P) for elem in range(len(nodes)): theta.append(math.atan(voltages[2 * elem + 1] / voltages[2 * elem])) # Finalizing the respective vm, va, vmin values given the nodes present node_count = 0 for node in nodes: temp_thetaarr[node - 1] = theta[node_count] temp_varr[node - 1] = puVmag[node_count] temp_vminarr[node - 1] = 0.95 node_count += 1 busV_dict[bus_id]["nodes"] = nodes busV_dict[bus_id]["vmag"] = temp_varr busV_dict[bus_id]["vang"] = temp_thetaarr busV_dict[bus_id]["vmin"] = temp_vminarr for bus in network['bus'].keys(): temp_bus = network['bus'][bus]["name"] network['bus'][bus]["vm"] = busV_dict[temp_bus]["vmag"] network['bus'][bus]["va"] = busV_dict[temp_bus]["vang"] network['bus'][bus]["vmin"] = busV_dict[temp_bus]["vmin"] ## Getting the P, Q Solution circuit = Modeldss.engine.ActiveCircuit circuit.SetActiveElement("Vsource.SOURCE") PQsoln = circuit.ActiveElement.Powers PSoln = [ -1 * PQsoln[0] / (1000 * network['baseMVA']), -1 * PQsoln[2] / (1000 * network['baseMVA']), -1 * PQsoln[4] / (1000 * network['baseMVA']) ] QSoln = [ -1 * PQsoln[1] / (1000 * network['baseMVA']), -1 * PQsoln[3] / (1000 * network['baseMVA']), -1 * PQsoln[5] / (1000 * network['baseMVA']) ] for source in network['generator'].keys(): if network['generator'][source]["name"] == "Vsource.source": network['generator'][source]["pg"] = PSoln network['generator'][source]["qg"] = QSoln break with open('network_13bus.json', 'w') as f: f.write( json_tricks.dumps(network, allow_nan=True, sort_keys=True, indent=4)) with open('network_glabd.json', 'w') as f: f.write( json_tricks.dumps(network, allow_nan=True, sort_keys=True, indent=4)) print('...Done (in {} seconds'.format(end - start))
def test_capacitor_connectivity(): m = Store() r = Reader(master_file=os.path.join(current_directory, "test_capacitor_connectivity.dss")) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", )) parsed_values = d_v.parse() # Capacitor Cap1 should be a three phase capacitor (3 PhaseCapacitor objects) connected to bus1 assert len( m["cap1"].phase_capacitors) == 3 # Cap1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["cap1"].phase_capacitors ]) == pytest.approx(600 * 10**3, 0.0001) assert m["cap1"].name == "cap1" assert m["cap1"].nominal_voltage == float(4.16) * 10**3 assert m["cap1"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap1"].delay is None assert m["cap1"].mode is None assert m["cap1"].low is None assert m["cap1"].high is None assert m["cap1"].resistance == 0.0 assert m["cap1"].reactance == 0.0 assert m["cap1"].susceptance is None assert m["cap1"].conductance is None assert m["cap1"].pt_ratio is None assert m["cap1"].ct_ratio is None assert m["cap1"].pt_phase is None assert m["cap1"].connecting_element == "bus1" assert m["cap1"].measuring_element is None assert m["cap1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["cap1"].phase_capacitors]) == set(["A", "B", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["cap1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.sections for phase_capacitor in m["cap1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["cap1"].phase_capacitors ] == [None, None, None] # Capacitor Cap2 should be a one phase capacitor (1 PhaseCapacitor object) connected to bus2 on phase C assert len( m["cap2"].phase_capacitors) == 1 # Cap2 is a one phase capacitor assert m["cap2"].phase_capacitors[0].var == 100 * 10**3 assert m["cap2"].name == "cap2" assert m["cap2"].nominal_voltage == float(2.4) * 10**3 assert m["cap2"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap2"].delay is None assert m["cap2"].mode is None assert m["cap2"].low is None assert m["cap2"].high is None assert m["cap2"].resistance == 0.0 assert m["cap2"].reactance == 0.0 assert m["cap2"].susceptance is None assert m["cap2"].conductance is None assert m["cap2"].pt_ratio is None assert m["cap2"].ct_ratio is None assert m["cap2"].pt_phase is None assert m["cap2"].connecting_element == "bus2" assert m["cap2"].measuring_element is None assert m["cap2"].feeder_name == "sourcebus_src" assert m["cap2"].phase_capacitors[0].phase == "C" assert m["cap2"].phase_capacitors[0].switch == None assert m["cap2"].phase_capacitors[0].sections == None assert m["cap2"].phase_capacitors[0].normalsections == None # Capacitor Cap3 should be a one phase capacitor (1 PhaseCapacitor object) connected to bus3 on phase A assert len( m["cap3"].phase_capacitors) == 1 # Cap3 is a one phase capacitor assert m["cap3"].phase_capacitors[0].var == 200.37 * 10**3 assert m["cap3"].name == "cap3" assert m["cap3"].nominal_voltage == float(2.4) * 10**3 assert m["cap3"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap3"].delay is None assert m["cap3"].mode is None assert m["cap3"].low is None assert m["cap3"].high is None assert m["cap3"].resistance == 0.0 assert m["cap3"].reactance == 0.0 assert m["cap3"].susceptance is None assert m["cap3"].conductance is None assert m["cap3"].pt_ratio is None assert m["cap3"].ct_ratio is None assert m["cap3"].pt_phase is None assert m["cap3"].connecting_element == "bus3" assert m["cap3"].measuring_element is None assert m["cap3"].feeder_name == "sourcebus_src" assert m["cap3"].phase_capacitors[0].phase == "A" assert m["cap3"].phase_capacitors[0].switch == None assert m["cap3"].phase_capacitors[0].sections == None assert m["cap3"].phase_capacitors[0].normalsections == None # Capacitor Cap4 should be a two phase capacitor (2 PhaseCapacitor objects) connected to bus4 on phase A and C assert len( m["cap4"].phase_capacitors) == 2 # Cap4 is a two phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["cap4"].phase_capacitors ]) == pytest.approx(400 * 10**3, 0.0001) assert m["cap4"].name == "cap4" assert m["cap4"].nominal_voltage == float(2.4) * 10**3 assert m["cap4"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["cap4"].delay is None assert m["cap4"].mode is None assert m["cap4"].low is None assert m["cap4"].high is None assert m["cap4"].resistance == 0.0 assert m["cap4"].reactance == 0.0 assert m["cap4"].susceptance is None assert m["cap4"].conductance is None assert m["cap4"].pt_ratio is None assert m["cap4"].ct_ratio is None assert m["cap4"].pt_phase is None assert m["cap4"].connecting_element == "bus4" assert m["cap4"].measuring_element is None assert m["cap4"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["cap4"].phase_capacitors]) == set(["A", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["cap4"].phase_capacitors ] == [None, None] assert [ phase_capacitor.sections for phase_capacitor in m["cap4"].phase_capacitors ] == [None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["cap4"].phase_capacitors ] == [None, None] # Capacitors from epri_j1 assert len(m["b4909-1"].phase_capacitors ) == 3 # b4909-1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b4909-1"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["b4909-1"].name == "b4909-1" assert m["b4909-1"].nominal_voltage == float(12.47) * 10**3 assert m["b4909-1"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["b4909-1"].delay == 30 assert m["b4909-1"].mode == "voltage" assert m["b4909-1"].low == parsed_values["Capacitor"]["low"] assert m["b4909-1"].high == parsed_values["Capacitor"]["high"] assert m["b4909-1"].resistance == 0.0 assert m["b4909-1"].reactance == 0.0 assert m["b4909-1"].susceptance is None assert m["b4909-1"].conductance is None assert m["b4909-1"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b4909-1"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b4909-1"].pt_phase == "B" assert m["b4909-1"].connecting_element == "b4909" assert m["b4909-1"].measuring_element == "Line.OH_B4904" assert m["b4909-1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b4909-1"].phase_capacitors ]) == set(["A", "B", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["b4909-1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.sections for phase_capacitor in m["b4909-1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["b4909-1"].phase_capacitors ] == [None, None, None] assert len(m["b4909-2"].phase_capacitors ) == 3 # b4909-2 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b4909-2"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["b4909-2"].name == "b4909-2" assert m["b4909-2"].nominal_voltage == float(12.47) * 10**3 assert m["b4909-2"].connection_type == parsed_values["Capacitor"][ "connection_type"] assert m["b4909-2"].delay == 30 assert m["b4909-2"].mode == "voltage" assert m["b4909-2"].low == 120.5 assert m["b4909-2"].high == 125 assert m["b4909-2"].resistance == 0.0 assert m["b4909-2"].reactance == 0.0 assert m["b4909-2"].susceptance is None assert m["b4909-2"].conductance is None assert m["b4909-2"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b4909-2"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b4909-2"].pt_phase == "B" assert m["b4909-2"].connecting_element == "b4909" assert m["b4909-2"].measuring_element == "Line.OH_B4904" assert m["b4909-2"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b4909-2"].phase_capacitors ]) == set(["A", "B", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["b4909-2"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.sections for phase_capacitor in m["b4909-2"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["b4909-2"].phase_capacitors ] == [None, None, None] # oh_b4904 assert len(m["oh_b4904"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["oh_b4904"].wires]) == set(["A", "B", "C"]) assert m["oh_b4904"].name == "oh_b4904" assert (m["oh_b4904"].nameclass == "OH-3X_477AAC_4/0AAACN" ) # Linecode is OH-3X_477AAC_4/0AAACN assert m["oh_b4904"].line_type == "overhead" # OH in lincecode assert m["oh_b4904"].from_element == "b4909" assert m["oh_b4904"].to_element == "b4904" assert m["oh_b4904"].length == pytest.approx(161.84879) assert m["oh_b4904"].nominal_voltage == float(4.16) * 10**3 assert m["oh_b4904"].is_fuse is None assert m["oh_b4904"].is_switch is None assert m["oh_b4904"].faultrate == parsed_values["Line"]["faultrate"] assert m["oh_b4904"].impedance_matrix == [ [ (0.0001931617 + 0.0006880528j), (7.075159e-05 + 0.0002931119j), (7.075159e-05 + 0.0002931119j), ], [ (7.075159e-05 + 0.0002931119j), (0.0001931617 + 0.0006880528j), (7.075159e-05 + 0.0002931119j), ], [ (7.075159e-05 + 0.0002931119j), (7.075159e-05 + 0.0002931119j), (0.0001931617 + 0.0006880528j), ], ] assert m["oh_b4904"].capacitance_matrix == [ [(0.009067833 + 0j), (-0.002129467 + 0j), (-0.002129467 + 0j)], [(-0.002129467 + 0j), (0.009067833 + 0j), (-0.002129467 + 0j)], [(-0.002129467 + 0j), (-0.002129467 + 0j), (0.009067833 + 0j)], ] assert m["oh_b4904"].feeder_name == "sourcebus_src" assert m["oh_b4904"].is_recloser is None assert m["oh_b4904"].is_breaker is None for w in m["oh_b4904"].wires: assert w.nameclass == "4/0AAACN" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(732) assert w.emergency_ampacity == float(871) assert w.resistance is None assert w.insulation_thickness == 0.0 assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert (len(m["b18944-1"].phase_capacitors) == 3 ) # b18944-1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b18944-1"].phase_capacitors ]) == pytest.approx(1200 * 10**3, 0.0001) assert m["b18944-1"].name == "b18944-1" assert m["b18944-1"].nominal_voltage == float(12.47) * 10**3 assert (m["b18944-1"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["b18944-1"].delay == 31 assert m["b18944-1"].mode == "voltage" assert m["b18944-1"].low == parsed_values["Capacitor"]["low"] assert m["b18944-1"].high == parsed_values["Capacitor"]["high"] assert m["b18944-1"].resistance == 0.0 assert m["b18944-1"].reactance == 0.0 assert m["b18944-1"].susceptance is None assert m["b18944-1"].conductance is None assert m["b18944-1"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b18944-1"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b18944-1"].pt_phase == "A" assert m["b18944-1"].connecting_element == "b18941" assert m["b18944-1"].measuring_element == "Line.OH_B18944" assert m["b18944-1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b18944-1"].phase_capacitors ]) == set(["A", "B", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["b18944-1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.sections for phase_capacitor in m["b18944-1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["b18944-1"].phase_capacitors ] == [None, None, None] assert (len(m["b18944-2"].phase_capacitors) == 3 ) # b18944-2 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["b18944-2"].phase_capacitors ]) == pytest.approx(1200 * 10**3, 0.0001) assert m["b18944-2"].name == "b18944-2" assert m["b18944-2"].nominal_voltage == float(12.47) * 10**3 assert (m["b18944-2"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["b18944-2"].delay == 31 assert m["b18944-2"].mode == "voltage" assert m["b18944-2"].low == 118 assert m["b18944-2"].high == 124 assert m["b18944-2"].resistance == 0.0 assert m["b18944-2"].reactance == 0.0 assert m["b18944-2"].susceptance is None assert m["b18944-2"].conductance is None assert m["b18944-2"].pt_ratio == parsed_values["Capacitor"]["pt_ratio"] assert m["b18944-2"].ct_ratio == parsed_values["Capacitor"]["ct_ratio"] assert m["b18944-2"].pt_phase == "A" assert m["b18944-2"].connecting_element == "b18941" assert m["b18944-2"].measuring_element == "Line.OH_B18944" assert m["b18944-2"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["b18944-2"].phase_capacitors ]) == set(["A", "B", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["b18944-2"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.sections for phase_capacitor in m["b18944-2"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["b18944-2"].phase_capacitors ] == [None, None, None] # oh_b18944 assert len(m["oh_b18944"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["oh_b18944"].wires]) == set(["A", "B", "C"]) assert m["oh_b18944"].name == "oh_b18944" assert m[ "oh_b18944"].nameclass == "OH-3X_4CU_4CUN" # Linecode is OH-3X_4CU_4CUN assert m["oh_b18944"].line_type == "overhead" # OH in lincecode assert m["oh_b18944"].from_element == "b18941" assert m["oh_b18944"].to_element == "b18944" assert m["oh_b18944"].length == pytest.approx(141.1224) assert m["oh_b18944"].nominal_voltage == float(4.16) * 10**3 assert m["oh_b18944"].is_fuse is None assert m["oh_b18944"].is_switch is None assert m["oh_b18944"].faultrate == parsed_values["Line"]["faultrate"] assert m["oh_b18944"].impedance_matrix == [ [ (0.0009792434 + 0.0008488938j), (0.0001254797 + 0.0003540439j), (0.0001254797 + 0.0003540439j), ], [ (0.0001254797 + 0.0003540439j), (0.0009792434 + 0.0008488938j), (0.0001254797 + 0.0003540439j), ], [ (0.0001254797 + 0.0003540439j), (0.0001254797 + 0.0003540439j), (0.0009792434 + 0.0008488938j), ], ] assert m["oh_b18944"].capacitance_matrix == [ [(0.007276067 + 0j), (-0.001514233 + 0j), (-0.001514233 + 0j)], [(-0.001514233 + 0j), (0.007276067 + 0j), (-0.001514233 + 0j)], [(-0.001514233 + 0j), (-0.001514233 + 0j), (0.007276067 + 0j)], ] assert m["oh_b18944"].feeder_name == "sourcebus_src" assert m["oh_b18944"].is_recloser is None assert m["oh_b18944"].is_breaker is None for w in m["oh_b18944"].wires: assert w.nameclass == "4CUN" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == float(142) assert w.emergency_ampacity == float(142) assert w.resistance is None assert w.insulation_thickness == 0.0 assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None # Capacitors from ieee 8500-node test feeder assert (len(m["capbank0a"].phase_capacitors) == 1 ) # capbank0a is a single phase capacitor assert m["capbank0a"].phase_capacitors[0].var == 400 * 10**3 assert m["capbank0a"].name == "capbank0a" assert m["capbank0a"].nominal_voltage == float(7.2) * 10**3 assert (m["capbank0a"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank0a"].delay == None assert m["capbank0a"].mode == None assert m["capbank0a"].low is None assert m["capbank0a"].high is None assert m["capbank0a"].resistance == 0.0 assert m["capbank0a"].reactance == 0.0 assert m["capbank0a"].susceptance is None assert m["capbank0a"].conductance is None assert m["capbank0a"].pt_ratio == None assert m["capbank0a"].ct_ratio is None assert m["capbank0a"].pt_phase == None assert m["capbank0a"].connecting_element == "r42246" assert m["capbank0a"].measuring_element == None assert m["capbank0a"].feeder_name == "sourcebus_src" assert m["capbank0a"].phase_capacitors[0].phase == "A" assert m["capbank0a"].phase_capacitors[0].switch == None assert m["capbank0a"].phase_capacitors[0].sections == None assert m["capbank0a"].phase_capacitors[0].normalsections == None assert (len(m["capbank0b"].phase_capacitors) == 1 ) # capbank0b is a single phase capacitor assert m["capbank0b"].phase_capacitors[0].var == 400 * 10**3 assert m["capbank0b"].name == "capbank0b" assert m["capbank0b"].nominal_voltage == float(7.2) * 10**3 assert (m["capbank0b"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank0b"].delay == None assert m["capbank0b"].mode == None assert m["capbank0b"].low is None assert m["capbank0b"].high is None assert m["capbank0b"].resistance == 0.0 assert m["capbank0b"].reactance == 0.0 assert m["capbank0b"].susceptance is None assert m["capbank0b"].conductance is None assert m["capbank0b"].pt_ratio == None assert m["capbank0b"].ct_ratio is None assert m["capbank0b"].pt_phase == None assert m["capbank0b"].connecting_element == "r42246" assert m["capbank0b"].measuring_element == None assert m["capbank0b"].feeder_name == "sourcebus_src" assert m["capbank0b"].phase_capacitors[0].phase == "B" assert m["capbank0b"].phase_capacitors[0].switch == None assert m["capbank0b"].phase_capacitors[0].sections == None assert m["capbank0b"].phase_capacitors[0].normalsections == None assert (len(m["capbank0c"].phase_capacitors) == 1 ) # capbank0c is a single phase capacitor assert m["capbank0c"].phase_capacitors[0].var == 400 * 10**3 assert m["capbank0c"].name == "capbank0c" assert m["capbank0c"].nominal_voltage == float(7.2) * 10**3 assert (m["capbank0c"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank0c"].delay == None assert m["capbank0c"].mode == None assert m["capbank0c"].low is None assert m["capbank0c"].high is None assert m["capbank0c"].resistance == 0.0 assert m["capbank0c"].reactance == 0.0 assert m["capbank0c"].susceptance is None assert m["capbank0c"].conductance is None assert m["capbank0c"].pt_ratio == None assert m["capbank0c"].ct_ratio is None assert m["capbank0c"].pt_phase == None assert m["capbank0c"].connecting_element == "r42246" assert m["capbank0c"].measuring_element == None assert m["capbank0c"].feeder_name == "sourcebus_src" assert m["capbank0c"].phase_capacitors[0].phase == "C" assert m["capbank0c"].phase_capacitors[0].switch == None assert m["capbank0c"].phase_capacitors[0].sections == None assert m["capbank0c"].phase_capacitors[0].normalsections == None # This is a 3-phase capacitor bank assert (len(m["capbank3"].phase_capacitors) == 3 ) # capbank3 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["capbank3"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["capbank3"].name == "capbank3" assert m["capbank3"].nominal_voltage == float(12.47112) * 10**3 assert (m["capbank3"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank3"].delay == None assert m["capbank3"].mode == None assert m["capbank3"].low is None assert m["capbank3"].high is None assert m["capbank3"].resistance == 0.0 assert m["capbank3"].reactance == 0.0 assert m["capbank3"].susceptance is None assert m["capbank3"].conductance is None assert m["capbank3"].pt_ratio == None assert m["capbank3"].ct_ratio is None assert m["capbank3"].pt_phase == None assert m["capbank3"].connecting_element == "r18242" assert m["capbank3"].measuring_element == None assert m["capbank3"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["capbank3"].phase_capacitors ]) == set(["A", "B", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["capbank3"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.sections for phase_capacitor in m["capbank3"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["capbank3"].phase_capacitors ] == [None, None, None] # 3-phase capacitor with number of phases mentioned assert (len(m["capbank3-1"].phase_capacitors) == 3 ) # capbank3-1 is a three phase capacitor assert sum([ phase_capacitor.var for phase_capacitor in m["capbank3-1"].phase_capacitors ]) == pytest.approx(900 * 10**3, 0.0001) assert m["capbank3-1"].nominal_voltage == float(12.47112) * 10**3 assert m["capbank3-1"].name == "capbank3-1" assert (m["capbank3-1"].connection_type == parsed_values["Capacitor"] ["connection_type"]) assert m["capbank3-1"].delay == None assert m["capbank3-1"].mode == None assert m["capbank3-1"].low is None assert m["capbank3-1"].high is None assert m["capbank3-1"].resistance == 0.0 assert m["capbank3-1"].reactance == 0.0 assert m["capbank3-1"].susceptance is None assert m["capbank3-1"].conductance is None assert m["capbank3-1"].pt_ratio == None assert m["capbank3-1"].ct_ratio is None assert m["capbank3-1"].pt_phase == None assert m["capbank3-1"].connecting_element == "r18242" assert m["capbank3-1"].measuring_element == None assert m["capbank3-1"].feeder_name == "sourcebus_src" assert set([pc.phase for pc in m["capbank3-1"].phase_capacitors ]) == set(["A", "B", "C"]) assert [ phase_capacitor.switch for phase_capacitor in m["capbank3-1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.sections for phase_capacitor in m["capbank3-1"].phase_capacitors ] == [None, None, None] assert [ phase_capacitor.normalsections for phase_capacitor in m["capbank3-1"].phase_capacitors ] == [None, None, None]
logger = logging.getLogger(__name__) test_list = os.walk('data') for (dirpath, dirname, files) in test_list: if files != []: reader_type = dirpath.split('\\')[2] m = Store() if reader_type == 'opendss': reader = Reader_opendss( master_file=os.path.join('..', dirpath, 'master.dss'), buscoordinates_file=os.path.join('..', dirpath, 'buscoord.dss')) elif reader_type == 'cyme': reader = Reader_cyme(data_folder_path=os.path.join('..', dirpath)) else: #Update with other tests if they get added to the persistence tests continue reader.parse(m) m.set_names() output_path = tempfile.TemporaryDirectory() w = Writer(output_path=output_path.name, log_path=output_path) w.write(m) original = json_tricks.load(open(os.path.join(dirpath, files[0]), 'r')) update = json_tricks.load( open(os.path.join(output_path.name, 'Model.json'), 'r')) try: assert update["model"] == original["model"] except AssertionError as e: logger.error("Model differs for usecase {loc}".format(loc=dirpath)) e.args += ("Model differs for usecase {loc}".format(loc=dirpath), ) raise
def test_switches(): from ditto.store import Store from ditto.readers.opendss.read import Reader from ditto.default_values.default_values_json import Default_Values m = Store() r = Reader( master_file=os.path.join(current_directory, "test_switches.dss")) r.parse(m) m.set_names() # Reading OpenDSS default values d_v = Default_Values( os.path.join( current_directory, "../../../../ditto/default_values/opendss_default_values.json", )) parsed_values = d_v.parse() assert len(m["origin"].wires) == 3 # Phases of the different wires assert set([w.phase for w in m["origin"].wires]) == set(["A", "B", "C"]) assert m["origin"].name == "origin" assert m["origin"].nominal_voltage == float(12.47) * 10**3 assert m["origin"].line_type is None assert m["origin"].length == 0.001 * 1000 # units = km assert m["origin"].from_element == "sourcebus" assert m["origin"].to_element == "node1" assert m["origin"].is_fuse is None assert m["origin"].is_switch is None assert m["origin"].faultrate == parsed_values["Line"]["faultrate"] z1 = complex( parsed_values["Line"]["R1"], parsed_values["Line"]["X1"]) # r1,x1 taken from default values z0 = complex( parsed_values["Line"]["R0"], parsed_values["Line"]["X0"]) # r0,x0 taken from default values diag = ((2 * z1 + z0) / 3) * 0.001 # Units = km diag = round(diag.real, 11) + round(diag.imag, 10) * 1j rem = ((z0 - z1) / 3) * 0.001 # Units = km rem = round(rem.real, 11) + rem.imag * 1j imp_matrix = np.zeros((3, 3), dtype=np.complex_) imp_matrix.fill(rem) np.fill_diagonal(imp_matrix, diag) imp_matrix = imp_matrix.tolist() assert m["origin"].impedance_matrix == imp_matrix c1 = complex(parsed_values["Line"]["C1"], 0) # c1 taken from default values c0 = complex(parsed_values["Line"]["C0"], 0) # c0 taken from default values c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 10) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = round(c_rem.real, 10) + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() assert m["origin"].capacitance_matrix == cap_matrix assert m["origin"].feeder_name == "sourcebus_src" assert m["origin"].is_recloser is None assert m["origin"].is_breaker is None assert m["origin"].nameclass == "" for w in m["origin"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == parsed_values["Wire"]["ampacity"] assert w.emergency_ampacity == parsed_values["Wire"][ "emergency_ampacity"] assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open is None assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch1"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["switch1"].wires]) == set(["A", "B", "C"]) assert m["switch1"].name == "switch1" assert m["switch1"].nominal_voltage == float(12.47) * 10**3 assert m["switch1"].line_type is None assert m["switch1"].length == 0.001 * 1000 assert m["switch1"].from_element == "node1" assert m["switch1"].to_element == "node2" assert m["switch1"].is_fuse is None assert m["switch1"].is_switch == 1 assert m["switch1"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch1"].impedance_matrix == [ [(0.001 + 0.001j), 0j, 0j], [0j, (0.001 + 0.001j), 0j], [0j, 0j, (0.001 + 0.001j)], ] c1 = complex(1.1, 0) c0 = complex(1, 0) c_diag = ((2 * c1 + c0) / 3) * 0.001 # Units = km c_diag = round(c_diag.real, 9) + c_diag.imag * 1j c_rem = ((c0 - c1) / 3) * 0.001 # Units = km c_rem = c_rem.real + c_rem.imag * 1j cap_matrix = np.zeros((3, 3), dtype=np.complex_) cap_matrix.fill(c_rem) np.fill_diagonal(cap_matrix, c_diag) cap_matrix = cap_matrix.tolist() np.testing.assert_array_almost_equal(m["switch1"].capacitance_matrix, cap_matrix) assert m["switch1"].feeder_name == "sourcebus_src" assert m["switch1"].is_recloser is None assert m["switch1"].is_breaker is None assert m["switch1"].nameclass == "switch1" for w in m["switch1"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open == 0 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch2"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["switch2"].wires]) == set(["A", "B", "C"]) assert m["switch2"].name == "switch2" assert m["switch2"].nominal_voltage == float(12.47) * 10**3 assert m["switch2"].line_type is None assert m["switch2"].length == 0.001 * 1000 assert m["switch2"].from_element == "node1" assert m["switch2"].to_element == "node3" assert m["switch2"].is_fuse is None assert m["switch2"].is_switch == 1 assert m["switch2"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch2"].impedance_matrix == [ [(0.001 + 0.001j), 0j, 0j], [0j, (0.001 + 0.001j), 0j], [0j, 0j, (0.001 + 0.001j)], ] assert m["switch2"].capacitance_matrix == [ [ (0.001066667 + 0j), (-3.3333330000000004e-05 + 0j), (-3.3333330000000004e-05 + 0j), ], [ (-3.3333330000000004e-05 + 0j), (0.001066667 + 0j), (-3.3333330000000004e-05 + 0j), ], [ (-3.3333330000000004e-05 + 0j), (-3.3333330000000004e-05 + 0j), (0.001066667 + 0j), ], ] assert m["switch2"].feeder_name == "sourcebus_src" assert m["switch2"].is_recloser is None assert m["switch2"].is_breaker is None assert m["switch2"].nameclass == "switch2" for w in m["switch2"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open == 1 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch3"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["switch3"].wires]) == set(["A", "B", "C"]) assert m["switch3"].name == "switch3" assert m["switch3"].nominal_voltage == float(12.47) * 10**3 assert m["switch3"].line_type is None assert m["switch3"].length == 0.001 * 1000 assert m["switch3"].from_element == "node1" assert m["switch3"].to_element == "node4" assert m["switch3"].is_fuse is None assert m["switch3"].is_switch == 1 assert m["switch3"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch3"].impedance_matrix == [ [(0.001 + 0.001j), 0j, 0j], [0j, (0.001 + 0.001j), 0j], [0j, 0j, (0.001 + 0.001j)], ] assert m["switch3"].capacitance_matrix == [ [ (0.001066667 + 0j), (-3.3333330000000004e-05 + 0j), (-3.3333330000000004e-05 + 0j), ], [ (-3.3333330000000004e-05 + 0j), (0.001066667 + 0j), (-3.3333330000000004e-05 + 0j), ], [ (-3.3333330000000004e-05 + 0j), (-3.3333330000000004e-05 + 0j), (0.001066667 + 0j), ], ] assert m["switch3"].feeder_name == "sourcebus_src" assert m["switch3"].is_recloser is None assert m["switch3"].is_breaker is None assert m["switch3"].nameclass == "switch3" for w in m["switch3"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open == 1 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch4"].wires) == 3 # Number of wires # Phases of the different wires assert set([w.phase for w in m["switch4"].wires]) == set(["A", "B", "C"]) assert m["switch4"].name == "switch4" assert m["switch4"].nominal_voltage == float(12.47) * 10**3 assert m["switch4"].line_type is None assert m["switch4"].length == 0.001 * 1000 assert m["switch4"].from_element == "node1" assert m["switch4"].to_element == "node5" assert m["switch4"].is_fuse is None assert m["switch4"].is_switch == 1 assert m["switch4"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch4"].impedance_matrix == [ [(0.001 + 0.001j), 0j, 0j], [0j, (0.001 + 0.001j), 0j], [0j, 0j, (0.001 + 0.001j)], ] assert m["switch4"].capacitance_matrix == [ [ (0.001066667 + 0j), (-3.3333330000000004e-05 + 0j), (-3.3333330000000004e-05 + 0j), ], [ (-3.3333330000000004e-05 + 0j), (0.001066667 + 0j), (-3.3333330000000004e-05 + 0j), ], [ (-3.3333330000000004e-05 + 0j), (-3.3333330000000004e-05 + 0j), (0.001066667 + 0j), ], ] assert m["switch4"].feeder_name == "sourcebus_src" assert m["switch4"].is_recloser is None assert m["switch4"].is_breaker is None assert m["switch4"].nameclass == "switch4" for w in m["switch4"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open == 0 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch5"].wires) == 1 # Phases of the different wires assert m["switch5"].wires[0].phase == "A" assert m["switch5"].name == "switch5" assert m["switch5"].nominal_voltage == float(12.47) * 10**3 assert m["switch5"].line_type is None assert m["switch5"].length == 0.001 * 1000 assert m["switch5"].from_element == "node1" assert m["switch5"].to_element == "node6" assert m["switch5"].is_fuse is None assert m["switch5"].is_switch == 1 assert m["switch5"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch5"].impedance_matrix == [[(0.001 + 0.001j)]] assert m["switch5"].capacitance_matrix == [[(0.0011 + 0j)]] assert m["switch5"].feeder_name == "sourcebus_src" assert m["switch5"].is_recloser is None assert m["switch5"].is_breaker is None assert m["switch5"].nameclass == "switch5" for w in m["switch5"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open == 0 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch6"].wires) == 1 # Phases of the different wires assert m["switch6"].wires[0].phase == "C" assert m["switch6"].name == "switch6" assert m["switch6"].nominal_voltage == float(12.47) * 10**3 assert m["switch6"].line_type is None assert m["switch6"].length == 0.001 * 1000 assert m["switch6"].from_element == "node1" assert m["switch6"].to_element == "node7" assert m["switch6"].is_fuse is None assert m["switch6"].is_switch == 1 assert m["switch6"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch6"].impedance_matrix == [[(0.001 + 0.001j)]] assert m["switch6"].capacitance_matrix == [[(0.0011 + 0j)]] assert m["switch6"].feeder_name == "sourcebus_src" assert m["switch6"].is_recloser is None assert m["switch6"].is_breaker is None assert m["switch6"].nameclass == "switch6" for w in m["switch6"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.is_open == 1 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch7"].wires) == 2 # Phases of the different wires assert set([w.phase for w in m["switch7"].wires]) == set(["B", "C"]) assert m["switch7"].name == "switch7" assert m["switch7"].nominal_voltage == float(12.47) * 10**3 assert m["switch7"].line_type is None assert m["switch7"].length == 0.001 * 1000 assert m["switch7"].from_element == "node1" assert m["switch7"].to_element == "node8" assert m["switch7"].is_fuse is None assert m["switch7"].is_switch == 1 assert m["switch7"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch7"].impedance_matrix == [ [(0.001 + 0.001j), 0j], [0j, (0.001 + 0.001j)], ] assert m["switch7"].capacitance_matrix == [ [(0.001066667 + 0j), (-3.3333330000000004e-05 + 0j)], [(-3.3333330000000004e-05 + 0j), (0.001066667 + 0j)], ] assert m["switch7"].feeder_name == "sourcebus_src" assert m["switch7"].is_recloser is None assert m["switch7"].is_breaker is None assert m["switch7"].nameclass == "switch7" for w in m["switch7"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.insulation_thickness == parsed_values["Wire"][ "insulation_thickness"] assert w.is_open == 1 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None assert len(m["switch8"].wires) == 2 # Phases of the different wires assert set(w.phase for w in m["switch8"].wires) == set(["A", "B"]) assert m["switch8"].name == "switch8" assert m["switch8"].nominal_voltage == float(12.47) * 10**3 assert m["switch8"].line_type is None assert m["switch8"].length == 0.001 * 1000 assert m["switch8"].from_element == "node1" assert m["switch8"].to_element == "node9" assert m["switch8"].is_fuse is None assert m["switch8"].is_switch == 1 assert m["switch8"].faultrate == parsed_values["Line"]["faultrate"] assert m["switch8"].impedance_matrix == [ [(0.001 + 0.001j), 0j], [0j, (0.001 + 0.001j)], ] assert m["switch8"].capacitance_matrix == [ [(0.001066667 + 0j), (-3.3333330000000004e-05 + 0j)], [(-3.3333330000000004e-05 + 0j), (0.001066667 + 0j)], ] assert m["switch8"].feeder_name == "sourcebus_src" assert m["switch8"].is_recloser is None assert m["switch8"].is_breaker is None assert m["switch8"].nameclass == "switch8" for w in m["switch8"].wires: assert w.nameclass == "" assert w.X is None assert w.Y is None assert w.diameter is None assert w.gmr is None assert w.ampacity == 3000 assert w.emergency_ampacity == 4000 assert w.resistance is None assert w.is_open == 0 assert w.concentric_neutral_gmr is None assert w.concentric_neutral_resistance is None assert w.concentric_neutral_diameter is None assert w.concentric_neutral_outside_diameter is None assert w.concentric_neutral_nstrand is None
Tests: + Check if the system has any loops (once open switches are removed) + Check if there is a path from each load to the head node + Check that the phases on the high and low side of the transformer match + Check if there's a unique path from load to the source (transformer_phase_path does all of these): + Check that only zero or one transformers are on the path to the head node (excluding regulators) + Check that the number of phases increases from the transformer to the substation + Check that the number of phases increases from a three phase load to the substation + Check that the number of phases is the same from the load to the transformer """ model = Store() r = Reader(master_file = test_system_master,buscoords_file = test_system_coords) r.parse(model) for i in model.models: if isinstance(i,PowerTransformer): i.is_substation = True #Only for 13 node system. Need to fix in readers print('Pass loops check:',flush=True) loops_res = check_loops(model,verbose=True) print(loops_res) print() print('Pass loads connected check:',flush=True) loads_connected_res = check_loads_connected(model,verbose=True) print(loads_connected_res) print()