Ejemplo n.º 1
0
def add_regions_with_names(years_string, plot_position, plotting_offset,
                           shapefile, modelrun_id, modelrun_params,
                           global_strategy, local_strategies, plotting_objects,
                           cnxn, zorder):
    plotting_order = zorder
    # find region shapes
    cursor = cnxn.cursor()
    shapes = prs.load_regionshapes_from_file(shapefile)
    # derive demands and supplies from database and feed into shape objects
    for region in shapes.keys():
        shape_name = str(shapes[str(region)].name) + '_' + str(region)
        shape_outline = shapes[str(region)].outline_coordinates
        shape = prs.Region_Shape(shape_outline)
        shape.zorder = plotting_order
        plotting_order += 1
        shape.offset_coordinates(plot_position, plotting_offset)
        years = tuple(
            np.arange(modelrun_params.start_year, modelrun_params.end_year,
                      global_strategy.planning_interval))
        for year in years:
            shape.set_demand_fulfillment_values(1, year)
            shape.set_missing_supply_values(0, year)
            #shape.text = shape_name
            shape.text = ''
        #shape_object.set_plotting_order(plot_position)
        plotting_objects[0][shape_name] = shape
    return plotting_objects, plotting_order
Ejemplo n.º 2
0
def add_stacked_transmission_capacity_thumbs(
        years_string, plot_position, plotting_offset, submodel, modelrun_id,
        modelrun_params, global_strategy, local_strategies, plotting_objects,
        cnxn, zorder, rescale_factor, order_of_networks):
    plotting_order = zorder
    # find region shapes
    cursor = cnxn.cursor()
    shapes = prs.load_regionshapes_from_file(
        local_strategies[submodel].shapefile)
    years = tuple(
        np.arange(modelrun_params.start_year, modelrun_params.end_year,
                  global_strategy.planning_interval))
    theSQL = 'SELECT network, SUM(total_flow), SUM(maxcap), origin, destination, simulation_year  FROM "ISL_IO_FinalFlows_DistributionNetworks" WHERE modelrun_id = ' + str(
        modelrun_id) + ' AND \
        submodel = ' + str("'") + submodel + str(
            "'") + ' AND cur_future_plan = ' + str(
                "'current'") + ' AND simulation_year IN ' + str(
                    years_string) + '\
        GROUP BY network, origin, destination, simulation_year'

    cursor.execute(theSQL)
    new_line = cursor.fetchone()
    while new_line:
        [network, supply, maxcap, origin, destination, year] = new_line
        if submodel not in plotting_objects[5].keys():
            plotting_objects[5][submodel] = [[], {}]
            plotting_objects[5][submodel][0] = order_of_networks
        #if network not in plotting_objects[5][submodel][0]:
        #plotting_objects[5][submodel][0].append(network)
        thumb_name = str(submodel) + '_' + str(origin) + '_' + str(destination)
        if thumb_name not in plotting_objects[5][submodel][1].keys():
            [ox, oy] = shapes[str(origin)].center
            [dx, dy] = shapes[str(destination)].center
            coordinates = [ox + (dx - ox) / 3, oy + (dy - oy) / 3]
            cap_thumb = prs.Stacked_Asset_Capacity_And_Usage(
                coordinates, order_of_networks)
            cap_thumb.zorder = plotting_order
            plotting_order += 1
            cap_thumb.offset_coordinates(plot_position, plotting_offset)
        else:
            cap_thumb = plotting_objects[5][submodel][1][thumb_name]
        try:
            cap_thumb.set_values(network,
                                 int(maxcap) * rescale_factor,
                                 int(supply) * rescale_factor, year)
            if network not in cap_thumb.networks:
                cap_thumb.networks.append(network)
        except:
            cap_thumb.set_values(0, 0, year)
            print 'error: maxcap and supply of assets ' + str(
                thumb_name) + ' not found for year ' + str(year)
        plotting_objects[5][submodel][1][thumb_name] = cap_thumb
        new_line = cursor.fetchone()
    return plotting_objects, plotting_order
