示例#1
0
    agg.to_csv(fn)

if __name__ == '__main__':
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=Dict(technology='solar'),
            input=Dict(
                base_network="networks/base.nc",
                corine="data/bundle/corine/g250_clc06_V18_5.tif",
                natura="resources/natura.tiff",
                gebco="data/bundle/GEBCO_2014_2D.nc",
                country_shapes='resources/country_shapes.geojson',
                offshore_shapes='resources/offshore_shapes.geojson',
                pietzker="data/pietzker2014.xlsx"
            ),
            output=Dict(
                area="resources/country_flh_area_{technology}.csv",
                aggregated="resources/country_flh_aggregated_{technology}.csv",
                uncorrected="resources/country_flh_uncorrected_{technology}.csv",
                plot="resources/country_flh_{technology}.pdf",
                exclusion="resources/country_exclusion_{technology}"
            )
        )
        snakemake.input['regions'] = os.path.join(snakemake.path, "resources",
                                                  "country_shapes.geojson"
                                                  if snakemake.wildcards.technology in ('onwind', 'solar')
                                                  else "offshore_shapes.geojson")
        snakemake.input['cutout'] = os.path.join(snakemake.path, "cutouts",
                                                 snakemake.config["renewable"][snakemake.wildcards.technology]['cutout'])
示例#2
0
if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=dict(network='elec',
                           simpl='',
                           clusters='39',
                           lv='1.0',
                           sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
                           co2_budget_name='b30b3',
                           planning_horizons='2050'),
            input=dict(
                network=
                "pypsa-eur-sec/results/test/prenetworks_brownfield/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_{planning_horizons}.nc"
            ),
            output=[
                "results/networks/s{simpl}_{clusters}_lv{lv}_{sector_opts}_{co2_budget_name}_{planning_horizons}-test.nc"
            ],
            log=dict(
                gurobi=
                "logs/{network}_s{simpl}_{clusters}_lv{lv}_{sector_opts}_{co2_budget_name}_{planning_horizons}_gurobi-test.log",
                python=
                "logs/{network}_s{simpl}_{clusters}_lv{lv}_{sector_opts}_{co2_budget_name}_{planning_horizons}_python-test.log"
            ))
        import yaml
        with open('config.yaml', encoding='utf8') as f:
            snakemake.config = yaml.safe_load(f)
    tmpdir = snakemake.config['solving'].get('tmpdir')
    if tmpdir is not None:
示例#3
0
    return generators


if __name__ == __main__:
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            path='..',
            wildcards={
                'clusters': '45,90,181,full',
                'country': 'all'
            },
            params=dict(techs=['onwind', 'offwind-ac', 'offwind-dc', 'solar']),
            input=Dict(
                **{
                    'full': 'networks/elec_s.nc',
                    '45': 'networks/elec_s_45.nc',
                    '90': 'networks/elec_s_90.nc',
                    '181': 'networks/elec_s_181.nc',
                }),
            output=['results/plots/cum_p_nom_max_{clusters}_{country}.pdf'])

    logging.basicConfig(level=snakemake.config['logging_level'])

    plot_kwds = dict(drawstyle="steps-post")

    clusters = snakemake.wildcards.clusters.split(',')
    techs = snakemake.params.techs
    country = snakemake.wildcards.country
示例#4
0
if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=dict(network='elec',
                           simpl='',
                           clusters='38',
                           lv='1.0',
                           opts='Co2p10L0-24H-T-H-B'),
            input=dict(
                network=
                "results/new_costs/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{opts}.nc"
            ),
            output=[
                "results/191108-h2_pipeline_network/postnetworks/s{simpl}_{clusters}_lv{lv}_{opts}-test.nc"
            ],
            log=dict(
                gurobi=
                "logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_gurobi-test.log",
                python=
                "logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_python-test.log",
                solver=
                "logs/distribution_grid/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_solver.log",
                memory=
                "logs/distribution_grid/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_memory.log"
            ))

    tmpdir = snakemake.config['solving'].get('tmpdir')
    if tmpdir is not None:
        patch_pyomo_tmpdir(tmpdir)
示例#5
0
if 'snakemake' not in globals():
    from vresutils.snakemake import MockSnakemake, Dict
    from snakemake.rules import expand
    import yaml
    snakemake = Dict()
    snakemake = MockSnakemake(
        path='..',
        wildcards=dict(network='elec', simpl='', clusters='90', lv='1.25', opts='Co2L-3H', attr='p_nom', ext="pdf"),
        input=dict(network="results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc",
                   tech_costs="data/costs.csv"),
        output=dict(only_map="results/plots/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{attr}.{ext}",
                    ext="results/plots/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{attr}_ext.{ext}")
    )

import pypsa

from _helpers import load_network, aggregate_p, aggregate_costs
from vresutils import plot as vplot

import os
import pypsa
import pandas as pd
import geopandas as gpd
import numpy as np
from itertools import product, chain
from six.moves import map, zip
from six import itervalues, iterkeys
from collections import OrderedDict as odict

import matplotlib.pyplot as plt
import matplotlib as mpl
        import yaml
        import os
        from vresutils.snakemake import MockSnakemake
        snakemake = MockSnakemake(
            wildcards=dict(network='elec',
                           simpl='',
                           clusters='48',
                           lv='1',
                           opts='Co2L-3H',
                           sector_opts="[Co2L0p0-168H-T-H-B-I]"),
            input=dict(
                building_stock="data/retro/data_building_stock.csv",
                data_tabula="data/retro/tabula-calculator-calcsetbuilding.csv",
                u_values_PL="data/retro/u_values_poland.csv",
                air_temperature=
                "resources/temp_air_total_{network}_s{simpl}_{clusters}.nc",
                tax_w="data/retro/electricity_taxes_eu.csv",
                construction_index=
                "data/retro/comparative_level_investment.csv",
                floor_area_missing="data/retro/floor_area_missing.csv",
                clustered_pop_layout=
                "resources/pop_layout_elec_s{simpl}_{clusters}.csv",
                cost_germany="data/retro/retro_cost_germany.csv",
                window_assumptions="data/retro/window_assumptions.csv"),
            output=dict(
                retro_cost="resources/retro_cost_elec_s{simpl}_{clusters}.csv",
                floor_area="resources/floor_area_elec_s{simpl}_{clusters}.csv")
        )
        with open('config.yaml', encoding='utf8') as f:
            snakemake.config = yaml.safe_load(f)
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        import os
        os.chdir("/home/ws/bw0928/mnt/lisa/pypsa-eur-sec")
        from vresutils.snakemake import MockSnakemake
        import yaml
        snakemake = MockSnakemake(
            wildcards=dict(
                network='elec',
                simpl='',
                clusters='48',
                lv='2',
                opts='Co2L-3H',
                year='2015',
                sector_opts="[Co2L0p0-3h-T-H-B-I-retro-noigas-tes]"),
            input=dict(
                nuts3_shapes='../pypsa-eur/resources/nuts3_shapes.geojson',
                district_heat_share='data/district_heat_share.csv',
                idee_dir='data/jrc-idees-2015',
                eea_co2="data/eea/UNFCCC_v21.csv",
                swiss="data/switzerland-sfoe/switzerland-new_format.csv"),
            output=dict(energy_name='data/{year}/energy_totals.csv',
                        co2_name='data/{year}/co2_totals.csv',
                        transport_name='data/{year}/transport_data.csv'))
        with open('/home/ws/bw0928/Dokumente/pypsa-eur-sec/config.yaml',
                  encoding='utf8') as f:
            snakemake.config = yaml.safe_load(f)

    nuts3 = gpd.read_file(snakemake.input.nuts3_shapes).set_index('index')
    population = nuts3['pop'].groupby(nuts3.country).sum()
