首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >循环中的SolaR包

循环中的SolaR包
EN

Stack Overflow用户
提问于 2014-08-01 11:56:37
回答 2查看 207关注 0票数 0

我试图使用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/

详情如下:

代码语言:javascript
运行
复制
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.,.:下标超出界限”。这似乎表明我的循环不够大,但我已经获得了行数。我尝试过各种列表和数据格式的辐照度数据,但这并不能解决问题。如有任何建议,将不胜感激。

EN

Stack Overflow用户

回答已采纳

发布于 2014-08-04 18:28:25

calcG0是为时间序列设计的fSolDfSolIfCompI的包装器。它不能正确地工作,只有一行。解决方案是自己计算每一步。在这种情况下,这是非常容易的,因为你只需要在水平平面上的辐射成分。

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
> 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
票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25079738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档