Ejemplo n.º 3
0
def add_transmission_asset_capacity_thumbs(years_string, plot_position,
                                           plotting_offset, network,
                                           modelrun_id, modelrun_params,
                                           global_strategy, local_strategies,
                                           plotting_objects, cnxn, zorder,
                                           rescale_factor):
    plotting_order = zorder
    # find submodel and region shapes
    cursor = cnxn.cursor()
    theSQL = 'SELECT submodel from "ISL_I_KeyServices" WHERE supplynw = ' + str(
        "'") + str(network) + str(
            "'") + ' GROUP BY "ISL_I_KeyServices".submodel'
    (submodel, ) = list(cursor.execute(theSQL))[0]
    shapes = prs.load_regionshapes_from_file(
        local_strategies[submodel].shapefile)
    years = tuple(
        np.arange(modelrun_params.start_year, modelrun_params.end_year,
                  global_strategy.planning_interval))
    theSQL = 'SELECT SUM(total_flow), SUM(maxcap), origin, destination, simulation_year  FROM "ISL_IO_FinalFlows_DistributionNetworks" WHERE modelrun_id = ' + str(
        modelrun_id) + ' AND \
        network = ' + str("'") + network + str(
            "'") + ' AND cur_future_plan = ' + str(
                "'current'") + ' AND simulation_year IN ' + str(
                    years_string) + '\
        GROUP BY origin, destination, simulation_year'

    cursor.execute(theSQL)
    new_line = cursor.fetchone()
    while new_line:
        [supply, maxcap, origin, destination, year] = new_line
        thumb_name = str(network) + '_' + str(origin) + '_' + str(destination)
        if thumb_name not in plotting_objects[4].keys():
            [ox, oy] = shapes[str(origin)].center
            [dx, dy] = shapes[str(destination)].center
            coordinates = [ox + (dx - ox) / 4, oy + (dy - oy) / 4]
            cap_thumb = prs.Asset_Capacity_And_Usage(coordinates)
            cap_thumb.zorder = plotting_order
            plotting_order += 1
            cap_thumb.offset_coordinates(plot_position, plotting_offset)
        else:
            cap_thumb = plotting_objects[4][thumb_name]
        try:
            cap_thumb.set_values(
                int(maxcap) * rescale_factor,
                int(supply) * rescale_factor, year)
        except:
            cap_thumb.set_values(0, 0, year)
            print 'error: maxcap and supply of assets ' + str(
                thumb_name) + ' not found for year ' + str(year)
        plotting_objects[4][thumb_name] = cap_thumb
        new_line = cursor.fetchone()
    return plotting_objects, plotting_order
Ejemplo n.º 4
0
def add_internet_commodity_transfers(years, plot_position, plotting_offset,
                                     upORdown, keyservice, supplynetwork,
                                     modelrun_id, modelrun_params,
                                     global_strategy, local_strategies,
                                     plotting_objects, cnxn, zorder):
    plotting_order = zorder
    transfers = plotting_objects[1]
    # find submodel and region shapes
    cursor = cnxn.cursor()
    cursor_2 = cnxn.cursor()
    theSQL = 'SELECT submodel from "ISL_I_KeyServices" WHERE supplynw = ' + str(
        "'") + str(supplynetwork) + str(
            "'") + ' GROUP BY "ISL_I_KeyServices".submodel'
    (submodel, ) = list(cursor.execute(theSQL))[0]
    shapes = prs.load_regionshapes_from_file(
        local_strategies[submodel].shapefile)
    # report transfers between regions
    #years = tuple(np.arange(modelrun_params.start_year, modelrun_params.end_year, global_strategy.planning_interval))
    theSQL = 'SELECT simulation_year, region, total_flow FROM "ISL_IO_FinalFlows_SuppliesByNetwork" WHERE modelrun_id = ' + str(
        modelrun_id) + ' AND \
                network = ' + str("'") + str(supplynetwork) + str(
            "'") + ' AND keyservice = ' + str("'") + str(keyservice) + str(
                "'") + ' AND cur_fut_plan = ' + str(
                    "'current'") + ' AND simulation_year IN ' + str(years)
    cursor.execute(theSQL)
    new_line = cursor.fetchone()
    while new_line:
        [simulation_year, origin, total_flow] = new_line
        transfername = str(supplynetwork) + '_' + str(origin) + '_' + str(
            keyservice)
        if transfername not in transfers.keys():
            [ox, oy] = shapes[str(origin)].center
            if upORdown == 1:
                origin_coord = [ox, oy]
                destination_coord = [
                    ox, oy + 5 * upORdown * plotting_offset / 8
                ]
            else:
                origin_coord = [ox, oy + 4 * upORdown * plotting_offset / 8]
                destination_coord = [ox, oy + upORdown * plotting_offset]
            new_transfer_object = prs.Transfer(transfername, origin_coord,
                                               destination_coord)
            new_transfer_object.zorder = plotting_order
            plotting_order += 1
            new_transfer_object.offset_coordinates(plot_position,
                                                   plotting_offset)
            transfers[transfername] = new_transfer_object
        transfers[transfername].add_transfer(total_flow, simulation_year)
        new_line = cursor.fetchone()
    plotting_objects[1] = transfers
    return plotting_objects, plotting_order
