I have a NetCDF file of a probability surface. It's a 30x30 grid of 0.25 degree lat/lon intervals with a probability surface described in the z dimension. I can easily import this into Panoply, a NetCDF viewer:
And it's then a breeze (checking one box) to interpolate/smooth the raw data to a finer grid size:
However, I don't just want to visualize the data, I want to plot it in R along with bathymetry and point data. That all is no problem, but I have not found a straightforward way to interpolate the gridded data in R. Here's the code I use to import and plot the 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 I end up with this, which is the same as using Panoply but with a different color scheme:
Is there a straightforward way to interpolate/smooth this data? I know how to create kernel utilization densities etc. using point data, but not using gridded data.
Many thanks for your assistance!
raster()
orbrick()
and to then smooth the data to a finer-scale resolution usingresample()
. – Andyane