Commit 0aa7a979 authored by jbferet's avatar jbferet
Browse files

- Added NEWS.md

- Updated README.md: transfered from gitlab.irstea to github
- changed return() into return(invisible())
- updated vignettes & tutorial with latest outputs and figures from code
parent b750254b
Package: biodivMapR
Title: biodivMapR: an R package for α- and β-diversity mapping using remotely-sensed images
Version: 1.0.0
Version: 1.0.1
Authors@R: c(person(given = "Jean-Baptiste",
family = "Feret",
email = "jb.feret@teledetection.fr",
......
### biodivMapR v1.0.1 (Release date: 2019-09-27)
Added NEWS.md
Updated README.md: transfered from gitlab.irstea to github
changed return() into return(invisible())
updated vignettes & tutorial with latest outputs and figures from code
# biodivMapR v1.0.0 (Release date: 2019-09-26)
First release in GitHub
Submission accepted to Methods in Ecology and Evolution
\ No newline at end of file
......@@ -157,7 +157,7 @@ raster2BIL <- function(Raster_Path, Sensor = "unknown", Output_Dir = FALSE, Conv
#' @param Raster_Path character. full path for the raster to be converted
#' @param Mask boolean. Set true if the raster is a mask
#'
#' @return nothing
#' @return None
#' @export
check_data <- function(Raster_Path, Mask = FALSE) {
HDR_Path <- get_HDR_name(Raster_Path)
......
......@@ -988,6 +988,7 @@ revert_resolution_HDR <- function(HDR, window_size) {
# Zips an image file
#
# @param ImagePath path for the image
# @return None
ZipFile <- function(ImagePath) {
PathRoot <- getwd()
ImageDir <- dirname(ImagePath)
......@@ -996,5 +997,5 @@ ZipFile <- function(ImagePath) {
zip::zip(zipfile = paste0(ImageName, ".zip"), files = ImageName)
file.remove(ImageName)
setwd(PathRoot)
return()
return(invisible())
}
......@@ -26,6 +26,7 @@
#' @param MaxRAM numeric. MaxRAM maximum size of chunk in GB to limit RAM allocation when reading image file.
#' @param Index_Alpha character. Either 'Shannon', 'Simpson' or 'Fisher'.
#'
#' @return None
#' @export
map_alpha_div <- function(Input_Image_File, Output_Dir, window_size,
TypePCA = "SPCA", nbclusters = 50,
......@@ -79,7 +80,7 @@ map_alpha_div <- function(Input_Image_File, Output_Dir, window_size,
write_raster_alpha(ALPHA$Simpson.SD, ALPHA$HDR, Alpha_Path, window_size, Index, FullRes = FullRes, LowRes = LowRes)
}
}
return()
return(invisible())
}
# Map alpha diversity metrics based on spectral species
......
......@@ -29,6 +29,7 @@
#' @param MaxRAM numeric. MaxRAM maximum size of chunk in GB to limit RAM allocation when reading image file.
#' @param pcelim numeric. Minimum contribution (in \%) required for a spectral species
#'
#' @return None
#' @export
map_beta_div <- function(Input_Image_File, Output_Dir, window_size,
TypePCA = "SPCA", nb_partitions = 20,nbclusters = 50,
......@@ -45,7 +46,7 @@ map_beta_div <- function(Input_Image_File, Output_Dir, window_size,
Index <- paste("BetaDiversity_BCdiss_", scaling, sep = "")
Beta.Path <- paste(Output_Dir_BETA, Index, "_", window_size, sep = "")
write_raster_beta(Beta$BetaDiversity, Beta$HDR, Beta.Path, window_size, FullRes = FullRes, LowRes = LowRes)
return()
return(invisible())
}
......
......@@ -28,6 +28,7 @@
#' @param MaxRAM numeric. MaxRAM maximum size of chunk in GB to limit RAM allocation when reading image file.
#' @param nbclusters numeric. number of clusters defined in k-Means
#'
#' @return None
#' @importFrom utils read.table
#' @export
map_spectral_species <- function(Input_Image_File,Output_Dir,PCA_Files,PCA_model,SpectralFilter,MaskPath,Pix_Per_Partition,nb_partitions,CR= TRUE,TypePCA = "SPCA", nbclusters = 50, nbCPU = 1, MaxRAM = FALSE) {
......@@ -87,7 +88,7 @@ map_spectral_species <- function(Input_Image_File,Output_Dir,PCA_Files,PCA_model
print("apply Kmeans to the whole image and determine spectral species")
apply_kmeans(PCA_Files, PC_Select, MaskPath, Kmeans_info, Spectral_Species_Path, nbCPU, MaxRAM)
}
return()
return(invisible())
}
# computes k-means from nb_partitions subsets taken from dataPCA
......@@ -133,7 +134,7 @@ init_kmeans <- function(dataPCA, Pix_Per_Partition, nb_partitions, nbclusters, n
# @param MaxRAM
# @param Spectral_Species_Path path for spectral species file to be written
#
# @return
# @return None
apply_kmeans <- function(PCA_Path, PC_Select, MaskPath, Kmeans_info, Spectral_Species_Path, nbCPU = 1, MaxRAM = FALSE) {
ImPathHDR <- get_HDR_name(PCA_Path)
HDR_PCA <- read_ENVI_header(ImPathHDR)
......@@ -181,7 +182,7 @@ apply_kmeans <- function(PCA_Path, PC_Select, MaskPath, Kmeans_info, Spectral_Sp
Location_RW$lenBin_SS <- nb_partitions * (SeqRead_Shade$ReadByte_End[i] - SeqRead_Shade$ReadByte_Start[i]) + 1
compute_spectral_species(PCA_Path, MaskPath, Spectral_Species_Path, Location_RW, PC_Select, Kmeans_info, nbCPU)
}
return()
return(invisible())
}
# this function reads PCA file and defines the spectral species for each pixel
......@@ -196,7 +197,7 @@ apply_kmeans <- function(PCA_Path, PC_Select, MaskPath, Kmeans_info, Spectral_Sp
# @param nbCPU
# @param Kmeans_info information about kmeans computed in previous step
#
# @return
# @return None
#' @importFrom snow splitRows
#' @importFrom future plan multiprocess sequential
#' @importFrom future.apply future_lapply
......@@ -265,7 +266,7 @@ compute_spectral_species <- function(PCA_Path, MaskPath, Spectral_Species_Path,
close(fidSS)
rm(list = ls())
gc()
return()
return(invisible())
}
# Compute distance between each pixel of input data and each of the nbClusters x nb_partitions centroids
......
......@@ -302,7 +302,7 @@ filter_PCA <- function(ImPath, HDR, MaskPath, Shade_Update, Spectral, CR, PCA_mo
# @param nbCPU number of CPUs to process data
# @param MaxRAM max RAM when initial image is read (in Gb)
#
# @return
# @return None
write_PCA_raster <- function(ImPath, MaskPath, PCA_Path, PCA_model, Spectral, Nb_PCs, CR, TypePCA, nbCPU = 1, MaxRAM = 0.25) {
ImPathHDR <- get_HDR_name(ImPath)
HDR <- read_ENVI_header(ImPathHDR)
......@@ -410,7 +410,7 @@ write_PCA_raster <- function(ImPath, MaskPath, PCA_Path, PCA_model, Spectral, Nb
list <- ls()
rm(list = list)
gc()
return()
return(invisible())
}
# Function to perform PCA on a matrix
......
......@@ -53,7 +53,7 @@ list_shp <- function(x){
# @param Initial.File path for a shapefile to be reprojected
# @param Projection projection to be applied to Initial.File
# @param Reprojected.File path for the reprojected shapefile
# @return
# @return None
#' @importFrom rgdal readOGR writeOGR
#' @importFrom sp spTransform
#' @import tools
......@@ -70,7 +70,7 @@ reproject_vector = function(Initial.File,Projection,Reprojected.File){
Vect.reproj = spTransform(Vect.Init, Projection)
writeOGR(obj = Vect.reproj, dsn = Shp.Path,layer = Shp.Name, driver="ESRI Shapefile",overwrite_layer = TRUE) #also you were missing the driver argument
}
return()
return(invisible())
}
# Extracts pixels coordinates from raster corresponding to an area defined by a vector
......
......@@ -4,7 +4,7 @@
# 1 Install
After installing packages `devtools` and `getPass`, package `biodivMapR` can then be installed with the folloqing command line in R session, where `uname` is your gitlab.irstea.fr username:
```
devtools::install_git('https://gitlab.irstea.fr/jean-baptiste.feret/biodivMapR.git')
devtools::install_git('https://github.com/jbferet/biodivMapR.git')
```
# 2 Tutorial
......
......@@ -59,19 +59,20 @@ knitr::opts_chunk$set(
## ----Spectral species map------------------------------------------------
# print("MAP SPECTRAL SPECIES")
# map_spectral_species(Input_Image_File, Output_Dir, PCA_Files,PCA_model, SpectralFilter, Input_Mask_File,
# Pix_Per_Partition, nb_partitions, nbCPU=nbCPU, MaxRAM=MaxRAM)
# map_spectral_species(Input_Image_File, Output_Dir, PCA_Files, PCA_model, SpectralFilter, Input_Mask_File,
# Pix_Per_Partition, nb_partitions, nbCPU=nbCPU, MaxRAM=MaxRAM,
# nbclusters = nbclusters, TypePCA = TypePCA, CR = TRUE)
## ----alpha and beta diversity maps---------------------------------------
# print("MAP ALPHA DIVERSITY")
# # Index.Alpha = c('Shannon','Simpson')
# Index_Alpha = c('Shannon')
# map_alpha_div(Input_Image_File, Output_Dir, window_size,
# nbCPU=nbCPU, MaxRAM=MaxRAM, Index_Alpha = Index_Alpha)
# map_alpha_div(Input_Image_File, Output_Dir, window_size, nbCPU=nbCPU,
# MaxRAM=MaxRAM, Index_Alpha = Index_Alpha, nbclusters = nbclusters)
#
# print("MAP BETA DIVERSITY")
# map_beta_div(Input_Image_File, Output_Dir, window_size, nb_partitions=nb_partitions,
# nbCPU=nbCPU, MaxRAM=MaxRAM)
# nbCPU=nbCPU, MaxRAM=MaxRAM, nbclusters = nbclusters)
## ----alpha and beta diversity indices from vector layer------------------
# # location of the spectral species raster needed for validation
......@@ -142,7 +143,7 @@ knitr::opts_chunk$set(
# scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
# filename = file.path(Path.Results,'BetaDiversity_PcoA1_vs_PcoA2.png')
# ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
# scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
# scale = 1, width = 6, height = 4, units = "in",
# dpi = 600, limitsize = TRUE)
#
#
......@@ -151,7 +152,7 @@ knitr::opts_chunk$set(
# scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
# filename = file.path(Path.Results,'BetaDiversity_PcoA1_vs_PcoA3.png')
# ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
# scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
# scale = 1, width = 6, height = 4, units = "in",
# dpi = 600, limitsize = TRUE)
#
# ggplot(Results, aes(x=pco2, y=pco3, color=vgtype,size=shannon)) +
......@@ -159,7 +160,7 @@ knitr::opts_chunk$set(
# scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
# filename = file.path(Path.Results,'BetaDiversity_PcoA2_vs_PcoA3.png')
# ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
# scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
# scale = 1, width = 6, height = 4, units = "in",
# dpi = 600, limitsize = TRUE)
#
......@@ -120,16 +120,16 @@ The resulting PCA raster are then stored in a binalry file in the results direct
This PCA raster file can be displayed using QGIS or any GIS / image processing software. Here, the PCs corresponding to our image look like this:
<img align="bottom" width="100%" height="100%" src="../man/figures/02_PCs_comp.png">
<img align="bottom" width="100%" height="100%" src="../man/figures/PCs_1234.png">
<img align="bottom" width="100%" height="100%" src="../man/figures/PCs_5678.png">
This PCA band selection left to user judgement, who then writes the band to be kept in a `.txt` file located in the same directory as the PCA raster file. The file is automatically created and ready to edit with function `select_PCA_components`. Each selected band should be identified per line in this file.
The main goal of PC selection is to discard PCs showing no relevant information corresponding to vegetation, or including artifacts possibly explained by sensor properties. It is somehow a subjective process, and we are currently working on automatic selection of these components.
For this example, PCA bands 1, 2, 4, 5, 6 and 8 can be kept if writing the following lines in file `Selected_Components.txt` opened for edition (do not forget carriage return after last value):
For this example, PCA bands 1, 2, 5, 6 and 8 can be kept if writing the following lines in file `Selected_Components.txt` opened for edition (do not forget carriage return after last value):
```
1
2
4
5
6
8
......@@ -167,8 +167,9 @@ The first step towards \alpha and \beta diversity mapping corresponds to the co
```{r Spectral species map}
print("MAP SPECTRAL SPECIES")
map_spectral_species(Input_Image_File, Output_Dir, PCA_Files,PCA_model, SpectralFilter, Input_Mask_File,
Pix_Per_Partition, nb_partitions, nbCPU=nbCPU, MaxRAM=MaxRAM)
map_spectral_species(Input_Image_File, Output_Dir, PCA_Files, PCA_model, SpectralFilter, Input_Mask_File,
Pix_Per_Partition, nb_partitions, nbCPU=nbCPU, MaxRAM=MaxRAM,
nbclusters = nbclusters, TypePCA = TypePCA, CR = TRUE)
```
SpectralSpecies is then stored in a raster file located here:
......@@ -182,12 +183,12 @@ The code to compute $\alpha$ and $\beta$ diversity maps from this file is as fol
print("MAP ALPHA DIVERSITY")
# Index.Alpha = c('Shannon','Simpson')
Index_Alpha = c('Shannon')
map_alpha_div(Input_Image_File, Output_Dir, window_size,
nbCPU=nbCPU, MaxRAM=MaxRAM, Index_Alpha = Index_Alpha)
map_alpha_div(Input_Image_File, Output_Dir, window_size, nbCPU=nbCPU,
MaxRAM=MaxRAM, Index_Alpha = Index_Alpha, nbclusters = nbclusters)
print("MAP BETA DIVERSITY")
map_beta_div(Input_Image_File, Output_Dir, window_size, nb_partitions=nb_partitions,
nbCPU=nbCPU, MaxRAM=MaxRAM)
nbCPU=nbCPU, MaxRAM=MaxRAM, nbclusters = nbclusters)
```
$\alpha$ and $\beta$ diversity maps are then stored in raster files located here:
......@@ -288,7 +289,7 @@ ggplot(Results, aes(x=pco1, y=pco2, color=vgtype,size=shannon)) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path.Results,'BetaDiversity_PcoA1_vs_PcoA2.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
......@@ -297,7 +298,7 @@ ggplot(Results, aes(x=pco1, y=pco3, color=vgtype,size=shannon)) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path.Results,'BetaDiversity_PcoA1_vs_PcoA3.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
ggplot(Results, aes(x=pco2, y=pco3, color=vgtype,size=shannon)) +
......@@ -305,7 +306,7 @@ ggplot(Results, aes(x=pco2, y=pco3, color=vgtype,size=shannon)) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path.Results,'BetaDiversity_PcoA2_vs_PcoA3.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
```
......
This diff is collapsed.
......@@ -64,7 +64,7 @@ TypePCA = 'SPCA'
################################################################################
## DEFINE PARAMETERS FOR METHOD ##
################################################################################
nbCPU = 2
nbCPU = 4
MaxRAM = 0.5
nbclusters = 50
......@@ -178,7 +178,7 @@ ggplot(Results, aes(x=pco1, y=pco2, color=vgtype,size=shannon)) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path.Results,'BetaDiversity_PcoA1_vs_PcoA2.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
......@@ -187,7 +187,7 @@ ggplot(Results, aes(x=pco1, y=pco3, color=vgtype,size=shannon)) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path.Results,'BetaDiversity_PcoA1_vs_PcoA3.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
ggplot(Results, aes(x=pco2, y=pco3, color=vgtype,size=shannon)) +
......@@ -195,5 +195,5 @@ ggplot(Results, aes(x=pco2, y=pco3, color=vgtype,size=shannon)) +
scale_color_manual(values=c("#e6140a", "#e6d214", "#e68214", "#145ae6"))
filename = file.path(Path.Results,'BetaDiversity_PcoA2_vs_PcoA3.png')
ggsave(filename, plot = last_plot(), device = 'png', path = NULL,
scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
scale = 1, width = 6, height = 4, units = "in",
dpi = 600, limitsize = TRUE)
......@@ -12,7 +12,7 @@ check_data(Raster_Path, Mask = FALSE)
\item{Mask}{boolean. Set true if the raster is a mask}
}
\value{
nothing
None
}
\description{
Checks if the data to be processed has the format type expected
......
man/figures/03_AlphaBeta.png

1.01 MB | W: | H:

man/figures/03_AlphaBeta.png

370 KB | W: | H:

man/figures/03_AlphaBeta.png
man/figures/03_AlphaBeta.png
man/figures/03_AlphaBeta.png
man/figures/03_AlphaBeta.png
  • 2-up
  • Swipe
  • Onion skin
man/figures/04_RGB_FieldLegend.png

1.32 MB | W: | H:

man/figures/04_RGB_FieldLegend.png

672 KB | W: | H:

man/figures/04_RGB_FieldLegend.png
man/figures/04_RGB_FieldLegend.png
man/figures/04_RGB_FieldLegend.png
man/figures/04_RGB_FieldLegend.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment