def test_cyme_to_ephasor(): ''' Test the Cyme to Ephasor conversion. ''' from ditto.store import Store from ditto.readers.cyme.read import Reader from ditto.writers.ephasor.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) #TODO: Log properly print('>Cyme 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 Ephasor.\n')
def test_cyme_to_opendss(): ''' Test the Cyme to OpenDSS conversion. ''' list_of_directories = [] from ditto.store import Store from ditto.readers.cyme.read import Reader from ditto.writers.opendss.write import Writer import opendssdirect as dss 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: print(model) m = Store() r = Reader(data_folder_path=os.path.join( current_directory, 'data/small_cases/cyme', model)) r.parse(m) #TODO: Log properly # print('>Cyme model {model} read...'.format(model=model)) output_path = tempfile.TemporaryDirectory() list_of_directories.append(output_path) w = Writer(output_path=output_path.name) w.write(m) #TODO: Log properly # print('>...and written to OpenDSS.\n') print(model) dss.run_command("clear")
def test_transformer_connection_mapping(cyme_value, winding, expected): reader = Reader() actual = reader.transformer_connection_configuration_mapping( cyme_value, winding) assert actual == expected # Function also takes strings actual = reader.transformer_connection_configuration_mapping( str(cyme_value), winding) assert actual == expected
def main(): ''' Conversion example of the IEEE 123 node system. CYME ---> OpenDSS example. This example uses the glm file located in tests/data/big_cases/cyme/ieee_123node ''' #Path settings (assuming it is run from examples folder) #Change this if you wish to use another system path = '../tests/data/big_cases/cyme/ieee_123node' ############################ # STEP 1: READ FROM CYME # ############################ # #Create a Store object print('>>> Creating empty model...') model = Store() #Instanciate a Reader object r = Reader(data_folder_path=path) #Parse (can take some time for large systems...) print('>>> Reading from CYME...') 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...) print('>>> Writing to OpenDSS...') start = time.time() #basic timer w.write(model) end = time.time() print('...Done (in {} seconds'.format(end - start))
def test_phase_mapping(cyme_value, expected): reader = Reader() actual = reader.phase_mapping(cyme_value) assert actual == expected
def test_cap_connection_mapping_invalid_type(): reader = Reader() with pytest.raises(ValueError): reader.capacitors_connection_mapping(0.0)
def test_cap_connection_mapping(cyme_value, expected): reader = Reader() actual = reader.capacitors_connection_mapping(cyme_value) assert actual == expected
def test_load_value_mapping_amp_pf_not_impl(load_type): reader = Reader() with pytest.raises(NotImplementedError): reader.load_value_type_mapping(load_type, 100, 0.9)
def test_load_value_mapping_invalid_value(v1, v2): reader = Reader() with pytest.raises(ValueError): reader.load_value_type_mapping(0, v1, v2)
def test_load_value_mapping_invalid_type(): reader = Reader() with pytest.raises(ValueError): reader.load_value_type_mapping(0.0, 100, 10)
def test_load_value_mapping(load_type, v1, v2, expected): reader = Reader() actual = reader.load_value_type_mapping(load_type, v1, v2) assert actual == expected
def test_transformer_connection_mapping_invalid_winding(): reader = Reader() with pytest.raises(ValueError): reader.transformer_connection_configuration_mapping(0.0, 2)
def test_unmapped_inputs_to_connection_configuration_mapping(value): with pytest.raises(NotImplementedError): Reader().connection_configuration_mapping(value)
def test_connection_configuration_mapping(value, expected_configuration): configuration = Reader().connection_configuration_mapping(value) assert configuration == expected_configuration
def test_breakers(): """ Tests the breakers parsing. """ from ditto.readers.cyme.read import Reader from ditto.store import Store from ditto.models.line import Line m = Store() r = Reader(data_folder_path=os.path.join( current_directory, "data", "ditto-validation", "cyme", "breakers")) r.parse(m) for obj in m.models: if isinstance(obj, Line): # Section A is ABC and the breaker is closed on ABC if obj.name == "a": # The line should be a breaker... assert obj.is_breaker # ...and it should have 4 wires: A, B, C, and N assert len(obj.wires) == 4 for wire in obj.wires: # All wires should be flaged as breaker assert wire.is_breaker # All wires should be closed assert not wire.is_open # The breaker ampacity should be 100 amps for all wires assert wire.ampacity == 100.0 # The breaker limit should be 600 amps for all wires assert wire.interrupting_rating == 600.0 # Section B is AC and the breaker is closed on C only elif obj.name == "b": # The line should be a breaker... assert obj.is_breaker # ...and it should have 3 wires: A, C, and N assert len(obj.wires) == 3 for wire in obj.wires: # Check phase is valid assert wire.phase in ["A", "C", "N"] # All wires should be flaged as a breaker assert wire.is_breaker # Wires C and N should be closed if wire.phase in ["C", "N"]: assert not wire.is_open # And should be open on phase A else: assert wire.is_open # The breaker ampacity should be 300 amps for all wires assert wire.ampacity == 300.0 # The breaker limit should be 800 amps for all wires assert wire.interrupting_rating == 800.0 else: raise ValueError( "Unknown line name {name}".format(name=obj.name))