This function retrieves spatial columns from one or more SyncroSim Scenario Datasheets.

datasheetSpatRaster(
  ssimObject,
  datasheet,
  column = NULL,
  scenario = NULL,
  iteration = NULL,
  timestep = NULL,
  filterColumn = NULL,
  filterValue = NULL,
  subset = NULL,
  forceElements = FALSE,
  pathOnly = FALSE
)

# S4 method for character
datasheetSpatRaster(
  ssimObject,
  datasheet,
  column = NULL,
  scenario = NULL,
  iteration = NULL,
  timestep = NULL,
  filterColumn = NULL,
  filterValue = NULL,
  subset = NULL,
  forceElements = FALSE,
  pathOnly = FALSE
)

# S4 method for list
datasheetSpatRaster(
  ssimObject,
  datasheet,
  column = NULL,
  scenario = NULL,
  iteration = NULL,
  timestep = NULL,
  filterColumn = NULL,
  filterValue = NULL,
  subset = NULL,
  forceElements = FALSE,
  pathOnly = FALSE
)

# S4 method for SsimObject
datasheetSpatRaster(
  ssimObject,
  datasheet,
  column = NULL,
  scenario = NULL,
  iteration = NULL,
  timestep = NULL,
  filterColumn = NULL,
  filterValue = NULL,
  subset = NULL,
  forceElements = FALSE,
  pathOnly = FALSE
)

# S4 method for Scenario
datasheetSpatRaster(
  ssimObject,
  datasheet,
  column = NULL,
  scenario = NULL,
  iteration = NULL,
  timestep = NULL,
  filterColumn = NULL,
  filterValue = NULL,
  subset = NULL,
  forceElements = FALSE,
  pathOnly = FALSE
)

Arguments

ssimObject

SsimLibrary/Project/Scenario object or list of Scenario objects. If SsimLibrary/Project, then scenario argument is required

datasheet

character string. The name of the Datasheet containing the raster data

column

character string. The name of the column in the datasheet containing the file names for raster data. If NULL (default) then use the first column that contains raster file names

scenario

character string, integer, or vector of these. The Scenarios to include. Required if SsimObject is an SsimLibrary/Project, ignored if SsimObject is a list of Scenarios (optional)

iteration

integer, character string, or vector of integer/character strings. Iteration(s) to include. If NULL (default) then all iterations are included. If no Iteration column is in the Datasheet, then ignored

timestep

integer, character string, or vector of integer/character string. Timestep(s) to include. If NULL (default) then all timesteps are included. If no Timestep column is in the Datasheet, then ignored

filterColumn

character string. The column to filter a Datasheet by. (e.g. "TransitionGroupID"). Note that to use the filterColumn argument, you must also specify a filterValue. Default is NULL

filterValue

character string or integer. The value of the filterColumn to filter the Datasheet by. To use the filterValue argument, you must also specify a filterColumn. Default is NULL

subset

logical expression indicating Datasheet rows to return. e.g. expression(grepl("Ts0001", Filename, fixed=T)). See subset() for details (optional)

forceElements

logical. If TRUE then returns a single raster as a RasterStack; otherwise returns a single raster as a RasterLayer directly. Default is FALSE

pathOnly

logical. If TRUE then returns a list of filepaths to the raster files on disk. Default is FALSE

Value

A SpatRaster object, or List. See terra package documentation for details.

Details

The names of the returned SpatRaster contain metadata. For Datasheets without Filename this is:

paste0(<datasheet name>,".Scn",<scenario id>,".",<tif name>).

For Datasheets containing Filename this is:

paste0(<datasheet name>,".Scn",<scenario id>,".It",<iteration>,".Ts",<timestep>).

Examples

if (FALSE) {
# Install the helloworldSpatial package from the server
addPackage("helloworldSpatial")

# Specify file path and name of new SsimLibrary
myLibraryName <- file.path(tempdir(), "testlib_datasheetSpatRaster")

# Set up a SyncroSim Session
mySession <- session()

# Use the example template library from helloworldSpatial
myLibrary <- ssimLibrary(name = myLibraryName,
                         session = mySession,
                         package = "helloworldSpatial",
                         template = "example-library",
                         forceUpdate = TRUE,
                         overwrite=TRUE)

# Set up Project and Scenario
myProject <- project(myLibrary, project = "Definitions")
myScenario <- scenario(myProject, scenario = "My Scenario")

# Run Scenario to generate results
resultScenario <- run(myScenario)

# Extract specific Datasheet rasters by iteration and timestep
resultRaster <- datasheetSpatRaster(resultScenario,
                  datasheet = "IntermediateDatasheet",
                  column = "OutputRasterFile",
                  iteration = 3,
                  timestep = 2
)

# Extract specific Datasheet SpatRasters using pattern matching
resultDatasheet <- datasheet(resultScenario, name = "IntermediateDatasheet")
colnames(resultDatasheet)
outputRasterPaths <- resultDatasheet$OutputRasterFile
resultRaster <- datasheetSpatRaster(resultScenario, 
                  datasheet = "IntermediateDatasheet",
                  column = "OutputRasterFile",
                  subset = expression(grepl("ts20", 
                                             outputRasterPaths,
                                             fixed = TRUE))
)

# Return the raster Datasheets as a SpatRaster list
resultRaster <- datasheetSpatRaster(resultScenario, 
                 datasheet = "IntermediateDatasheet",
                 column = "OutputRasterFile",
                 forceElements = TRUE
                 )
                 
# Filter for only rasters that fit specific criteria
# Load the ST-Sim spatial example library
addPackage("stsim")

# Set the file path and name of the new SsimLibrary
myLibraryName <- file.path(tempdir(),"testlib_stsim_datasheet")

# Set the SyncroSim Session
mySession <- session()

# Create a new SsimLibrary with the example template from ST-Sim
myLibrary <- ssimLibrary(name = myLibraryName,
                         session = mySession, 
                         package = "stsim",
                         template = "spatial-example",
                         forceUpdate = TRUE)
                         
myScenario <- scenario(myLibrary, scenario = 16)

# Run Scenario to generate results
resultScenario <- run(myScenario)


resultRaster <- datasheetSpatRaster(resultScenario,
                 datasheet = "stsim_OutputSpatialState",
                 timestep = 5,
                 iteration = 5,
                 filterColumn = "TransitionTypeID",
                 filterValue = "Fire")
}