获取多年月度温度数据的栅格文件,其名称可通过以下格式“Jan.1981”、“Feb.1981”等访问(使用以下names(object)
代码的两年示例文件- 添加所有文件让它太大了。
使用以下代码将其读入并将其写入 NetCDF:
#Load Packages
library(raster)
library(ncdf4)
#Read in temperature files
r1 <- brick('TavgM_1981.grd')
r2 <- brick('TavgM_1982.grd')
#stack them together
TempStack = stack(r1, r2)
#set the coordinate system (as it was missing)
crs(TempStack) <- ('+proj=lcc +lat_1=53.5 +lat_2=53.5 +lat_0=46.834 +lon_0=5 +x_0=1488375 +y_0=-203375 +datum=WGS84 +to_meter=2500 +no_defs +ellps=WGS84 +towgs84=0,0,0')
#reproject to get in lat/lon instead of meters
TempStack<-projectRaster(TempStack, crs=CRS("+init=epsg:4326"))
#Extract monthly data names to assign to netCDf later
names <- names(TempStack)
#write the raster file to NetCDF
writeRaster(TempStack, "Temp.nc", overwrite=TRUE, format="CDF", varname="Temperature", varunit="degC",
longname="Temperature -- raster stack to netCDF, monthly average", xname="Longitude", yname="Latitude", zname='Time', zunit=names)
当我将其写入 NetCDF 并绘制从第 1 个月到第 24 个月组织的月度数据时,但我希望它具有“1981 年 1 月”、“1981 年 2 月”等。
我认为通过在 writeRaster 中添加 zunit 参数会起作用,但事实并非如此,数字仍然是 1-24 而不是 Jan、Feb 等。