示例#8
0
        s = s.reset_index()
    s.to_file(fn, driver='GeoJSON')


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            path='..',
            wildcards={},
            input=Dict(
                naturalearth=
                'data/bundle/naturalearth/ne_10m_admin_0_countries.shp',
                eez='data/bundle/eez/World_EEZ_v8_2014.shp',
                nuts3='data/bundle/NUTS_2013_60M_SH/data/NUTS_RG_60M_2013.shp',
                nuts3pop='data/bundle/nama_10r_3popgdp.tsv.gz',
                nuts3gdp='data/bundle/nama_10r_3gdp.tsv.gz',
                ch_cantons='data/bundle/ch_cantons.csv',
                ch_popgdp='data/bundle/je-e-21.03.02.xls'),
            output=Dict(country_shapes='resources/country_shapes.geojson',
                        offshore_shapes='resource/offshore_shapes.geojson',
                        europe_shape='resources/europe_shape.geojson',
                        nuts3_shapes='resources/nuts3_shapes.geojson'))

    country_shapes = countries()
    save_to_geojson(country_shapes, snakemake.output.country_shapes)

    offshore_shapes = eez(country_shapes)
    save_to_geojson(offshore_shapes, snakemake.output.offshore_shapes)

    europe_shape = country_cover(country_shapes, offshore_shapes)
示例#9
0
    network.lopf(solver_name=solver_name,
                 solver_logfile=snakemake.log.solver,
                 solver_options=solver_options,
                 extra_functionality=extra_functionality,
                 extra_postprocessing=extra_postprocessing)


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=dict(assumptions='wind1100-sola750-nucl4000',
                           policy="OCGT",
                           parameter="101"),
            #input=dict(network="networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc"),
            #output=["results/networks/s{simpl}_{clusters}_lv{lv}_{opts}-test.nc"],
            #log=dict(gurobi="logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_gurobi-test.log",
            #         python="logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_python-test.log")
        )
        import yaml
        with open('config.yaml') as f:
            snakemake.config = yaml.load(f)

    #change to cbc or glpk for open-source solvers
    solver_name = snakemake.config["solver"]["name"]

    #1 is hourly, 3 is 3-hourly
    frequency = snakemake.config["frequency"]

    if "storage" in snakemake.wildcards.policy:
示例#10
0
        solver_name=snakemake.config['solving']['solver']['name'])

    return clustering.network, clustering.busmap


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            path='..',
            wildcards=Dict(simpl='1024', network='elec'),
            input=Dict(network='networks/{network}.nc',
                       tech_costs="data/costs.csv",
                       regions_onshore="resources/regions_onshore.geojson",
                       regions_offshore="resources/regions_offshore.geojson"),
            output=Dict(
                network='networks/{network}_s{simpl}.nc',
                regions_onshore=
                "resources/regions_onshore_{network}_s{simpl}.geojson",
                regions_offshore=
                "resources/regions_offshore_{network}_s{simpl}.geojson",
                clustermaps='resources/clustermaps_{network}_s{simpl}.h5'))

    logging.basicConfig(level=snakemake.config['logging_level'])

    n = pypsa.Network(snakemake.input.network)

    n, trafo_map = simplify_network_to_380(n)

    n, simplify_links_map = simplify_links(n)
# -*- coding: utf-8 -*-
"""
script to convert the technology data assumptions of the Study
"Global Energy System based on 100% Renewable Energy" of Energywatchgroup/LTU University
http://energywatchgroup.org/wp-content/uploads/EWG_LUT_100RE_All_Sectors_Global_Report_2019.pdf
(see also pdf in folder docu) into a .csv format
"""

import pandas as pd
from tabula import read_pdf
import numpy as np

# Detect running outside of snakemake and mock snakemake for testing
if 'snakemake' not in globals():
    from vresutils.snakemake import MockSnakemake
    snakemake = MockSnakemake()
    snakemake.input = dict(EWG = "docu/EWG_LUT_100RE_All_Sectors_Global_Report_2019.pdf")
    snakemake.output = dict(costs = "inputs/EWG_costs.csv")

df_list = read_pdf(snakemake.input["EWG"],
                   pages="305-309",
                   multiple_tables=True)
