一般而言,我对netCDF数据和空间数据非常陌生,如果我的问题不是很清楚,请对不起。
我正在使用R,我的目标是从可以为downloaded here的温度数据中提取栅格。
我运行以下代码:
pathname <- ".../"
filename <- "tas_Amon_IPSL-CM6A-LR_ssp126_r1i1p1f1_gr_201501-210012"
file <- nc_open(paste0(pathname, filename, '.nc'))
# get longitude, latitude and time
lon <- ncvar_get(file,"lon")
lat <- ncvar_get(file,"lat")
# get time
time <- ncvar_get(file,"time")
nt <- dim(time)
tunits <- ncatt_get(file,"time","units")
# get the variable and convert as rasterBrick
thevar <- ncvar_get(file, 'tas')
thevar_b <- brick(thevar)
# take a slice of it and plot as image
thevar_slice <- thevar[,,1]
image(lon,lat,thevar_slicev, col=rev(brewer.pal(10,"RdBu")))
问题是我无法使用brick()
提取netCDF数据的crs和范围。 image()
正确绘制了数据,但是当我使用proj4string
投影到+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
时,lon和lat被交换,并且网格被拉伸。
感谢您的帮助!
我认为您的文件很好。
r <- brick("tas_Amon_IPSL-CM6A-LR_ssp126_r1i1p1f1_gr_201501-210012.nc")
plot(r$X2015.01.16)
#r$X2015.01.16
class : RasterLayer
band : 1 (of 1032 bands)
dimensions : 143, 144, 20592 (nrow, ncol, ncell)
resolution : 2.5, 1.267606 (x, y)
extent : -1.25, 358.75, -90.6338, 90.6338 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : C:....
names : X2015.01.16
z-value : 2015-01-16
zvar : tas
如果使用的是NOAA POD:点的经度写为正0到360W或正0到180W,负0到180E。易于转换,但完全不是R问题。