示例#1
0
def test_solve_gams(config):
    from dispaset.misc.gdx_handler import get_gams_path
    r = ds.solve_GAMS(config['SimulationDirectory'], get_gams_path())

    assert r
示例#2
0
# Import Dispa-SET
import dispaset as ds

# Load the configuration file
config = ds.load_config_excel('../ConfigFiles/ConfigEU.xlsx')

# Limit the simulation period (for testing purposes, comment the line to run the whole year)
config['StartDate'] = (2016, 1, 1, 0, 0, 0)
config['StopDate'] = (2016, 1, 7, 0, 0, 0)

# Build the simulation environment:
SimData = ds.build_simulation(config)

# Solve using GAMS:
_ = ds.solve_GAMS(config['SimulationDirectory'], config['GAMS_folder'])

# Load the simulation results:
inputs, results = ds.get_sim_results(config['SimulationDirectory'],
                                     cache=False)

# Generate country-specific plots
ds.plot_country(inputs, results)

# Bar plot with the installed capacities in all countries:
cap = ds.plot_country_capacities(inputs)

# Bar plot with the energy balances in all countries:
ds.plot_energy_country_fuel(inputs, results,
                            ds.get_indicators_powerplant(inputs, results))
                                 value=load_max * cap * (1 - flex))
    SimData = ds.adjust_storage(SimData, ('HPHS', 'WAT'),
                                value=hours * load_max)
    # For wind and PV, the units should be lumped into a single unit:
    SimData = ds.adjust_capacity(SimData, ('WTON', 'WIN'),
                                 value=load_max * cap * wind / CF_wton,
                                 singleunit=True)
    # In this last iteration, the new gdx file is written to the simulation folder:
    SimData = ds.adjust_capacity(SimData, ('PHOT', 'SUN'),
                                 value=load_max * cap * pv / CF_pv,
                                 singleunit=True,
                                 write_gdx=True,
                                 dest_path=folder)

    # Finally the modified simulation environment is simulated:
    r = ds.solve_GAMS(folder, config['GAMS_folder'])

#%%
# Read all the simulation folders one by one and store key results in dataframe:
paths = os.listdir(sim_folder)
# Only take into account the ones for which a valid dispa-set result file is present
paths_ok = [
    x for x in paths if os.path.isfile(sim_folder + x + '/Results.gdx')
]

N = len(paths_ok)
data = pd.DataFrame(index=range(N))

for i, path in enumerate(paths_ok):

    inputs, results = ds.get_sim_results(path=sim_folder + path, cache=True)