Skip to content

Commit

Permalink
Merge pull request #68 from rl-institut/features/prepare-ror-timeseries
Browse files Browse the repository at this point in the history
Preparation of ROR timeseries
  • Loading branch information
juliusmeier authored Oct 28, 2021
2 parents b53190f + 82fb51a commit b90f821
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ docs/_build
*.egg
*.egg-info
dist
build
build
gurobi.log
5 changes: 3 additions & 2 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ rule prepare_feedin:
input:
wind_feedin="raw/time_series/ninja_wind_country_DE_current_merra-2_nuts-2_corrected.csv",
pv_feedin="raw/time_series/ninja_pv_country_DE_merra-2_nuts-2_corrected.csv",
ror_feedin="raw/time_series/DIW_Hydro_availability.csv",
script="scripts/prepare_feedin.py"
output:
"results/_resources/feedin_time_series.csv"
shell:
"python {input.script} {input.wind_feedin} {input.pv_feedin} {output}"
"python {input.script} {input.wind_feedin} {input.pv_feedin} {input.ror_feedin} {output}"

rule build_datapackage:
input:
Expand Down Expand Up @@ -159,4 +160,4 @@ rule plot_joined_scalars:
output:
directory("results/joined_scenarios/{scenario_list}/joined_plotted/")
shell:
"python scripts/plot_joined_scalars.py {input} {output}"
"python scripts/plot_joined_scalars.py {input} {output}"
76 changes: 66 additions & 10 deletions scripts/prepare_feedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
Description
-------------
This script prepares wind and pv feed-in time series for the regions Berlin and Brandenburg. Raw
data is read from csvs from https://www.renewables.ninja/ and then formatted to fit the time series
template for oemof-B3.
This script prepares wind, pv and run-of-the-river (ror) feed-in time series for the regions Berlin
and Brandenburg. Raw data is read from csvs from https://www.renewables.ninja/ (wind+pv) and
https://zenodo.org/record/1044463 (ror) and is then formatted to fit the time series template of
oemof-B3 (`schema/timeseries.csv`).
"""

# todo ROR could be included here

import sys
import pandas as pd
import os
import oemof_b3.tools.data_processing as dp

# global variables
# specific to wind and pv time series
RE_NINJA_YEARS = list(
range(2010, 2020)
) # re ninja wind+pv time series are prepared for these years
Expand All @@ -37,9 +37,14 @@
TS_VAR_UNIT = "None"
TS_SOURCE = "https://www.renewables.ninja/"
TS_COMMENT = "navigate to country Germany"
# specific to ror time series
REGIONS = ["BB", "B"]
TS_SOURCE_ROR = "https://zenodo.org/record/1044463"
TS_COMMENT_ROR = "Isolated ror availability time series from DIW data"
YEAR_ROR = 2017


def prepare_time_series(filename_ts, year, type):
def prepare_wind_and_pv_time_series(filename_ts, year, type):
r"""
Prepares and formats time series of `type` 'wind' or 'pv' for region 'B' and 'BB'.
Expand All @@ -55,7 +60,7 @@ def prepare_time_series(filename_ts, year, type):
Returns
-------
ts_prepared : pd.DataFrame
Contains time series in the format of template in `filename_template`
Contains time series in the format of time series template of oemof-B3
"""
# load raw time series and copy data frame
Expand Down Expand Up @@ -87,29 +92,80 @@ def prepare_time_series(filename_ts, year, type):
return ts_prepared


def prepare_ror_time_series(filename_ts, region):
r"""
Prepares and formats run-of-the-river (ror) time series for region 'B' and 'BB'.
Parameters
----------
filename_ts : str
Path including file name to ror time series of DIW Data Documentation 92
region : str
Region of time series; used for column 'region' in output
Returns
-------
ts_prepared : pd.DataFrame
Contains time series in the format of time series template of oemof-B3
"""
# load raw time series and copy data frame
ts_raw = pd.read_csv(filename_ts, index_col=0, skiprows=3, delimiter=";")
time_series = ts_raw.copy()

time_series.index = pd.date_range(
f"{YEAR_ROR}-01-01 00:00:00", f"{YEAR_ROR}-12-31 23:00:00", 8760
)
# bring time series to oemof-B3 format with `stack_timeseries()` and `format_header()`
ts_stacked = dp.stack_timeseries(time_series).rename(columns={"var_name": "region"})
ts_prepared = dp.format_header(
df=ts_stacked, header=dp.HEADER_B3_TS, index_name="id_ts"
)

# add additional information as required by template
ts_prepared.loc[:, "region"] = region
ts_prepared.loc[:, "var_unit"] = TS_VAR_UNIT
ts_prepared.loc[:, "var_name"] = "ror-profile"
ts_prepared.loc[:, "source"] = TS_SOURCE_ROR
ts_prepared.loc[:, "comment"] = TS_COMMENT_ROR
ts_prepared.loc[:, "scenario"] = f"ts_{YEAR_ROR}"

return ts_prepared


if __name__ == "__main__":
filename_wind = sys.argv[1]
filename_pv = sys.argv[2]
output_file = sys.argv[3]
filename_ror = sys.argv[3]
output_file = sys.argv[4]

# initialize data frame
time_series_df = pd.DataFrame()

# prepare time series for each year
for year in RE_NINJA_YEARS:
# prepare wind time series
wind_ts = prepare_time_series(
wind_ts = prepare_wind_and_pv_time_series(
filename_ts=filename_wind,
year=year,
type="wind",
)

# prepare pv time series
pv_ts = prepare_time_series(filename_ts=filename_pv, year=year, type="pv")
pv_ts = prepare_wind_and_pv_time_series(
filename_ts=filename_pv, year=year, type="pv"
)

# add time series to `time_series_df`
time_series_df = pd.concat([time_series_df, wind_ts, pv_ts], axis=0)

# prepare ror time series
for region in REGIONS:
ror_ts = prepare_ror_time_series(filename_ts=filename_ror, region=region)

# add time series to `time_series_df`
time_series_df = pd.concat([time_series_df, ror_ts], axis=0)

# set index
time_series_df.index = range(0, len(time_series_df))

Expand Down
10 changes: 5 additions & 5 deletions tests/test_prepare_feedin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from pandas.util.testing import assert_frame_equal, assert_series_equal

from scripts.prepare_feedin import prepare_time_series
from scripts.prepare_feedin import prepare_wind_and_pv_time_series
from oemof_b3.tools.data_processing import load_b3_timeseries, save_df

# Paths
Expand All @@ -20,8 +20,8 @@
)


def test_prepare_time_series_wind():
df = prepare_time_series(
def test_prepare_wind_and_pv_time_series_wind():
df = prepare_wind_and_pv_time_series(
filename_ts=filename_wind,
year=2012, # in the test files only years 2010, 2012 and 2013 are included
type="wind",
Expand All @@ -46,8 +46,8 @@ def test_prepare_time_series_wind():
os.remove(temp_filename)


def test_prepare_time_series_pv():
df = prepare_time_series(
def test_prepare_wind_and_pv_time_series_pv():
df = prepare_wind_and_pv_time_series(
filename_ts=filename_pv,
year=2012, # in the test files only years 2010, 2012 and 2013 are included
type="pv",
Expand Down

0 comments on commit b90f821

Please sign in to comment.