-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild_hydro_profile.py
More file actions
157 lines (118 loc) · 4.58 KB
/
build_hydro_profile.py
File metadata and controls
157 lines (118 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build hydroelectric inflow time-series for each country.
Relevant Settings
-----------------
.. code:: yaml
countries:
renewable:
hydro:
cutout:
clip_min_inflow:
.. seealso::
Documentation of the configuration file ``config/config.yaml`` at
:ref:`toplevel_cf`, :ref:`renewable_cf`
Inputs
------
- ``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>`_)
.. image:: img/hydrogeneration.png
:scale: 33 %
- ``resources/country_shapes.geojson``: confer :ref:`shapes`
- ``"cutouts/" + config["renewable"]['hydro']['cutout']``: confer :ref:`cutout`
Outputs
-------
- ``resources/profile_hydro.nc``:
=================== ================ =========================================================
Field Dimensions Description
=================== ================ =========================================================
inflow countries, time Inflow to the state of charge (in MW),
e.g. due to river inflow in hydro reservoir.
=================== ================ =========================================================
.. image:: img/inflow-ts.png
:scale: 33 %
.. image:: img/inflow-box.png
:scale: 33 %
Description
-----------
.. seealso::
:mod:`build_renewable_profiles`
"""
import logging
import atlite
import country_converter as coco
import geopandas as gpd
import pandas as pd
from _helpers import configure_logging
cc = coco.CountryConverter()
def get_eia_annual_hydro_generation(fn, countries):
# in billion kWh/a = TWh/a
df = pd.read_csv(fn, skiprows=2, index_col=1, na_values=[" ", "--"]).iloc[1:, 1:]
df.index = df.index.str.strip()
former_countries = {
"Former Czechoslovakia": dict(
countries=["Czech Republic", "Slovakia"], start=1980, end=1992
),
"Former Serbia and Montenegro": dict(
countries=["Serbia", "Montenegro"], start=1992, end=2005
),
"Former Yugoslavia": dict(
countries=[
"Slovenia",
"Croatia",
"Bosnia and Herzegovina",
"Serbia",
"Montenegro",
"North Macedonia",
],
start=1980,
end=1991,
),
}
for k, v in former_countries.items():
period = [str(i) for i in range(v["start"], v["end"] + 1)]
ratio = df.loc[v["countries"]].T.dropna().sum()
ratio /= ratio.sum()
for country in v["countries"]:
df.loc[country, period] = df.loc[k, period] * ratio[country]
baltic_states = ["Latvia", "Estonia", "Lithuania"]
df.loc[baltic_states] = (
df.loc[baltic_states].T.fillna(df.loc[baltic_states].mean(axis=1)).T
)
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")]
df.drop(["Europe", "Germany, West", "Germany, East", "Kosovo"], inplace=True)
df.index = cc.convert(df.index, to="iso2")
df.index.name = "countries"
df = df.T[countries] * 1e6 # in MWh/a
return df
logger = logging.getLogger(__name__)
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("build_hydro_profile")
configure_logging(snakemake)
config_hydro = snakemake.config["renewable"]["hydro"]
cutout = atlite.Cutout(snakemake.input.cutout)
countries = snakemake.config["countries"]
country_shapes = (
gpd.read_file(snakemake.input.country_shapes)
.set_index("name")["geometry"]
.reindex(countries)
)
country_shapes.index.name = "countries"
fn = snakemake.input.eia_hydro_generation
eia_stats = get_eia_annual_hydro_generation(fn, countries)
inflow = cutout.runoff(
shapes=country_shapes,
smooth=True,
lower_threshold_quantile=True,
normalize_using_yearly=eia_stats,
)
if "clip_min_inflow" in config_hydro:
inflow = inflow.where(inflow > config_hydro["clip_min_inflow"], 0)
inflow.to_netcdf(snakemake.output[0])