rm(list = ls())
library(RNetCDF)
library(rgl)
library(plot3D)
library(plot3Drgl)
library(OceanView)
vec_surf_field=TRUE
###
### read variables(lon,lat,u,v)
###
u2<-array(0,c(120,110,30,120))
v2<-array(0,c(120,110,30,120))
vec2<-c(0:9)
for(j in vec2){
readname="/data1/kimyy/oman_restore_04_18/197"
readname2="12/ocean_snap_197"
readname3="12.nc"
rname=paste(readname,as.character(j),readname2,as.character(j),readname3,sep="")
nc2 <- open.nc(rname)
u2_temp<-var.get.nc(nc2,"u");
v2_temp<-var.get.nc(nc2,"v");
temp2_temp<-var.get.nc(nc2,"temp")
eta_t2_temp<-var.get.nc(nc2,"eta_t")
lon2<-var.get.nc(nc2,"xt_ocean");
lat2<-var.get.nc(nc2,"yt_ocean");
level2<-var.get.nc(nc2,"st_ocean");
ilevel2 = -level2
for (i in c(1:12))
{
u2[1:length(lon2),1:length(lat2),1:length(level2),j*12+i]<-u2_temp[1:length(lon2),1:length(lat2),1:length(level2),i]
v2[1:length(lon2),1:length(lat2),1:length(level2),j*12+i]<-v2_temp[1:length(lon2),1:length(lat2),1:length(level2),i]
temp2[1:length(lon2),1:length(lat2),1:length(level2),j*12+i]<-temp2_temp[1:length(lon2),1:length(lat2),1:length(level2),i]
eta_t2[1:length(lon2),1:length(lat2),j*12+i]<-eta_t2_temp[1:length(lon2),1:length(lat2),i]
}
}
###
### surface vector field
###
if (vec_surf_field==TRUE)
{
for (l in c(1:120))
{
year=as.character(as.integer((l-1)/12))
month=as.character(l-as.integer((l-1)/12)*12)
if (as.integer(month)<=9) {
filename=paste("/data1/kimyy/oman_restore_04_18/gif/vec_surf_field/197",as.character(year),"0",as.character(month),".png",sep="");
gifname=paste("Surface Vector (", as.character(year),"year ",as.character(month),"month)",sep="");
} else {
filename=paste("/data1/kimyy/oman_restore_04_18/gif/vec_surf_field/197",as.character(year),as.character(month),".png",sep="");
gifname=paste("Surface Vector (", as.character(year),"year ",as.character(month),"month)",sep="");
}
png(file=filename,width=1300,height=1100)
par(mar=c(9,10,7,7), mgp = c(7, 3, 0))
#par(mar=c(10,11,8,8), mgp = c(8, 4, 0))
quiver2D(u=u2[1:120,1:110,1,l],v=v2[1:120,1:110,1,l], x = lon2, y = lat2,
colvar = sqrt(u2[1:120,1:110,1,l]^2 + v2[1:120,1:110,1,l]^2), clim = c(0, 0.5), col="black",
main = paste (gifname), xlab = "Degrees East (°E)", ylab = "Degrees North (°N)",
arr.max = 0.15, arr.min = 0.15, clab = "Speed (m/s)", scale=2.5, by=4, NAcol="white", asp=1,
cex.axis=3, cex.main=3.5, cex.lab=3, colkey=NULL)
dev.off()
}
}
该代码具有此过程 1.阅读120个月度数据 2.绘制120表面矢量场
在这个过程中,我无法修复矢量(箭头长度)比例。
你可以看到两张图片的区别, 矢量比例是不同的。 你能帮我解决这个问题吗?
在matlab中,我可以解决这个'箭头(x,y,u,v,'AutoScale','off');