multiyear: fallbacks for hydro and load profiles
This commit is contained in:
parent
ca0ad08438
commit
dacfc8a9a4
@ -166,6 +166,8 @@ if config['enable'].get('retrieve_natura_raster', True):
|
|||||||
script: 'scripts/retrieve_natura_raster.py'
|
script: 'scripts/retrieve_natura_raster.py'
|
||||||
|
|
||||||
|
|
||||||
|
ruleorder: build_hydro_profile > build_renewable_profiles
|
||||||
|
|
||||||
rule build_renewable_profiles:
|
rule build_renewable_profiles:
|
||||||
input:
|
input:
|
||||||
base_network="networks/base.nc",
|
base_network="networks/base.nc",
|
||||||
|
@ -169,6 +169,7 @@ transformers:
|
|||||||
|
|
||||||
load:
|
load:
|
||||||
scaling_factor: 1.0
|
scaling_factor: 1.0
|
||||||
|
fallback_year: 2013
|
||||||
|
|
||||||
costs:
|
costs:
|
||||||
year: 2030
|
year: 2030
|
||||||
|
@ -147,6 +147,7 @@ transformers:
|
|||||||
|
|
||||||
load:
|
load:
|
||||||
scaling_factor: 1.0
|
scaling_factor: 1.0
|
||||||
|
fallback_year: 2013
|
||||||
|
|
||||||
costs:
|
costs:
|
||||||
year: 2030
|
year: 2030
|
||||||
|
@ -212,11 +212,28 @@ def attach_load(n):
|
|||||||
substation_lv_i = n.buses.index[n.buses['substation_lv']]
|
substation_lv_i = n.buses.index[n.buses['substation_lv']]
|
||||||
regions = (gpd.read_file(snakemake.input.regions).set_index('name')
|
regions = (gpd.read_file(snakemake.input.regions).set_index('name')
|
||||||
.reindex(substation_lv_i))
|
.reindex(substation_lv_i))
|
||||||
# TODO: is there a fallback if year not in timeseries_opsd?
|
|
||||||
opsd_load = (timeseries_opsd(slice(*n.snapshots[[0,-1]].year.astype(str)),
|
available_years = range(2011,2016)
|
||||||
|
requested_years = n.snapshots.year[[0,-1]]
|
||||||
|
use_fallback = any(year not in available_years for year in requested_years)
|
||||||
|
|
||||||
|
if use_fallback:
|
||||||
|
fallback_year = str(snakemake.config["load"]["fallback_year"])
|
||||||
|
load_years = [fallback_year, fallback_year]
|
||||||
|
logger.warning(f"Requested years {list(requested_years.unique().values)} "
|
||||||
|
f"for load time series not in available years {list(available_years)}. "
|
||||||
|
f"Falling back to year {fallback_year}.")
|
||||||
|
else:
|
||||||
|
load_years = requested_years.astype(str)
|
||||||
|
|
||||||
|
opsd_load = (timeseries_opsd(slice(*load_years),
|
||||||
snakemake.input.opsd_load) *
|
snakemake.input.opsd_load) *
|
||||||
snakemake.config.get('load', {}).get('scaling_factor', 1.0))
|
snakemake.config.get('load', {}).get('scaling_factor', 1.0))
|
||||||
|
|
||||||
|
if use_fallback:
|
||||||
|
assert len(requested_years.unique()) == 1, "Fallback for load time series requires single year!"
|
||||||
|
opsd_load.index = opsd_load.index.map(lambda t: t.replace(year=requested_years[0]))
|
||||||
|
|
||||||
# Convert to naive UTC (has to be explicit since pandas 0.24)
|
# Convert to naive UTC (has to be explicit since pandas 0.24)
|
||||||
opsd_load.index = opsd_load.index.tz_localize(None)
|
opsd_load.index = opsd_load.index.tz_localize(None)
|
||||||
|
|
||||||
|
@ -75,15 +75,23 @@ if __name__ == "__main__":
|
|||||||
snakemake = mock_snakemake('build_hydro_profile')
|
snakemake = mock_snakemake('build_hydro_profile')
|
||||||
configure_logging(snakemake)
|
configure_logging(snakemake)
|
||||||
|
|
||||||
|
year = snakemake.wildcards.year
|
||||||
config = snakemake.config['renewable']['hydro']
|
config = snakemake.config['renewable']['hydro']
|
||||||
cutout_dir = os.path.dirname(snakemake.input.cutout)
|
cutout_dir = os.path.dirname(snakemake.input.cutout)
|
||||||
cutout = atlite.Cutout(config['cutout'], cutout_dir=cutout_dir)
|
cutout_config = config['cutout']
|
||||||
|
if year: cutout_config = cutout_config.format(year=year)
|
||||||
|
|
||||||
|
cutout = atlite.Cutout(cutout_config, cutout_dir=cutout_dir)
|
||||||
|
|
||||||
countries = snakemake.config['countries']
|
countries = snakemake.config['countries']
|
||||||
country_shapes = gpd.read_file(snakemake.input.country_shapes).set_index('name')['geometry'].reindex(countries)
|
country_shapes = gpd.read_file(snakemake.input.country_shapes).set_index('name')['geometry'].reindex(countries)
|
||||||
country_shapes.index.name = 'countries'
|
country_shapes.index.name = 'countries'
|
||||||
|
|
||||||
eia_stats = vhydro.get_eia_annual_hydro_generation(snakemake.input.eia_hydro_generation).reindex(columns=countries)
|
eia_stats = vhydro.get_eia_annual_hydro_generation(snakemake.input.eia_hydro_generation).reindex(columns=countries)
|
||||||
|
|
||||||
|
if year not in eia_stats.index:
|
||||||
|
eia_stats.loc[year] = eia_stats.mean()
|
||||||
|
|
||||||
inflow = cutout.runoff(shapes=country_shapes,
|
inflow = cutout.runoff(shapes=country_shapes,
|
||||||
smooth=True,
|
smooth=True,
|
||||||
lower_threshold_quantile=True,
|
lower_threshold_quantile=True,
|
||||||
|
@ -282,14 +282,16 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
pgb.streams.wrap_stderr()
|
pgb.streams.wrap_stderr()
|
||||||
|
|
||||||
config = snakemake.config['renewable'][snakemake.wildcards.technology]
|
|
||||||
|
|
||||||
year = snakemake.wildcards.year
|
year = snakemake.wildcards.year
|
||||||
|
config = snakemake.config['renewable'][snakemake.wildcards.technology]
|
||||||
|
cutout_name = config['cutout']
|
||||||
|
if year: cutout_name = cutout_name.format(year=year)
|
||||||
|
|
||||||
snapshots = dict(start=year, end=str(int(year)+1), closed="left") if year else snakememake.config['snapshots']
|
snapshots = dict(start=year, end=str(int(year)+1), closed="left") if year else snakememake.config['snapshots']
|
||||||
time = pd.date_range(freq='m', **snapshots)
|
time = pd.date_range(freq='m', **snapshots)
|
||||||
params = dict(years=slice(*time.year[[0, -1]]), months=slice(*time.month[[0, -1]]))
|
params = dict(years=slice(*time.year[[0, -1]]), months=slice(*time.month[[0, -1]]))
|
||||||
|
|
||||||
cutout = atlite.Cutout(config['cutout'],
|
cutout = atlite.Cutout(cutout_name,
|
||||||
cutout_dir=os.path.dirname(snakemake.input.cutout),
|
cutout_dir=os.path.dirname(snakemake.input.cutout),
|
||||||
**params)
|
**params)
|
||||||
|
|
||||||
|
@ -147,6 +147,7 @@ transformers:
|
|||||||
|
|
||||||
load:
|
load:
|
||||||
scaling_factor: 1.0
|
scaling_factor: 1.0
|
||||||
|
fallback_year: 2013
|
||||||
|
|
||||||
costs:
|
costs:
|
||||||
year: 2030
|
year: 2030
|
||||||
|
Loading…
Reference in New Issue
Block a user