Mercurial > repos > ecology > srs_process_data
annotate alpha_beta.r @ 0:cf69ad260611 draft default tip
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
| author | ecology | 
|---|---|
| date | Mon, 09 Jan 2023 13:36:02 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 1 #Rscript | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 2 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 3 ########################################### | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 4 ## Mapping alpha and beta diversity ## | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 5 ########################################### | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 6 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 7 #####Packages : stars | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 8 # utils | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 9 # biodivmapr | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 10 # raster | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 11 # sf | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 12 # mapview | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 13 # leafpop | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 14 # RColorBrewer | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 15 # labdsv | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 16 # rgdal | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 17 # ggplot2 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 18 # gridExtra | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 19 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 20 #####Load arguments | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 21 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 22 args <- commandArgs(trailingOnly = TRUE) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 23 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 24 #####Import the S2 data | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 25 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 26 if (length(args) < 1) { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 27 stop("This tool needs at least 1 argument") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 28 }else { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 29 data_raster <- args[1] | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 30 rasterheader <- args[2] | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 31 data <- args[3] | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 32 # type of PCA: | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 33 # PCA: no rescaling of the data | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 34 # SPCA: rescaling of the data | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 35 typepca <- as.character(args[4]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 36 alpha <- as.logical(args[5]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 37 beta <- as.logical(args[6]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 38 funct <- as.logical(args[7]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 39 all <- as.logical(args[8]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 40 nbcpu <- as.integer(args[9]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 41 source(args[10]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 42 } | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 43 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 44 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 45 ## DEFINE PARAMETERS FOR DATASET TO BE PROCESSED ## | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 46 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 47 if (data_raster == "") { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 48 #Create a directory where to unzip your folder of data | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 49 dir.create("data_dir") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 50 unzip(data, exdir = "data_dir") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 51 # Path to raster | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 52 data_raster <- list.files("data_dir/results/Reflectance", pattern = "_Refl") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 53 input_image_file <- file.path("data_dir/results/Reflectance", data_raster[1]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 54 input_header_file <- file.path("data_dir/results/Reflectance", data_raster[2]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 55 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 56 } else { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 57 input_image_file <- file.path(getwd(), data_raster, fsep = "/") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 58 input_header_file <- file.path(getwd(), rasterheader, fsep = "/") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 59 } | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 60 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 61 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 62 ## PROCESS IMAGE ## | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 63 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 64 # 1- Filter data in order to discard non vegetated / shaded / cloudy pixels | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 65 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 66 print("PERFORM PCA ON RASTER") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 67 pca_output <- biodivMapR::perform_PCA(Input_Image_File = input_image_file, Input_Mask_File = input_mask_file, | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 68 Output_Dir = output_dir, TypePCA = typepca, FilterPCA = filterpca, nbCPU = nbcpu, MaxRAM = maxram) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 69 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 70 pca_files <- pca_output$PCA_Files | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 71 pix_per_partition <- pca_output$Pix_Per_Partition | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 72 nb_partitions <- pca_output$nb_partitions | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 73 # path for the updated mask | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 74 input_mask_file <- pca_output$MaskPath | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 75 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 76 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 77 selected_pcs <- seq(1, dim(raster::stack(input_image_file))[3]) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 78 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 79 selected_pcs <- all(selected_pcs) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 80 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 81 ## MAP ALPHA AND BETA DIVERSITY ## | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 82 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 83 print("MAP SPECTRAL SPECIES") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 84 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 85 kmeans_info <- biodivMapR::map_spectral_species(Input_Image_File = input_image_file, Output_Dir = output_dir, PCA_Files = pca_files, Input_Mask_File = input_mask_file, SelectedPCs = selected_pcs, Pix_Per_Partition = pix_per_partition, nb_partitions = nb_partitions, TypePCA = typepca, nbCPU = nbcpu, MaxRAM = maxram, nbclusters = nbclusters) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 86 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 87 image_name <- tools::file_path_sans_ext(basename(input_image_file)) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 88 if (alpha == TRUE || beta == TRUE || all == TRUE) { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 89 ## alpha | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 90 print("MAP ALPHA DIVERSITY") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 91 index_alpha <- c("Shannon") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 92 alpha_div <- biodivMapR::map_alpha_div(Input_Image_File = input_image_file, Output_Dir = output_dir, TypePCA = typepca, window_size = window_size, nbCPU = nbcpu, MaxRAM = maxram, Index_Alpha = index_alpha, nbclusters = nbclusters, FullRes = TRUE, LowRes = FALSE, MapSTD = FALSE) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 93 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 94 alpha_zip <- file.path(output_dir, image_name, typepca, "ALPHA", "Shannon_10_Fullres.zip") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 95 alpha_path <- file.path(output_dir, image_name, typepca, "ALPHA") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 96 unzip(alpha_zip, exdir = alpha_path) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 97 alpha_path <- file.path(output_dir, image_name, typepca, "ALPHA", "Shannon_10_Fullres") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 98 alpha_raster <- raster::raster(alpha_path) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 99 get_alpha <- convert_raster(alpha_raster) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 100 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 101 if (alpha == TRUE || all == TRUE) { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 102 colnames(get_alpha) <- c("Alpha", "longitude", "latitude") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 103 plot_indices(get_alpha, titre = "Alpha") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 104 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 105 write.table(get_alpha, file = "alpha.tabular", sep = "\t", dec = ".", na = " ", row.names = FALSE, col.names = TRUE, quote = FALSE) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 106 } | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 107 if (beta == TRUE || all == TRUE) { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 108 ## beta | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 109 print("MAP BETA DIVERSITY") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 110 beta_div <- biodivMapR::map_beta_div(Input_Image_File = input_image_file, Output_Dir = output_dir, TypePCA = typepca, window_size = window_size, nb_partitions = nb_partitions, nbCPU = nbcpu, MaxRAM = maxram, nbclusters = nbclusters) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 111 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 112 beta_path <- file.path(output_dir, image_name, typepca, "BETA", "BetaDiversity_BCdiss_PCO_10") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 113 beta_raster <- raster::raster(beta_path) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 114 get_beta <- convert_raster(beta_raster) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 115 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 116 colnames(get_beta) <- c("Beta", "longitude", "latitude") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 117 plot_indices(get_beta, titre = "Beta") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 118 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 119 write.table(get_beta, file = "beta.tabular", sep = "\t", dec = ".", na = " ", row.names = FALSE, col.names = TRUE, quote = FALSE) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 120 } | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 121 } | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 122 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 123 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 124 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 125 ## COMPUTE ALPHA AND BETA DIVERSITY FROM FIELD PLOTS ## | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 126 ################################################################################ | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 127 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 128 if (funct == TRUE || all == TRUE) { | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 129 mapper <- biodivMapR::map_functional_div(Original_Image_File = input_image_file, Functional_File = pca_files, Selected_Features = selected_pcs, Output_Dir = output_dir, window_size = window_size, nbCPU = nbcpu, MaxRAM = maxram, TypePCA = typepca, FullRes = TRUE, LowRes = FALSE, MapSTD = FALSE) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 130 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 131 funct_zip <- file.path(output_dir, image_name, typepca, "FUNCTIONAL", "FunctionalDiversity_Map_MeanFilter_Fullres.zip") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 132 funct_path <- file.path(output_dir, image_name, typepca, "FUNCTIONAL") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 133 unzip(funct_zip, exdir = funct_path) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 134 funct_path <- file.path(output_dir, image_name, typepca, "FUNCTIONAL", "FunctionalDiversity_Map_MeanFilter_Fullres") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 135 funct_raster <- raster::raster(funct_path) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 136 get_funct <- convert_raster(funct_raster) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 137 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 138 colnames(get_funct) <- c("Functionnal", "longitude", "latitude") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 139 plot_indices(get_funct, titre = "Functionnal") | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 140 | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 141 write.table(get_funct, file = "Functionnal.tabular", sep = "\t", dec = ".", na = " ", row.names = FALSE, col.names = TRUE, quote = FALSE) | 
| 
cf69ad260611
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 ecology parents: diff
changeset | 142 } | 
