Transforms raster to a specified statistical transformation

Transformation option details:

  • norm - (Normalization_ (0-1): if min(x) < 0 ( x - min(x) ) / ( max(x) - min(x) )

  • rstd - (Row standardize) (0-1): if min(x) >= 0 x / max(x) This normalizes data

  •    with negative distributions
    
  • std - (Standardize) (x - mean(x)) / sdv(x)

  • stretch - (Stretch) ((x - min(x)) * max.stretch / (max(x) - min(x)) + min.stretch) This will stretch values to the specified minimum and maximum values (eg., 0-255 for 8-bit)

  • nl - (Natural logarithms) if min(x) > 0 log(x)

  • slog - (Signed log 10) (for skewed data): if min(x) >= 0 ifelse(abs(x) <= 1, 0, sign(x)*log10(abs(x)))

  • sr - (Square-root) if min(x) >= 0 sqrt(x)

raster.transformation(x, trans = "norm", smin = 0, smax = 255)

Arguments

x

raster class object

trans

Transformation method: "norm", "rstd", "std", "stretch", "nl", "slog", "sr" (please see notes)

smin

Minimum value for stretch

smax

Maximum value for stretch

Value

raster class object of transformation

Author

Jeffrey S. Evans jeffrey_evans@tnc.org

Examples

# \donttest{ library(raster) r <- raster(nrows=100, ncols=100, xmn=571823, xmx=616763, ymn=4423540, ymx=4453690) r[] <- runif(ncell(r), 1000, 2500) # Postive values so, can apply any transformation for( i in c("norm", "rstd", "std", "stretch", "nl", "slog", "sr")) { print( raster.transformation(r, trans = i) ) }
#> applying normalization transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 0, 1 (min, max) #>
#> applying row-standardization transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 0.40009, 1 (min, max) #>
#> applying standardization transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : -1.739012, 1.722989 (min, max) #>
#> applying stretch transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 0, 255 (min, max) #>
#> applying log transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 6.907824, 7.823889 (min, max) #>
#> applying singned-log10 transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 3.00003, 3.397872 (min, max) #>
#> applying sqare-root transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 31.62386, 49.99609 (min, max) #>
# Negative values so, can't transform using "nl", "slog" or "sr" r[] <- runif(ncell(r), -1, 1) for( i in c("norm", "rstd", "std", "stretch", "nl", "slog", "sr")) { try( print( raster.transformation(r, trans = i) ) ) }
#> [1] " Min value < 0, running row standardization instead" #> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : -1.000017, 1 (min, max) #>
#> applying row-standardization transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : -1.000017, 1 (min, max) #>
#> applying standardization transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : -1.718704, 1.742859 (min, max) #>
#> applying stretch transformation
#> class : RasterLayer #> dimensions : 100, 100, 10000 (nrow, ncol, ncell) #> resolution : 449.4, 301.5 (x, y) #> extent : 571823, 616763, 4423540, 4453690 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 0, 255 (min, max) #> #> Error in h(simpleError(msg, call)) : #> error in evaluating the argument 'x' in selecting a method for function 'print': Minimum value < 0, cannot log transform #> Error in h(simpleError(msg, call)) : #> error in evaluating the argument 'x' in selecting a method for function 'print': Minimum value < 0, cannot log transform #> Error in h(simpleError(msg, call)) : #> error in evaluating the argument 'x' in selecting a method for function 'print': Minimum value < 0, cannot log transform
# }