To setup SPAMc two steps need to be taken (the order is important!). It is assumed that all required software is already installed and working (see software and hardware). As mentioned, it is by far the easiest to install the template in an RStudio project first and then start to work on your own country SPAMc version as all the steps discussed from now on are already pre-coded in the template.

Create SPAMc folder structure

mapspam2globiom includes a function to create all necessary folders create_spam_folders(). The only input it requires is a path on your harddisk. We do not recommend using a server to store the model as the potential increase in file access time might seriously affect the time it takes to process some of the spatial datasets which can be very large. Note that it is perfectly fine to store large raw data files on a server (see below).

# Load mapspam2globiom
library("mapspam2globiom")

# Set the folder where the model will be stored
# Note that R uses forward slashes even in Windows!!
spamc_path <- "C:/Users/dijk158/Dropbox/mapspam2globiom_mwi"

# Create SPAMc folder structure in the spamc_path
create_spam_folders(spamc_path)

Set model parameters and location of files

Nearly all functions in mapspam2globiom need input on (1) key parameters that determine the design of the model and how will be solved and (2) the location of raw and intermediate data, which will be processed (see model structure. Both pieces of information are bundled and stored by the function set_spam_par() in a spam_par object.

# Set SPAMc parameters
par <- set_spam_par(spam_path = spamc_path,
 iso3c_sel = "MWI",
 year_sel = 2010,
 grid_sel = "5min",
 adm_sel = 1,
 solve_sel = 0,
 model_sel = "max_score")

# check class
class(par)
#> [1] "spam_par"

# Show parameters
print(par)
#> iso3c:  MWI 
#> year:  2010 
#> resolution:  5min 
#> adm level:  1 
#> solve level:  0 
#> model:  max_score 
#> spam path:  C:/Users/dijk158/Dropbox/mapspam2globiom_mwi 
#> raw data path:  C:/Users/dijk158/Dropbox/mapspam2globiom_mwi/raw_data 
#> processed data:  C:/Users/dijk158/Dropbox/mapspam2globiom_mwi/processed_data 
#> parameter path:  C:/Users/dijk158/Dropbox/mapspam2globiom_mwi/parameters 
#> country name:  Malawi 
#> iso3n:  454 
#> fao code:  130 
#> continent:

This object need to be saved in the parameters folder that was created together with all the other folders when running create_spam_folders. Elements in a spam_par object class can be extracted by using the dollar sign ($). This feature is used to save par the temporary object of class spam_par into the relevant folder.

# Save 
saveRDS(par, file.path(par$spam_path, "parameters/spam_par.rds"))

That is all it takes to set up the SPAMc model! The next step is processing the raw subnational statistics and spatial data.