Commit eb64ea9d authored by Toni's avatar Toni
Browse files

Plotting custom ticks for y-axis

Modified how price of electricity is handled and plotted
parent fc59b506
......@@ -210,12 +210,12 @@ Parameters
p_stepLength(mType, f, t) "Length of an interval in hours"
p_stepLengthNoReset(mType, f, t) "Length of an interval in hours - includes also lengths of previously realized intervals"
p_s_discountFactor(s) "Discount factor for samples when using a multi-year horizon"
p_price_el_select "Use flat price 1 EUR/MWh (set 0). Use elspot price (set 1)"
;
* --- Energy modelling for buildings -----------------------------------------
Parameters
ts_priceElspot(t) "Elspot prices (EUR/MWh)"
ts_priceElspot_backup(t) "Elspot Prices_2013 inc. tarifs and taxes (backup) (EUR/MWh)"
building_squares(node_building) "Building square meters (m2)"
c2k "Convert celcius to kelvin degrees"
;
......@@ -92,6 +92,7 @@ $loaddc gnss_bound
$loaddc uss_bound
* Energy modelling for buildings
$loaddc ts_priceElspot
$loaddc ts_priceElspot_backup
$loaddc node_building
$loaddc node_building_DHWT
$loaddc node_building_envelope_mass
......@@ -104,7 +105,6 @@ $loaddc unit_DHW
$loaddc unit_heat_and_cool
$loaddc node_building2unit
$loaddc building_squares c2k
$loaddc p_price_el_select
$gdxin
......
......@@ -24,13 +24,8 @@ Parameter
*node_building_DHWT node_building_envelope_mass node_building_interior_air_and_furniture node_building_internal_mass
*ts_priceElspotNode(node_building_DHWT,t)=ts_priceElspot(t);
*ts_priceElspotNode(node_building_interior_air_and_furniture,t)=ts_priceElspot(t);
if(0=p_price_el_select,
ts_priceElspotNode("link_node",t)=1$ts_priceElspot(t);
elseif 1=p_price_el_select,
ts_priceElspotNode("link_node",t)=ts_priceElspot(t);
else
abort "Error, invalid value for p_price_el_select, set 0 or 1";
);
ts_priceElspotNode("link_node",t)=ts_priceElspot(t);
q_obj ..
+ v_obj * 1e6 // Objective function valued in MEUR instead of EUR (or whatever monetary unit the data is in)
......
......@@ -118,9 +118,10 @@ Set
tsIso Time-stamp in ISO8601 format
;
Parameters
elspotIsoBB(t,tsIso) "Elspot Prices_2013 (EUR/MWh) with backbone timestamp and ISO date"
ts_priceElspotNP(t) "Elspot NordPool Prices_2013 (EUR/MWh)"
ts_priceElspot(t) "Elspot Prices_2013 inc. tarifs and taxes (EUR/MWh)"
elspotIsoBB(t,tsIso) "Elspot Prices_2013 (EUR/MWh) with backbone timestamp and ISO date"
ts_priceElspotNP(t) "Elspot NordPool Prices_2013 (EUR/MWh)"
ts_priceElspot(t) "Elspot Prices_2013 inc. tarifs and taxes (EUR/MWh)"
ts_priceElspot_backup(t) "Elspot Prices_2013 inc. tarifs and taxes (backup) (EUR/MWh)"
;
$gdxIn input\elspot_prices_2013.gdx
$load tsIso elspotIsoBB ts_priceElspotNP=elspotBB
......@@ -131,11 +132,20 @@ $gdxin
* Ignoring basic fee: 0,24 snt/kWh --> 2,4 /MWh
* https://www.sahkon-kilpailutus.fi/en/market-electricity-price/
ts_priceElspot(t)=ts_priceElspotNP(t) + 22.53 + 2.4
ts_priceElspot(t)=ts_priceElspotNP(t) + 22.53 + 2.4 ;
ts_priceElspot_backup(t)=ts_priceElspot(t);
*Setting
Parameter p_price_el_select "Use flat price 1 EUR/MWh (set 0). Use elspot price (set 1)" /0/;
if(0=p_price_el_select,
ts_priceElspot(t)=1$ts_priceElspot(t);
elseif 1=p_price_el_select,
ts_priceElspot(t)=ts_priceElspot(t);
else
abort "Error, invalid value for p_price_el_select, set 0 or 1";
);
* Adding temperature data
Parameter
......
......@@ -37,6 +37,10 @@ suppressMessages(library(this.path))
custom_x_axis_tick_distance = 24
max_nr_of_custom_x_axis_ticks = 20
# Use custom y-axis ticks distance for graphs (0 disabled)
custom_y_axis_tick_distance = 10
max_nr_of_custom_y_axis_ticks = 21
#Preprocessing : set working directory
r_dir <- this.dir()
print(paste("Rscript working directory:",r_dir,sep=" "))
......@@ -195,7 +199,6 @@ if (!is.null(opt$window) && !is.na(opt$window)) {
df_p[,1] <- ordered(df_p[,1])
levels(df_p[,1]) <- 1:nrow(unique(df_p[1]))
df_p[,1] <- as.numeric(as.character(df_p[,1]))
xvar_tail = tail(df_p[,1],n=1)
# Prepare plot p(x,y)
xvar <- sym(colnames(df_p)[1])
......@@ -269,11 +272,12 @@ if(!empty(df_p2)){
geom_line(data=df_p2, aes(x=!!xvar2, y=!!value2*scaleFactor, group=df_p2_index2_ordered, linetype=df_p2_index2_ordered)) +
scale_y_continuous(
name = paste(value, "-axis. ", ylabel),
breaks = get_custom_x_axis_breaks(custom_y_axis_tick_distance, max_nr_of_custom_y_axis_ticks, df_p[,3]),
sec.axis = sec_axis(~./scaleFactor, name=paste(value2, "-axis. ",zlabel))) +
scale_linetype_discrete(name = paste(value2))+
guides(linetype=guide_legend(ncol=3))
}
g3 <- g2 + scale_x_continuous(breaks = get_custom_x_axis_breaks(custom_x_axis_tick_distance, max_nr_of_custom_x_axis_ticks, 10, xvar_tail))
g3 <- g2 + scale_x_continuous(breaks = get_custom_x_axis_breaks(custom_x_axis_tick_distance, max_nr_of_custom_x_axis_ticks, df_p[,1]))
#g3_copy<-g3 # to avoid errors we create a copy, g2 changes with switch -w
#plot(g3_copy)
......@@ -291,8 +295,7 @@ if(window_step>=1){
}
xlabel <- paste(xvar_desc,xvar,"(",xvar_labels[window_curr_start,1],"=",window_curr_start,", ...,",xvar_labels[window_curr_end,1],"=",window_curr_end,")")
g4 <- g2 +xlab(xlabel) + coord_cartesian(xlim = c(window_curr_start,window_curr_end), expand=0)+
scale_x_continuous(breaks = get_custom_x_axis_breaks(custom_x_axis_tick_distance, max_nr_of_custom_x_axis_ticks, window_step, xvar_tail))
scale_x_continuous(breaks = get_custom_x_axis_breaks(custom_x_axis_tick_distance, max_nr_of_custom_x_axis_ticks, df_p[,1], window_step))
print(g4)
cnt_plots=cnt_plots+1
}
......
......@@ -3,13 +3,20 @@
# Author: Toni Lastusilta (VTT) 2022/01
# Function to set custom distance for x-axis tick marks or return default on failure
get_custom_x_axis_breaks <- function(custom_x_axis_tick_distance, max_nr_of_custom_x_axis_ticks, window_step, xvar_tail){
#print(paste("Input: custom_x_axis_tick_distance",custom_x_axis_tick_distance,"max_nr_of_custom_x_axis_ticks",max_nr_of_custom_x_axis_ticks,"window_step, xvar_tail",window_step, "xvar_tail",xvar_tail," (defines last element of full x-range)"))
nr_x_axis_tick_marks= window_step%/%24
if(nr_x_axis_tick_marks > max_nr_of_custom_x_axis_ticks){
print(paste("Custom x-axis tick marks ignored. nr_x_axis_tick_marks(",nr_x_axis_tick_marks,") > max_nr_of_custom_x_axis_ticks(",max_nr_of_custom_x_axis_ticks,")"))
# window_step == 0 (disabled)
get_custom_x_axis_breaks <- function(axis_tick_distance, max_nr_of_axis_ticks, axis_vec, window_step=0, x_round_denom=10){
minval_in = min(axis_vec)
minval_used = (floor(minval_in)%/%x_round_denom)*x_round_denom
maxval_used = ceiling(max(axis_vec))
if(window_step<=0){
window_step=axis_range = abs(maxval_used- minval_used)
}
# debug print(paste("Input: axis_tick_distance",axis_tick_distance,"max_nr_of_axis_ticks",max_nr_of_axis_ticks,"window_step",window_step, "minval_in",minval_in,"minval_used",minval_used, "maxval_used",maxval_used))
nr_axis_tick_marks= window_step%/%axis_tick_distance
if(nr_axis_tick_marks > max_nr_of_axis_ticks || nr_axis_tick_marks<3){
print(paste("Custom axis tick marks ignored. 3 <= nr_axis_tick_marks(",nr_axis_tick_marks,") <= max_nr_of_axis_ticks(",max_nr_of_axis_ticks,")"))
waiver()
} else {
seq(0,xvar_tail,by=custom_x_axis_tick_distance)
seq(minval_used,maxval_used,by=axis_tick_distance)
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ $offtext
* Set TRUE or FALSE
$set archive FALSE
* Set file name prefix for archivation
$set archive_prefix 2022-01-XX_Testing
$set archive_prefix 2022-01-19_TESTING_Case_flat_elec_price
$set archive_exec 0
$if "%archive%"=="TRUE" $set archive_exec 1
......
......@@ -52,12 +52,12 @@ tmp_cost("cost_ideal_heating_by_m2",node_building,tparam(t)) = max(0, tmp_cost(
tmp_cost("cost_ideal_cooling_by_m2",node_building,tparam(t)) = max(0, tmp_cost("cost_ideal_cooling_by_m2",node_building,t) );
tmp_cost("cost_ideal_DHW_by_m2" ,node_building,tparam(t)) = max(0, tmp_cost("cost_ideal_DHW_by_m2" ,node_building,t) );
tmp_cost("cost_tot_by_m2",node_building,tparam(t)) = max(0, tmp_cost("cost_tot_by_m2",node_building,t) );
* calculate cost : ts_priceElspot
summary("cost_ideal_heating_by_m2",node_building) = sum(tparam(t),ts_priceElspot(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_ideal_heating_by_m2",node_building,t));
summary("cost_ideal_cooling_by_m2",node_building) = sum(tparam(t),ts_priceElspot(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_ideal_cooling_by_m2",node_building,t));
summary("cost_ideal_DHW_by_m2" ,node_building) = sum(tparam(t),ts_priceElspot(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_ideal_DHW_by_m2" ,node_building,t));
summary("cost_tot_by_m2",node_building) = sum(tparam(t),ts_priceElspot(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_tot_by_m2" ,node_building,t));
summary("cost_tot",node_building) = sum(tparam(t),ts_priceElspot(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_tot" ,node_building,t));
* calculate cost : ts_priceElspot_backup
summary("cost_ideal_heating_by_m2",node_building) = sum(tparam(t),ts_priceElspot_backup(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_ideal_heating_by_m2",node_building,t));
summary("cost_ideal_cooling_by_m2",node_building) = sum(tparam(t),ts_priceElspot_backup(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_ideal_cooling_by_m2",node_building,t));
summary("cost_ideal_DHW_by_m2" ,node_building) = sum(tparam(t),ts_priceElspot_backup(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_ideal_DHW_by_m2" ,node_building,t));
summary("cost_tot_by_m2",node_building) = sum(tparam(t),ts_priceElspot_backup(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_tot_by_m2" ,node_building,t));
summary("cost_tot",node_building) = sum(tparam(t),ts_priceElspot_backup(t) * e_per_Mw_2_e_per_kw * tmp_cost("cost_tot" ,node_building,t));
*Error checks
error_elec_tot = sum(node_building,summary("elec_tot_kWh_by_m2",node_building) - (
summary("elec_ideal_heating_kWh_by_m2",node_building) +
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment