-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notwithstanding the dress standards outlined above, MCC reserves the …
…right to refuse entry to any person considered unsuitably attired
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' @title Standardise raster | ||
#' @description Standardises all layers in a `SpatRaster` to a scale of 0-1, | ||
#' by dividing by the maximum value in each layer. | ||
#' | ||
#' @param x `SpatRaster` to standardise | ||
#' @param filename Optional `character` path and filename to write output | ||
#' @param overwrite `logical` if `TRUE` will overwrite `filename` | ||
#' | ||
#' @return | ||
#' @export | ||
#' | ||
#' @details | ||
#' Will break for non-numeric rasters | ||
#' | ||
#' | ||
#' @examples | ||
#' example_raster() |> | ||
#' std_rast() | ||
std_rast <- function(x, filename = NULL, overwrite = TRUE){ | ||
if(terra::nlyr(x)>1){ | ||
|
||
vals <- terra::values(x) | ||
|
||
nvs <- apply( | ||
vals, | ||
MARGIN = 2, | ||
FUN = function(x){ | ||
x/max(x, na.rm = TRUE) | ||
} | ||
) | ||
|
||
r <- x | ||
|
||
r[] <- nvs | ||
|
||
|
||
} else { | ||
r <- x / max(x) | ||
} | ||
|
||
if(is.null(filename)){ | ||
return(r) | ||
} | ||
|
||
writereadrast( | ||
r, | ||
filename, | ||
overwrite | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.