#%%
# wished columns
wished_columns = ['Technologies', 'Type', 'Units',
                  '2015', '2020', '2025', '2030',
                  '2035', '2040', '2045', '2050', 'Ref']
# clean data frame
split_units = df_list[0]["Units 2015"].fillna(" ").str.split(" ", expand=True)
# check where split is too long
to_be_merged = split_units[split_units[2].apply(lambda x: x!=None)].index
示例#12
0
            # delete links if their lifetime is over and p_nom=0
            n.mremove("Link", [index for index in n.links.index.to_list() if str(grouping_year) in index and n.links.p_nom[index]<snakemake.config['existing_capacities']['threshold_capacity']])


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake
        snakemake = MockSnakemake(
            wildcards=dict(network='elec', simpl='', clusters='45', lv='1.0',
                           sector_opts='Co2L0-3H-T-H-B-I-solar3-dist1',
                           planning_horizons='2020'),
            input=dict(network='pypsa-eur-sec/results/version-2/prenetworks/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc',
                       powerplants='pypsa-eur/resources/powerplants.csv',
                       busmap_s='pypsa-eur/resources/busmap_elec_s{simpl}.csv',
                       busmap='pypsa-eur/resources/busmap_elec_s{simpl}_{clusters}.csv',
                       costs='technology_data/outputs/costs_{planning_horizons}.csv',
                       cop_air_total="pypsa-eur-sec/resources/cop_air_total_elec_s{simpl}_{clusters}.nc",
                       cop_soil_total="pypsa-eur-sec/resources/cop_soil_total_elec_s{simpl}_{clusters}.nc",
                       clustered_pop_layout="pypsa-eur-sec/resources/pop_layout_elec_s{simpl}_{clusters}.csv",),
            output=['pypsa-eur-sec/results/version-2/prenetworks_brownfield/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc'],
        )
        import yaml
        with open('config.yaml', encoding='utf8') as f:
            snakemake.config = yaml.safe_load(f)


    logging.basicConfig(level=snakemake.config['logging_level'])

    options = snakemake.config["sector"]
    opts = snakemake.wildcards.sector_opts.split('-')
示例#13
0
        regions_c.index.name = 'name'
        save_to_geojson(regions_c, getattr(output, which))

if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=Dict(network='elec', simpl='', clusters='45'),
            input=Dict(
                network='networks/{network}_s{simpl}.nc',
                regions_onshore='resources/regions_onshore_{network}_s{simpl}.geojson',
                regions_offshore='resources/regions_offshore_{network}_s{simpl}.geojson',
                clustermaps='resources/clustermaps_{network}_s{simpl}.h5',
                tech_costs='data/costs.csv',

            ),
            output=Dict(
                network='networks/{network}_s{simpl}_{clusters}.nc',
                regions_onshore='resources/regions_onshore_{network}_s{simpl}_{clusters}.geojson',
                regions_offshore='resources/regions_offshore_{network}_s{simpl}_{clusters}.geojson',
                clustermaps='resources/clustermaps_{network}_s{simpl}_{clusters}.h5'
            )
        )

    logging.basicConfig(level=snakemake.config['logging_level'])

    n = pypsa.Network(snakemake.input.network)

    focus_weights = snakemake.config.get('focus_weights', None)
    if 'snakemake' not in globals():
        import yaml
        import os
        from vresutils.snakemake import MockSnakemake
        os.chdir("/home/ws/bw0928/Dokumente/pypsa-eur-sec/")
        snakemake = MockSnakemake(
            wildcards=dict(
                network='elec',
                simpl='',
                clusters='38',
                lv='1',
                opts='Co2L-3H',
                sector_opts="[Co2L0p0-24H-T-H-B-I]"),
            input=dict(
                building_stock="data/retro/data_building_stock.csv",
                u_values_PL="data/retro/u_values_poland.csv",
                tax_w="data/retro/electricity_taxes_eu.csv",
                construction_index="data/retro/comparative_level_investment.csv",
                average_surface="data/retro/average_surface_components.csv",
                floor_area_missing="data/retro/floor_area_missing.csv",
                clustered_pop_layout="resources/pop_layout_{network}_s{simpl}_{clusters}.csv",
                cost_germany="data/retro/retro_cost_germany.csv",
                window_assumptions="data/retro/window_assumptions.csv"),
            output=dict(
                retro_cost="resources/retro_cost_{network}_s{simpl}_{clusters}.csv",
                floor_area="resources/floor_area_{network}_s{simpl}_{clusters}.csv")
        )
        with open('/home/ws/bw0928/Dokumente/pypsa-eur-sec/config.yaml', encoding='utf8') as f:
            snakemake.config = yaml.safe_load(f)
        os.chdir("/home/ws/bw0928/Dokumente/pypsa-eur-sec/scripts")

