use set_scenario_config everywhere

This commit is contained in:
Fabian Neumann 2024-02-12 11:53:20 +01:00
parent bb7b65eebd
commit 40b27b4107
47 changed files with 127 additions and 37 deletions

View File

@ -12,7 +12,7 @@ import numpy as np
import pandas as pd import pandas as pd
import pypsa import pypsa
import xarray as xr import xarray as xr
from _helpers import update_config_with_sector_opts from _helpers import update_config_with_sector_opts, configure_logging, set_scenario_config
from add_existing_baseyear import add_build_year_to_new_assets from add_existing_baseyear import add_build_year_to_new_assets
from pypsa.clustering.spatial import normed_or_uniform from pypsa.clustering.spatial import normed_or_uniform
@ -210,7 +210,8 @@ if __name__ == "__main__":
planning_horizons=2030, planning_horizons=2030,
) )
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts) update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)

View File

@ -15,7 +15,7 @@ import numpy as np
import pandas as pd import pandas as pd
import pypsa import pypsa
import xarray as xr import xarray as xr
from _helpers import update_config_with_sector_opts from _helpers import update_config_with_sector_opts, set_scenario_config, configure_logging
from add_electricity import sanitize_carriers from add_electricity import sanitize_carriers
from prepare_sector_network import cluster_heat_buses, define_spatial, prepare_costs from prepare_sector_network import cluster_heat_buses, define_spatial, prepare_costs
@ -552,7 +552,8 @@ if __name__ == "__main__":
planning_horizons=2020, planning_horizons=2020,
) )
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts) update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)

View File

@ -9,6 +9,8 @@ Build historical annual ammonia production per country in ktonNH3/a.
import country_converter as coco import country_converter as coco
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
cc = coco.CountryConverter() cc = coco.CountryConverter()
@ -18,6 +20,8 @@ if __name__ == "__main__":
snakemake = mock_snakemake("build_ammonia_production") snakemake = mock_snakemake("build_ammonia_production")
set_scenario_config(snakemake)
ammonia = pd.read_excel( ammonia = pd.read_excel(
snakemake.input.usgs, snakemake.input.usgs,
sheet_name="T12", sheet_name="T12",

View File

@ -16,6 +16,8 @@ import pandas as pd
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
AVAILABLE_BIOMASS_YEARS = [2010, 2020, 2030, 2040, 2050] AVAILABLE_BIOMASS_YEARS = [2010, 2020, 2030, 2040, 2050]
from _helpers import configure_logging, set_scenario_config
def build_nuts_population_data(year=2013): def build_nuts_population_data(year=2013):
pop = pd.read_csv( pop = pd.read_csv(
@ -220,6 +222,9 @@ if __name__ == "__main__":
clusters="5", clusters="5",
planning_horizons=2050, planning_horizons=2050,
) )
configure_logging(snakemake)
set_scenario_config(snakemake)
overnight = snakemake.config["foresight"] == "overnight" overnight = snakemake.config["foresight"] == "overnight"
params = snakemake.params.biomass params = snakemake.params.biomass

View File

@ -12,6 +12,8 @@ import geopandas as gpd
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
@ -22,6 +24,8 @@ if __name__ == "__main__":
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
cutout = atlite.Cutout(snakemake.input.cutout) cutout = atlite.Cutout(snakemake.input.cutout)
clustered_regions = ( clustered_regions = (

View File

@ -15,6 +15,8 @@ https://doi.org/10.1039/C2EE22653G.
import xarray as xr import xarray as xr
from _helpers import set_scenario_config
def coefficient_of_performance(delta_T, source="air"): def coefficient_of_performance(delta_T, source="air"):
if source == "air": if source == "air":
@ -35,6 +37,8 @@ if __name__ == "__main__":
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
for area in ["total", "urban", "rural"]: for area in ["total", "urban", "rural"]:
for source in ["air", "soil"]: for source in ["air", "soil"]:
source_T = xr.open_dataarray(snakemake.input[f"temp_{source}_{area}"]) source_T = xr.open_dataarray(snakemake.input[f"temp_{source}_{area}"])

View File

@ -12,6 +12,7 @@ import numpy as np
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
from dask.distributed import Client, LocalCluster from dask.distributed import Client, LocalCluster
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
@ -23,6 +24,7 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
nprocesses = int(snakemake.threads) nprocesses = int(snakemake.threads)
cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1) cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1)

View File

@ -10,6 +10,7 @@ import logging
import pandas as pd import pandas as pd
from prepare_sector_network import get from prepare_sector_network import get
from _helpers import configure_logging, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -24,6 +25,8 @@ if __name__ == "__main__":
clusters=48, clusters=48,
planning_horizons="2050", planning_horizons="2050",
) )
configure_logging(snakemake)
set_scenario_config(snakemake)
investment_year = int(snakemake.wildcards.planning_horizons[-4:]) investment_year = int(snakemake.wildcards.planning_horizons[-4:])

