Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbferet committed Jan 9, 2023
2 parents d1370ce + a02c4eb commit 0c27938
Show file tree
Hide file tree
Showing 29 changed files with 1,518 additions and 762 deletions.
5 changes: 3 additions & 2 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: 1.9.10
Version: 1.9.11
Authors@R: c(person(given = "Jean-Baptiste",
family = "Feret",
email = "jb.feret@teledetection.fr",
Expand Down Expand Up @@ -42,7 +42,8 @@ Imports:
sf,
rgeos,
progress,
progressr
progressr,
cli
RoxygenNote: 7.2.3
Suggests:
knitr,
Expand Down
15 changes: 14 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(Compute_ALPHA_SSD_per_window)
export(Compute_ALPHA_SSD_per_window_list)
export(Compute_ALPHA_per_window)
export(ContinuumRemoval)
export(ENVI_type2bytes)
export(IQR_outliers)
Expand All @@ -20,6 +23,8 @@ export(compute_BCdiss)
export(compute_BETA_FromPlots)
export(compute_FUNCT)
export(compute_NN_from_ordination)
export(compute_SSD)
export(compute_alpha_metrics)
export(compute_beta_metrics)
export(compute_spectral_species)
export(compute_spectral_species_FieldPlots)
Expand All @@ -42,6 +47,9 @@ export(get_BB)
export(get_BB_from_Vector)
export(get_BB_from_fullImage)
export(get_HDR_name)
export(get_SSpath)
export(get_Shannon)
export(get_Simpson)
export(get_alpha_metrics)
export(get_byte_order)
export(get_image_bands)
Expand All @@ -51,6 +59,7 @@ export(get_sunlit_pixels)
export(ind2sub)
export(ind2sub2)
export(init_kmeans)
export(kmeans_progressr)
export(list_shp)
export(map_alpha_div)
export(map_beta_div)
Expand All @@ -60,8 +69,8 @@ export(mean_filter)
export(minmax)
export(mnf)
export(noise)
export(ordination_parallel)
export(ordination_to_NN)
export(ordination_to_NN_list)
export(pca)
export(perform_PCA)
export(perform_radiometric_filtering)
Expand Down Expand Up @@ -89,6 +98,7 @@ export(write_ENVI_header)
export(write_PCA_raster)
export(write_StarsStack)
export(write_raster)
import(cli)
import(stars)
import(tools)
importFrom(data.table,data.table)
Expand Down Expand Up @@ -129,12 +139,15 @@ importFrom(raster,projection)
importFrom(raster,raster)
importFrom(raster,values)
importFrom(raster,writeRaster)
importFrom(rgdal,GDALinfo)
importFrom(rgdal,readOGR)
importFrom(rgdal,writeOGR)
importFrom(rgeos,gBuffer)
importFrom(sf,st_bbox)
importFrom(sf,st_crop)
importFrom(sf,st_read)
importFrom(snow,splitCols)
importFrom(snow,splitList)
importFrom(snow,splitRows)
importFrom(sp,SpatialPoints)
importFrom(sp,spTransform)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# biodivMapR v1.9.11

## Addition
- optimized codes for the computation of spectral species, alpha and beta diversity
- addition of progress bars during the different steps of the computation of spectral species, alpha and beta diversity maps
- addition of functions Compute_ALPHA_SSD_per_window_list, Compute_ALPHA_SSD_per_window, Compute_ALPHA_per_window, prepare_HDR_SSD, prepare_HDR_Sunlit, RW_bytes_all, RW_bytes
- use multisession instead of multiprocess where it was forgotten

# biodivMapR v1.9.10

## Addition
Expand Down
23 changes: 14 additions & 9 deletions R/Lib_ContinuumRemoval.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@ apply_continuum_removal <- function(Spectral_Data, Spectral, nbCPU = 1) {
# corresponds to ~ 40 Mb data, but CR tends to requires ~ 10 times memory
# avoids memory crash
Max.nb.Values <- 2e6
nb.CR <- ceiling(nb.Values / Max.nb.Values)
Spectral_Data <- snow::splitRows(Spectral_Data, nb.CR)
nb_CR <- ceiling(nb.Values / Max.nb.Values)
Spectral_Data <- snow::splitRows(Spectral_Data, nb_CR)
# perform multithread continuum removal
if (nbCPU>1){
future::plan(multiprocess, workers = nbCPU) ## Parallelize using four cores
Schedule_Per_Thread <- ceiling(nb.CR / nbCPU)
Spectral_Data_tmp <- future.apply::future_lapply(Spectral_Data, FUN = ContinuumRemoval,
Spectral_Bands = Spectral$Wavelength,
future.scheduling = Schedule_Per_Thread)
future::plan(multisession, workers = nbCPU)
handlers(global = TRUE)
handlers("cli")
with_progress({
p <- progressr::progressor(steps = nb_CR)
Spectral_Data_tmp <- future.apply::future_lapply(Spectral_Data,
FUN = ContinuumRemoval,
Spectral_Bands = Spectral$Wavelength,
p = p)
})
future::plan(sequential)
} else {
Spectral_Data_tmp <- lapply(Spectral_Data, FUN = ContinuumRemoval,
Spectral_Bands = Spectral$Wavelength)
}

Spectral_Data <- do.call("rbind", Spectral_Data_tmp)
rm(Spectral_Data_tmp)
} else {
Expand All @@ -66,11 +70,12 @@ apply_continuum_removal <- function(Spectral_Data, Spectral, nbCPU = 1) {
#'
#' @param Minit numeric. initial data matrix (nb samples x nb bands)
#' @param Spectral_Bands numeric. central wavelength for the spectral bands
#' @param p list. progressor object for progress bar
#
#' @return samples from image and updated number of pixels to sampel if necessary
#' @export

ContinuumRemoval <- function(Minit, Spectral_Bands) {
ContinuumRemoval <- function(Minit, Spectral_Bands, p = NULL) {

# Filter and prepare data prior to continuum removal
CR_data <- filter_prior_CR(Minit, Spectral_Bands)
Expand Down
Loading

0 comments on commit 0c27938

Please sign in to comment.