Mercurial > repos > ecology > srs_pca
annotate comparison_div.r @ 1:9300a492b634 draft default tip
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit 0f331043178bbfbe5cda0e31d887971464b3071c
| author | ecology | 
|---|---|
| date | Fri, 07 Apr 2023 15:58:46 +0000 | 
| parents | 79bcb8c6dff0 | 
| children | 
| rev | line source | 
|---|---|
| 
0
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
1 #Rscript | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
2 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
3 ########################################### | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
4 ## Mapping alpha and beta diversity ## | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
5 ########################################### | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
6 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
7 #####Packages : stars | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
8 # utils | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
9 # biodivmapr | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
10 # raster | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
11 # sf | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
12 # mapview | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
13 # leafpop | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
14 # RColorBrewer | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
15 # labdsv | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
16 # rgdal | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
17 # ggplot2 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
18 # gridExtra | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
19 ##remotes::install_github("jbferet/biodivMapR") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
20 #####Load arguments | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
21 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
22 args <- commandArgs(trailingOnly = TRUE) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
23 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
24 #####Import the S2 data | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
25 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
26 if (length(args) < 1) { | 
| 
 
79bcb8c6dff0
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") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
28 }else { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
29 data_raster <- args[1] | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
30 rasterheader <- args[2] | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
31 data <- args[3] | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
32 plots_zip <- args[4] | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
33 choice <- as.character(args[5]) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
34 source(args[6]) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
35 # type of PCA: | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
36 # PCA: no rescaling of the data | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
37 # SPCA: rescaling of the data | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
38 typepca <- as.character(args[7]) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
39 } | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
40 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
41 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
42 ## DEFINE PARAMETERS FOR DATASET TO BE PROCESSED ## | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
43 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
44 if (data_raster == "") { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
45 #Create a directory where to unzip your folder of data | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
46 dir.create("data_dir") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
47 unzip(data, exdir = "data_dir") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
48 # Path to raster | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
49 data_raster <- list.files("data_dir/results/Reflectance", pattern = "_Refl") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
50 input_image_file <- file.path("data_dir/results/Reflectance", data_raster[1]) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
51 input_header_file <- file.path("data_dir/results/Reflectance", data_raster[2]) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
52 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
53 } else { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
54 input_image_file <- file.path(getwd(), data_raster, fsep = "/") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
55 input_header_file <- file.path(getwd(), rasterheader, fsep = "/") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
56 } | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
57 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
58 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
59 ## PROCESS IMAGE ## | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
60 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
61 # 1- Filter data in order to discard non vegetated / shaded / cloudy pixels | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
62 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
63 print("PERFORM PCA ON RASTER") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
64 pca_output <- biodivMapR::perform_PCA(Input_Image_File = input_image_file, Input_Mask_File = input_mask_file, | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
65 Output_Dir = output_dir, TypePCA = typepca, FilterPCA = filterpca, nbCPU = nbcpu, MaxRAM = maxram) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
66 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
67 pca_files <- pca_output$PCA_Files | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
68 pix_per_partition <- pca_output$Pix_Per_Partition | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
69 nb_partitions <- pca_output$nb_partitions | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
70 # path for the updated mask | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
71 input_mask_file <- pca_output$MaskPath | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
72 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
73 # 3- Select principal components from the PCA raster | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
74 # Select components from the PCA/SPCA/MNF raster | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
75 sel_compo <- c("1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
76 image_name <- tools::file_path_sans_ext(basename(input_image_file)) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
77 output_dir_full <- file.path(output_dir, image_name, typepca, "PCA") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
78 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
79 write.table(sel_compo, paste0(output_dir_full, "/Selected_Components.txt")) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
80 sel_pc <- file.path(output_dir_full, "Selected_Components.txt") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
81 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
82 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
83 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
84 ## MAP ALPHA AND BETA DIVERSITY ## | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
85 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
86 print("MAP SPECTRAL SPECIES") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
87 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
88 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, Pix_Per_Partition = pix_per_partition, nb_partitions = nb_partitions, nbCPU = nbcpu, MaxRAM = maxram, nbclusters = nbclusters, TypePCA = typepca) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
89 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
90 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
91 ## COMPUTE ALPHA AND BETA DIVERSITY FROM FIELD PLOTS ## | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
92 ################################################################################ | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
93 ## read selected features from dimensionality reduction | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
94 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
95 ## path for selected components | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
96 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
97 # location of the directory where shapefiles used for validation are saved | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
98 dir.create("VectorDir") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
99 unzip(plots_zip, exdir = "VectorDir") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
100 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
101 # list vector data | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
102 path_vector <- biodivMapR::list_shp("VectorDir") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
103 name_vector <- tools::file_path_sans_ext(basename(path_vector)) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
104 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
105 # location of the spectral species raster needed for validation | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
106 path_spectralspecies <- kmeans_info$SpectralSpecies | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
107 # get diversity indicators corresponding to shapefiles (no partitioning of spectral dibversity based on field plots so far...) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
108 biodiv_indicators <- biodivMapR::diversity_from_plots(Raster_SpectralSpecies = path_spectralspecies, Plots = path_vector, nbclusters = nbclusters, Raster_Functional = pca_files, Selected_Features = FALSE) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
109 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
110 shannon_rs <- c(biodiv_indicators$Shannon)[[1]] | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
111 fric <- c(biodiv_indicators$FunctionalDiversity$FRic) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
112 feve <- c(biodiv_indicators$FunctionalDiversity$FEve) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
113 fdiv <- c(biodiv_indicators$FunctionalDiversity$FDiv) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
114 # if no name for plots | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
115 biodiv_indicators$Name_Plot <- seq(1, length(biodiv_indicators$Shannon[[1]]), by = 1) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
116 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
117 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
118 #################################################### | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
119 # write RS indicators # | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
120 #################################################### | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
121 # write a table for Shannon index | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
122 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
123 # write a table for all spectral diversity indices corresponding to alpha diversity | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
124 results <- data.frame(name_vector, biodiv_indicators$Richness, biodiv_indicators$Fisher, | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
125 biodiv_indicators$Shannon, biodiv_indicators$Simpson, | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
126 biodiv_indicators$FunctionalDiversity$FRic, | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
127 biodiv_indicators$FunctionalDiversity$FEve, | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
128 biodiv_indicators$FunctionalDiversity$FDiv) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
129 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
130 names(results) <- c("ID_Plot", "Species_Richness", "Fisher", "Shannon", "Simpson", "fric", "feve", "fdiv") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
131 write.table(results, file = "Diversity.tabular", sep = "\t", dec = ".", na = " ", row.names = FALSE, col.names = TRUE, quote = FALSE) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
132 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
133 if (choice == "Y") { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
134 # write a table for Bray Curtis dissimilarity | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
135 bc_mean <- biodiv_indicators$BCdiss | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
136 bray_curtis <- data.frame(name_vector, bc_mean) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
137 colnames(bray_curtis) <- c("ID_Plot", bray_curtis[, 1]) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
138 write.table(bray_curtis, file = "BrayCurtis.tabular", sep = "\t", dec = ".", na = " ", row.names = FALSE, col.names = TRUE, quote = FALSE) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
139 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
140 #################################################### | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
141 # illustrate results | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
142 #################################################### | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
143 # apply ordination using PCoA (same as done for map_beta_div) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
144 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
145 mat_bc_dist <- as.dist(bc_mean, diag = FALSE, upper = FALSE) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
146 betapco <- labdsv::pco(mat_bc_dist, k = 3) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
147 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
148 # assign a type of vegetation to each plot, assuming that the type of vegetation | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
149 # is defined by the name of the shapefile | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
150 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
151 nbsamples <- shpname <- c() | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
152 for (i in 1:length(path_vector)) { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
153 shp <- path_vector[i] | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
154 nbsamples[i] <- length(rgdal::readOGR(shp, verbose = FALSE)) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
155 shpname[i] <- tools::file_path_sans_ext(basename(shp)) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
156 } | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
157 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
158 type_vegetation <- c() | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
159 for (i in 1: length(nbsamples)) { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
160 for (j in 1:nbsamples[i]) { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
161 type_vegetation <- c(type_vegetation, shpname[i]) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
162 } | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
163 } | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
164 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
165 #data frame including a selection of alpha diversity metrics and beta diversity expressed as coordinates in the PCoA space | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
166 results <- data.frame("vgtype" = type_vegetation, "pco1" = betapco$points[, 1], "pco2" = betapco$points[, 2], "pco3" = betapco$points[, 3], "shannon" = shannon_rs, "fric" = fric, "feve" = feve, "fdiv" = fdiv) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
167 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
168 #plot field data in the PCoA space, with size corresponding to shannon index | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
169 g1 <- ggplot2::ggplot(results, ggplot2::aes(x = pco1, y = pco2, color = vgtype, size = shannon)) + ggplot2::geom_point(alpha = 0.6) + ggplot2::scale_color_manual(values = c("#e6140a", "#e6d214", "#e68214", "#145ae6")) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
170 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
171 g2 <- ggplot2::ggplot(results, ggplot2::aes(x = pco1, y = pco3, color = vgtype, size = shannon)) + ggplot2::geom_point(alpha = 0.6) + ggplot2::scale_color_manual(values = c("#e6140a", "#e6d214", "#e68214", "#145ae6")) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
172 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
173 g3 <- ggplot2::ggplot(results, ggplot2::aes(x = pco2, y = pco3, color = vgtype, size = shannon)) + ggplot2::geom_point(alpha = 0.6) + ggplot2::scale_color_manual(values = c("#e6140a", "#e6d214", "#e68214", "#145ae6")) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
174 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
175 #extract legend | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
176 get_legend <- function(a_gplot) { | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
177 tmp <- ggplot2::ggplot_gtable(ggplot2::ggplot_build(a_gplot)) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
178 leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box") | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
179 legend <- tmp$grobs[[leg]] | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
180 return(legend) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
181 } | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
182 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
183 legend <- get_legend(g3) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
184 gall <- gridExtra::grid.arrange(gridExtra::arrangeGrob(g1 + ggplot2::theme(legend.position = "none"), g2 + ggplot2::theme(legend.position = "none"), g3 + ggplot2::theme(legend.position = "none"), nrow = 1), legend, nrow = 2, heights = c(3, 2)) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
185 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
186 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
187 filename <- ggplot2::ggsave("BetaDiversity_PcoA1_vs_PcoA2_vs_PcoA3.png", gall, scale = 0.65, width = 12, height = 9, units = "in", dpi = 200, limitsize = TRUE) | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
188 | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
189 filename | 
| 
 
79bcb8c6dff0
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
190 } | 