View File

@ -14,7 +14,7 @@ import country_converter as coco
import geopandas as gpd import geopandas as gpd
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from _helpers import mute_print from _helpers import mute_print, configure_logging, set_scenario_config
from tqdm import tqdm from tqdm import tqdm
cc = coco.CountryConverter() cc = coco.CountryConverter()
@ -743,7 +743,8 @@ if __name__ == "__main__":
snakemake = mock_snakemake("build_energy_totals") snakemake = mock_snakemake("build_energy_totals")
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
params = snakemake.params.energy params = snakemake.params.energy

View File

@ -9,6 +9,7 @@ horizon.
import country_converter as coco import country_converter as coco
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
cc = coco.CountryConverter() cc = coco.CountryConverter()
@ -126,5 +127,6 @@ if __name__ == "__main__":
clusters=48, clusters=48,
planning_horizons=2050, planning_horizons=2050,
) )
set_scenario_config(snakemake)
build_existing_heating() build_existing_heating()

View File

@ -12,6 +12,7 @@ import logging
import geopandas as gpd import geopandas as gpd
import pandas as pd import pandas as pd
from cluster_gas_network import load_bus_regions from cluster_gas_network import load_bus_regions
from _helpers import configure_logging, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -134,7 +135,8 @@ if __name__ == "__main__":
clusters="128", clusters="128",
) )
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
regions = load_bus_regions( regions = load_bus_regions(
snakemake.input.regions_onshore, snakemake.input.regions_offshore snakemake.input.regions_onshore, snakemake.input.regions_offshore

View File

@ -13,6 +13,7 @@ import geopandas as gpd
import pandas as pd import pandas as pd
from pypsa.geo import haversine_pts from pypsa.geo import haversine_pts
from shapely.geometry import Point from shapely.geometry import Point
from _helpers import configure_logging, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -143,7 +144,8 @@ if __name__ == "__main__":
snakemake = mock_snakemake("build_gas_network") snakemake = mock_snakemake("build_gas_network")
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
gas_network = load_dataset(snakemake.input.gas_network) gas_network = load_dataset(snakemake.input.gas_network)

View File

@ -10,7 +10,7 @@ from itertools import product
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
from _helpers import generate_periodic_profiles from _helpers import generate_periodic_profiles, set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
@ -22,6 +22,7 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
snapshots = pd.date_range(freq="h", **snakemake.params.snapshots) snapshots = pd.date_range(freq="h", **snakemake.params.snapshots)

View File

@ -14,6 +14,8 @@ import country_converter as coco
import geopandas as gpd import geopandas as gpd
import pandas as pd import pandas as pd
from _helpers import configure_logging, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
cc = coco.CountryConverter() cc = coco.CountryConverter()
@ -148,8 +150,8 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=128, clusters=128,
) )
configure_logging(snakemake)
logging.basicConfig(level=snakemake.config["logging"]["level"]) set_scenario_config(snakemake)
countries = snakemake.params.countries countries = snakemake.params.countries

