#Interpolation of magpie objects
splineInterpolate<-function(x,years,method="fmm",...){
if(!is.magpie(x)) stop("input has to be a MAgPIE object!")
xvals<-getYears(x,as.integer=T)
if(all(is.character(years))) years <- as.integer(substring(years,2))
if(min(years)<min(xvals)||max(years)>max(xvals)) stop("Only interpolation allowed, no extrapolation.")
out<-new.magpie(cells_and_regions=getCells(x),years=years,names=getNames(x))
for(i in getCells(x)){
for(j in ifelse(is.null(getNames(x)),1,getNames(x))){
if(is.null(j)) j <- 1
tmp <-spline(x=xvals,y=as.vector(x[i,,j]),method=method,xout=years,...)
suppressWarnings(out[i,tmp$x,j] <- tmp$y)
}
}
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.