Mercurial > repos > ecology > srs_spectral_indices
annotate preprocess_S2.r @ 1:0c6db524ae70 draft default tip
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit 0f331043178bbfbe5cda0e31d887971464b3071c
| author | ecology | 
|---|---|
| date | Fri, 07 Apr 2023 16:00:20 +0000 | 
| parents | 20604db47df5 | 
| children | 
| rev | line source | 
|---|---|
| 
0
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
1 #Rscript | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
2 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
3 ########################################### | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
4 ## Preprocessing Sentinel 2 data ## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
5 ########################################### | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
6 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
7 #####Packages : sen2r, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
8 # jqr, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
9 # protolite, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
10 # raster, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
11 # sf, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
12 # rgeos, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
13 # sp, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
14 # raster, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
15 # stars, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
16 # stringr, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
17 # progress, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
18 # rgdal, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
19 # R.utils, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
20 # gdalUtils, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
21 # fasterize, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
22 # XML, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
23 # XML2 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
24 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
25 #####Load arguments | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
26 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
27 args <- commandArgs(trailingOnly = TRUE) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
28 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
29 if (length(args) < 1) { | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
30 stop("This tool needs at least 1 argument") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
31 }else { | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
32 data <- args[1] | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
33 source(args[2]) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
34 data_source <- as.character(args[3]) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
35 sat_type <- as.character(args[4]) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
36 } | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
37 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
38 ##____________________________________________________________________## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
39 ## Define where data is stored and where to write results ## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
40 ##--------------------------------------------------------------------## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
41 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
42 #Create a directory where to unzip your folder of data | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
43 dir.create("data_dir") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
44 unzip(data, exdir = "data_dir") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
45 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
46 # Result directory | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
47 result_path <- "results" | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
48 dir.create(path = result_path, showWarnings = FALSE, recursive = TRUE) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
49 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
50 #Csv file for output useless but needed for linter | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
51 write.csv(data_source, "Mission.csv") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
52 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
53 # define raster path | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
54 if (data_source == "SAFE") { | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
55 path_s2 <- file.path("data_dir", list.files("data_dir", pattern = ".SAFE")) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
56 #To define the level and know if a correction is needed (convert not ready yet) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
57 level_info <- get_s2_level(path_s2) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
58 if (level_info == "L1C") { | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
59 stop("! This tool works for data of L2A level and NOT for the L1C level which is currently a work in progress !") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
60 } | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
61 }else { | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
62 path_s2 <- file.path("data_dir") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
63 } | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
64 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
65 ##____________________________________________________________________## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
66 ## Extract, resample & stack data ## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
67 ##--------------------------------------------------------------------## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
68 # define resolution | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
69 resolution <- 10 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
70 # define source of data | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
71 s2source <- data_source | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
72 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
73 s2obj <- extract_from_s2_l2a(path_dir_s2 = path_s2, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
74 path_vector = NULL, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
75 s2source = s2source, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
76 resolution = resolution) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
77 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
78 ##____________________________________________________________________## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
79 ## Write CLOUD MASK ## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
80 ##--------------------------------------------------------------------## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
81 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
82 # directory for cloud mask | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
83 cloud_path <- file.path(result_path, "CloudMask") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
84 dir.create(path = cloud_path, showWarnings = FALSE, recursive = TRUE) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
85 # Filename for cloud mask | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
86 cloudmasks <- save_cloud_s2(s2_stars = s2obj$s2_stack, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
87 cloud_path = cloud_path, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
88 s2source = s2source, saveraw = TRUE) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
89 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
90 zip_cloud <- file.path("Cloud.zip") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
91 zip::zip(zip_cloud, cloud_path) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
92 ##____________________________________________________________________## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
93 ## Write REFLECTANCE ## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
94 ##--------------------------------------------------------------------## | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
95 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
96 # directory for Reflectance | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
97 refl_dir <- file.path(result_path, "Reflectance") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
98 dir.create(path = refl_dir, showWarnings = FALSE, recursive = TRUE) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
99 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
100 if (data_source == "SAFE") { | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
101 # filename for Reflectance | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
102 refl_path <- file.path(refl_dir, paste(basename(s2obj$s2_bands$GRANULE), "_Refl", sep = "")) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
103 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
104 # Save Reflectance file as ENVI image with BIL interleaves | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
105 tile_s2 <- substring(strsplit(basename(s2obj$s2_bands$GRANULE), "_")[[1]][2], 2) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
106 dateacq_s2 <- as.Date(substring(strsplit(basename(s2obj$s2_bands$GRANULE), "_")[[1]][4], 1, 8), format = "%Y%m%d") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
107 }else { | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
108 # filename for Reflectance | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
109 refl_path <- file.path(refl_dir, paste(basename(s2obj$s2_bands$path_tile_s2), "_Refl", sep = "")) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
110 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
111 # Save Reflectance file as ENVI image with BIL interleaves | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
112 tile_s2 <- substring(strsplit(basename(s2obj$s2_bands$path_tile_s2), "_")[[1]][2], 2) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
113 dateacq_s2 <- as.Date(substring(strsplit(basename(s2obj$s2_bands$path_tile_s2), "_")[[1]][4], 1, 8), format = "%Y%m%d") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
114 } | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
115 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
116 save_data <- save_reflectance_s2(s2_stars = s2obj$s2_stack, refl_path = refl_path, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
117 s2sat = sat_type, tile_s2 = tile_s2, dateacq_s2 = dateacq_s2, | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
118 format = "ENVI", datatype = "Int16", mtd = s2obj$s2_bands$metadata, mtd_msi = s2obj$s2_bands$metadata_MSI) | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
119 | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
120 zip_files <- file.path("Refl.zip") | 
| 
 
20604db47df5
planemo upload for repository https://github.com/Marie59/Sentinel_2A/srs_tools commit b32737c1642aa02cc672534e42c5cb4abe0cd3e7
 
ecology 
parents:  
diff
changeset
 | 
121 zip::zip(zip_files, refl_dir) | 
