spm_discretize: Discretize a 'sspm' model object

spm_discretizeR Documentation

Discretize a sspm model object

Description

Discretize a sspm model object with a function from a discretization_method object class. This function divides the boundary polygons into smaller patches.

Usage

spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

## S4 method for signature 'sspm_boundary,missing,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

## S4 method for signature 'sspm_boundary,ANY,missing'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

## S4 method for signature 'sspm_boundary,character,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

## S4 method for signature 'sspm_boundary,function,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

## S4 method for signature 'sspm_boundary,discretization_method,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

Arguments

boundary_object

[sspm] An object of class sspm_boundary.

method

[character OR method] Either a character from the list of available methods (see spm_methods for the list) OR an object of class discretization_method.

with

[sspm_dataset OR sf] Either an object of class sspm_dataset or a set of custom points.

...

[named list] Further arguments to be passed onto the function used in method.

Details

Custom discretization functions can be written. The function must:

  1. Accept at least 1 argument: boundaries (the sf boundary object), and optionnaly with (can be NULL) a separate object to be used for discretization and boundary, the boundary column of boundaries (these last 2 arguments are passed and connot be overwritten but could be ignored).

  2. Returns a named list with 2 elements: patches. an sf object that stores the discretized polygons, and points, an sf object that stores the points that were used for discretization.

Value

An object of class sspm_discrete_boundary (the updated and discretized sspm object given as input).

Examples

# Voronoi tesselation
sfa_boundaries
bounds <- spm_as_boundary(boundaries = sfa_boundaries,
                          boundary = "sfa")
biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis",
                                  density = "weight_per_km2",
                                  time = "year_f",
                                  coords = c('lon_dec','lat_dec'),
                                  uniqueID = "uniqueID")
bounds_voronoi <- bounds %>%
  spm_discretize(method = "tesselate_voronoi",
                 with = biomass_dataset,
                 nb_samples = 10)

# Custom method
custom_func <- function(boundaries, ...){
  args <- list(...)
  # Can access passed arguments with args$arg_name
  # Do your custom discretization
  # Careful: must return sf objects!
  return(list(patches = c(),
              points = c())
         )
}


pedersen-fisheries-lab/spaspm documentation built on Feb. 16, 2025, 7:39 p.m.