r - Interpolating Gridded 3D Data to a finer scale -
i have netcdf file of probability surface. it's 30x30 grid of 0.25 degree lat/lon intervals probability surface described in z dimension. can import panoply, netcdf viewer:
and it's breeze (checking 1 box) interpolate/smooth raw data finer grid size:
however, don't want visualize data, want plot in r along bathymetry , point data. no problem, have not found straightforward way interpolate gridded data in r. here's code use import , plot data:
library(rnetcdf) nc <- open.nc("132235-1.nc") print.nc(nc) tmp <- read.nc(nc) probs<-tmp$likelihoods xran <- range(tmp$longitude) yran <- range(tmp$latitude) zran <- range(probs,na.rm=t) lon <- tmp$longitude lat <- tmp$latitude[30:1] z <- array(probs, dim=dim(probs)) z <- z[,rev(seq(ncol(z)))] z <- z[,seq(ncol(z))] prob.pal<-colorramppalette( c("#c1ffc1","#8fbc8f","#2f4f4f") ) zbreaks <- seq(0.0001, 0.063, by=0.001) cols<- c(prob.pal(length(zbreaks)-1)) png("probtest.png", width=7.5, height=6, units="in", res=200) layout(matrix(1:2, 1,2), widths=c(6,1.5), heights=c(6)) par(mar=c(2,2,1,1), ps=10) image(lon, lat, z=z, col=cols, breaks=zbreaks, useraster=true, ylim=c(13,28), xlim=c(-115,-100)) dev.off()
and end this, same using panoply different color scheme:
is there straightforward way interpolate/smooth data? know how create kernel utilization densities etc. using point data, not using gridded data.
many assistance!
this solution think you're looking for, uses bilinear resampling. not way such interpolation , you'd need justify not using more sophisticated approach (e.g. geostatistical, splines, etc.):
library(raster) set.seed(2002) ## create extent boundary: ex <- extent(c(0, 20, 0, 20)) ## simulate coarse raster: r.small <- raster(ex, vals=rnorm(10*10, mean=5, sd=1), nrow=10, ncol=10) ## simulate grid of finer-scale raster: r.big <- raster(ncol=200, nrow=200, ext=ex) ## resample coarser raster match finer grid: r.res <- resample(x=r.small, y=r.big, method="bilinear") plot(r.small) plot(r.res)
coarse:
fine:
Comments
Post a Comment