示例#1
0
def run_scenario(scenario):
    # scenario name
    sce = scenario.__name__
    sce_nice_name = sce.replace('_', ' ').title()

    # prepare input data
    data = rivus.read_excel(data_spreadsheet)
    vertex = pdshp.read_shp(vertex_shapefile)
    edge = prepare_edge(edge_shapefile, building_shapefile)

    # apply scenario function to input data
    data, vertex, edge = scenario(data, vertex, edge)

    # create & solve model
    model = rivus.create_model(data, vertex, edge)
    prob = model.create()
    optim = SolverFactory('gurobi')
    optim = setup_solver(optim)
    result = optim.solve(prob, tee=True)
    prob.load(result)

    # create result directory if not existent
    result_dir = os.path.join('result', os.path.basename(base_directory))
    if not os.path.exists(result_dir):
        os.makedirs(result_dir)

    # report
    rivus.report(prob, os.path.join(result_dir, 'report.xlsx'))

    # plots
    for com, plot_type in [('Elec', 'caps'), ('Heat', 'caps'), ('Gas', 'caps'),
                           ('Elec', 'peak'), ('Heat', 'peak')]:

        # two plot variants
        for plot_annotations in [False, True]:
            # create plot
            fig = rivus.plot(prob,
                             com,
                             mapscale=False,
                             tick_labels=False,
                             plot_demand=(plot_type == 'peak'),
                             annotations=plot_annotations)
            plt.title('')

            # save to file
            for ext, transp in [('png', True), ('png', False), ('pdf', True)]:
                transp_str = ('-transp' if transp and ext != 'pdf' else '')
                annote_str = ('-annote' if plot_annotations else '')

                # determine figure filename from scenario name, plot type,
                # commodity, transparency, annotations and extension
                fig_filename = '{}-{}-{}{}{}.{}'.format(
                    sce, plot_type, com, transp_str, annote_str, ext)
                fig_filename = os.path.join(result_dir, fig_filename)
                fig.savefig(fig_filename,
                            dpi=300,
                            bbox_inches='tight',
                            transparent=transp)

    return prob
示例#2
0
文件: runhaag.py 项目: tum-ens/rivus
def run_scenario(scenario):
    # scenario name
    sce = scenario.__name__
    sce_nice_name = sce.replace('_', ' ').title()
    
    # prepare input data 
    data = rivus.read_excel(data_spreadsheet)
    vertex = pdshp.read_shp(vertex_shapefile)    
    edge = prepare_edge(edge_shapefile, building_shapefile)
    
    # apply scenario function to input data
    data, vertex, edge = scenario(data, vertex, edge)
    
    # create & solve model
    model = rivus.create_model(data, vertex, edge)
    prob = model.create()
    optim = SolverFactory('gurobi')
    optim = setup_solver(optim)
    result = optim.solve(prob, tee=True)
    prob.load(result)
        
    # create result directory if not existent
    result_dir = os.path.join('result', os.path.basename(base_directory))
    if not os.path.exists(result_dir):
        os.makedirs(result_dir)
    
    # report    
    rivus.report(prob, os.path.join(result_dir, 'report.xlsx'))
    
    # plots
    for com, plot_type in [('Elec', 'caps'), ('Heat', 'caps'), ('Gas', 'caps'),
                           ('Elec', 'peak'), ('Heat', 'peak')]:
        
        # two plot variants
        for plot_annotations in [False, True]:
            # create plot
            fig = rivus.plot(prob, com, mapscale=False, tick_labels=False, 
                             plot_demand=(plot_type == 'peak'),
                             annotations=plot_annotations)
            plt.title('')
            
            # save to file
            for ext, transp in [('png', True), ('png', False), ('pdf', True)]:
                transp_str = ('-transp' if transp and ext != 'pdf' else '')
                annote_str = ('-annote' if plot_annotations else '')
                
                # determine figure filename from scenario name, plot type, 
                # commodity, transparency, annotations and extension
                fig_filename = '{}-{}-{}{}{}.{}'.format(
                    sce, plot_type, com, transp_str, annote_str, ext) 
                fig_filename = os.path.join(result_dir, fig_filename)
                fig.savefig(fig_filename, dpi=300, bbox_inches='tight', 
                            transparent=transp)
                
    return prob
示例#3
0
result_dir = os.path.join('result', os.path.basename(base_directory))

# create result directory if not existing already
if not os.path.exists(result_dir):
    os.makedirs(result_dir)

rivus.save(prob, os.path.join(result_dir, 'prob.pgz'))
rivus.report(prob, os.path.join(result_dir, 'report.xlsx'))

# plot all caps (and demands if existing)
for com, plot_type in [('Elec', 'caps'), ('Heat', 'caps'), ('Gas', 'caps'),
                       ('Elec', 'peak'), ('Heat', 'peak')]:

    # create plot
    fig = rivus.plot(prob,
                     com,
                     mapscale=False,
                     tick_labels=False,
                     plot_demand=(plot_type == 'peak'))
    plt.title('')
    # save to file
    for ext in ['png', 'pdf']:

        # determine figure filename from plot type, commodity and extension
        fig_filename = os.path.join(result_dir,
                                    '{}-{}.{}').format(plot_type, com, ext)
        fig.savefig(fig_filename,
                    dpi=300,
                    bbox_inches='tight',
                    transparent=(ext == 'pdf'))
示例#4
0
文件: runmin.py 项目: tum-ens/rivus
# load results
costs, Pmax, Kappa_hub, Kappa_process = rivus.get_constants(prob)
source, flows, hub_io, proc_io, proc_tau = rivus.get_timeseries(prob)


result_dir = os.path.join('result', os.path.basename(base_directory))

# create result directory if not existing already
if not os.path.exists(result_dir):
    os.makedirs(result_dir)
    
rivus.save(prob, os.path.join(result_dir, 'prob.pgz'))
rivus.report(prob, os.path.join(result_dir, 'report.xlsx'))

# plot all caps (and demands if existing)
for com, plot_type in [('Elec', 'caps'), ('Heat', 'caps'), ('Gas', 'caps'),
                       ('Elec', 'peak'), ('Heat', 'peak')]:
    
    # create plot
    fig = rivus.plot(prob, com, mapscale=False, tick_labels=False, 
                      plot_demand=(plot_type == 'peak'))
    plt.title('')
    # save to file
    for ext in ['png', 'pdf']:
            
        # determine figure filename from plot type, commodity and extension
        fig_filename = os.path.join(
            result_dir, '{}-{}.{}').format(plot_type, com, ext)
        fig.savefig(fig_filename, dpi=300, bbox_inches='tight', 
                    transparent=(ext=='pdf'))