Ejemplo n.º 5
0
def add_transport_supply_over_demand(years, plot_position, plotting_offset,
                                     keyservice, modelrun_id, modelrun_params,
                                     global_strategy, local_strategies,
                                     plotting_objects, cnxn, zorder):
    plotting_order = zorder
    transports = plotting_objects[2]
    # find submodel and region shapes
    cursor = cnxn.cursor()
    theSQL = 'SELECT submodel from "ISL_I_KeyServices" WHERE ks = ' + str(
        "'") + str(keyservice) + str(
            "'") + ' GROUP BY "ISL_I_KeyServices".submodel'
    (submodel, ) = list(cursor.execute(theSQL))[0]
    shapes = prs.load_regionshapes_from_file(
        local_strategies[submodel].shapefile)
    # derive demands and supplies from database and feed into shape objects
    #years = tuple(np.arange(modelrun_params.start_year, modelrun_params.end_year, global_strategy.planning_interval))
    theSQL = 'SELECT demand, demand_value, supply, simulation_year, region FROM "ISL_IO_FinalFlows_DemandFulfillments" WHERE modelrun_id = ' + str(
        modelrun_id) + ' AND \
        keyservice = ' + str("'") + keyservice + str(
            "'") + ' AND current_forecast = ' + str(
                "'current'") + ' AND simulation_year IN ' + str(years)
    cursor.execute(theSQL)
    new_line = cursor.fetchone()
    while new_line:
        [demand_name, demand, supply, year, origin] = new_line
        destination = demand_name.split('_')[-1]
        transportname = str(keyservice) + '_' + str(origin) + '_' + str(
            destination)
        if transportname not in transports.keys():
            [ox, oy] = shapes[str(origin)].center
            [dx, dy] = shapes[str(destination)].center
            dx = dx - (dx - ox) / 2
            dy = dy - (dy - oy) / 2
            origin_coord = [ox, oy]
            destination_coord = [dx, dy]
            transports[transportname] = prs.Transport(origin_coord,
                                                      destination_coord)
            transports[transportname].zorder = plotting_order
            plotting_order += 1
            transports[transportname].offset_coordinates(
                plot_position, plotting_offset)
        if demand != 0:
            transports[transportname].add_transport(1.0 * supply / demand,
                                                    year)
        else:
            transports[transportname].add_transport(0, year)
        transports[transportname].add_missing_supply_values(
            demand, supply, year)
        new_line = cursor.fetchone()
    plotting_objects[2] = transports
    return plotting_objects, plotting_order
Ejemplo n.º 6
0
def add_commodity_supply_over_demand(years, plot_position, plotting_offset,
                                     keyservice, modelrun_id, modelrun_params,
                                     global_strategy, local_strategies,
                                     plotting_objects, cnxn, zorder):
    plotting_order = zorder
    # find submodel and region shapes
    cursor = cnxn.cursor()
    theSQL = 'SELECT submodel from "ISL_I_KeyServices" WHERE ks = ' + str(
        "'") + str(keyservice) + str(
            "'") + ' GROUP BY "ISL_I_KeyServices".submodel'
    (submodel, ) = list(cursor.execute(theSQL))[0]
    shapes = prs.load_regionshapes_from_file(
        local_strategies[submodel].shapefile)
    # derive demands and supplies from database and feed into shape objects
    #years = tuple(np.arange(modelrun_params.start_year, modelrun_params.end_year, global_strategy.planning_interval))
    theSQL = 'SELECT demand_value, supply, simulation_year, region FROM "ISL_IO_FinalFlows_DemandFulfillments" WHERE modelrun_id = ' + str(
        modelrun_id) + ' AND \
        keyservice = ' + str("'") + keyservice + str(
            "'") + ' AND current_forecast = ' + str(
                "'current'") + ' AND simulation_year IN ' + str(years)
    cursor.execute(theSQL)
    new_line = cursor.fetchone()
    while new_line:
        [demand, supply, year, region] = new_line
        shape_name = str(keyservice) + '_' + str(region)
        shape_outline = shapes[str(region)].outline_coordinates
        if shape_name not in plotting_objects[0].keys():
            shape = prs.Region_Shape(shape_outline)
            shape.zorder = plotting_order
            shape.text = ''
            plotting_order += 1
            shape.offset_coordinates(plot_position, plotting_offset)
        else:
            shape = plotting_objects[0][shape_name]
        if demand != 0:
            shape.set_demand_fulfillment_values(1.0 * supply / demand, year)
        else:
            shape.set_demand_fulfillment_values(1.0, year)
        shape.set_missing_supply_values(float(demand - supply), year)
        #shape_object.set_plotting_order(plot_position)
        plotting_objects[0][shape_name] = shape
        new_line = cursor.fetchone()
    return plotting_objects, plotting_order
