So, I have some variables from a .nc file that are in 4D arrays (x,y,z,t). The thing is, the z coordinates are not evenly spaced like the x and y coordinates are, i.e., z goes something like 25 meters, 75m, 125, 175,..., 500, 600, 700,..., 20000, 21000, 22000. I'm trying to linearly interpolate the data to get uniform 50m spacing throughout z. But the approx function in R is working too slowly (the arrays are too large, I think):
library(ncdf)
x = get.var.ncdf(nc,'x'); y = get.var.ncdf(nc,'y'); z = get.var.ncdf(nc,'z')
t = get.var.ncdf(nc,'t') # time
qc1 = get.var.ncdf(nc,'qc',start=c(1,1,1,1),count=c(-1,-1,-1,-1))
zlin = seq(z[1],z[length(z)],50)
qc1_lin = array(0,c(length(x),length(y),length(zlin),length(t)))
for (i in 1:length(x)) {
for (j in 1:length(y)) {
for (k in 1:length(t)) {
qc1_lin[i,j,,k] = approx(z,qc1[i,j,,k],xout = zlin)
}
}
}
Is there a way to do this faster? Or, someone told me to look into regridding the data to make this easier, but I'm not quite sure what he means. Can someone help me? Thanks.