首页 > 解决方案 > NetCDF 变量没有 crs 和 extent

问题描述

一般来说,我对 netCDF 数据和空间数据非常陌生,如果我的问题不是很明确,请见谅。

我正在使用 R,我的目标是从可以在此处下载的温度数据中提取栅格。

我运行以下代码:

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(). 正确地image()绘制了数据,但是当我使用proj4string投影到时+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0,交换了 lon 和 lat,并且网格被拉伸了。

谢谢你的帮助 !

标签: rnetcdfextent

解决方案


我认为你的文件很好。

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 问题。


推荐阅读