Skip to content

v.surf.rst.cv

Performs cross-validation proceedure to optimize the parameterization of v.surf.rst tension and smoothing paramters.

v.surf.rst.cv point_cloud=name [mask=name] [tension=integer [,integer,...]] [smooth=float [,float,...]] [layer=string] [zcolumn=name] [where=sql_query] [segmax=integer] [dmin=float] [dmax=float] [zscale=float] [theta=float] [scalex=float] [cv_prefix=string] [output_file=name] [format=string] [nprocs=integer] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

v.surf.rst.cv point_cloud=name

grass.script.parse_command("v.surf.rst.cv", point_cloud, mask=None, tension=10, 20, 40, 60, 80, 100, smooth=0.01, 0.1, 0.5, 1.0, 5.0, 10.0, layer="1", zcolumn=None, where=None, segmax=40, dmin=0.0, dmax=0.0, zscale=1.0, theta=None, scalex=None, cv_prefix=None, output_file=None, format=None, nprocs=1, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.parse_command("v.surf.rst.cv", point_cloud="name")

Parameters

point_cloud=name [required]
    Name of the input point cloud vector map
    Name of the input point cloud vector map
mask=name
    Mask raster map
    Name of the mask raster map
tension=integer [,integer,...]
    Tension parameter for cross-validation
    Default: 10, 20, 40, 60, 80, 100
smooth=float [,float,...]
    Smoothing parameter for cross-validation
    Default: 0.01, 0.1, 0.5, 1.0, 5.0, 10.0
layer=string
    Layer number or name
    Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
    Default: 1
zcolumn=name
    Name of the attribute column with values to be used for approximation
    If not given and input is 2D vector map then category values are used. If input is 3D vector map then z-coordinates are used.
where=sql_query
    WHERE conditions of SQL statement without 'where' keyword
    Example: elevation < 500 and elevation >= 1
segmax=integer
    Maximum number of points in segment
    Default: 40
dmin=float
    Minimum distance between points
    Default: 0.0
dmax=float
    Maximum distance between points on isoline (to insert additional points)
    Default: 0.0
zscale=float
    Conversion factor for values used for approximation
    Default: 1.0
theta=float
    Anisotropy angle (in degrees counterclockwise from East)
scalex=float
    Anisotropy scaling factor
cv_prefix=string
    Prefix to use for cross-validation output maps
    Prefix to use for cross-validation output cross-validation errors vector point map. Value must be set to save the cross-validation errors to a vector maps.
output_file=name
    Output file
    Output file for the results (default: None) json or csv
format=string
    Output format
    Output format for the results
    Allowed values: json, text
nprocs=integer
    Number of threads for parallel computing
    Default: 1
--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

point_cloud : str, required
    Name of the input point cloud vector map
    Name of the input point cloud vector map
    Used as: input, vector, name
mask : str, optional
    Mask raster map
    Name of the mask raster map
    Used as: input, raster, name
tension : int | list[int] | str, optional
    Tension parameter for cross-validation
    Default: 10, 20, 40, 60, 80, 100
smooth : float | list[float] | str, optional
    Smoothing parameter for cross-validation
    Default: 0.01, 0.1, 0.5, 1.0, 5.0, 10.0
layer : str, optional
    Layer number or name
    Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
    Used as: input, layer
    Default: 1
zcolumn : str, optional
    Name of the attribute column with values to be used for approximation
    If not given and input is 2D vector map then category values are used. If input is 3D vector map then z-coordinates are used.
    Used as: input, dbcolumn, name
where : str, optional
    WHERE conditions of SQL statement without 'where' keyword
    Example: elevation < 500 and elevation >= 1
    Used as: input, sql_query, sql_query
segmax : int, optional
    Maximum number of points in segment
    Default: 40
dmin : float, optional
    Minimum distance between points
    Default: 0.0
dmax : float, optional
    Maximum distance between points on isoline (to insert additional points)
    Default: 0.0
zscale : float, optional
    Conversion factor for values used for approximation
    Default: 1.0
theta : float, optional
    Anisotropy angle (in degrees counterclockwise from East)
scalex : float, optional
    Anisotropy scaling factor
cv_prefix : str, optional
    Prefix to use for cross-validation output maps
    Prefix to use for cross-validation output cross-validation errors vector point map. Value must be set to save the cross-validation errors to a vector maps.
output_file : str, optional
    Output file
    Output file for the results (default: None) json or csv
    Used as: output, file, name
format : str, optional
    Output format
    Output format for the results
    Allowed values: json, text
nprocs : int, optional
    Number of threads for parallel computing
    Default: 1
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

v.surf.rst.cv - Cross-validation of regularized spline with tension (RST) surface model.

Predictive error of surface approximation for given parameters are computed and a cross-validation procedure is then performed using the data given in the vector map input. The estimated predictive errors are stored in the optionally saved vector point map cvdev.

For larger data sets, CV should be applied to a representative subset of the data. The cross-validation procedure works well only for well-sampled phenomena and when minimizing the predictive error is the goal. The parameters found by minimizing the predictive (CV) error may not not be the best for for poorly sampled phenomena (result could be strongly smoothed with lost details and fluctuations) or when significant noise is present that needs to be smoothed out.

EXAMPLES

import grass.script as gs

gs.run_command(
    "g.region",
    raster="elevation",
    res=30,
    n=220790,
    s=218390,
    w=632680,
    e=635910,
    flags="a",
)

# Extract random elevation points from the DEM
gs.run_command(
    "r.random",
    input="elevation",
    npoints=500,
    seed=0,
    vector="points",
    flags="z",
    overwrite=True,
)

# Run the cross validation proceedure
# using the random points
gs.run_command('v.surf.rst.cv',
    point_cloud="points",
    tension=[10, 100],
    smooth=[0.5, 5.0],
    segmax=600,
    format="json",
    output_file="test_cv.json",
    cv_prefix='cvdev',
    overwrite=True
)

By setting the output_file and format options the output of the above command will be a JSON file with the cross-validation results. The file will contain the following information:

[
    {
        "tension": "10",
        "smooth": "0.5",
        "rmse": 3.938792429360747,
        "mae": 3.2086477739999997
    },
    {
        "tension": "10",
        "smooth": "5.0",
        "rmse": 4.921535874096144,
        "mae": 4.075445157999998
    },
    {
        "tension": "100",
        "smooth": "0.5",
        "rmse": 2.715355217413409,
        "mae": 2.0061099599999994
    },
    {
        "tension": "100",
        "smooth": "5.0",
        "rmse": 3.438609351379808,
        "mae": 2.73388017
    }
]

A report of the best parameter combination and the RMSE and MAE values will be printed to the stderr.

Best parameter combination
--------------------------------------------------
Tension: 100
Smoothing: 0.5
RMSE: 2.715355217413409
MAE: 2.0061099599999994
--------------------------------------------------

When the cv_prefix option is set, the vector point maps with the cross-validation results will be saved and interpolated into a new surface that displays the residuals of the cross-validation. The surface will be saved in the current mapset with the name <cv_prefix>_<tension>_<smooth>.

cdev-surface
Tension: 100 Smooth: 0.5 cdev-surface
Tension: 100 Smooth: 5 cdev-surface
Tension: 10 Smooth: 0.5 cdev-surface
Tension: 10 Smooth: 5

REFERENCES

  • Mitasova, H., Mitas, L. and Harmon, R.S., 2005, Simultaneous spline approximation and topographic analysis for lidar elevation data in open source GIS, IEEE GRSL 2 (4), 375- 379.
  • Hofierka, J., 2005, Interpolation of Radioactivity Data Using Regularized Spline with Tension. Applied GIS, Vol. 1, No. 2, pp. 16-01 to 16-13. DOI: 10.2104/ag050016
  • Hofierka J., Parajka J., Mitasova H., Mitas L., 2002, Multivariate Interpolation of Precipitation Using Regularized Spline with Tension. Transactions in GIS 6(2), pp. 135-150.
  • H. Mitasova, L. Mitas, B.M. Brown, D.P. Gerdes, I. Kosinovsky, 1995, Modeling spatially and temporally distributed phenomena: New methods and tools for GRASS GIS. International Journal of GIS, 9 (4), special issue on Integrating GIS and Environmental modeling, 433-446.
  • Mitasova, H. and Mitas, L., 1993: Interpolation by Regularized Spline with Tension: I. Theory and Implementation, Mathematical Geology ,25, 641-655.
  • Mitasova, H. and Hofierka, J., 1993: Interpolation by Regularized Spline with Tension: II. Application to Terrain Modeling and Surface Geometry Analysis, Mathematical Geology 25, 657-667.
  • Mitas, L., and Mitasova H., 1988, General variational approach to the approximation problem, Computers and Mathematics with Applications, v.16, p. 983-992.
  • Neteler, M. and Mitasova, H., 2008, Open Source GIS: A GRASS GIS Approach, 3rd Edition, Springer, New York, 406 pages.
  • Talmi, A. and Gilat, G., 1977 : Method for Smooth Approximation of Data, Journal of Computational Physics, 23, p.93-123.
  • Wahba, G., 1990, : Spline Models for Observational Data, CNMS-NSF Regional Conference series in applied mathematics, 59, SIAM, Philadelphia, Pennsylvania.

SEE ALSO

v.surf.rst

AUTHORS

Corey T. White NCSU GeoForAll Lab

SOURCE CODE

Available at: v.surf.rst.cv source code (history)
Latest change: Saturday Apr 05 13:02:33 2025 in commit cafc53f