Skip to content

Commit

Permalink
# biodivMapR2 v2.2.0
Browse files Browse the repository at this point in the history
## change
- merge v2 from gitlab repository
- update vignettes for use of v2
  • Loading branch information
jbferet committed Jan 24, 2025
1 parent 2c7125f commit cb93ca6
Show file tree
Hide file tree
Showing 157 changed files with 987 additions and 5,129 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
^.*\.Rproj$
^\.Rproj\.user$
^doc
^doc/
^examples
^TODO.md
^\.travis\.yml$
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Meta
doc
doc/
.Rproj.user
.Rbuildignore
.Rhistory
Expand Down
19 changes: 9 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: biodivMapR
Title: biodivMapR: an R package for a- and ß-diversity mapping using remotely-sensed images
Version: 2.1.4
Version: 2.2.0
Authors@R: c(person(given = "Jean-Baptiste",
family = "Feret",
email = "[email protected]",
Expand All @@ -13,27 +13,24 @@ Authors@R: c(person(given = "Jean-Baptiste",
comment = c(ORCID = "0000-0002-2185-9952", "clean code, format as package, build website")))
Description: this packages allows processing image data based on the method described in the following publication:
Féret, J.-B., Asner, G.P., 2014. Mapping tropical forest canopy diversity using high-fidelity imaging spectroscopy. Ecol. Appl. 24, 1289–1296. https://doi.org/10.1890/13-1824.1
It expects a raster file as input, with ENVI HDR header file including spectral bands of the sensor, if optical sensor.
biodivMapR v2 produces spectral diversity maps, and more broadly 'remotely sensed' diversity maps.
It can process any type of raster data, as long as the driver is compatible with drivers accepted by the terra package.
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
License: GPL-3 + file LICENSE
LazyData: true
Imports:
ape,
bigRaster,
cli,
dissUtils,
doFuture,
doParallel,
dplyr,
fields,
foreach,
fundiversity,
future,
future.apply,
geometry,
labdsv,
pracma,
progress,
progressr,
purrr,
Expand All @@ -43,11 +40,13 @@ Imports:
stats,
terra,
tidyr,
tools,
vegan,
zip
vegan
Suggests:
ggplot2,
gridExtra,
knitr,
RColorBrewer,
readr,
rmarkdown,
testthat (>= 2.0.0)
Remotes: gitlab::jbferet/bigRaster
Expand Down
25 changes: 15 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,44 @@ export(get_image_bands)
export(get_kmeans)
export(get_raster_diversity)
export(get_raster_extent)
export(get_raster_functional)
export(get_spectralSpecies)
export(get_sunlitwindows)
export(get_xy_samples)
export(init_PCoA)
export(init_PCoA_samples)
export(init_kmeans)
export(init_kmeans_samples)
export(kmeans_iter)
export(kmeans_progressr)
export(load_tutorialdataset)
export(maxRows_chunk)
export(mnf)
export(nbRows_chunk)
export(noise)
export(pca)
export(pco)
export(perform_PCA)
export(print_error_message)
export(produce_win_ID)
export(radiometric_filtering)
export(radiometricfilter_chunk)
export(randperm)
export(read_ENVI_header)
export(repmat)
export(rm_invariant_bands)
export(sample_exact_raster)
export(sample_from_raster)
export(sample_from_raster_coords)
export(sample_plots_from_raster)
export(sample_raster)
export(save_diversity_maps)
export(scatter_alphabeta)
export(select_PCA_components)
export(spectralspecies_per_polygon)
export(split_chunk)
export(split_line)
export(wrapperBig_PCA)
import(cli)
import(doParallel)
import(tools)
importFrom(ape,mst)
importFrom(bigRaster,apply_bigRaster)
importFrom(dissUtils,diss)
importFrom(doFuture,registerDoFuture)
Expand All @@ -91,15 +95,17 @@ importFrom(dplyr,select)
importFrom(fields,rdist)
importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)
importFrom(fundiversity,fd_fdis)
importFrom(fundiversity,fd_fdiv)
importFrom(fundiversity,fd_feve)
importFrom(fundiversity,fd_fric)
importFrom(fundiversity,fd_raoq)
importFrom(future,multisession)
importFrom(future,plan)
importFrom(future,sequential)
importFrom(future.apply,future_lapply)
importFrom(geometry,convhulln)
importFrom(labdsv,pco)
importFrom(parallel,makeCluster)
importFrom(parallel,stopCluster)
importFrom(pracma,randperm)
importFrom(progress,progress_bar)
importFrom(progressr,handlers)
importFrom(progressr,progressor)
Expand All @@ -111,8 +117,9 @@ importFrom(sf,st_sample)
importFrom(snow,splitRows)
importFrom(stats,IQR)
importFrom(stats,as.dist)
importFrom(stats,cmdscale)
importFrom(stats,cor.test)
importFrom(stats,dist)
importFrom(stats,cov)
importFrom(stats,kmeans)
importFrom(stats,na.omit)
importFrom(stats,prcomp)
Expand Down Expand Up @@ -142,9 +149,7 @@ importFrom(terra,xyFromCell)
importFrom(tidyr,nest)
importFrom(tidyr,unnest)
importFrom(tools,file_path_sans_ext)
importFrom(utils,download.file)
importFrom(utils,file.edit)
importFrom(utils,read.csv)
importFrom(vegan,fisher.alpha)
importFrom(vegan,mantel)
importFrom(zip,unzip)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# biodivMapR2 v2.2.0
## change
- merge v2 from gitlab repository
- update vignettes for use of v2

# biodivMapR2 v2.1.4
## fix
- in 'get_diversity_from_plots' :
Expand Down
3 changes: 0 additions & 3 deletions R/apply_continuum_removal.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#
#' @return samples from image and updated number of pixels to sample if necessary
#' @importFrom snow splitRows
#' @importFrom future plan multisession sequential
#' @importFrom future.apply future_lapply
#' @importFrom progressr progressor handlers with_progress
#' @export

apply_continuum_removal <- function(Spectral_Data, Spectral) {
Expand Down
3 changes: 1 addition & 2 deletions R/biodivMapR_OptClusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
#'
#' @return list including performances (correlation) of SFS with additional
#' features and assessed diversity metrics corresponding to each step
#' @import doParallel
#' @importFrom doFuture registerDoFuture
#' @importFrom future plan multisession sequential
#' @importFrom foreach foreach %dopar%
#' @importFrom dplyr group_split
#' @importFrom vegan mantel
#' @importFrom progress progress_bar
#' @importFrom stats cor.test
Expand Down Expand Up @@ -98,6 +96,7 @@ biodivMapR_OptClusters <- function(input_raster, obs_vect, obs2optimize, SelectB
registerDoFuture()
cl <- parallel::makeCluster(nbCPU)
plan("cluster", workers = cl)
kmit <- NULL
get_diversity_from_plots_list <- function() {
foreach(kmit = Kmeans_info) %dopar% {
divplots <- get_diversity_from_plots(input_rast = input_raster,
Expand Down
2 changes: 1 addition & 1 deletion R/biodivMapR_SFS.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#'
#' @return list including performances (correlation) of SFS with additional
#' features and assessed diversity metrics corresponding to each step
#' @import doParallel
#' @importFrom doFuture registerDoFuture
#' @importFrom future plan multisession sequential
#' @importFrom foreach foreach %dopar%
Expand Down Expand Up @@ -135,6 +134,7 @@ biodivMapR_SFS <- function(input_raster, obs_vect, obs2optimize,

for (nbvars2select in seq_len(NbPCs_To_Keep)){
NumVar_list <- as.list(seq_len(length(AllVars)))
numvar <- win_ID <- NULL
subfeatures_SFS <- function() {
foreach(numvar = NumVar_list) %dopar% {
CorrVal <- Assess <- list()
Expand Down
6 changes: 4 additions & 2 deletions R/biodivMapR_chunk.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ biodivMapR_chunk <- function(blk, r_in, window_size, Kmeans_info, Beta_info = NU
alphametrics = alphametrics,
Beta_info = Beta_info,
Hill_order = Hill_order,
pcelim = pcelim)
pcelim = pcelim,
future.seed = TRUE)
if (!is.null(FDmetric)){
FunctionalIdx_CPU <- future.apply::future_lapply(X = windows_per_CPU$SSwindow_perCPU,
FUN = functional_window_list,
FDmetric = FDmetric)
FDmetric = FDmetric,
future.seed = TRUE)
}
parallel::stopCluster(cl)
plan(sequential)
Expand Down
3 changes: 2 additions & 1 deletion R/explore_kmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#'
#' @return Kmeans_info
#' @importFrom dplyr select all_of
#' @importFrom doFuture registerDoFuture
#' @export

explore_kmeans <- function(input_rast,
Expand Down Expand Up @@ -43,7 +44,7 @@ explore_kmeans <- function(input_rast,
registerDoFuture()
cl <- parallel::makeCluster(nbCPU)
plan("cluster", workers = cl)

nbclust <- NULL
get_kmeans_list <- function() {
foreach(nbclust = nbClust_list) %dopar% {
Kmeans_info <- get_kmeans(rast_sample = rast_sample,
Expand Down
5 changes: 3 additions & 2 deletions R/get_diversity_from_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#'
#' @return SpatVector including diversity metrics and BC dissimilarity for the plots
#' @importFrom dplyr group_split
#' @importFrom stats as.dist
#' @export

get_diversity_from_plots <- function(input_rast, validation_vect,
Expand All @@ -31,7 +32,7 @@ get_diversity_from_plots <- function(input_rast, validation_vect,
MinSun = 0.25, pcelim = 0.02, nbCPU = 1, getBeta = T,
verbose = F){
if (verbose == T) message('Compute diversity from vector plot network')
FunctDiv <- MatBC_Full <- NULL
FunctDiv <- MatBC_Full <- win_ID <- NULL
# get nbIter and nbclusters
nbIter <- length(Kmeans_info$Centroids)
nbclusters <- dim(Kmeans_info$Centroids[[1]])[1]
Expand Down Expand Up @@ -169,7 +170,7 @@ get_diversity_from_plots <- function(input_rast, validation_vect,
MatBC_Full[IDwindow,IDwindow] <- MatBC
MatBCdist <- stats::as.dist(MatBC, diag = FALSE, upper = FALSE)
colnames(MatBC_Full) <- rownames(MatBC_Full) <- Attributes$ID_biodivMapR
BetaPCO <- labdsv::pco(MatBCdist, k = dimPCO)
BetaPCO <- pco(MatBCdist, k = dimPCO)
PCoA_BC <- matrix(data = NA,nrow = nbPlots_init, ncol = dimPCO)
PCoA_BC[IDwindow,] <- BetaPCO$points
Attributes$BetaPlots_PCoA_1 <- PCoA_BC[,1]
Expand Down
66 changes: 0 additions & 66 deletions R/get_raster_functional.R

This file was deleted.

1 change: 1 addition & 0 deletions R/get_sunlitwindows.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @export
#'
get_sunlitwindows <- function(inputdata, pixperplot, MinSun = 0.25){
win_ID <- data <- ID <- NULL
inputwindow <- inputdata %>% dplyr::group_by(win_ID) %>% nest()
nbPix_Sunlit <- unlist(purrr::map(inputwindow$data,nrow))
PCsun <- nbPix_Sunlit/pixperplot
Expand Down
3 changes: 1 addition & 2 deletions R/get_xy_samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#' @param input_mask SpatRaster. mask corresponding to raster to extract data from
#'
#' @return xy matrix
#' @importFrom pracma randperm
#' @importFrom terra values xyFromCell
#' @export

Expand All @@ -17,7 +16,7 @@ get_xy_samples <- function(input_rast, nbSamples, input_mask = NULL){
# adjust if mask provided
if (!is.null(input_mask)) nbPixels <- sum(terra::values(input_mask),na.rm = T)
if (nbSamples>nbPixels) nbSamples <- nbPixels
choicePix <- pracma::randperm(seq_len(nbPixels),nbSamples)
choicePix <- randperm(seq_len(nbPixels),nbSamples)
if (!is.null(input_mask)){
whichPix <- which(terra::values(input_mask)==1)
} else {
Expand Down
3 changes: 0 additions & 3 deletions R/init_PCoA.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#' @importFrom future plan multisession sequential
#' @importFrom future.apply future_lapply
#' @importFrom progressr progressor handlers with_progress
#' @importFrom labdsv pco
#' @importFrom dplyr group_split
#' @importFrom stats as.dist
#' @importFrom parallel makeCluster stopCluster
#' @export

Expand Down
Loading

0 comments on commit cb93ca6

Please sign in to comment.