多年来我一直用它ggplot2来绘制气候网格数据.这些通常是预计的NetCDF文件.单元格在模型坐标中是方形的,但取决于模型使用的投影,在现实世界中可能不是这样.
我通常的方法是首先在合适的常规网格上重新映射数据,然后绘图.这引入了对数据的小修改,通常这是可以接受的.
但是,我已经确定这已经不够好了:我想直接绘制投影数据而不重新映射,因为其他程序(例如ncl)可以,如果我没有弄错的话,可以不触及模型输出值.
但是,我遇到了一些问题.我将从下面逐步详细介绍可能的解决方案,从最简单到最复杂,以及它们的问题.我们能克服它们吗?
#Load packages
library(raster)
library(ggplot2)
#This gives you the starting data, 's'
load(url('https://files.fm/down.php?i=kew5pxw7&n=loadme.Rdata'))
#If you cannot download the data, maybe you can try to manually download it from http://s000.tinyupload.com/index.php?file_id=04134338934836605121
#Check the data projection, it's Lambert Conformal Conic
projection(s)
#The data (precipitation) has a 'model' grid (125x125, units are integers from 1 to 125)
#for each point a lat-lon value is also assigned
pr …Run Code Online (Sandbox Code Playgroud) 我已经将此问题作为在不规则网格问题上绘制数据的有效方法的一部分,但一般反馈是将原始问题拆分为更易于管理的块.因此,这个新问题.
我使用组织在不规则二维网格上的卫星数据,其尺寸为扫描线(沿轨道尺寸,即Y轴)和地面像素(跨越轨道尺寸,即X轴).每个中心像素的纬度和经度信息存储在辅助坐标变量中,以及四个角坐标对(纬度和经度坐标在WGS84参考椭球上给出).
让我们构建一个玩具数据集,包括12x10可能不规则的网格和相关的表面温度测量.
library(pracma) # for the meshgrid function
library(ggplot2)
num_sl <- 12 # number of scanlines
num_gp <- 10 # number of ground pixels
l <- meshgrid(seq(from=-20, to=20, length.out = num_gp),
seq(from=30, to=60, length.out = num_sl))
lon <- l[[1]] + l[[2]]/10
lat <- l[[2]] + l[[1]]/10
data <- matrix(seq(from = 30, to = 0, length.out = num_sl*num_gp),
byrow = TRUE, nrow = num_sl, ncol = num_gp) +
matrix(runif(num_gp*num_sl)*6, nrow = num_sl, ncol = …Run Code Online (Sandbox Code Playgroud)