2018-01-29 21:28:33 +00:00
|
|
|
#!/usr/bin/env python
|
2022-09-16 13:04:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-05-29 07:50:55 +00:00
|
|
|
|
2023-02-16 10:50:55 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
|
2020-05-29 07:50:55 +00:00
|
|
|
#
|
2021-09-14 14:37:41 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
2019-08-11 20:34:18 +00:00
|
|
|
Build hydroelectric inflow time-series for each country.
|
2019-08-08 13:02:28 +00:00
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Relevant Settings
|
|
|
|
-----------------
|
|
|
|
|
2019-08-11 11:17:36 +00:00
|
|
|
.. code:: yaml
|
|
|
|
|
|
|
|
countries:
|
|
|
|
|
|
|
|
renewable:
|
|
|
|
hydro:
|
|
|
|
cutout:
|
|
|
|
clip_min_inflow:
|
|
|
|
|
2019-11-14 16:50:24 +00:00
|
|
|
.. seealso::
|
2023-04-21 08:41:44 +00:00
|
|
|
Documentation of the configuration file ``config/config.yaml`` at
|
2019-08-13 08:03:46 +00:00
|
|
|
:ref:`toplevel_cf`, :ref:`renewable_cf`
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Inputs
|
|
|
|
------
|
|
|
|
|
2019-08-12 17:01:53 +00:00
|
|
|
- ``data/bundle/EIA_hydro_generation_2000_2014.csv``: Hydroelectricity net generation per country and year (`EIA <https://www.eia.gov/beta/international/data/browser/#/?pa=000000000000000000000000000000g&c=1028i008006gg6168g80a4k000e0ag00gg0004g800ho00g8&ct=0&ug=8&tl_id=2-A&vs=INTL.33-12-ALB-BKWH.A&cy=2014&vo=0&v=H&start=2000&end=2016>`_)
|
|
|
|
|
2023-03-09 12:28:42 +00:00
|
|
|
.. image:: img/hydrogeneration.png
|
2019-08-12 17:01:53 +00:00
|
|
|
:scale: 33 %
|
|
|
|
|
2019-08-11 20:34:18 +00:00
|
|
|
- ``resources/country_shapes.geojson``: confer :ref:`shapes`
|
|
|
|
- ``"cutouts/" + config["renewable"]['hydro']['cutout']``: confer :ref:`cutout`
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Outputs
|
|
|
|
-------
|
|
|
|
|
2019-08-11 20:34:18 +00:00
|
|
|
- ``resources/profile_hydro.nc``:
|
|
|
|
|
2019-08-12 21:48:16 +00:00
|
|
|
=================== ================ =========================================================
|
|
|
|
Field Dimensions Description
|
|
|
|
=================== ================ =========================================================
|
|
|
|
inflow countries, time Inflow to the state of charge (in MW),
|
|
|
|
e.g. due to river inflow in hydro reservoir.
|
|
|
|
=================== ================ =========================================================
|
|
|
|
|
2023-03-09 12:28:42 +00:00
|
|
|
.. image:: img/inflow-ts.png
|
2019-08-13 13:48:21 +00:00
|
|
|
:scale: 33 %
|
2019-11-14 16:50:24 +00:00
|
|
|
|
2023-03-09 12:28:42 +00:00
|
|
|
.. image:: img/inflow-box.png
|
2019-08-13 13:48:21 +00:00
|
|
|
:scale: 33 %
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Description
|
|
|
|
-----------
|
|
|
|
|
|
|
|
.. seealso::
|
2019-08-12 17:01:53 +00:00
|
|
|
:mod:`build_renewable_profiles`
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
2018-01-29 21:28:33 +00:00
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
import logging
|
|
|
|
|
2018-01-29 21:28:33 +00:00
|
|
|
import atlite
|
2022-09-16 13:04:04 +00:00
|
|
|
import country_converter as coco
|
2018-08-03 09:53:14 +00:00
|
|
|
import geopandas as gpd
|
2022-03-28 10:02:08 +00:00
|
|
|
import pandas as pd
|
2022-09-16 13:04:04 +00:00
|
|
|
from _helpers import configure_logging
|
2022-03-28 10:02:08 +00:00
|
|
|
|
|
|
|
cc = coco.CountryConverter()
|
|
|
|
|
|
|
|
|
|
|
|
def get_eia_annual_hydro_generation(fn, countries):
|
|
|
|
# in billion kWh/a = TWh/a
|
2023-01-06 20:51:49 +00:00
|
|
|
df = pd.read_csv(
|
|
|
|
fn, skiprows=2, index_col=1, na_values=[" ", "--"], decimal=","
|
|
|
|
).iloc[1:, 1:]
|
2022-03-28 10:02:08 +00:00
|
|
|
df.index = df.index.str.strip()
|
|
|
|
|
2022-07-20 11:01:14 +00:00
|
|
|
former_countries = {
|
|
|
|
"Former Czechoslovakia": dict(
|
2023-01-06 20:51:33 +00:00
|
|
|
countries=["Czechia", "Slovakia"], start=1980, end=1992
|
2022-09-16 13:04:04 +00:00
|
|
|
),
|
2022-07-20 11:01:14 +00:00
|
|
|
"Former Serbia and Montenegro": dict(
|
2022-09-16 13:04:04 +00:00
|
|
|
countries=["Serbia", "Montenegro"], start=1992, end=2005
|
|
|
|
),
|
2022-07-20 11:01:14 +00:00
|
|
|
"Former Yugoslavia": dict(
|
2022-09-16 13:04:04 +00:00
|
|
|
countries=[
|
|
|
|
"Slovenia",
|
|
|
|
"Croatia",
|
|
|
|
"Bosnia and Herzegovina",
|
|
|
|
"Serbia",
|
|
|
|
"Montenegro",
|
|
|
|
"North Macedonia",
|
|
|
|
],
|
|
|
|
start=1980,
|
|
|
|
end=1991,
|
|
|
|
),
|
2022-07-20 11:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v in former_countries.items():
|
2022-09-16 13:04:04 +00:00
|
|
|
period = [str(i) for i in range(v["start"], v["end"] + 1)]
|
|
|
|
ratio = df.loc[v["countries"]].T.dropna().sum()
|
2022-07-20 11:01:14 +00:00
|
|
|
ratio /= ratio.sum()
|
2022-09-16 13:04:04 +00:00
|
|
|
for country in v["countries"]:
|
2022-07-20 11:01:14 +00:00
|
|
|
df.loc[country, period] = df.loc[k, period] * ratio[country]
|
|
|
|
|
|
|
|
baltic_states = ["Latvia", "Estonia", "Lithuania"]
|
2022-09-16 13:04:04 +00:00
|
|
|
df.loc[baltic_states] = (
|
|
|
|
df.loc[baltic_states].T.fillna(df.loc[baltic_states].mean(axis=1)).T
|
|
|
|
)
|
2022-07-20 11:01:14 +00:00
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
df.loc["Germany"] = df.filter(like="Germany", axis=0).sum()
|
|
|
|
df.loc["Serbia"] += df.loc["Kosovo"].fillna(0.0)
|
|
|
|
df = df.loc[~df.index.str.contains("Former")]
|
2022-07-20 11:01:14 +00:00
|
|
|
df.drop(["Europe", "Germany, West", "Germany, East", "Kosovo"], inplace=True)
|
2022-03-28 10:02:08 +00:00
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
df.index = cc.convert(df.index, to="iso2")
|
|
|
|
df.index.name = "countries"
|
2022-03-28 10:02:08 +00:00
|
|
|
|
|
|
|
df = df.T[countries] * 1e6 # in MWh/a
|
|
|
|
|
|
|
|
return df
|
|
|
|
|
2018-01-29 21:28:33 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
if __name__ == "__main__":
|
2022-09-16 13:04:04 +00:00
|
|
|
if "snakemake" not in globals():
|
2019-12-09 20:29:15 +00:00
|
|
|
from _helpers import mock_snakemake
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
snakemake = mock_snakemake("build_hydro_profile")
|
2019-11-28 07:22:52 +00:00
|
|
|
configure_logging(snakemake)
|
2019-12-09 20:29:15 +00:00
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
params_hydro = snakemake.params.hydro
|
2022-01-24 18:48:26 +00:00
|
|
|
cutout = atlite.Cutout(snakemake.input.cutout)
|
2019-08-08 13:02:28 +00:00
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
countries = snakemake.params.countries
|
2022-09-16 13:04:04 +00:00
|
|
|
country_shapes = (
|
|
|
|
gpd.read_file(snakemake.input.country_shapes)
|
|
|
|
.set_index("name")["geometry"]
|
|
|
|
.reindex(countries)
|
|
|
|
)
|
|
|
|
country_shapes.index.name = "countries"
|
2018-01-29 21:28:33 +00:00
|
|
|
|
2022-03-28 10:02:08 +00:00
|
|
|
fn = snakemake.input.eia_hydro_generation
|
|
|
|
eia_stats = get_eia_annual_hydro_generation(fn, countries)
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
inflow = cutout.runoff(
|
|
|
|
shapes=country_shapes,
|
|
|
|
smooth=True,
|
|
|
|
lower_threshold_quantile=True,
|
|
|
|
normalize_using_yearly=eia_stats,
|
|
|
|
)
|
|
|
|
|
2023-05-17 17:25:45 +00:00
|
|
|
if "clip_min_inflow" in params_hydro:
|
|
|
|
inflow = inflow.where(inflow > params_hydro["clip_min_inflow"], 0)
|
2018-12-21 12:44:59 +00:00
|
|
|
|
2022-01-24 18:48:26 +00:00
|
|
|
inflow.to_netcdf(snakemake.output[0])
|