gpt4 book ai didi

r - 从 netcdf 文件 "increasing x y values expected"绘制数据时出错

转载 作者:行者123 更新时间:2023-12-02 22:04:26 25 4
gpt4 key购买 nike

我想绘制规则网格中的海面温度数据,但找不到正确的方法。我的数据是 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。我在使用 akima 创建新网格时看到了一些关于 stackoverflow 的问题包,但在这种情况下没有必要。

在这里你可以找到数据文件的摘要

http://ubuntuone.com/1mIdYVqoePn24gKQbtXy7K

预先感谢您的帮助

已解决

感谢 Paul Hiemstra

重点不是从数据集中读取经纬度值,而是了解矩阵中数据点的 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()

导致这张图片: enter image description here

关于r - 从 netcdf 文件 "increasing x y values expected"绘制数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16353857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com