错误绘制来自netcdf文件的数据“期望增加x y值" [英] Error plotting data from netcdf file "increasing x y values expected"
问题描述
我想从规则的网格中绘制海面温度数据,但找不到正确的方法.我的数据为nc格式 可以从 http://www.nodc.noaa.gov/SatelliteData/pathfinder4km/<下载/a>
I want to plot sea surface temperature data from a regular grid but can't find the proper way to do it. My data comes in nc format and can be downloaded from http://www.nodc.noaa.gov/SatelliteData/pathfinder4km/
我使用此R代码访问数据,但是在尝试绘制时出现了问题
I use this R code to access data but the problem appears when trying to plot
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)
然后收到此错误消息
filled.contour(x,y,sst,color = terrain.colors,asp = 1)错误: 预期增加"x"和"y"值
Error en filled.contour(x, y, sst, color = terrain.colors, asp = 1) : increasing 'x' and 'y' values expected
我认为问题出在y坐标,纬度从90到-90.我已经在使用akima创建新网格时看到了一些关于stackoverflow的问题 包,但在这种情况下不必要.
I think the problem comes from y coordinate, latitude runs from 90 to -90. I've seen some questions on stackoverflow in creating a new grid with akima package but it should not be necessary in this case.
在这里您可以找到数据文件的摘要
Here you can find a summary of data file
http://ubuntuone.com/1mIdYVqoePn24gKQbtXy7K
预先感谢您的帮助
已解决
感谢Paul Hiemstra
Thanks to Paul Hiemstra
该点不是从数据集中读取纬度值,而是要知道矩阵中数据点的i,j坐标,然后选择要绘制的地理区域.以下是对我有用的命令:
The point was not read lat-lon values from data set but to know the i,j coordinates of data points in the matrix and then select the geographic area I want to plot. Following are the commands that work for me:
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坐标处以经度和纬度标记图.
Now I have to figure out how to label the plot with longtiude and latitude at x-y coordinates.
推荐答案
问题可能出在下面.您的x
和y
变量的大小与sst
相同,即它们提供了x
和y
坐标的映射. filled_contour
函数所需的不是这些映射,而是更简单的x
和y
坐标,它们与sst
中的行和列关联,且x
值增加.
The problem is probably the following. Your x
and y
variables are of the same size of sst
, i.e. they provide maps of x
and y
coordinates. What the filled_contour
function needs is not these maps, but more simply the x
and y
coordinates associated with the rows and columns in sst
with increasing x
values.
这篇关于错误绘制来自netcdf文件的数据“期望增加x y值"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!