【发布时间】:2017-11-10 19:13:48
【问题描述】:
我正在尝试从一系列 .nc 文件中提取海面温度数据。 所以我有一个文件夹,其中包含 30 个下载的 .nc 文件,所有文件都写成“1981.nc”、“1982.nc”等。
但不是单独加载它们,我想循环遍历每个文件并计算每个文件的平均温度,所以最后我会有 30 个温度值。
问题是每个文件的日期参数必须更改年份。我想在提取年份值的文件中包含years<-substr(filenames, 1,4) 之类的内容,但它不起作用。
我正在考虑以下几点:
library(ncdf4)
setwd("C:\\Users\\Desktop\\sst")
source("C:\\Users\\Desktop\\NOAA_OISST_ncdf4.R")
out.file<-""
filenames <- dir(pattern =".nc")
years<-substr(filenames, 1,4)
lst <- vector("list", length(filenames ))
for (i in 1:length(filenames)) {
ssts = extractOISSTdaily(filenames[i], "C:\\Users\\Desktop\\lsmask.oisst.v2.nc",
lonW=350,lonE=351,latS=52,latN=56,date1='years[i]-11-23', date2='years[i]-12-31')
mean(ssts)
}
这里描述了用于提取的extractOISSTdaily函数:http://lukemiller.org/index.php/2014/11/extracting-noaa-sea-surface-temperatures-with-ncdf4/
.nc 文件在这里:https://www.esrl.noaa.gov/psd/data/gridded/data.noaa.oisst.v2.highres.html#detail
【问题讨论】: