我想从常规网格中绘制海面温度数据,但找不到正确的方法。我的数据采用 nc 格式 可以从http://www.nodc.noaa.gov/SatelliteData/pathfinder4km/下载
我使用此 R 代码来访问数据,但在尝试绘图时出现问题
library("ncdf")
download.file("ftp://ftp.nodc.noaa.gov/pub/data.nodc/pathfinder/Version5.2/2003/20030715000715-NODC-L3C_GHRSST-SSTskin-AVHRR_Pathfinder-PFV5.2_NOAA17_G_2003196_night-v02.0-fv02.0.nc", destfile="sst.nc")
data=open.ncdf("sst.nc")
x <- get.var.ncdf(data,"lon")
y <- get.var.ncdf(data,"lat")
sst=get.var.ncdf(data,"sea_surface_temperature")
filled.contour(x,y,sst, color = terrain.colors, asp = 1)
然后收到此错误消息
Error en filled.contour(x, y, sst, color = terrain.colors, asp = 1) : increasing 'x' and 'y' values expected
我认为问题出在y坐标上,纬度从90到-90。我在 stackoverflow 上看到了一些关于使用 akima 创建新网格的问题 包,但在这种情况下不是必需的。
在这里您可以找到数据文件的摘要
http://ubuntuone.com/1mIdYVqoePn24gKQbtXy7K
预先感谢您的帮助
已解决
感谢保罗·希姆斯特拉
该点不是从数据集中读取经纬度值,而是了解矩阵中数据点的 i,j 坐标,然后选择我想要绘制的地理区域。以下是对我有用的命令:
library("ncdf")
download.file("ftp://ftp.nodc.noaa.gov/pub/data.nodc/pathfinder/Version5.2/2003/20030715000715-NODC-L3C_GHRSST-SSTskin-AVHRR_Pathfinder-PFV5.2_NOAA17_G_2003196_night-v02.0-fv02.0.nc", destfile="sst.nc")
data=open.ncdf("sst.nc")
sst=get.var.ncdf(data,"sea_surface_temperature")
x = seq(1, 8640, length.out = nrow(sst)) # Matrix dimension 8640x4320
y = seq(1, 4320, length.out = ncol(sst))
sst1 <- sst[c(1000:1500),c(1000:1500)] # Subsetting a region
x = seq(1, 500, length.out = nrow(sst1))
y = seq(1, 500, length.out = ncol(sst1))
png(filename="sst.png",width=800,height=600,bg="white")
filled.contour(x,y,sst1, color = terrain.colors, asp = 1)
dev.off()
现在我必须弄清楚如何在 x-y 坐标处用经度和纬度标记绘图。
最佳答案
虽然我的问题在 Paul Hiemstra 的帮助下得到了解决,但我仍然研究了绘制 netcdf 数据,并在 Stackoverflow 中发现了另一个对我有帮助的线程。它使用图像而不是filled.contour。
您可以在 The variable from a netcdf file comes out flipped 找到该帖子
现在,这是我用来绘制 SST 数据的代码:
library("ncdf")
download.file("ftp://ftp.nodc.noaa.gov/pub/data.nodc/pathfinder/Version5.2/2000/20000107010122-NODC-L3C_GHRSST-SSTskin-AVHRR_Pathfinder-PFV5.2_NOAA14_G_2000007_night-v02.0-fv01.0.nc", destfile="sst.nc")
data=open.ncdf("sst.nc")
sst=get.var.ncdf(data,"sea_surface_temperature")
lon=get.var.ncdf(data,"lon")
lat=get.var.ncdf(data,"lat")
data$dim$lon$vals -> lon
data$dim$lat$vals -> lat
lat <- rev(lat)
sst <- sst[,ncol(sst):1]
png(filename="sst2.png",width=1215,height=607,bg="white")
image(lon, lat, sst, zlim=c(270,320), col = heat.colors(37))
library("sp", lib.loc="/usr/lib/R/site-library")
library("maptools", lib.loc="/usr/lib/R/site-library")
data(wrld_simpl)
plot(wrld_simpl, add = TRUE)
dev.off()
这导致了这个图像:
关于r - 从 netcdf 文件 "increasing x y values expected"绘制数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16353857/