View File

@ -12,6 +12,7 @@ from functools import partial
import country_converter as coco import country_converter as coco
import pandas as pd import pandas as pd
from tqdm import tqdm from tqdm import tqdm
from _helpers import set_scenario_config
cc = coco.CountryConverter() cc = coco.CountryConverter()
@ -175,6 +176,7 @@ if __name__ == "__main__":
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("build_industrial_energy_demand_per_country_today") snakemake = mock_snakemake("build_industrial_energy_demand_per_country_today")
set_scenario_config(snakemake)
params = snakemake.params.industry params = snakemake.params.industry
year = params.get("reference_year", 2015) year = params.get("reference_year", 2015)

View File

@ -8,6 +8,8 @@ Build industrial energy demand per model region.
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
@ -18,6 +20,7 @@ if __name__ == "__main__":
clusters=48, clusters=48,
planning_horizons=2030, planning_horizons=2030,
) )
set_scenario_config(snakemake)
# import EU ratios df as csv # import EU ratios df as csv
fn = snakemake.input.industry_sector_ratios fn = snakemake.input.industry_sector_ratios

View File

@ -11,6 +11,8 @@ from itertools import product
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
# map JRC/our sectors to hotmaps sector, where mapping exist # map JRC/our sectors to hotmaps sector, where mapping exist
sector_mapping = { sector_mapping = {
"Electric arc": "Iron and steel", "Electric arc": "Iron and steel",
@ -75,5 +77,6 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
build_nodal_industrial_energy_demand() build_nodal_industrial_energy_demand()

View File

@ -13,7 +13,7 @@ from functools import partial
import country_converter as coco import country_converter as coco
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from _helpers import mute_print from _helpers import mute_print, set_scenario_config, configure_logging
from tqdm import tqdm from tqdm import tqdm
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -274,8 +274,8 @@ if __name__ == "__main__":
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("build_industrial_production_per_country") snakemake = mock_snakemake("build_industrial_production_per_country")
configure_logging(snakemake)
logging.basicConfig(level=snakemake.config["logging"]["level"]) set_scenario_config(snakemake)
countries = snakemake.params.countries countries = snakemake.params.countries

View File

@ -9,11 +9,14 @@ Build future industrial production per country.
import pandas as pd import pandas as pd
from prepare_sector_network import get from prepare_sector_network import get
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("build_industrial_production_per_country_tomorrow") snakemake = mock_snakemake("build_industrial_production_per_country_tomorrow")
set_scenario_config(snakemake)
params = snakemake.params.industry params = snakemake.params.industry

View File

@ -7,6 +7,7 @@ Build industrial production per model region.
""" """
from itertools import product from itertools import product
from _helpers import set_scenario_config
import pandas as pd import pandas as pd
@ -72,5 +73,6 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
build_nodal_industrial_production() build_nodal_industrial_production()

View File

@ -7,7 +7,7 @@ Build specific energy consumption by carrier and industries.
""" """
import pandas as pd import pandas as pd
from _helpers import mute_print from _helpers import mute_print, set_scenario_config
# GWh/ktoe OR MWh/toe # GWh/ktoe OR MWh/toe
toe_to_MWh = 11.630 toe_to_MWh = 11.630
@ -1464,6 +1464,7 @@ if __name__ == "__main__":
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("build_industry_sector_ratios") snakemake = mock_snakemake("build_industry_sector_ratios")
set_scenario_config(snakemake)
# TODO make params option # TODO make params option
year = 2015 year = 2015

View File

@ -14,6 +14,8 @@ import numpy as np
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
from _helpers import configure_logging, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
if __name__ == "__main__": if __name__ == "__main__":
@ -22,7 +24,8 @@ if __name__ == "__main__":
snakemake = mock_snakemake("build_population_layouts") snakemake = mock_snakemake("build_population_layouts")
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
cutout = atlite.Cutout(snakemake.input.cutout) cutout = atlite.Cutout(snakemake.input.cutout)

View File

@ -8,6 +8,8 @@ Distribute country-level energy demands by population.
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
@ -17,6 +19,7 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0) pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0)

