我正在尝试使用 rnoaa 包下载 NOAA 数据,但遇到了一些麻烦。
我从数据框中获取了一个向量,它看起来像这样:
df <- dataframe$ghcnd
抓取必要的列
这给了我这样的输出:
[1] "GHCND:US1AKAB0058" "GHCND:US1AKAB0015" "GHCND:US1AKAB0021" "GHCND:US1AKAB0061"
[5] "GHCND:US1AKAB0055" "GHCND:US1AKAB0038" "GHCND:US1AKAB0051" "GHCND:US1AKAB0052"
[9] "GHCND:US1AKAB0060" "GHCND:US1AKAB0065" "GHCND:US1AKAB0062" "GHCND:US1AKFN0016"
[13] "GHCND:US1AKFN0018" "GHCND:US1AKFN0015" "GHCND:US1AKFN0011" "GHCND:US1AKFN0013"
[17] "GHCND:US1AKFN0030" "GHCND:US1AKJB0011" "GHCND:US1AKJB0014" "GHCND:US1AKKP0005"
[21] "GHCND:US1AKMS0011" "GHCND:US1AKMS0019" "GHCND:US1AKMS0012" "GHCND:US1AKMS0020"
[25] "GHCND:US1AKMS0018" "GHCND:US1AKMS0014" "GHCND:US1AKPW0001" "GHCND:US1AKSH0002"
[29] "GHCND:US1AKVC0006" "GHCND:US1AKWH0012" "GHCND:US1AKWP0001" "GHCND:US1AKWP0002"
[33] "GHCND:US1ALAT0014" "GHCND:US1ALAT0013" "GHCND:US1ALBW0095" "GHCND:US1ALBW0087"
[37] "GHCND:US1ALBW0020" "GHCND:US1ALBW0066" "GHCND:US1ALBW0031" "GHCND:US1ALBW0082"
[41] "GHCND:US1ALBW0099" "GHCND:US1ALBW0040" "GHCND:US1ALBW0004" "GHCND:US1ALBW0085"
[45] "GHCND:US1ALBW0009" "GHCND:US1ALBW0001" "GHCND:US1ALBW0094" "GHCND:US1ALBW0013"
[49] "GHCND:US1ALBW0079" "GHCND:US1ALBW0060"
实际上,我有大约 22,000 个气象站。这只是显示前 50 个。
核酸编码
library(rnoaa)
options("noaakey" = Sys.getenv("noaakey"))
Sys.getenv("noaakey")
weather <- ncdc(datasetid = 'GHCND', stationid = df, var = 'PRCP', startdate = "2020-05-30",
enddate = "2020-05-30", add_units = TRUE)
这会产生以下错误:
Error: Request-URI Too Long (HTTP 414)
但是,当我将 df 子集为前 100 个条目时,我无法获取超过前 25 个的数据。但是,包详细信息表明我应该能够每天运行 10,000 个查询。
循环尝试
df1 <- df[1:125] ## Splitting dataframe. Too big otherwise
for (i in 1:length(df1)){
weather2<-ncdc(datasetid = 'GHCND', stationid=df1[i],var='PRCP',startdate ='2020-06-30',enddate='2020-06-30',
add_units = TRUE)
}
但这只是产生单行的数据框,该行是第 125 个气象站。
如果有人可以就下一步尝试什么提供建议,那就太好了:)
此外,交叉链接:https ://discuss.ropensci.org/t/rnoaa-getting-county-level-rain-data/2403