Skip to content

2 examples from R #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ coverage.xml

# Pycharm
.idea

# data for r examples
session3_r/data/time_series_60min_singleindex.csv

16 changes: 16 additions & 0 deletions session3_r/data/results_ubrmskript.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Scenario,Total Cost,Emissions,Emission Cost,Effective Cost
EUA160,36565865.34,73998.29,11839726.76,24726138.58
s1 ,17449018.62,310000,1834182.25,15614836.37
s2 ,17582040.87,290000,1718150.62,15863890.25
s3 ,17758154.39,270000,1599613.6,16158540.79
s4 ,17967819.71,250000,1482636.85,16485182.86
s5 ,18226832.31,230000,1362914.56,16863917.75
s6 ,18553157.49,210000,1246233.1,17306924.39
s7 ,19024149.18,190000,1129364.67,17894784.51
s8 ,19609195.86,170000,1009683.16,18599512.7
s9 ,20269960.94,150000,891754.21,19378206.73
s10 ,21065706.54,130000,774290.22,20291416.32
s11 ,22048343.39,110000,658222.07,21390121.32
s12,23399710.17,90000,540872.81,22858837.36
s13,25866808.68,70000,423623.79,25443184.89
s14,33875183.48,50000,303411.2,33571772.28
Binary file added session3_r/figures/figure_multi_objective.pdf
Binary file not shown.
Binary file added session3_r/figures/figure_multi_objective.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions session3_r/scripts/emissions_figure.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
library(tidyverse)
library(ggplot)
# Plot Figure on Multi-Objective Analysis of electricity systems
# for UBRM-Book/Chapter 6.1

### Set Working Directory - works in R-Studio only
scriptDir<-dirname(rstudioapi::getActiveDocumentContext()$path)
setwd(paste0(scriptDir,"/../"))


tab_emissions_costs<-read_csv("data/results_ubrmskript.csv")

points_scenarios<-tab_emissions_costs %>%
filter(Scenario %in% c("EUA160","s8")) %>%
mutate(Szenario=Scenario)

points_scenarios$Szenario<-c("160 Euro CO2-Preis","170 Millionen tCO2 Limit")

erc_colors<-c("#C72321","#6E9B9E")

tab_emissions_costs %>% ggplot(aes(x=Emissions/1000,y=`Effective Cost`/10^6)) +
geom_line() +
geom_point() +
theme_bw() +
xlab("Emissionen (Millionen tCO2/Jahr)") +
ylab("Brennstoff- und Kapitalkosten des Stromsystems (Milliarden Euro/Jahr)") +
geom_point(data=points_scenarios,aes(x=Emissions/1000,y=`Effective Cost`/10^6,col=Szenario,shape=Szenario),size=5) +
scale_color_manual(values=c(erc_colors,erc_colors))


ggsave("figures/figure_multi_objective.png")

ggsave("figures/figure_multi_objective.pdf")
52 changes: 52 additions & 0 deletions session3_r/scripts/market_value_renewables.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Calculates the market value of renewables (Wind and PV) for the German market
# using Open Power System Data

library(ggplot2)
library(tidyverse)
library(wesanderson)

### Set Working Directory - works in R-Studio only
scriptDir<-dirname(rstudioapi::getActiveDocumentContext()$path)
setwd(paste0(scriptDir,"/../"))

# Download file from open power system data (opsd)

opsd_filename<-"data/time_series_60min_singleindex.csv"

if(!file.exists(opsd_filename)){
download.file("https://data.open-power-system-data.org/time_series/2018-06-30/time_series_60min_singleindex.csv",
destfile=opsd_filename)
}

opsd<-read.csv(opsd_filename,sep=",") %>%
as_tibble()

SECONDS_PER_HOUR <- 3600
MWH_TO_GWH <- 1/1000
TO_PERCENT <- 100

opsd$utc_timestamp<-strptime(as.character(opsd$utc_timestamp),format="%Y-%m-%dT%H:%M:%SZ")
opsd$cet_cest_timestamp<-opsd$utc_timestamp + SECONDS_PER_HOUR

market_value<-opsd %>%
select(-utc_timestamp) %>%
mutate(year=year(cet_cest_timestamp)) %>%
filter(year>2009&year<2018) %>%
select(year,DE_price_day_ahead,DE_wind_generation_actual,DE_solar_generation_actual,DE_load_entsoe_power_statistics) %>%
gather(Generation_Type,Generation,-year,-DE_price_day_ahead,-DE_load_entsoe_power_statistics) %>%
mutate(Price=as.numeric(DE_price_day_ahead),
Generation=as.numeric(Generation)*MWH_TO_GWH,
Load=as.numeric(DE_load_entsoe_power_statistics)*MWH_TO_GWH) %>%
mutate(Market_Value=Generation*Price) %>%
group_by(year,Generation_Type) %>%
summarize(Market_Value=mean(Market_Value,na.rm=TRUE)/(mean(Generation,na.rm=TRUE)*mean(Price,na.rm=TRUE)),
Load=sum(Load,na.rm=TRUE),
Generation_Share=TO_PERCENT*sum(Generation,na.rm=TRUE)/Load) %>%
na.omit()

market_value %>% ggplot(aes(x=Generation_Share,y=Market_Value)) +
xlab("Market Share (%)") + ylab("Normalized Market Value") +
scale_color_brewer("",type="qual",palette=2) +
geom_line(aes(col=Generation_Type),size=1,linetype=1) +
geom_point(aes(col=Generation_Type),size=2)