r - 如何通过循环R下载每年的数据
问题描述
我可以使用下面的脚本下载一年(即 2008 年)的数据,详情可在此处找到:
library (ecmwfr)
# Specify the data set
request <- list("dataset" = "reanalysis-era5-pressure-levels",
"product_type" = "reanalysis",
"variable" = "temperature",
"pressure_level" = "850",
"year" = "2008",
"month" = "04",
"day" = "04",
"time" = "00:00",
"area" = "70/-20/30/60",
"format" = "netcdf",
"target" = "era5-demo.nc")
# Start downloading the data, the path of the file
# will be returned as a variable (ncfile)
ncfile <- wf_request(user = "2088",
request = request,
transfer = TRUE,
path = "~",
verbose = FALSE)
问题:如何使用上面的代码下载 2008-2017 年期间的数据?下载的文件名应附加特定年份。
解决方案
library(foreach)
library (ecmwfr)
foreach(i=c(2008:2017))%do%{
# Specify the data set
request <- list("dataset" = "reanalysis-era5-pressure-levels",
"product_type" = "reanalysis",
"variable" = "temperature",
"pressure_level" = "850",
"year" = paste0(i),
"month" = "04",
"day" = "04",
"time" = "00:00",
"area" = "70/-20/30/60",
"format" = "netcdf",
"target" = paste0("era5-demo_",i,".nc"))
# Start downloading the data, the path of the file
# will be returned as a variable (ncfile)
ncfile <- wf_request(user = "2088",
request = request,
transfer = TRUE,
path = "~",
verbose = FALSE)
}
此外,专业提示:veloxV1 ( https://cran.r-project.org/src/contrib/Archive/velox/ ) 在提取光栅值时比光栅包快约 10 倍。一定要使用 veloxV1,v2 有问题。
推荐阅读
- php - PHP 代码已替换为 '0000 0000 0000 0000....'
- python - Conda 环境与第三方软件冲突
- amazon-web-services - 在 aws 和 gcp 之间 Ping
- ansible - 使用列表变量通过 apt 安装软件列表
- php - 如何按照条件在表格中划线?
- reactjs - 使用 react-native-svg 的不变违规
- c++ - 当这段代码执行时,它没有显示输出。这是为什么?
- here-api - Here Fleet Telematics CalculateRoute 服务无法使用 api 密钥访问
- python - 为什么 PyPy 中没有名为 queue 的模块?
- git - 解析 heroku.yml 的问题 - build.web 是一个被禁止的属性