#  ******** (1) ASSUMPTIONS - PARAMETERS **********************************
示例#15
0
        regions_c.index.name = 'name'
        save_to_geojson(regions_c, getattr(output, which))


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=Dict(network='elec', simpl='', clusters='45'),
            input=Dict(
                network='networks/{network}_s{simpl}.nc',
                regions_onshore=
                'resources/regions_onshore_{network}_s{simpl}.geojson',
                regions_offshore=
                'resources/regions_offshore_{network}_s{simpl}.geojson'),
            output=Dict(
                network='networks/{network}_s{simpl}_{clusters}.nc',
                regions_onshore=
                'resources/regions_onshore_{network}_s{simpl}_{clusters}.geojson',
                regions_offshore=
                'resources/regions_offshore_{network}_s{simpl}_{clusters}.geojson'
            ))

    logging.basicConfig(level=snakemake.config['logging_level'])

    n = pypsa.Network(snakemake.input.network)

    if snakemake.wildcards.clusters.endswith('m'):
        n_clusters = int(snakemake.wildcards.clusters[:-1])
        aggregate_renewables = False
示例#16
0
    n = _adjust_capacities_of_under_construction_branches(n)

    return n


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            path='..',
            wildcards={},
            input=Dict(eg_buses='data/entsoegridkit/buses.csv',
                       eg_lines='data/entsoegridkit/lines.csv',
                       eg_links='data/entsoegridkit/links.csv',
                       eg_converters='data/entsoegridkit/converters.csv',
                       eg_transformers='data/entsoegridkit/transformers.csv',
                       parameter_corrections='data/parameter_corrections.yaml',
                       links_p_nom='data/links_p_nom.csv',
                       links_tyndp='data/links_tyndp.csv',
                       country_shapes='resources/country_shapes.geojson',
                       offshore_shapes='resources/offshore_shapes.geojson',
                       europe_shape='resources/europe_shape.geojson'),
            output=['networks/base.nc'])

    logging.basicConfig(level=snakemake.config['logging_level'])

    n = base_network()
    n.export_to_netcdf(snakemake.output[0])
示例#17
0
if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake
        snakemake = MockSnakemake(
            wildcards=dict(network='elec',
                           simpl='',
                           clusters='37',
                           lv='1.0',
                           sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
                           co2_budget_name='go',
                           planning_horizons='2030'),
            input=dict(
                network=
                'pypsa-eur-sec/results/test/prenetworks/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_{planning_horizons}.nc',
                network_p=
                'pypsa-eur-sec/results/test/postnetworks/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_2020.nc',
                costs='pypsa-eur-sec/data/costs/costs_{planning_horizons}.csv',
                cop_air_total=
                "pypsa-eur-sec/resources/cop_air_total_elec_s{simpl}_{clusters}.nc",
                cop_soil_total=
                "pypsa-eur-sec/resources/cop_soil_total_elec_s{simpl}_{clusters}.nc"
            ),
            output=[
                'pypsa-eur-sec/results/test/prenetworks_brownfield/elec_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc'
            ])
        import yaml
        with open('config.yaml', encoding='utf8') as f:
            snakemake.config = yaml.safe_load(f)

    print(snakemake.input.network_p)