View File

@ -68,6 +68,7 @@ The script has the following structure:
""" """
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
from _helpers import set_scenario_config
# (i) --- FIXED PARAMETER / STANDARD VALUES ----------------------------------- # (i) --- FIXED PARAMETER / STANDARD VALUES -----------------------------------
@ -1053,6 +1054,7 @@ if __name__ == "__main__":
ll="v1.0", ll="v1.0",
sector_opts="Co2L0-168H-T-H-B-I-solar3-dist1", sector_opts="Co2L0-168H-T-H-B-I-solar3-dist1",
) )
set_scenario_config(snakemake)
# ******** config ********************************************************* # ******** config *********************************************************

View File

@ -24,6 +24,7 @@ onshore (>50km from sea), offshore (Figure 7).
import geopandas as gpd import geopandas as gpd
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
def concat_gdf(gdf_list, crs="EPSG:4326"): def concat_gdf(gdf_list, crs="EPSG:4326"):
@ -77,6 +78,8 @@ if __name__ == "__main__":
"build_salt_cavern_potentials", simpl="", clusters="37" "build_salt_cavern_potentials", simpl="", clusters="37"
) )
set_scenario_config(snakemake)
fn_onshore = snakemake.input.regions_onshore fn_onshore = snakemake.input.regions_onshore
fn_offshore = snakemake.input.regions_offshore fn_offshore = snakemake.input.regions_offshore

View File