Ejemplo n.º 7
0
def add_intranet_commodity_transfers(years, plot_position, plotting_offset,
                                     network, modelrun_id, modelrun_params,
                                     global_strategy, local_strategies,
                                     plotting_objects, cnxn, zorder):
    plotting_order = zorder
    transfers = plotting_objects[1]
    # find submodel and region shapes
    cursor = cnxn.cursor()
    cursor_2 = cnxn.cursor()
    theSQL = 'SELECT submodel from "ISL_I_KeyServices" WHERE supplynw = ' + str(
        "'") + str(network) + str(
            "'") + ' GROUP BY "ISL_I_KeyServices".submodel'
    (submodel, ) = list(cursor.execute(theSQL))[0]
    shapes = prs.load_regionshapes_from_file(
        local_strategies[submodel].shapefile)
    # report transfers between regions
    #years = tuple(np.arange(modelrun_params.start_year, modelrun_params.end_year, global_strategy.planning_interval))
    theSQL = 'SELECT simulation_year, origin, destination, total_flow FROM "ISL_IO_FinalFlows_DistributionNetworks" WHERE modelrun_id = ' + str(
        modelrun_id) + ' AND \
                network = ' + str("'") + str(network) + str(
            "'") + ' AND cur_future_plan = ' + str(
                "'current'") + ' AND simulation_year IN ' + str(years)
    cursor.execute(theSQL)
    new_line = cursor.fetchone()
    while new_line:
        [simulation_year, origin, destination, total_flow] = new_line
        theSQL = 'SELECT total_flow FROM "ISL_IO_FinalFlows_DistributionNetworks" WHERE (modelrun_id = ' + str(
            modelrun_id) + ' AND \
                    network = ' + str("'") + str(network) + str(
                "'") + ' AND cur_future_plan = ' + str(
                    "'current'") + ' AND origin = ' + str(
                        destination) + ' AND \
                    destination = ' + str(
                            origin) + ' AND simulation_year = ' + str(
                                simulation_year) + ')'
        cursor_2.execute(theSQL)
        try:
            [total_flow_back] = cursor_2.fetchone()
        except:
            total_flow_back = 0
        net_flow = total_flow - total_flow_back
        #if net_flow > 0:
        transfername = str(network) + '_' + str(origin) + '_' + str(
            destination)
        if transfername not in transfers.keys():
            [ox, oy] = shapes[str(origin)].center
            [dx, dy] = shapes[str(destination)].center
            origin_coord = [ox, oy]
            destination_coord = [dx, dy]
            transfers[transfername] = prs.Transfer(transfername, origin_coord,
                                                   destination_coord)
            transfers[transfername].zorder = plotting_order
            plotting_order += 1
            transfers[transfername].offset_coordinates(plot_position,
                                                       plotting_offset)
            if transfername == 'Electricity_9_11':
                pass
                #print 'E_9_11 installed with origi  coords' + str(origin_coord) + ', ' + str(destination_coord)
                #print 'E_9_11 installed with offset coords' + str(transfers[transfername].origin) + ', ' + str(transfers[transfername].destination)
        transfers[transfername].add_transfer(net_flow, simulation_year)
        if transfername == 'Electricity_9_11':
            pass
            #print 'E_9_11 - new transfer added ' + str(transfers[transfername].origin) + ', ' + str(transfers[transfername].destination)
        new_line = cursor.fetchone()
    plotting_objects[1] = transfers
    return plotting_objects, plotting_order