r - 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,并且网格被拉伸了。
谢谢你的帮助 !
解决方案
我认为你的文件很好。
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 问题。
推荐阅读
- google-cloud-platform - GKE:防止集群被意外删除
- tpm - 从 TPM2 模块中获取持久字符串
- c++11 - C++11 及更高版本中的异常安全和并发性:STL 实现函数的指南
- jmeter - JMETER 5.1.1:合并来自同一会话的相同采样器(与 JMETER 3.2 一样)
- php - 检测到服务的循环参考
- java - 给定一个全为 0 的二进制字符串,将其隐藏在目标字符串中
- java - 在 java 中,System.out.println 方法如何在静态和非静态上下文中工作?
- c - 为什么使用 \"%s\" 时 sprintf 不起作用?
- android - 当应用程序来自后台时始终触发观察者
- angular - 嵌套子项的 ngxs 状态更改