Hi Meha
 
check your pixels!
Probably NA values are causing that problem! Check if there are any pixels with no (or less than 4) values.
 
Matteo
 
a<- raster(,ncol=10,nrow=10)
a[]<-runif(ncell(a),0,0.2) # some noise
b<- raster(,ncol=10,nrow=10)
b[]<-runif(ncell(a),0,0.1)
c<- raster(,ncol=10,nrow=10)
c[]<-runif(ncell(a),0,0.5)
 
r<- stack(rep(c(a,b,c),80))
 
r<- calc(r, function(x){x+sin(0.1*(0:nlayers(r)))}) # adding some periodicy
 
splinepixel<- function(x){
  yvalues<-smooth.spline(x,df=60)$y
return(yvalues)}
 
output = calc(r,fun=splinepixel)
 
cell<- runif(1,1,ncell(r))
 
plot(r[cell],x=1:nlayers(r),type="n")
lines(r[cell],x=1:nlayers(r),col=1)
lines(output[cell],x=1:nlayers(r),col=2)
 
 
>>> Meha Jain <mehajain13@gmail.com> 10.06.2011 16:53 >>>
Dear all,

I am trying to use the function smooth.spline with the calc function in the
raster package for x,y,z files. I would like to perform the following
function across the z time series (n=248) for my x by y matrix:

> smooth.spline(z, df = 60)$y

I wrote the function

> splinepixel<- function(x){

  yvalues<-smooth.spline(x,df=60)$y

return(yvalues)}


and then ran it with calc:

> output = calc(r,fun=splinepixel)


I get the error:

Error in smooth.spline(x, df = 60) : need at least four unique 'x' values


Any help is much appreciated! Thanks.

Meha

[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

	[[alternative HTML version deleted]]

