Commit 2e935e93 authored by jbferet's avatar jbferet
Browse files

- delete call to 'PCA_Info.RData' in function map_spectral_species

parent b114983d
......@@ -47,9 +47,9 @@ map_spectral_species <- function(Input_Image_File,Output_Dir,PCA_Files,PCA_model
message("")
stop()
} else {
WS_Save <- paste(Output_Dir_PCA, "PCA_Info.RData", sep = "")
load(file = WS_Save)
## 1- Select components used to perform clustering ##
# WS_Save <- paste(Output_Dir_PCA, "PCA_Info.RData", sep = "")
# load(file = WS_Save)
## 1- Select components used to perform clustering
PC_Select_Path <- paste(Output_Dir_PCA, "Selected_Components.txt", sep = "")
if (file.exists(PC_Select_Path)) {
PC_Select <- read.table(PC_Select_Path)[[1]]
......@@ -79,11 +79,11 @@ map_spectral_species <- function(Input_Image_File,Output_Dir,PCA_Files,PCA_model
print("Image processing aborted")
stop()
}
## 2- PERFORM KMEANS FOR EACH ITERATION & DEFINE SPECTRAL SPECIES ##
## 2- PERFORM KMEANS FOR EACH ITERATION & DEFINE SPECTRAL SPECIES
print("perform k-means clustering for each subset and define centroids")
# scaling factor subPCA between 0 and 1
Kmeans_info <- init_kmeans(dataPCA, Pix_Per_Partition, nb_partitions, nbclusters, nbCPU)
## 3- ASSIGN SPECTRAL SPECIES TO EACH PIXEL ##
## 3- ASSIGN SPECTRAL SPECIES TO EACH PIXEL
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)
}
......
......@@ -16,6 +16,7 @@
#' @param Output_Dir character. Path for output directory
#' @param Continuum_Removal boolean. Set to TRUE if continuum removal should be applied
#' @param TypePCA character. Type of PCA: choose either "PCA" or "SPCA"
#' @param NbPCs_To_Keep numeric. number of components to ke saved in the PCA file. default = 30 if set to FALSE (or nb PC if <30)
#' @param FilterPCA boolean. Set to TRUE if 2nd filtering based on PCA is required
#' @param Excluded_WL numeric. Water Vapor Absorption domains (in nanometers, min and max WL). Can also be used to exclude spectific domains. dims = N x 2 (N = number of domains to be eliminated)
#' @param nb_partitions numeric. Number of repetitions to estimate diversity from the raster (averaging repetitions).
......@@ -24,7 +25,8 @@
#'
#' @return list of paths corresponding to resulting PCA files
#' @export
perform_PCA <- function(ImPath, MaskPath, Output_Dir, Continuum_Removal = TRUE, TypePCA = "SPCA", FilterPCA = FALSE, Excluded_WL = FALSE, nb_partitions = 20, nbCPU = 1, MaxRAM = 0.25) {
perform_PCA <- function(ImPath, MaskPath, Output_Dir, Continuum_Removal=TRUE, TypePCA="SPCA", NbPCs_To_Keep=FALSE,
FilterPCA = FALSE, Excluded_WL = FALSE, nb_partitions = 20, nbCPU = 1, MaxRAM = 0.25) {
# check if format of raster data is as expected
check_data(ImPath)
if (!MaskPath==FALSE){
......@@ -124,9 +126,13 @@ perform_PCA <- function(ImPath, MaskPath, Output_Dir, Continuum_Removal = TRUE,
}
}
# Number of PCs computed and written in the PCA file: 30 if hyperspectral
Nb_PCs <- dim(PCA_model$dataPCA)[2]
if (Nb_PCs > 30) {
Nb_PCs <- 30
if (NbPCs_To_Keep==FALSE){
Nb_PCs <- dim(PCA_model$dataPCA)[2]
if (Nb_PCs > 30) {
Nb_PCs <- 30
}
} else {
Nb_PCs = NbPCs_To_Keep
}
PCA_model$Nb_PCs <- Nb_PCs
PCA_model$dataPCA <- NULL
......
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