如何使用`SpaDES.project::setupProject`和`SpaDES.experiment::experiment2`?

kg7wmglp  于 2023-06-27  发布在  其他
关注(0)|答案(1)|浏览(75)

我已经设置了我的项目,但我的目标是创建两个simList对象,并将其传递给experiment2。这失败了,因为我通过...传递了模拟中需要的对象。我是否错误地使用了...?如果没有,我如何传递其他对象?

options(repos = c(CRAN = "https://cloud.r-project.org"))

if (getRversion() < "4.2.1") {
  warning(paste("dismo::maxent may create a fatal error",
                "when using R version < v4.2.1 and from RStudio.\n", 
                "Please upgrade R, or run this script outside of RStudio.\n",
                "See https://github.com/rspatial/dismo/issues/13"))
}

## check Java
if (!require(rJava)) {
  stop(paste("Your Java installation may have problems, please check.\n", 
             "See https://www.java.com/en/download/manual.jsp for Java installation.\n",
             "Alternatively, 'rJava' could be having issues assessing your system Java installation."))
}

## install SpaDES.project -- it'll setup everything for us ;)
if (!requireNamespace("SpaDES.project"))
  install.packages("SpaDES.project", repos= c("https://predictiveecology.r-universe.dev", getOption("repos")))

if (!requireNamespace("SpaDES.tools"))
  install.packages("SpaDES.tools", repos= c("https://predictiveecology.r-universe.dev", getOption("repos")))

if (!requireNamespace("terra"))
  install.packages("terra")

library(SpaDES.project)

## make a random study area.
##  Here use seed to make sure the same study area is always generated
studyArea <- SpaDES.tools::randomStudyArea(size = 1e10, seed = 123)
studyAreaRas <- terra::rasterize(studyArea, 
                                 terra::rast(extent = terra::ext(studyArea), 
                                             crs = terra::crs(studyArea, proj = TRUE), 
                                             resolution = 1000))

projOut <- setupProject(name = "SpaDES4Dummies_Part2",
                        paths = list(projectPath = normalizePath(file.path(tempdir(), "SpaDES4Dummies_Part2"))), ## use a temporary dir
                        modules = c("CeresBarros/SpaDES4Dummies"), ## get the full repo project, we'll work around it to keep only the modules we need
                        require = c("SpaDES.core",
                                    "ggpubr",
                                    "PredictiveEcology/SpaDES.experiment@development",
                                    "SpaDES.tools", 
                                    "DiagrammeR"),
                        options = list("reproducible.rasterRead" = "terra::rast",
                                       "reproducible.useTerra" = TRUE),
                        studyAreaRas = studyAreaRas
)

## only keep necessary modules
projOut$modules <- c("climateData", "speciesAbundanceData", "projectSpeciesDist") # <-- use only 3 modules
projOut$paths$modulePath <- "modules/SpaDES4Dummies/modules"  # specify that the actual module path is inside

## parameters/objects for workflow computations
projOut$times <- list(start = 1, end = 5, timeunit = "year")
projOut$params <- list(
  "speciesAbundanceData" = list(
    ".plots" = c("png"),
    ".useCache" = FALSE
  ),
  "climateData" = list(
    ".plots" = c("png"),
    ".useCache" = FALSE
  ),
  "projectSpeciesDist" = list(
    "statModel" = "MaxEnt",
    ".plots" = c("png"),
    ".useCache" = FALSE
  ))

## before we run the workflow, dismo needs a few tweaks to run MaxEnt
maxentFile <- reproducible::preProcess(targetFile = "maxent.jar",
                                       url = "https://github.com/mrmaxent/Maxent/blob/master/ArchivedReleases/3.4.4/maxent.jar?raw=true",
                                       destinationPath = projOut$paths$inputPath,
                                       fun = NA)
file.copy(from = maxentFile$targetFilePath, 
          to = file.path(system.file("java", package = "dismo"), "maxent.jar"))

## initialise workflows using MaxEnt (parameters set above)
## SpaDES.experiment::experiment2, will take care of subdirectories to store outputs
wrkflwMaxEnt <- do.call(simInit, projOut)
pjngdqdw

pjngdqdw1#

你只需要?simInit来查看它期望的参数。所以,在这种情况下,您需要它们作为objects ...

projOut$objects$studyArea <- SpaDES.tools::randomStudyArea(size = 1e10, seed = 123)
    projOut$objects$studyAreaRas <- terra::rasterize(projOut$objects$studyArea, 
                                     terra::rast(extent = terra::ext(projOut$objects$studyArea), 
                                                 crs = terra::crs(projOut$objects$studyArea, proj = TRUE), 
                                                 resolution = 1000))

相关问题