genesis: Generate a raster stack representing variables on a landscape

View source: R/genesis.r

genesisR Documentation

Generate a raster stack representing variables on a landscape

Description

This function generates a raster stack in which each layer represents a variable. Each variable can have one of several spatial patterns: linear, uniform, random, step, hinge, Gaussian, or sine. Random noise can also be added to any one of these patterns, and the layer pattern can be split in half (e.g., increasing in the "east" side and decreasing in the "west" side). The landscape can be circular or square. Layers can be rotated around their center to have different orientations relative to other rasters.

Usage

genesis(geography, size = 1024, circle = TRUE, verbose = FALSE, ...)

Arguments

geography

List object composed of lists, with one list per layer on the landscape. The name of the sublists correspond to the names of the layers to be generated. Each sublist has some of the following components (some are required, some optional).

  • type (REQUIRED) Character, specifies the spatial pattern of the values of the variable. Depending on the type, different subsequent items in the list can be used to specify the parameters of the pattern:

    • uniform: Spatially uniform with all values equal to 1.

    • random: Uniformly randomly drawn values across the range specified by:

      • min and max: Numeric, minimum and maximum value.

    • linear: Variable changes linearly across the landscape with these parameters:

      • min and max: Numeric, minimum and maximum value.

    • step: A step function pattern with these parameters:

      • min and max: Numeric, minimum and maximum value below and above the step.

      • at Numeric, location of the step specified such that the bottom ("south") edge of the raster is at position -1 and the top ("north") edge is at position 1.

    • hinge: An area with a constant value adjacent to an area with a linearly increasing or decreasing value, which is in turn adjacent to an area with another constant value.

      • min and max: Numeric, minimum and maximum value below and above the step.

      • from Numeric, location where the hinge "starts" such that the bottom ("south") edge of the raster is at position -1 and the top ("north") edge is at position 1.

      • to Numeric, location where the hinge "ends" such that the bottom ("south") edge of the raster is at position -1 and the top ("north") edge is at position 1.

    • gaussian: A spatially Gaussian distribution with these parameters:

      • center1 and center2: Numeric, position on (or off) the landscape where the center of the distribution lies where position -1 is at the "south" (center1) or "west" (center2) of the raster, and position 1 is at the "north" or "east" side of the raster.

      • sd1 and sd2: Numeric, standard deviation in the x- and y-directions.

      • rho Numeric, rotation (interaction between x and y directions). A value of 0 yields no rotation with values closer to 1 collapsing into a univariate distribution in the x-direction and closer to -1 in the y-direction.

    • sin A sine wave with these parameters:

      • freq Numeric, frequency (assumes going from one edge of the landscape to the other is equal to one wavelength).

      • offset Numeric, value to add/subtract from the position the the sine wave (when this is 0 then the value of sine(0) = 1 is positioned at the edge of the landscape).

      • min and max Numeric, amplitude of the sine wave.

  • rot (Optional) Numeric, degrees by which to rotate the raster relative to "north". This is useful for manipulating the correlation between layers.

  • randOrient (Optional) Logical, if TRUE then then rotate the raster in a random direction.

  • noise (Optional) Numeric or NULL, if not equal to 0 or NULL, add random noise by randomly swapping values across cells after the pattern specified by type has been created. This element states gives the proportion of cells to swap, so much be in the range [0, 1]. Note that swapping ensures the original frequency distribution of the values of the variable is retained.

  • split (Optional) Logical, if TRUE then before any rotation is performed swap values between the upper left ("northwest") corner and the lower right ("southeast") corners of the raster.

size

Positive integer, number of rows/columns in each landscape raster.

circle

Logical, if TRUE then the raster stack is cropped to a circle with values outside the circle left as NA. If FALSE (default), then the stack is left as a square.

verbose

Logical, if TRUE display progress. Default is FALSE.

...

Other arguments (unused).

Value

A raster stack.

Examples

geog1 <- list(
	uniform=list(type='uniform'),
	random=list(type='random', min=-1, max=1),
	linear=list(type='linear', min=-1, max=1),
	linearNoise=list(type='linear', min=-1, max=1, noise=0.3),
	step=list(type='step', min=-1, max=1, at=0.5),
	hinge=list(type='hinge', min=-1, max=1, from=-0.5, to=0),
	gauss=list(type='gaussian', center1=0, center2=0.25,
		sd1=0.5, sd2=0.25, rho=2/3),
	sine=list(type='sin', freq=2, offset=0, min=-1, max=1)
)

# square landscape
land <- genesis(geography=geog1, size=201, circle=FALSE)
raster::plot(land)

# circular landscape
land <- genesis(geography=geog1, size=201)
raster::plot(land)

# layer rotation
geog2 <- list(
	x1=list(type='linear', min=-1, max=1),
	x2=list(type='linear', min=-1, max=1, rot=45)
)
land <- genesis(geog2, size=201, circle=TRUE)
raster::plot(land)

# fancy stuff
set.seed(123)
geog3 <- list(
	control=list(type='linear', min=-1, max=1),
	noisy=list(type='linear', min=-1, max=1, noisy=TRUE),
	split=list(type='linear', min=-1, max=1, split=TRUE),
	randOrient=list(type='linear', min=-1, max=1, randOrient=TRUE),
	all=list(type='linear', min=-1, max=1, noisy=TRUE, split=TRUE,
		randOrient=TRUE)
)
land <- genesis(geog3, size=201)
raster::plot(land)

adamlilith/enmSdmPredImport documentation built on Dec. 31, 2022, 5:40 p.m.