我试图使用R软件包solaR来计算水平平面上的全球、扩散和光束辐照度,使用气象站的全球水平数据作为输入。我想计算84个气象站一小时读数的结果。这涉及到在循环中运行calcG0,但我在理解错误消息时遇到了问题。
我的数据在csv文件中,如下所示:
日期,Lat,Long,G0 23/07/201312:00,54.02441365,-8.110721855,565.452 23/07/201312:00,54.87162166,-8.238676542,289.398 23/07/201312:00,53.79503931,-8.077173903,240.192
我已经修改了以下代码来源:
solaR timestamp for radiation on a tilted surface
http://www.r-bloggers.com/maps-of-solar-radiation/
详情如下:
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)
}我得到以下错误消息“error in rvali,j,drop = drop.,.:下标超出界限”。这似乎表明我的循环不够大,但我已经获得了行数。我尝试过各种列表和数据格式的辐照度数据,但这并不能解决问题。如有任何建议,将不胜感激。
发布于 2014-08-04 18:28:25
calcG0是为时间序列设计的fSolD、fSolI和fCompI的包装器。它不能正确地工作,只有一行。解决方案是自己计算每一步。在这种情况下,这是非常容易的,因为你只需要在水平平面上的辐射成分。
library(solaR)
vals <- read.csv(text = "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")
lat <- vals$Lat
lon <- vals$Long
G0 <- vals$G0
## Correct time using longitude and time zone information
idxLocal <- as.POSIXct(vals$Date, tz="Europe/London", format='%d/%m/%Y %H:%M')
idxSun <- local2Solar(idxLocal, lon)
comp <- lapply(seq_len(nrow(vals)),
FUN = function(i){
## Sun geometry
sol <- calcSol(lat[i], BTi = idxSun[i],
method = 'spencer')
## Radiation components (horizontal plane)
compI <- fCompI(sol, G0I = G0[i],
corr = "EKDh")
## Join results
res <- cbind(compI, as.zooI(sol),
cbind(lat = lat[i], lon = lon[i]))
})
comp <- do.call(rbind, comp)这就是结果,一个由索引(indexSun)排序的indexSun。
> comp
kt fd G0 D0 B0 w
2013-07-23 10:27:02 0.2828014 0.9592704 289.398 277.6109 11.787074 -0.4323576
2013-07-23 10:27:33 0.5470501 0.5574753 565.452 315.2255 250.226467 -0.4301032
2013-07-23 10:27:41 0.2317589 0.9780899 240.192 234.9294 5.262642 -0.4295214
aman cosThzS AlS AzS Bo0 rd
2013-07-23 10:27:02 1 0.7732174 0.8838992 -0.6686494 1023.326 0.09543889
2013-07-23 10:27:33 1 0.7810095 0.8962807 -0.6769279 1033.638 0.09609447
2013-07-23 10:27:41 1 0.7830865 0.8996133 -0.6792742 1036.387 0.09626831
rg lat lon
2013-07-23 10:27:02 0.1020801 54.87162 -8.238677
2013-07-23 10:27:33 0.1027433 54.02441 -8.110722
2013-07-23 10:27:41 0.1029189 53.79504 -8.077174发布于 2014-08-01 13:14:36
看起来,您将z定义为一个带有3列c('Lat‘、'Long’、'G0')列的动物园对象,但随后试图引用sol =动物园中的第4列(zi,1,as.numeric(zi,2:4))。在动物园对象中,索引不是列,而是作为索引(Z)或时间(Z)引用的(在您的例子中)。
https://stackoverflow.com/questions/25079738
复制相似问题