示例#18
0
    _set_links_underwater_fraction(n)

    _replace_b2b_converter_at_country_border_by_link(n)

    _adjust_capacities_of_under_construction_branches(n)

    return n


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            path='..',
            wildcards={},
            input=Dict(eg_buses='data/entsoegridkit/buses.csv',
                       eg_lines='data/entsoegridkit/lines.csv',
                       eg_links='data/entsoegridkit/links.csv',
                       eg_converters='data/entsoegridkit/converters.csv',
                       eg_transformers='data/entsoegridkit/transformers.csv',
                       parameter_corrections='data/parameter_corrections.yaml',
                       links_p_nom='data/links_p_nom.csv'),
            output=['networks/base_LC.nc'])

    logging.basicConfig(level=snakemake.config['logging_level'])

    n = base_network()
    n.export_to_netcdf(snakemake.output[0])
示例#19
0
    for c in n.iterate_components():
        pnl = getattr(m, c.list_name+"_t")
        for k, df in iteritems(c.pnl):
            if not df.empty:
                pnl[k] = df.resample(offset).mean()

    return m


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake
        snakemake = MockSnakemake(
            wildcards=dict(network='elec', simpl='', clusters='37', ll='v2', opts='Co2L-3H'),
            input=['networks/{network}_s{simpl}_{clusters}.nc'],
            output=['networks/{network}_s{simpl}_{clusters}_l{ll}_{opts}.nc']
        )

    logging.basicConfig(level=snakemake.config['logging_level'])

    opts = snakemake.wildcards.opts.split('-')

    n = pypsa.Network(snakemake.input[0])
    Nyears = n.snapshot_weightings.sum()/8760.

    set_line_s_max_pu(n)

    for o in opts:
        m = re.match(r'^\d+h$', o, re.IGNORECASE)
        if m is not None:
    return n


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake
        snakemake = MockSnakemake(
            wildcards=dict(network='elec',
                           simpl='',
                           clusters='45',
                           lv='1.5',
                           opts='Co2L-3H'),
            input=dict(
                unprepared="networks/{network}_s{simpl}_{clusters}.nc",
                optimized=
                "results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc"
            ),
            output=[
                "results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_op.nc"
            ],
            log=dict(
                solver="logs/s{simpl}_{clusters}_lv{lv}_{opts}_op_solver.log",
                python="logs/s{simpl}_{clusters}_lv{lv}_{opts}_op_python.log"))

    tmpdir = snakemake.config['solving'].get('tmpdir')
    if tmpdir is not None:
        patch_pyomo_tmpdir(tmpdir)

    logging.basicConfig(filename=snakemake.log.python,
                        level=snakemake.config['logging_level'])
示例#21
0
    busmap = busmap_by_stubs(n, ['country'])
    _aggregate_and_move_components(n, busmap)

    return n, busmap


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            path='..',
            wildcards=Dict(simpl=''),
            input=Dict(network='networks/elec.nc',
                       regions_onshore='resources/regions_onshore.geojson',
                       regions_offshore='resources/regions_offshore.geojson'),
            output=Dict(
                network='networks/elec_s{simpl}.nc',
                regions_onshore='resources/regions_onshore_s{simpl}.geojson',
                regions_offshore='resources/regions_offshore_s{simpl}.geojson')
        )

    logger = logging.getLogger()
    logger.setLevel(snakemake.config['logging_level'])

    n = pypsa.Network(snakemake.input.network)

    n, trafo_map = simplify_network_to_380(n)

    n, simplify_links_map = simplify_links(n)
