thresholder: Apply a Threshold to a Field

View source: R/DataObjects.R

thresholderR Documentation

Apply a Threshold to a Field

Description

App;y a threshold to a field and return either a binary field or a field with replace.width everywhere the rule is not true.

Usage

thresholder(x, type = c("binary", "replace.below"), th, rule = ">=",
    replace.with = 0, ...)

## Default S3 method:
thresholder(x, type = c("binary", "replace.below"), th, rule = ">=", 
    replace.with = 0, ... )

## S3 method for class 'SpatialVx'
thresholder(x, type = c("binary", "replace.below"), th, rule = ">=",
    replace.with = 0, ..., time.point = 1, obs = 1, model = 1 )

Arguments

x

A field or “SpatialVx” object to which to apply the thresholds.

type

character describing which type of field(s) to return: binary or replace.

rule

If type is “binary”, return 0 when the rule applied to a grid point's value is not true in relation to the threshold value, and 1 elsewhere. If type is “replace.below”, then return replace.with wherever the rule is not true and return the original value otherwise. By default, it replaces values below the threshold with zero (hence its name), but if rule is, e.g., “<=”, then it will replace values above with zero; or whatever value is chosen for replace.with.

replace.with

Only used if type is “replace.below”. The value with which to replace values that are below (default) the threshold.

th

Value of the threshold (default) or index to which row of threshold matrices in thresholds attribute of “SpatialVx” object. Must be a single number.

time.point

numeric or character indicating which time point from the “SpatialVx” verification set to select for analysis.

obs, model

numeric indicating which observation/forecast model to select for the analysis.

...

Not used.

Details

At each point, p, in the field, the expression: p rule threshold is applied. If type is “binary”, then if the expression is false, zero is returned for that grid point, and if it is true, then one is returned. If type is “replace.below”, then if the expression is false, replace.with is returned for that grid point, and if true, then the original value is returned. By default, the original field is returned, but with values below the threshold set to zero. If rule is “<=”, then replace.below will actually replace values above the threshold with “replace.with” instead.

If applied to a “SpatialVx” class object, then observation obs and model model at time point time.point will each be thresholded using the respective th threshold value for the observed and modeled fields as taken from the thresholds attribute of the object (see the help file for make.SpatialVx).

Value

A field of the same dimension as x if a matrix. If x is a “SpatialVx” class object, then a list is returned with components:

X, Xhat

The matrices giving the respective thresholded fields for the observation and forecast.

Author(s)

Eric Gilleland

See Also

make.SpatialVx

Examples


x <- matrix( 12 + rnorm( 100, 10, 10 ), 10, 10 )

par( mfrow = c(2, 2) )
image.plot( thresholder( x, th = 12 ), main = "binary" )

image.plot( thresholder( x, type = "replace.below", th = 12 ),
    main = "replace.below" ) 

image.plot( thresholder( x, th = 12, rule = "<=" ),
    main = "binary with rule <=" )

image.plot( thresholder( x, type = "replace.below", th = 12, rule = "<=" ),
    main = "replace.below with rule <=" )

par( mfrow = c(1,1) )
## Not run: 
data("geom000")
data("geom004")
data("ICPg240Locs")

hold <- make.SpatialVx( geom000, geom004, thresholds = c(0.01, 50.01),
    projection = TRUE, map = TRUE, loc = ICPg240Locs, loc.byrow = TRUE,
    field.type = "Geometric Objects Pretending to be Precipitation",
    units = "mm/h", data.name = "ICP Geometric Cases", obs.name = "geom000",
    model.name = "geom004" )

# Note: th = 1 means threshold = 0.01.
look <- thresholder( hold, th = 1 )

image.plot( look$X )
contour( look$Xhat, add = TRUE, col = "white" )

# Note: th = 2, means threshold = 50.01
look <- thresholder( hold, th = 2 )

image.plot( look$X )
contour( look$Xhat, add = TRUE, col = "white" )

look <- thresholder( hold, th = 1, rule = "<" )

image.plot( look$X )
contour( look$Xhat, add = TRUE, col = "white" )

## End(Not run)

SpatialVx documentation built on May 29, 2024, 9:31 a.m.