Mercurial > repos > ecology > srs_global_indices
annotate biodiv_indices_global.r @ 0:5cae678042ec 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:33 +0000 |
parents | |
children |
rev | line source |
---|---|
0
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
1 #Rscript |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
2 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
3 ########################################### |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
4 ## Mapping biodiversity indicators ## |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
5 ########################################### |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
6 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
7 #####Packages : raster, |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
8 # rgdal, |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
9 # sp, |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
10 # rasterdiv, |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
11 # ggplot2, |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
12 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
13 #####Load arguments |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
14 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
15 args <- commandArgs(trailingOnly = TRUE) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
16 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
17 #####Import the S2 data |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
18 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
19 if (length(args) < 1) { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
20 stop("This tool needs at least 1 argument") |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
21 }else { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
22 data_raster <- args[1] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
23 data_header <- args[2] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
24 data <- args[3] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
25 alpha <- as.numeric(args[4]) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
26 source(args[5]) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
27 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
28 } |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
29 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
30 ######################################################################## |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
31 ## COMPUTE BIODIVERSITY INDICES ## |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
32 ######################################################################## |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
33 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
34 if (data_raster == "") { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
35 #Create a directory where to unzip your folder of data |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
36 dir.create("data_dir") |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
37 unzip(data, exdir = "data_dir") |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
38 # Path to raster |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
39 data_raster <- list.files("data_dir/results/Reflectance", pattern = "_Refl") |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
40 data_raster <- file.path("data_dir/results/Reflectance", data_raster[1]) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
41 } |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
42 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
43 # Read raster |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
44 copndvi <- raster::raster(data_raster) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
45 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
46 copndvilr <- raster::reclassify(copndvi, cbind(252, 255, NA), right = TRUE) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
47 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
48 #Resample using raster::aggregate and a linear factor of 10 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
49 copndvilr <- raster::aggregate(copndvilr, fact = 20) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
50 #Set float numbers as integers to further speed up the calculation |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
51 storage.mode(copndvilr[]) <- "integer" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
52 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
53 # Convert raster to SpatialPointsDataFrame |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
54 r_pts <- convert_raster(copndvilr) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
55 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
56 #Shannon's Diversity |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
57 sha <- rasterdiv::Shannon(copndvilr, window = 9, np = 1) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
58 sha_df <- data.frame(raster::rasterToPoints(sha, spatial = TRUE)) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
59 sha_name <- "Shannon" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
60 r_pts[, sha_name] <- sha_df[, 1] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
61 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
62 #Renyi's Index |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
63 ren <- rasterdiv::Renyi(copndvilr, window = 9, alpha = alpha, np = 1) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
64 ren_df <- data.frame(raster::rasterToPoints(ren[[1]])) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
65 ren_name <- "Renyi" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
66 r_pts[, ren_name] <- ren_df[, 3] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
67 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
68 #Berger-Parker's Index |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
69 ber <- rasterdiv::BergerParker(copndvilr, window = 9, np = 1) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
70 ber_df <- data.frame(raster::rasterToPoints(ber, spatial = TRUE)) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
71 ber_name <- "Berger-Parker" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
72 r_pts[, ber_name] <- ber_df[, 1] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
73 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
74 #Pielou's Evenness |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
75 pie <- rasterdiv::Pielou(copndvilr, window = 9, np = 1) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
76 pie_df <- data.frame(raster::rasterToPoints(pie)) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
77 if (length(pie_df[, 1]) == length(r_pts[, 1])) { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
78 pie_name <- "Pielou" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
79 r_pts[, pie_name] <- pie_df[, 1] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
80 } |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
81 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
82 #Hill's numbers |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
83 hil <- rasterdiv::Hill(copndvilr, window = 9, alpha = alpha, np = 1) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
84 hil_df <- data.frame(raster::rasterToPoints(hil[[1]])) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
85 hil_name <- "Hill" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
86 r_pts[, hil_name] <- hil_df[, 3] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
87 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
88 #Parametric Rao's quadratic entropy with alpha ranging from 1 to 5 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
89 prao <- rasterdiv::paRao(copndvilr, window = 9, alpha = alpha, dist_m = "euclidean", np = 1) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
90 prao_df <- data.frame(raster::rasterToPoints(prao$window.9[[1]])) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
91 prao_name <- "Prao" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
92 r_pts[, prao_name] <- prao_df[, 3] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
93 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
94 #Cumulative Residual Entropy |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
95 cre <- rasterdiv::CRE(copndvilr, window = 9, np = 1) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
96 cre_df <- data.frame(raster::rasterToPoints(cre)) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
97 if (length(cre_df[, 1]) == length(r_pts[, 1])) { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
98 cre_name <- "CRE" |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
99 r_pts[, cre_name] <- cre_df[, 1] |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
100 } |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
101 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
102 if (length(cre_df[, 1]) == length(r_pts[, 1]) || length(pie_df[, 1]) == length(r_pts[, 1])) { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
103 list_indice <- list("Shannon", "Renyi", "Berger-Parker", "Pielou", "Hill", "Prao", "CRE") |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
104 } else { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
105 list_indice <- list("Shannon", "Renyi", "Berger-Parker", "Hill", "Prao") |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
106 } |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
107 ## Plotting all the graph and writing a tabular |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
108 for (indice in list_indice) { |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
109 plot_indices(data = r_pts, titre = indice) |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
110 } |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
111 |
5cae678042ec
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
ecology
parents:
diff
changeset
|
112 write.table(r_pts, file = "BiodivIndex.tabular", sep = "\t", dec = ".", na = " ", row.names = FALSE, col.names = TRUE, quote = FALSE) |