@ -11,6 +11,8 @@ database_en>`_.
import geopandas as gpd import geopandas as gpd
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
def area(gdf): def area(gdf):
""" """
@ -39,6 +41,8 @@ if __name__ == "__main__":
"build_sequestration_potentials", simpl="", clusters="181" "build_sequestration_potentials", simpl="", clusters="181"
) )
set_scenario_config(snakemake)
cf = snakemake.params.sequestration_potential cf = snakemake.params.sequestration_potential
gdf = gpd.read_file(snakemake.input.sequestration_potential[0]) gdf = gpd.read_file(snakemake.input.sequestration_potential[0])

View File

@ -11,6 +11,7 @@ import json
import geopandas as gpd import geopandas as gpd
import pandas as pd import pandas as pd
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
@ -21,6 +22,7 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
scope = gpd.read_file(snakemake.input.scope).geometry[0] scope = gpd.read_file(snakemake.input.scope).geometry[0]
regions = gpd.read_file(snakemake.input.regions).set_index("name") regions = gpd.read_file(snakemake.input.regions).set_index("name")

View File

@ -13,6 +13,8 @@ import pandas as pd
import xarray as xr import xarray as xr
from dask.distributed import Client, LocalCluster from dask.distributed import Client, LocalCluster
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
@ -22,6 +24,7 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
nprocesses = int(snakemake.threads) nprocesses = int(snakemake.threads)
cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1) cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1)

View File

@ -12,6 +12,7 @@ import numpy as np
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
from dask.distributed import Client, LocalCluster from dask.distributed import Client, LocalCluster
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
@ -22,6 +23,7 @@ if __name__ == "__main__":
simpl="", simpl="",
clusters=48, clusters=48,
) )
set_scenario_config(snakemake)
nprocesses = int(snakemake.threads) nprocesses = int(snakemake.threads)
cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1) cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1)

View File

@ -13,7 +13,7 @@ import logging
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import xarray as xr import xarray as xr
from _helpers import configure_logging, generate_periodic_profiles from _helpers import configure_logging, generate_periodic_profiles, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -171,6 +171,7 @@ if __name__ == "__main__":
clusters=48, clusters=48,
) )
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0) pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0)

View File

@ -12,6 +12,7 @@ import geopandas as gpd
import pandas as pd import pandas as pd
from pypsa.geo import haversine_pts from pypsa.geo import haversine_pts
from shapely import wkt from shapely import wkt
from _helpers import set_scenario_config, configure_logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -105,8 +106,8 @@ if __name__ == "__main__":
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("cluster_gas_network", simpl="", clusters="37") snakemake = mock_snakemake("cluster_gas_network", simpl="", clusters="37")
configure_logging(snakemake)
logging.basicConfig(level=snakemake.config["logging"]["level"]) set_scenario_config(snakemake)
fn = snakemake.input.cleaned_gas_network fn = snakemake.input.cleaned_gas_network
df = pd.read_csv(fn, index_col=0) df = pd.read_csv(fn, index_col=0)

View File

@ -15,7 +15,7 @@ import fiona
import geopandas as gpd import geopandas as gpd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from _helpers import configure_logging from _helpers import configure_logging, set_scenario_config
from atlite.gis import shape_availability from atlite.gis import shape_availability
from rasterio.plot import show from rasterio.plot import show
@ -38,6 +38,7 @@ if __name__ == "__main__":
"determine_availability_matrix_MD_UA", technology="solar" "determine_availability_matrix_MD_UA", technology="solar"
) )
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
nprocesses = None # snakemake.config["atlite"].get("nprocesses") nprocesses = None # snakemake.config["atlite"].get("nprocesses")
noprogress = not snakemake.config["atlite"].get("show_progress", True) noprogress = not snakemake.config["atlite"].get("show_progress", True)

View File

@ -14,6 +14,7 @@ import numpy as np
import pandas as pd import pandas as pd
import pypsa import pypsa
from prepare_sector_network import prepare_costs from prepare_sector_network import prepare_costs
from _helpers import set_scenario_config, configure_logging
idx = pd.IndexSlice idx = pd.IndexSlice
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -673,7 +674,8 @@ if __name__ == "__main__":
snakemake = mock_snakemake("make_summary") snakemake = mock_snakemake("make_summary")
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
networks_dict = { networks_dict = {
(cluster, ll, opt + sector_opt, planning_horizon): "results/" (cluster, ll, opt + sector_opt, planning_horizon): "results/"

View File

@ -19,6 +19,7 @@ from make_summary import assign_carriers, assign_locations
from prepare_sector_network import prepare_costs from prepare_sector_network import prepare_costs
from pypsa.descriptors import get_active_assets from pypsa.descriptors import get_active_assets
from six import iteritems from six import iteritems
from _helpers import set_scenario_config
idx = pd.IndexSlice idx = pd.IndexSlice
@ -722,6 +723,7 @@ if __name__ == "__main__":
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("make_summary_perfect") snakemake = mock_snakemake("make_summary_perfect")
set_scenario_config(snakemake)
run = snakemake.config["run"]["name"] run = snakemake.config["run"]["name"]
if run != "": if run != "":

View File

@ -13,7 +13,7 @@ import geopandas as gpd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
import pypsa import pypsa
from _helpers import configure_logging from _helpers import configure_logging, set_scenario_config
from plot_power_network import assign_location, load_projection from plot_power_network import assign_location, load_projection
from pypsa.plot import add_legend_circles, add_legend_lines, add_legend_patches from pypsa.plot import add_legend_circles, add_legend_lines, add_legend_patches
@ -237,6 +237,7 @@ if __name__ == "__main__":
) )
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
n = pypsa.Network(snakemake.input.network) n = pypsa.Network(snakemake.input.network)

View File

@ -13,7 +13,7 @@ import geopandas as gpd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
import pypsa import pypsa
from _helpers import configure_logging from _helpers import configure_logging, set_scenario_config
from plot_power_network import assign_location, load_projection from plot_power_network import assign_location, load_projection
from pypsa.plot import add_legend_circles, add_legend_lines, add_legend_patches from pypsa.plot import add_legend_circles, add_legend_lines, add_legend_patches
@ -254,6 +254,7 @@ if __name__ == "__main__":
) )
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
n = pypsa.Network(snakemake.input.network) n = pypsa.Network(snakemake.input.network)

View File

@ -14,7 +14,7 @@ import geopandas as gpd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
import pypsa import pypsa
from _helpers import configure_logging from _helpers import configure_logging, set_scenario_config
from plot_summary import preferred_order, rename_techs from plot_summary import preferred_order, rename_techs
from pypsa.plot import add_legend_circles, add_legend_lines, add_legend_patches from pypsa.plot import add_legend_circles, add_legend_lines, add_legend_patches
@ -257,6 +257,7 @@ if __name__ == "__main__":
) )
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
n = pypsa.Network(snakemake.input.network) n = pypsa.Network(snakemake.input.network)

View File

@ -6,13 +6,13 @@
Plot clustered electricity transmission network. Plot clustered electricity transmission network.
""" """
import cartopy.crs as ccrs
import geopandas as gpd import geopandas as gpd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pypsa import pypsa
from matplotlib.lines import Line2D from matplotlib.lines import Line2D
from plot_power_network import load_projection from plot_power_network import load_projection
from pypsa.plot import add_legend_lines from pypsa.plot import add_legend_lines
from _helpers import set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
@ -23,6 +23,7 @@ if __name__ == "__main__":
clusters=128, clusters=128,
configfiles=["../../config/config.test.yaml"], configfiles=["../../config/config.test.yaml"],
) )
set_scenario_config(snakemake)
lw_factor = 2e3 lw_factor = 2e3

View File

@ -13,7 +13,7 @@ import geopandas as gpd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
import pypsa import pypsa
from _helpers import configure_logging from _helpers import configure_logging, set_scenario_config
from plot_power_network import assign_location, load_projection, rename_techs_tyndp from plot_power_network import assign_location, load_projection, rename_techs_tyndp
from plot_summary import preferred_order from plot_summary import preferred_order
from pypsa.plot import add_legend_circles, add_legend_lines from pypsa.plot import add_legend_circles, add_legend_lines
@ -184,6 +184,7 @@ if __name__ == "__main__":
) )
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
n = pypsa.Network(snakemake.input.network) n = pypsa.Network(snakemake.input.network)

View File

@ -12,6 +12,7 @@ import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
from prepare_sector_network import co2_emissions_year from prepare_sector_network import co2_emissions_year
from _helpers import configure_logging, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
plt.style.use("ggplot") plt.style.use("ggplot")
@ -572,7 +573,8 @@ if __name__ == "__main__":
snakemake = mock_snakemake("plot_summary") snakemake = mock_snakemake("plot_summary")
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake)
n_header = 4 n_header = 4

View File

@ -12,7 +12,7 @@ import re
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import pypsa import pypsa
from _helpers import update_config_with_sector_opts from _helpers import update_config_with_sector_opts, set_scenario_config, configure_logging
from add_existing_baseyear import add_build_year_to_new_assets from add_existing_baseyear import add_build_year_to_new_assets
from pypsa.descriptors import expand_series from pypsa.descriptors import expand_series
from pypsa.io import import_components_from_dataframe from pypsa.io import import_components_from_dataframe
@ -514,6 +514,8 @@ if __name__ == "__main__":
ll="v1.5", ll="v1.5",
sector_opts="1p7-4380H-T-H-B-I-A-dist1", sector_opts="1p7-4380H-T-H-B-I-A-dist1",
) )
configure_logging(snakemake)
set_scenario_config(snakemake)
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts) update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
# parameters ----------------------------------------------------------- # parameters -----------------------------------------------------------

View File

@ -18,7 +18,7 @@ import numpy as np
import pandas as pd import pandas as pd
import pypsa import pypsa
import xarray as xr import xarray as xr
from _helpers import set_scenario_config, update_config_with_sector_opts from _helpers import configure_logging, set_scenario_config, update_config_with_sector_opts
from add_electricity import calculate_annuity, sanitize_carriers, sanitize_locations from add_electricity import calculate_annuity, sanitize_carriers, sanitize_locations
from build_energy_totals import build_co2_totals, build_eea_co2, build_eurostat_co2 from build_energy_totals import build_co2_totals, build_eea_co2, build_eurostat_co2
from networkx.algorithms import complement from networkx.algorithms import complement
@ -3572,7 +3572,7 @@ if __name__ == "__main__":
planning_horizons="2030", planning_horizons="2030",
) )
logging.basicConfig(level=snakemake.config["logging"]["level"]) configure_logging(snakemake)
set_scenario_config(snakemake) set_scenario_config(snakemake)
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts) update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)

View File

@ -36,7 +36,7 @@ import logging
import tarfile import tarfile
from pathlib import Path from pathlib import Path
from _helpers import configure_logging, progress_retrieve, validate_checksum from _helpers import configure_logging, progress_retrieve, validate_checksum, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -49,9 +49,8 @@ if __name__ == "__main__":
rootpath = ".." rootpath = ".."
else: else:
rootpath = "." rootpath = "."
configure_logging( configure_logging(snakemake)
snakemake set_scenario_config(snakemake)
) # TODO Make logging compatible with progressbar (see PR #102)
if snakemake.config["tutorial"]: if snakemake.config["tutorial"]:
url = "https://zenodo.org/record/3517921/files/pypsa-eur-tutorial-data-bundle.tar.xz" url = "https://zenodo.org/record/3517921/files/pypsa-eur-tutorial-data-bundle.tar.xz"

View File

@ -12,7 +12,7 @@ import pandas as pd
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
from _helpers import configure_logging from _helpers import configure_logging, set_scenario_config
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
@ -23,6 +23,7 @@ if __name__ == "__main__":
else: else:
rootpath = "." rootpath = "."
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
url = "https://data.open-power-system-data.org/time_series/{version}/time_series_60min_singleindex.csv" url = "https://data.open-power-system-data.org/time_series/{version}/time_series_60min_singleindex.csv"

View File

@ -11,7 +11,7 @@ import logging
import zipfile import zipfile
from pathlib import Path from pathlib import Path
from _helpers import progress_retrieve, validate_checksum from _helpers import progress_retrieve, validate_checksum, set_scenario_config, configure_logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -24,6 +24,8 @@ if __name__ == "__main__":
rootpath = ".." rootpath = ".."
else: else:
rootpath = "." rootpath = "."
configure_logging(snakemake)
set_scenario_config(snakemake)
url = "https://zenodo.org/record/4767098/files/IGGIELGN.zip" url = "https://zenodo.org/record/4767098/files/IGGIELGN.zip"

View File

@ -26,7 +26,7 @@ This rule downloads the existing capacities from `IRENASTAT <https://www.irena.o
import logging import logging
import pandas as pd import pandas as pd
from _helpers import configure_logging from _helpers import configure_logging, set_scenario_config
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -80,6 +80,7 @@ if __name__ == "__main__":
snakemake = mock_snakemake("retrieve_irena") snakemake = mock_snakemake("retrieve_irena")
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake)
irena_raw = pd.read_csv( irena_raw = pd.read_csv(
"https://pxweb.irena.org:443/sq/99e64b12-fe03-4a7b-92ea-a22cc3713b92", "https://pxweb.irena.org:443/sq/99e64b12-fe03-4a7b-92ea-a22cc3713b92",

View File

@ -956,6 +956,7 @@ if __name__ == "__main__":
) )
configure_logging(snakemake) configure_logging(snakemake)
set_scenario_config(snakemake) set_scenario_config(snakemake)
if "sector_opts" in snakemake.wildcards.keys(): if "sector_opts" in snakemake.wildcards.keys():
update_config_with_sector_opts( update_config_with_sector_opts(
snakemake.config, snakemake.wildcards.sector_opts snakemake.config, snakemake.wildcards.sector_opts