# NOT RUN {
# Unsmoothed (Gulf Stream)
library(oce)
data(section)
gs <- subset(section, 115<=stationId&stationId<=125)
par(mfrow=c(2, 2))
plot(gs, which="temperature")
mtext("unsmoothed")
# Spline
gsg <- sectionGrid(gs, p=seq(0, 5000, 100))
gsSpline <- sectionSmooth(gsg, "spline")
plot(gsSpline, which="temperature")
mtext("spline-smoothed")
# Barnes
gsBarnes <- sectionSmooth(gs, "barnes", xr=50, yr=200)
plot(gsBarnes, which="temperature")
mtext("Barnes-smoothed")
# Kriging
if (requireNamespace("automap",quietly=TRUE)&&requireNamespace("sp",quietly=TRUE)) {
krig <- function(x, y, F, xg, xr, yg, yr) {
xy <- data.frame(x=x/xr, y=y/yr)
K <- automap::autoKrige(F~1, remove_duplicates=TRUE,
input_data=sp::SpatialPointsDataFrame(xy, data.frame(F)),
new_data=sp::SpatialPoints(expand.grid(xg/xr, yg/yr)))
matrix(K$krige_output@data$var1.pred, nrow=length(xg), ncol=length(yg))
}
gsKrig <- sectionSmooth(gs, krig)
plot(gsKrig, which="temperature")
mtext("Kriging-smoothed")
}
# }
Run the code above in your browser using DataLab