示例#22
0
def add_emission_prices(n, emission_prices=None, exclude_co2=False):
    if emission_prices is None:
        emission_prices = snakemake.config['costs']['emission_prices']
    if exclude_co2: emission_prices.pop('co2')
    ep = (pd.Series(emission_prices).rename(lambda x: x + '_emissions') *
          n.carriers).sum(axis=1)
    n.generators['marginal_cost'] += n.generators.carrier.map(ep)
    n.storage_units['marginal_cost'] += n.storage_units.carrier.map(ep)


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict

        snakemake = MockSnakemake(output=['networks/elec.nc'])
        snakemake.input = snakemake.expand(
            Dict(base_network='networks/base.nc',
                 tech_costs='data/costs.csv',
                 regions="resources/regions_onshore.geojson",
                 powerplants="resources/powerplants.csv",
                 hydro_capacities='data/bundle/hydro_capacities.csv',
                 opsd_load=
                 'data/bundle/time_series_60min_singleindex_filtered.csv',
                 nuts3_shapes='resources/nuts3_shapes.geojson',
                 **{
                     'profile_' + t: "resources/profile_" + t + ".nc"
                     for t in snakemake.config['renewable']
                 }))

    logging.basicConfig(level=snakemake.config['logging_level'])
示例#23
0
# coding: utf-8

import logging
import pandas as pd
from scipy.spatial import cKDTree as KDTree

import pypsa
import powerplantmatching as ppm

if 'snakemake' not in globals():
    from vresutils.snakemake import MockSnakemake, Dict

    snakemake = MockSnakemake(input=Dict(base_network='networks/base.nc'),
                              output=['resources/powerplants.csv'])

logging.basicConfig(level=snakemake.config['logging_level'])

n = pypsa.Network(snakemake.input.base_network)

ppl = (ppm.collection.matched_data()[lambda df: ~df.Fueltype.isin(
    ('Solar', 'Wind'))].pipe(ppm.cleaning.clean_technology).assign(
        Fueltype=lambda df: (df.Fueltype.where(
            df.Fueltype != 'Natural Gas',
            df.Technology.replace('Steam Turbine', 'OCGT').fillna('OCGT')))).
       pipe(ppm.utils.fill_geoposition, parse=True,
            only_saved_locs=True).pipe(ppm.heuristics.fill_missing_duration))

# ppl.loc[(ppl.Fueltype == 'Other') & ppl.Technology.str.contains('CCGT'), 'Fueltype'] = 'CCGT'
# ppl.loc[(ppl.Fueltype == 'Other') & ppl.Technology.str.contains('Steam Turbine'), 'Fueltype'] = 'CCGT'

ppl = ppl.loc[ppl.lon.notnull() & ppl.lat.notnull()]
示例#24
0
import pandas as pd
import logging
logger = logging.getLogger(__name__)

from solve_network import patch_pyomo_tmpdir, prepare_network, solve_network

import pypsa


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=dict(network='elec', simpl='', clusters='45', lv='1.25', opts='Co2L-3H'),
            input=["networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc"],
            output=["results/networks/s{simpl}_{clusters}_lv{lv}_{opts}_trace.nc"],
            log=dict(python="logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_python_trace.log")
        )

    tmpdir = snakemake.config['solving'].get('tmpdir')
    if tmpdir is not None:
        patch_pyomo_tmpdir(tmpdir)

    logging.basicConfig(filename=snakemake.log.python,
                        level=snakemake.config['logging_level'])

    n = pypsa.Network(snakemake.input[0])

    solver_log = 'solver.log'
    config = snakemake.config['solving']
    opts = snakemake.wildcards.opts.split('-')
示例#25
0
    return n


if __name__ == "__main__":
    # Detect running outside of snakemake and mock snakemake for testing
    if 'snakemake' not in globals():
        from vresutils.snakemake import MockSnakemake, Dict
        snakemake = MockSnakemake(
            wildcards=dict(network='elec',
                           simpl='',
                           clusters='45',
                           lv='1.25',
                           opts='Co2L-3H-T-H'),
            input=dict(
                network=
                "networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc"),
            output=[
                "results/networks/s{simpl}_{clusters}_lv{lv}_{opts}-test.nc"
            ],
            log=dict(
                gurobi=
                "logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_gurobi-test.log",
                python=
                "logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_python-test.log"
            ))

    tmpdir = snakemake.config['solving'].get('tmpdir')
    if tmpdir is not None:
        patch_pyomo_tmpdir(tmpdir)

    logging.basicConfig(filename=snakemake.log.python,
                        level=snakemake.config['logging_level'])