r - 倾斜表面辐射的 solarR 时间戳

标签 r time-series

我正在尝试使用 R 包 solaR 来计算倾斜平面上的辐照度,给定水平面上的测量辐照度。我可以让代码工作,但最终输出时间戳没有意义。

可以找到此代码的数据 here .这是德克萨斯州奥斯汀一天的测量辐照度值(全局水平 -- ghz、直接法线 -- dir、漫射水平 -- dhz 和室外温度 ta)。时间戳是本地“CST6CDT”时间。数据为晴天,因此全局水平(ghz)的最大值应大致对应于太阳正午(太阳穿过本地子午线的时间)。

我的代码如下:

library(solaR)

sol_data <- read.csv(file)

    # The data must be named a certain way.
names(sol_data) <- c('time', 'G0', 'B', 'D0', 'Ta')

    # The negatives are an artifact of the sensor and are set to 0.
sol_data$G0 <- ifelse(sol_data$G0 < 0, 0, sol_data$G0)
sol_data$B <- ifelse(sol_data$B < 0, 0, sol_data$B)
sol_data$D0 <- ifelse(sol_data$D0 < 0, 0, sol_data$D0)

# This calculates the beam incidence on the horizontal plane. 
sol_data$B0 <- sol_data$G0 - sol_data$D0
sol_data$B0 <- ifelse(sol_data$B0 < 0, 0, sol_data$B0)

    # This takes the data and assigns the timestamp to a certain format and timezone
idxLocal <- with(sol_data, as.POSIXct(time, format='%Y-%m-%d %H:%M:%S', tz = 'CST6CDT'))
    # This converts the timestamp to solar time
idx <- local2Solar(idxLocal, lon = -97.7428)

    # Creates a zoo object needed to make the Meteo file for input
z <- zoo(sol_data[,c('G0', 'D0', 'B0', 'Ta')], idx)

    # local latitude
lat = 30.2669

    # Creates a Meteo file
My_Meteo <- zoo2Meteo(z, lat=lat)


# Finds the start and end date of the input file
start <- idx[1] 
end <- idx[length(idx)] 

    # Returns a base time for the calculations
BTd <- fBTd(mode = 'serie', year = '2013', start = start, end = end, format = '%Y-%m-%d %H:%M:%S')
    # Computes the movement of the sun/earth
sol <- calcSol(lat = 30.2669, BTd, sample = 'min')

# Creates a G0 file for solar rad on horizontal surface
compI <- calcG0(30.2669, modeRad = 'bdI', dataRad = My_Meteo, corr = 'none')
    # creates the angles for calculation of the rad on a tilted surface
angGen <- fTheta(sol = sol, beta = 0, alfa = 0)
    # Calculates the irradiance on a tilted surface
irad_tilt <- fInclin(compI, angGen)

当我使用 beta = 0, alfa = 0(平面)时,我应该得到与我的输入大致相同的输出。但是,当我搜索全局水平辐照度的最大值时:

x <- which.max(irad_tilt$G) 
irad_tilt[x,]

我让它在 2013-05-05 10:43:01 返回最大值,但我无法弄清楚这次是什么/为什么会这样。现在不是本地时间,应该是13:24左右。本地太阳时应在 12:00 左右。 UTC时间应该是18:24左右,UTC太阳时(如果有的话)应该是17:00...

我知道这很晦涩,但有什么想法吗?

最佳答案

我已经在我的电脑上测试过代码和数据正确 结果。让我们用一些图形重现主要步骤 输出:

library(solaR)

sol_data <- read.csv('/tmp/one_day_WSL_8.csv')

## The data must be named a certain way.
names(sol_data) <- c('time', 'G0', 'B', 'D0', 'Ta')

## The negatives are an artifact of the sensor and are set to 0.
sol_data$G0 <- ifelse(sol_data$G0 < 0, 0, sol_data$G0)
sol_data$B <- ifelse(sol_data$B < 0, 0, sol_data$B)
sol_data$D0 <- ifelse(sol_data$D0 < 0, 0, sol_data$D0)

## This calculates the beam incidence on the horizontal plane.
sol_data$B0 <- sol_data$G0 - sol_data$D0
sol_data$B0 <- ifelse(sol_data$B0 < 0, 0, sol_data$B0)

## This takes the data and assigns the timestamp to a certain format and timezone
idxLocal <- with(sol_data, as.POSIXct(time, format='%Y-%m-%d %H:%M:%S', tz = 'CST6CDT'))

local2Solar 函数将 POSIXct 对象的时区转换为平太阳时,并将其时区设置为 UTC,作为平太阳时的同义词。它包括两个校正:位置和时区之间的经度差异,以及夏令时。

idx <- local2Solar(idxLocal, lon = -97.7428)

## Creates a zoo object needed to make the Meteo file for input
z <- zoo(sol_data[,c('G0', 'D0', 'B0', 'Ta')], idx)

因为你的数据属于晴天,而这个时间序列使用 平均太阳时,最大值应位于中午左右。

xyplot(z, type=c('l', 'g'))

data with mean solar time

现在我们使用 calcSol 计算太阳几何。我在这里使用 与您不同的代码。

## local latitude
lat = 30.2669
## Computes the movement of the sun/earth
sol <- calcSol(lat, BTi=idx)

xyplot(as.zooI(sol), type=c('l', 'g'))

sun geometry

接下来我们计算水平面上的辐射。

g0 <- calcG0(lat, modeRad = 'bdI', dataRad = z, corr = 'none')

xyplot(as.zooI(g0), type=c('l', 'g'))

horizontal irradiance

最后,我们使用 calcGef 获得倾斜表面上的辐照度:

gef <- calcGef(lat=lat, modeRad='bdI', dataRad=z)

xyplot(as.zooI(gef), type=c('l', 'g'))

irradiance on the tilted plane

我怀疑您的问题与定义的时区有关 你的电脑。你能检查一下这些结果吗?:

lonHH('America/Chicago')
## [1] -1.570796
lonHH('CDT6CST')
## [1] -1.570796

idxLocal1 <- as.POSIXct(sol_data$time, format='%Y-%m-%d %H:%M:%S', tz = 'CST6CDT')
idxLocal2 <- as.POSIXct(sol_data$time, format='%Y-%m-%d %H:%M:%S', tz = 'America/Chicago')

idxUTC1 <- as.POSIXct(format(idxLocal1, tz='UTC'), tz='UTC')
idxUTC2 <- as.POSIXct(format(idxLocal2, tz='UTC'), tz='UTC')

all.equal(idxUTC1, idxUTC2)
## [1] TRUE

也许这些技术说明对于有关的附加信息很有用 本主题:

此外,你应该看看help(timezone)的信息和例子。

关于r - 倾斜表面辐射的 solarR 时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17197654/

相关文章:

R - 将频率为 20 分钟的时间序列放入函数 STL()

r - 我如何让 ggplot 每天打破 x 轴?

r - 使用 matchit{MatchIt} 为 r 中的每个案例个体匹配 2 个控制匹配

r - 为什么我的 dplyr group_by & summarise 无法正常工作? (与 plyr 的名称冲突)

r - 如何在 nnet 包中的 multinom() 中设置特定对比度?

根据 R 中特定列中的值替换所有行值

python - 在 pandas 数据帧上滚动 720 分钟

r - 如何在 R 中重新采样和插入时间序列数据?

c# - 在 C# 中管理时间序列

r - ggplot : Boxplot by several categorical variables