• No results found

Programs for Annual and Time Slice Wise RE CF Cal- culation

Chapter 1 Introduction

B.1 Programs for Annual and Time Slice Wise RE CF Cal- culation

Appendix B

Programs and data for Chapter 4

B.1 Programs for Annual and Time Slice Wise RE CF Cal-

index_match1<-cbind.data.frame(Month, Season) Hour_n<-c(1:24)

d<-c("H01","H02","H03","H04","H05","H06", "H07", "H08", "H09", "H10","H11", "H12",

"H13", "H14", "H15", "H16", "H17", "H18", "H19", "H20", "H21", "H22", "H23", "H24") index_match2<-cbind.data.frame(Hour_n, d)

Month_day<-c(31,28,31,30,31,30, 31, 31, 30,31,30,31) day_month<-cbind.data.frame(Season, Month_day)

#read data

files_solar=list.files(path="F:/PhD/RE Supply curve/merra_soda/pvwatts_new", pattern=".csv", full.names=T, recursive=FALSE)

#create empty vectors for saving results grid_cells=NULL

ANN_CF=NULL ts_gcells<-NULL

#read data

for(i in 1:length(files_solar)){

filename_sol<-files_solar[i];

sol_pvwatts<-read.table(filename_sol, sep=',', skip=18, nrows = 8760);

sol_pvwatts<-select( sol_pvwatts, V1,V3,V8, V11)%>% rename(Month=V1, Hour=V3, IR_Module=V8, SG_AC=V11) sol_pvwatts<-mutate(sol_pvwatts, Hour_n=Hour+1)

sol_pvwatts$Month<-as.numeric(sol_pvwatts$Month)

sol_pvwatts<-left_join(sol_pvwatts, index_match1, by="Month"); sol_pvwatts<-left_join(sol_pvwatts, index_match2, by="Hour_n")

sol_pvwatts<-mutate(sol_pvwatts, ts=paste(Season,d, sep="-")) sol_pvwatts<-select(sol_pvwatts, Season, ts, IR_Module, SG_AC)

sol_pvwatts_group<-group_by(sol_pvwatts, Season, ts)%>%summarise(SG_TS=sum(SG_AC)) sol_pvwatts_group<-left_join(sol_pvwatts_group, day_month, by="Season")

sol_pvwatts_group$CF_TS<-sol_pvwatts_group$SG_TS/(sol_pvwatts_group$Month_day)/4000 sol_pvwatts_group$AFA=sum(sol_pvwatts_group$SG_TS)/(8760*4000);

sol_pvwatts_group$COM_FR=sol_pvwatts_group$SG_TS/sum(sol_pvwatts_group$SG_TS);

sol_pvwatts_group<-mutate(sol_pvwatts_group, Gid=gid_state_index$GID[i])

sol_pvwatts_final<-select(as.data.frame(sol_pvwatts_group), Gid, ts, SG_TS, AFA, CF_TS, COM_FR)

#Write data

file1<-paste("F:/PhD/RE Supply curve/merra_soda/PVWATTS_Out_Sol_New/new", "/","PVWatts_Sol_NI.xlsx", sep="") addWorksheet(wb, gid_state_index$GID[i])

writeData(wb, gid_state_index$GID[i], sol_pvwatts_final, rowNames = T )

#save output in matrix

# output[i,]<-sol_pvwatts_final$CF_TS

grid_cells=as.vector(append(grid_cells, gid_state_index$GID[i])) ANN_CF=as.vector(append(ANN_CF, sol_pvwatts_final$AFA[1])) ts_gcells<-as.matrix(cbind(ts_gcells, sol_pvwatts_final$CF_TS))

#colnames(ts_gcells, grid_cells) }

B.1 Programs for Annual and Time Slice Wise RE CF Calculation 169

saveWorkbook(wb, file1, overwrite = TRUE)

colnames(ts_gcells)<-grid_cells; rownames(ts_gcells)<-sol_pvwatts_final$ts grid_CF = data.frame(grid_cells, ANN_CF)

write.xlsx(grid_CF, "F:/PhD/RE Supply curve/merra_soda/PVWATTS_Out_Sol_New/new/sol_AFA.xlsx")

write.xlsx(ts_gcells, "F:/PhD/RE Supply curve/merra_soda/PVWATTS_Out_Sol_New/new/ts_sol_gcells.xlsx", rowNames = TRUE)

#---End of program---

B.1.2 R Program for Time Slice Wise Wind CF Calculation

#---

# wind_merra.r

# ---A program for annual and time slice wise wind capacity factor calculation for each grid-cell ---- library(dplyr)

library(openxlsx) library(ggplot2) library(ggthemes) library(reshape2)

# http://www.suzlon.com/products/S111#parentHorizontalTab5

#turbine technical specs rp<-2.1

cin<-3 cout<-21 cr<-10 sa<-9817 rho<-1.225 cp<-.35

#wind speed extrapolation to hub height Z1<-10

Z2<-120 sh<-1/7

gid_state_index<-read.xlsx("F:/PhD/RE Supply curve/merra_soda/new_index.xlsx", sheet=1);

wb<-createWorkbook("test") Month<-c(1:12)

#Season<-c("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG",

"SEP", "OCT", "NOV", "DEC")

