iterate: Generate disaggregated soil maps

View source: R/dsmartr_iterate.R

iterateR Documentation

Generate disaggregated soil maps

Description

Disaggregates an input soil map a given number of times.

Usage

iterate(
  prepped_map = NULL,
  covariates = NULL,
  prepped_points = NULL,
  id_field = NULL,
  n_iterations = NULL,
  t_factor = 10000,
  c5_ctrl = NULL,
  cpus = 1,
  write_files = c("native", "rds"),
  write_samples = FALSE,
  resume_from = NULL
)

Arguments

prepped_map

Data Frame; Returned by dsmartr::prep_polygons().

covariates

RasterStack or RasterBrick; environmental covariate datasets.

prepped_points

Data Frame; Returned by dsmartr::prep_points(); optional.

id_field

String; name of unique polygon identifier field.

n_iterations

Integer; desired number of model runs.

t_factor

Integer; dirichlet distribution modifier. Where map units have >1 soil class component, larger values of t_factor dampen variation away from the input proportions.

c5_ctrl

List; output of C5.0Control; optional.

cpus

Integer; number of processors to use in parallel.

write_files

String; choose 'native' to write outputs in GeoTIFF, GPKG, or csv as appropriate, or 'rds' for outputs in RDS format. Note that map rasters are always written as GeoTIFF.

write_samples

Logical; whether to retain the covariate samples taken during each iteration. If TRUE, each set of samples is written to disk as GPKG or RDS.

resume_from

Integer; If this function is interrupted, it can be resumed from a specified iteration number (prevents overwriting existing model iterations in output directory).

Value

RasterStack; n_iterations layers. As a side effect, for each model run, outputs written to disk include the predicted soils map, the C5.0 model summary, and optionally, the covariate sample points in spatial data format.

Note

This function writes a large number of files to disk.

Examples

## Not run: 
# Polygons only:
# run prep_polygons() example code, then
iteration_maps <- iterate(prepped_map = pr_ap,
                          covariates = heronvale_covariates,
                          id_field = 'POLY_NO', n_iterations = 20,
                          cpus = max(1, (parallel::detectCores() - 1)),
                          write_files = 'native', write_samples = TRUE)

 # Polygons, points and a C50 model tweak, no samples, rds output:
 win_on <- C50::C5.0Control(winnow = TRUE)
 iteration_maps <- iterate(prepped_map = pr_ap,
                           covariates = heronvale_covariates,
                           id_field = 'POLY_NO', prepped_points = pr_pts,
                           n_iterations = 20, c5_ctrl = win_on,
                           cpus = max(1, (parallel::detectCores() - 1)),
                           write_files = 'rds')

## Oh no, there was a blackout halfway through my model run:
iteration_maps_2 <- iterate(prepped_map = pr_ap,
                            covariates = heronvale_covariates,
                            id_field = 'POLY_NO', n_iterations = 6,
                            cpus = max(1, (parallel::detectCores() - 1)),
                            write_files = 'all', write_samples = TRUE,
                            resume_from = 14)

## End(Not run)

obrl-soil/dsmartr documentation built on Feb. 1, 2024, 10:57 p.m.