Skip to content

r.random.weight

Generates a binary raster layer with a random selection of raster cells depending on the weight of each cell in the input weight layer.

r.random.weight [-sn] weights=raster output=raster [start=float] [end=float] [subsample=string] [seed=integer] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

r.random.weight weights=raster output=raster seed=integer

grass.script.run_command("r.random.weight", weights, output, start=None, end=None, subsample=None, seed=None, flags=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("r.random.weight", weights="raster", output="raster", seed=integer)

Parameters

weights=raster [required]
    layer with weight
output=raster [required]
    output layer
start=float
    minimum weight
end=float
    maximum weight
subsample=string
    subsample
seed=integer
    set seed for random number generation
-s
    Generate random seed (result is non-deterministic)
-n
    set non-selected values to 0 (default to NULL)
--overwrite
    Allow output files to overwrite existing files
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output
--qq
    Very quiet module output
--ui
    Force launching GUI dialog

weights : str, required
    layer with weight
    Used as: input, raster, raster
output : str, required
    output layer
    Used as: output, raster, raster
start : float, optional
    minimum weight
end : float, optional
    maximum weight
subsample : str, optional
    subsample
seed : int, optional
    set seed for random number generation
flags : str, optional
    Allowed values: s, n
    s
        Generate random seed (result is non-deterministic)
    n
        set non-selected values to 0 (default to NULL)
overwrite: bool, optional
    Allow output files to overwrite existing files
    Default: False
verbose: bool, optional
    Verbose module output
    Default: False
quiet: bool, optional
    Quiet module output
    Default: False
superquiet: bool, optional
    Very quiet module output
    Default: False

DESCRIPTION

r.rand.weight generates a binary raster layer with a random selection of raster cells which are assigned 1. The other cells are assigned NULL (or optionally 0). The change for a raster cell to get assigned a 1 (to get selected) depends on the weight (value) of that cell in the input weight layer.

By default the script is run setting a random seed every time. To ensure that your results are reproducible you can set the seed value under the 'Sample options' tab. See the 'Random number generator initialization' in the r.mapcalc helpfile for more details.

You can play with the probability for a cell to be selected by changing the minimum and/or maximum weights. The script will give a warning if the user defined minimum > minimum raster value or if the user defined maximum is smaller then the maximum raster value. The script will still run as the user may have set this values intentionally.

You can also set the total number of sample points to be selected using the under the 'Sample options' tab. This can be done using an absolute number or as percentage (see the help file of the r.random function for more details).

Examples

See here for examples

See also

r.random, r.random.cells

AUTHOR

Paulo van Breugel, paulo at ecodiv.org

SOURCE CODE

Available at: r.random.weight source code (history)
Latest change: Thursday Feb 20 13:02:26 2025 in commit 53de819