GithubHelp home page GithubHelp logo

Comments (2)

sjevelazco avatar sjevelazco commented on September 26, 2024

Hi @Daviser95
The most simple solution I see is to predict in chunks. I would suggest dividing the projection region into tiles by creating a polygon with a regular grid. Then, write a loop tor project within each tile and merge the list of rasters into a single raster. Note that you can restring projection region using predict_area of the sdm_predict() function

r_tiles <- list()
for(i in 1:nrow(polytiles)){
r_tiles [[i]] <- sdm_predict(
  models = ens_m,
  pred = EnvVars,
  thr = "max_sens_spec",
  nchunk = 50,
  con_thr = FALSE,
  predict_area = polytiles[polytiles$id==i, ]
)
}

from flexsdm.

Daviser95 avatar Daviser95 commented on September 26, 2024

Hi @sjevelazco and thank you for this advice.
I am trying again to use the package for a different project, and after being able to get some predictions (the one with maxent), now I am getting a similar issue when making the prediction for other models (i.e., Error: std::bad_alloc and/or Error: Cannot allocate a vector of size 1.0 Gb). This is strange because I am working with a workstation with 128Gb RAM and there aren't other processes running and consuming memory). However, I was trying to predict in chunks, using a regular grid, and using your suggested code. I tried both with a SpatVector and with an sf object.

#load a regular grid for the study area
tiles_pol <- vect("G:/davide/africa/regular_grids.shp")
#crs(tiles_pol)<- "EPSG:4326"

r_tiles <- list()
for(i in 1:nrow(tiles_pol)){
  r_tiles [[i]] <- sdm_predict(
    models = f_glm,
    pred = predictors_2km_ready_nrm,
    thr = "max_sens_spec",
    nchunk = 50,
    con_thr = FALSE,
    predict_area = tiles_pol[tiles_pol$ID==i, ]
  )
}

but I am getting this error:

Predicting individual models
Errore in h(simpleError(msg, call)) : 
  errore durante la valutazione dell'argomento 'x' nella selezione di un metodo per la funzione 'mask': [crop] cannot crop a SpatRaster with an empty extent

While using this code:

for(i in 1:nrow(tiles_pol)){
  r_tiles [[i]] <- sdm_predict(
    models = f_glm,
    pred = predictors_2km_ready_nrm,
    thr = "max_sens_spec",
    nchunk = 20,
    predict_area = tiles_pol[tiles_pol]
  )
}

I get:

Predicting individual models
Errore in (function (cond)  : 
  errore durante la valutazione dell'argomento 'x' nella selezione di un metodo per la funzione 'mask': std::bad_alloc

I don't know if this error is related to the argument predict_area itself, because I was able to crop and mask the predictors with the spatvector regular grid, also using:

for(i in 1:nrow(tiles_pol)){
  r_tiles [[i]] <- predictors_2km_ready_nrm %>%
    crop(tiles_pol) %>%
    mask(tiles_pol)
}

from flexsdm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.