Skip to content

r.random.walk

Performs a 2D random walk inside the computational region and returns the resulting walk.

r.random.walk [-ast] output=name [steps=integer] [directions=string] [memory=memory in MB] [seed=integer] [nprocs=integer] [nwalkers=integer] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

r.random.walk output=name

grass.script.run_command("r.random.walk", output, steps=100000, directions="4", memory=300, seed=None, nprocs=1, nwalkers=1, flags=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("r.random.walk", output="name")

Parameters

output=name [required]
    Name for output raster map
steps=integer
    How many steps to take during walk.
    Default: 100000
directions=string
    How many directions should be used during walk.
    Allowed values: 4, 8
    Default: 4
memory=memory in MB
    Maximum memory to be used (in MB)
    Cache size for raster rows
    Default: 300
seed=integer
    Seed for random number generator
nprocs=integer
    Number of threads for parallel computing
    Default: 1
nwalkers=integer
    Number of walkers.
    Default: 1
-a
    Perform a self-avoiding random walk
-s
    Generate random seed (result is non-deterministic).
-t
    Each walker starts from the same point.
--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

output : str, required
    Name for output raster map
    Used as: output, raster, name
steps : int, optional
    How many steps to take during walk.
    Default: 100000
directions : str, optional
    How many directions should be used during walk.
    Allowed values: 4, 8
    Default: 4
memory : int, optional
    Maximum memory to be used (in MB)
    Cache size for raster rows
    Used as: memory in MB
    Default: 300
seed : int, optional
    Seed for random number generator
nprocs : int, optional
    Number of threads for parallel computing
    Default: 1
nwalkers : int, optional
    Number of walkers.
    Default: 1
flags : str, optional
    Allowed values: a, s, t
    a
        Perform a self-avoiding random walk
    s
        Generate random seed (result is non-deterministic).
    t
        Each walker starts from the same point.
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

The r.random.walk module generates a 2D random walk across the current computational region. The module provides control of the number of steps and directions (4 or 8) a walker can take and allows the walker's behavior to be set to be self-avoiding (Madras et al., 1996) or allow revisits. The output displays the frequency the walker visited each cell or the average frequency. The module can run multiple walks in parallel. It either samples the same starting location for each walk or generates a unique starting position for each walker.

EXAMPLE

Using the North Carolina full sample dataset:

# set computational region
g.region raster=elevation -p

# calculate smoothed random walk from a single starting locations.
r.random.walk -at output=random_walk_smooth_paths directions=8 steps=100000 memory=1800 seed=1 nprocs=6 nwalkers=100

image-alt
Smoothed random walk (Single Starting Location)

# calculate smoothed random walk from a multiple starting locations.
r.random.walk -as output=random_walk_smooth directions=8 steps=100000 memory=1800 nprocs=6 nwalkers=100

image-alt
Smoothed random walk (Multiple Starting Locations)

SEE ALSO

r.surf.fractal, r.surf.random

AUTHOR

Corey T. White, NCSU GeoForAll Lab

SOURCE CODE

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