I am trying to use the R package solaR to calculate global, diffuse and beam irradiance on the horizontal plane, using weather stations’ global horizontal data as input. I would like to calculate results for 84 weather stations for a one-hour reading. This involves running calcG0 in a loop, but I’m having problems understanding the error messages.
My data is in a csv file like the following sample:
Date, Lat, Long, G0
23/07/2013 12:00, 54.02441365, -8.110721855, 565.452
23/07/2013 12:00, 54.87162166, -8.238676542, 289.398
23/07/2013 12:00, 53.79503931, -8.077173903, 240.192
I’ve adapted the following sources of code:
solaR timestamp for radiation on a tilted surface
http://www.r-bloggers.com/maps-of-solar-radiation/
As follows:
sun <- read.csv("D:/R_Data_Test/solaR/12noon23July13.csv")
# This takes the data and assigns the timestamp to a certain format and timezone
idx <- as.POSIXct(sun$Date, tz="Europe/London", format='%d/%m/%Y %H:%M')
#This pads the time stamps with an "epsilon" (1.0e-7) increment to make them unique
#make.index.unique(idx)
# Creates a zoo object needed to make the Meteo file for input
z <- zoo(sun[,c('Lat', 'Long','G0')], make.index.unique(idx))
N=nrow(sun)
for (i in 1:N){
lat = as.numeric(sun[i,2])
sol = zoo(z[i,1],as.numeric(z[i,2:4]))
g0 <- calcG0(lat = lat, modeRad = 'bdI', dataRad = sol, keep.night=TRUE, sunGeometry='spencer', corr ="EKDh")
print(i)
print(lat)
print(sol)
print(g0)
}
I get the following error message “Error in rval[i, j, drop = drop., ...] : subscript out of bounds”. This seems to suggest my loop is not big enough but I’ve obtained the number of rows. I have tried various list and dataframe formats for my irradiance data but this does not solve the problem. Any suggestions would be much appreciated.