Season<-c("01-JAN", "02-FEB", "03-MAR", "04-APR", "05-MAY", "06-JUN",

"07-JUL", "08-AUG", "09-SEP", "10-OCT", "11-NOV", "12-DEC") index_match1<-cbind.data.frame(Month, Season)

Hour<-c(1:24)

d<-c("H01","H02","H03","H04","H05","H06", "H07", "H08", "H09", "H10","H11", "H12",

"H13", "H14", "H15", "H16", "H17", "H18", "H19", "H20", "H21", "H22", "H23", "H24") index_match2<-cbind.data.frame(Hour, d)

Month_day<-c(31,28,31,30,31,30, 31, 31, 30,31,30,31) day_month<-cbind.data.frame(Season, Month_day)

#create empty vectors for saving results

grid_cells=NULL ANN_CF=NULL ts_gcells<-NULL

#read data

files=list.files(path="F:/PhD/RE Supply curve/merra_soda/merra_new_data/Data_1", pattern=".csv", full.names=T, recursive=FALSE)

for(i in 1:2){

filename<-files[i];

merra<-read.table(filename, sep=';', skip=21);

sep=';', skip=21); head(merra)

merra<-select(merra, V1,V2,V6)%>% rename(Date=V1, Hour=V2, WS_10=V6) merra<-mutate(merra, WS_p=WS_10*(Z2/Z1)^sh)

merra<-mutate(merra, Year=as.numeric(substr(Date,1,4)),

Month=as.numeric(substr(Date,6,7)), Day=as.numeric(substr(Date,9,10))) merra$Hour=as.numeric(merra$Hour);

merra<-left_join(merra, index_match1, by="Month"); merra<-left_join(merra, index_match2, by="Hour") merra<-mutate(merra, ts=paste(Season,d, sep="-"))

merra<-select(merra, Season, ts, WS_10, WS_p)

#wind generation calculation

merra<-mutate(merra, WG=ifelse((WS_p>=cin & WS_p<=cr), 0.5*rho*(WS_p^3)*sa*cp/10^6,ifelse((WS_p>=cr & WS_p<=cout),rp,0)))

#merra<-mutate(merra, WG=0.5*rho*(WS_80m^3)*sa*cp/10^6)

merra_group<-group_by(merra, Season, ts)%>%summarise(WG_TS=sum(WG)/37) merra_group<-left_join(merra_group, day_month, by="Season")

merra_group$CF_TS<-merra_group$WG_TS/(merra_group$Month_day*rp) merra_group$AFA=sum(merra_group$WG_TS)/(8760*rp);

merra_group$COM_FR=merra_group$WG_TS/sum(merra_group$WG_TS);

#merra_group<-mutate(merra_group, Pset_PN=paste("T_WIN_",gid_state_index$GID[i])) merra_final<-select(as.data.frame(merra_group), ts, WG_TS, AFA, CF_TS, COM_FR)

#Write data

file1<-paste("F:/PhD/RE Supply curve/merra_soda/MERRA_Out_Win_New_test/120", "/","merra_win_NI.xlsx", sep="") addWorksheet(wb, gid_state_index$GID[i])

writeData(wb, gid_state_index$GID[i], merra_final, rowNames = T )

#save output in matrix

grid_cells=as.vector(append(grid_cells, gid_state_index$GID[i])) ANN_CF=as.vector(append(ANN_CF, merra_final$AFA[1]))

ts_gcells<-as.matrix(cbind(ts_gcells, merra_final$CF_TS)) }

saveWorkbook(wb, file1, overwrite = TRUE)

colnames(ts_gcells)<-grid_cells; rownames(ts_gcells)<-merra_final$ts grid_CF = data.frame(grid_cells, ANN_CF)

write.xlsx(grid_CF, "F:/PhD/RE Supply curve/merra_soda/MERRA_Out_Win_New_test/120/win_AFA.xlsx")

write.xlsx(ts_gcells, "F:/PhD/RE Supply curve/merra_soda/MERRA_Out_Win_New_test/120/ts_win_gcells.xlsx", rowNames = TRUE)

B.1 Programs for Annual and Time Slice Wise RE CF Calculation 171

#---End of program---