我有一个脚本将天气极地雷达数据处理成笛卡尔坐标,然后绘制它。我测试了每个单独的组件,并且各个组件每次都做他们应该做的事情。最近我需要简化所有内容,所以我把它放在一个脚本中,但当我尝试通过它运行我的数据时,它会发出一条我不完全理解的错误消息。任何帮助将不胜感激。提前致谢。我正在使用命令radProcess(test, 1, ref)
执行脚本。
我的数据看起来像这样(虽然这个例子已经从它所在的3600x800数据框缩小) -
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1 -96 -75 -69 -62 51 40 47 50 52 47
2 -94 -80 -67 -57 53 37 44 51 54 50
3 -100 -81 -72 -61 54 42 50 48 56 50
4 -101 -82 -72 -63 55 43 40 47 50 48
5 -999 -78 -73 -59 55 40 46 49 54 54
6 -102 -81 -71 -59 51 37 44 52 55 57
7 -101 -79 -74 -59 54 43 42 47 55 47
8 -95 -80 -73 -59 52 40 48 54 58 54
9 -96 -78 -75 -58 57 44 39 50 47 55
10 -99 -79 -73 -59 57 45 46 56 55 53
当我尝试运行看起来像这样的数据时,我遇到了一条错误消息 -
Error in radProcess(test, 10, ref) :
dims [product 864000] do not match the length of object [2880000]
In addition: Warning message:
In final.levl[cbind(z.rad, t.rad, r.rad)] * conversion.factor :
longer object length is not a multiple of shorter object length
脚本可以在下面看到 -
radProcess <- function(file, level, product){
## Convert file to 3 dimensional array format organized ##
## by scan level (10-top, 1-bottom of array) ##
print("Converting to 3D Array")
x.arr.vert <- array(unlist(file), dim = c(10,360,800))
x.arr.horz <- aperm(array(x.arr.vert, dim = c(360,10,800)), c(2,1,3))
final.levl <- x.arr.horz[ c(10:1),,]
## Create matrix of coordinates and values and then ##
## converts from polar to cartesian coordinates ##
print("Creating Matrix of Polar Coordinates")
mat <- which( (final.levl > -1000), arr.ind = TRUE)
z.rad <- mat[, 1]
t.rad <- mat[, 2]
r.rad <- mat[, 3]
print("Converting to Cartesian Coordinates")
theta.polar <- t.rad * pi / 180
r.polar <- r.rad * 0.075
x.cart <- r.polar * cos(theta.polar)
y.cart <- r.polar * sin(theta.polar)
## Reflectivity adjustment constant = .514245 ##
## Velocity adjustment constant = .1275628 ##
print("Determining Conversion Factor")
conversion.factor <- ifelse( (product == "ref"), yes = .514245, no = .1275628)
print("Copying Values from Array to Matrix")
value <- (final.levl[cbind(z.rad, t.rad, r.rad)] * conversion.factor)
Cart.Coord.Matrix <- matrix( NA, nrow = 2880000, ncol = 4)
Cart.Coord.Matrix <- cbind(z.rad, y.cart, x.cart, value)
## Create new matrix level wanted from transposed value matrix ##i
print("Reducing down to Level Wanted")
specified.level <- Cart.Coord.Matrix[z.rad == level,]
## Plot level values in Radar plot ##
print("Plotting Data Points")
x1<-specified.level[,3]
y2<-specified.level[,2]
z3<-specified.level[,4]
d1 <- data.frame(x1,y2,z3)
dg1 <-qplot(y2,x1,colour=z3,data=d1)
dg1 + scale_colour_gradientn(limits = c(0, 60), colours = rev(rainbow(10)))
}