Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading/wrong module code checks #255

Open
CeresBarros opened this issue Sep 14, 2023 · 2 comments
Open

Misleading/wrong module code checks #255

CeresBarros opened this issue Sep 14, 2023 · 2 comments

Comments

@CeresBarros
Copy link
Member

CeresBarros commented Sep 14, 2023

SpaDES,core module code checks are warning about non-declared (in metadata) inputs which are actually temporary objects using during the simulation.
In the message below, r, nn and sppKeep are not in sim.

Biomass_speciesData: inputObjects: r, nn, sppKeep are used from sim inside biomassDataInit, but are not declared in metadata inputObjects

reprex (currently failing downstream from the code checks, tho see PredictiveEcology/SpaDES.project#40)

Require::Require("PredictiveEcology/SpaDES.project@windowsTesting")
inputPath <- "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/inputs"

## it seems `params =`is evaluated first so all of these need to be defined here.
sppEquivCol <- "Boreal"
vegLeadingProportion <- 0
successionTimestep <- 10L
eventCaching <- c(".inputObjects", "init")
useParallel <- FALSE
simTimes <- list(start = 2001, end = 2031)

out <- setupProject(name = "LandRDemo_coreVeg",
                    options = list(
                      "reproducible.destinationPath" = inputPath
                      , "reproducible.useCache" = TRUE
                      , "reproducible.useNewDigestAlgorithm" = 2
                      , "reproducible.useTerra" = TRUE
                      , "spades.moduleCodeChecks" = TRUE
                      , "spades.inputPath" = inputPath
                    ),
                    paths = list(
                      projectPath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg"
                      , modulePath = "D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules"
                      , inputPath = inputPath
                      , scratchPath = tempdir()
                      , packagePath = "D:/GitHub/LandR-tutorials/packages"
                    ),
                    modules = c(
                      "PredictiveEcology/Biomass_speciesData@terra-migration"
                      , "PredictiveEcology/Biomass_borealDataPrep@terra-migration"
                      , "PredictiveEcology/Biomass_speciesParameters@development"
                      , "PredictiveEcology/Biomass_core@terra-migration"
                      , "PredictiveEcology/Biomass_validationKNN@development"
                    ),
                    ##
                    ## NECESSARY OBJECTS -----------------------------------
                    ## STUDY AREA(S)
                    studyAreaLarge = {
                      originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
                      Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

                      largeExtent <- c(xmin = -104.757, xmax = -104.2197, ymin = 55.68663, ymax = 56.20319)
                      studyAreaL <- terra::vect(terra::ext(largeExtent))
                      studyAreaL <-  terra::vect(terra::geom(studyAreaL), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaL)))
                      studyAreaL <- terra::project(studyAreaL, Biomass_corecrs)
                      studyAreaL
                    },
                    studyArea = {
                      originalcrs <- "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
                      Biomass_corecrs <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"

                      smallExtent <- c(xmin = -104.757, xmax = -104.48835, ymin = 55.68663, ymax = 55.94491)
                      studyAreaS <- terra::vect(terra::ext(smallExtent))
                      studyAreaS <-  terra::vect(terra::geom(studyAreaS), "polygons", crs = originalcrs, atts = data.frame(id = 1:length(studyAreaS)))
                      studyAreaS <- terra::project(studyAreaS, Biomass_corecrs)
                      studyAreaS
                    },
                    ##
                    ## SPECIES LISTS
                    sppEquiv = {
                      data("sppEquivalencies_CA", package = "LandR")
                      sppEquivalencies_CA[grep("Pin", LandR), `:=`(EN_generic_short = "Pine",
                                                                   EN_generic_full = "Pine",
                                                                   Leading = "Pine leading")]
                      sppEquivalencies_CA[grep("Betu_pap", LandR), `:=`(EN_generic_short = "Birch",
                                                                        EN_generic_full = "Birch",
                                                                        Leading = "Birch leading")]
                      ## all Popu will be merged
                      sppEquivalencies_CA[grep("Popu_", LandR), `:=`(EN_generic_short = "Poplar",
                                                                     EN_generic_full = "Poplar",
                                                                     Leading = "Poplar leading")]
                      sppEquivalencies_CA[grep("Popu_", LandR), Boreal := "Popu_Spp"]

                      ## define spp column to use for model
                      # sppEquivCol <- "Boreal"
                      sppEquivalencies_CA <- sppEquivalencies_CA[!"", on = sppEquivCol]
                      sppEquivalencies_CA <- na.omit(sppEquivalencies_CA, sppEquivCol)
                      sppEquivalencies_CA
                    },
                    sppColorVect = {
                      LandR::sppColors(sppEquiv, sppEquivCol, newVals = "Mixed", palette = "Accent")
                    },
                    speciesParams = {
                      list(
                        "shadetolerance" = list(
                          Betu_Pap = 1
                          , Lari_Lar = 1
                          , Pice_Gla = 2
                          , Pice_Mar = 3
                          , Pinu_Ban = 1.5
                          , Popu_Spp = 1
                        )
                      )
                    },
                    ##
                    ## SIMULATION SETUP ------------------------------------
                    times = simTimes,
                    params = source("params.R")
)

simInitOut <- do.call(SpaDES.core::simInit, out)
@CeresBarros
Copy link
Member Author

Found another one in the same example

rawBiomassMap is being assigned to sim in .inputObjects, but the following warning is issued:

D:/GitHub/LandR-tutorials/LandRDemo_coreVeg/modules/Biomass_borealDataPrep/Biomass_borealDataPrep.R
Biomass_borealDataPrep: module code: rawBiomassMap is declared in metadata outputObjects, but is not assigned in the module

@achubaty
Copy link
Contributor

with #223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants