Terra::interpolate problem with quantiles prediction (R)

20 views Asked by At

I have a problem. I am trying to generate prediction rasters for n tiles containing covariates of the following quantiles: 0.05,0.5,0.95. (I used to create the model)

Below is the part of the script

"tile" are the raster stacks (the study area was divided into n stacks to avoid problems with memory) containing all covariates "y" is the nth tile "Boruta_covs" is the list of covariates that were chosen in the Boruta feature selection

quant <- c(0.05,0.5,0.95)
for (y in seq_along(tile)) {
  gc()
  # load tiles
  tl <- rast(tile[y])
  # crop the selected covariates with the nth tile y
  covs_fin <- crop(covs[[Boruta_covs]], tl)
  
  # function to extract the predicted values from from the ranger model
  pfun <- \(...) { predict(...)$predictions |> tl() }
  
  # predict quantiles
  terra::interpolate(covs_fin, 
                     model = model_qrf$finalModel, 
                     fun=pfun, 
                     na.rm=TRUE, 
                     type = "quantiles", 
                     quantiles = quant,
                     filename = paste0("my directory",
                                       soilatt,"_tile50d_", y, ".tif"), 
                     overwrite = TRUE)
  
  print(paste("tile", y, "of", length(tile)))
}

Mean and standard deviation were calculated without any problems.

Eroor is a s following: ERROR: [writeValues] too many values for writing: 1751952 > 8588

I was trying to apply

type = "quantiles", 
quantiles =  c(0.05,0.5,0.95)`or predict individual
type = "quantiles", 
quantiles =  c(0.05)

But the same problem appeared

0

There are 0 answers