This function runs and returns output from a model of a StoX project.
runModel(
projectPath,
modelName,
processes = NULL,
startProcess = 1,
endProcess = Inf,
drop.datatype = TRUE,
unlistDepth2 = FALSE,
run = TRUE,
save = FALSE,
force.save = FALSE,
force.restart = FALSE,
replaceDataList = list(),
replaceArgsList = list(),
prependProcessList = list(),
fileOutput = NULL,
setUseProcessDataToTRUE = TRUE,
purge.processData = FALSE,
returnModelData = TRUE,
returnBootstrapData = FALSE,
selection = list(),
BootstrapID = NA,
unlistSingleTable = FALSE,
try = TRUE,
close = FALSE,
msg = TRUE,
...
)
The path to the StoX project, i.e., the folder of the project with the sub folders "input", "output" and "process". Can possibly be the path to a file inside the project folder.
The name of the model (possible values are "baseline", "analysis" and "report").
The name of the processes.
The process index, name or ID at which to start the model run.
The process index, name or ID at which to stop the model run.
Logical: If TRUE, drop the top level of the output list if it has length 1 and that single element is named by the datatype name.
Logical: Related to drop.datatype
, but setting this to TRUE unlists output data that are nested in 2 levels, such as output from ReadBiotic
, which outputs a set of tables for each input file. Using unlistDepth2 = TRUE puts all these tables in one list, and uses the concatenation of the file names and the table name separated by underscore. This is how it is displayed in the StoX GUI when selecting "View output".
Logical: If TRUE run the model.
Logical: If TRUE save the project after running.
If no changes are made to the project, force save anyway. Overrides the save
option.
Logical: If TRUE restart the model before running.
A list named by the processes to replace output data for. See runProcess
.
A list of replaceArgs
(see runProcess
) holding parameters to replace in the function call, named by the processes to modify.
A list of values
used in prependProcess
, named by the processes to prepend a process to.
Logical: If TRUE save the output as a text file (or other format specified by the class or attributes of the output). If NULL (defafult) use the corresponding parameter of the process.
Logical: If TRUE set the UseProcessData function parameter to TRUE in the process memory after execution, if the process is a ProcessData process.
Logical: If TRUE replace process data entirely.
Logical: If TRUE return the output of the model runs. Can also be given as a string vector holding the names of the models to return data from. If TRUE, the specific models to return data from (across models) can be given by processes
.
Logical: If TRUE read the content of any NetCDF4 files (i.e. output from Bootstrap
).
Hierarchical list of names of the groups/variables. The last element must be a vector of the variables to return from the table specified by the other elements. E.g., list("ImputeSuperIndividuals", "SuperIndividualsData", c("Stratum", "IndividualAge", "Abundance")) will return a data.table of the three columns "Stratum", "IndividualAge" and "Abundance", added the BootstrapID specified in BootstrapID
.
A sequence of bootstrap IDs, i.e., the indices of the bootstrap replicates. The default returns all bootstrap replicates.
Logical: For use when only single table process outputs are among the requested processes in OutputProcesses
of Bootstrap
. If FALSE (default) return a list named by the selection
with a sub-list named by the datatype holding the output data (e.g. $ImputeSuperIndividuals$SuperIndividualsData). If TRUE return a list named by the selection
holding the output data, replicating the output of Bootstrap
in StoX <= 3.6.2.
Logical: If FALSE do not run the process in a tryCatch
. Set this to FALSE when debugging, as the tryCatch
masks the errors in the traceback
.
Logical: If TRUE close the project after running and getting the output.
Logical: If FALSE no messages are printed to console (except possibly for extremely important ones).
Arguments passed on to runProcesses
.
A list of model output.
if (FALSE) { # \dontrun{
# Open and run the sandeel test project:
tmp <- tempdir()
sandeelZip <- system.file("testresources", "sandeel_20.zip", package = "RstoxFramework")
unzip(sandeelZip, exdir = tmp)
projectPath <- file.path(tmp, "sandeel_20")
d1 <- runModel(projectPath, modelName = "baseline")
# Define depth dependent acoustic target strength, and rerun:
process <- getProcess(
projectPath = projectPath,
modelName = "baseline",
processName = "DefineAcousticTargetStrength"
)
newAcousticTargetStrengthTable <- process$functionParameters$AcousticTargetStrengthTable
# Add the depth dependence:
newAcousticTargetStrengthTable$DepthExponent = -2.3
replaceArgsList <- list(
DefineAcousticTargetStrength = list(
UseProcessData = FALSE, # Needed to override the existing process data
AcousticTargetStrengthModel = "LengthAndDepthDependent",
AcousticTargetStrengthTable = newAcousticTargetStrengthTable
)
)
d2 <- RstoxFramework::runModel(
projectPath,
modelName = "baseline",
replaceArgsList = replaceArgsList
)
# Show the change in the output:
all.equal(d1, d2)
# The difference is larger at larger depths:
plot(
d1$Abundance$Data$MinLayerDepth,
d1$Abundance$Data$Abundance / d2$Abundance$Data$Abundance
)
} # }