Closed glaroc closed 1 year ago
If you read ?predict
you'll see that predict
is exported by namespace stats
; gstat
merely adds methods.
So, use stats::predict
if you must use the ::
construct.
Thanks for the clarification. We used to be able to do unconditional Gaussian simulations on a raster by giving gstat::predict a blank raster. Is that still possible through other functions ?
Please provide a reprex.
This used to work:
#read data frame with x,y coordinates and variables in other columns
Arbo<-read.csv(file.choose())
# Select a raster tiff file with a defined CRS
Arbo_mask<-rast(file.choose())
Arbo <- st_as_sf(Arbo, coords = c("X","Y"),crs=crs(Arbo_mask))
v <- vgm(1, "Sph", 200)
g.dummy <- gstat(formula = z~1, locations=Arbo, dummy = TRUE, beta = 0,model = v, nmax = 20)
g.prdSph<-predict(g.dummy,Arbo_mask,nsim=9)
Now this gives
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'obj' in selecting a method for function 'coordinates': no slot of name "bbox" for this object of class "SpatRaster"
I can supply the files if needed.
Definitely not a reprex, but isn't that a raster - terra issue?
Here is a more reproducible example:
data(meuse.grid)
m = SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")], data = meuse.grid)
r <- terra::rast(m)
# r <- raster::raster(m) # this gives same error
g.dummy <- gstat(formula = z~1, dummy = TRUE, beta = 0,
model = vgm(1,"Exp",15), nmax = 10)
y <- predict(g.dummy, r, nsim = 4)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'obj' in selecting a method for function 'coordinates': no slot of name "bbox" for this object of class "SpatRaster"
Ok, it works when the raster is a stars objects. So this works:
data(meuse.grid)
m = SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")], data = meuse.grid)
r <- st_as_stars(m)
g.dummy <- gstat(formula = z~1, dummy = TRUE, beta = 0,
model = vgm(1,"Exp",15), nmax = 10)
y <- predict(g.dummy, r, nsim = 4)
If I do
predict.gstat() is in the documentation, but doesn't appear to be exported.