|
72 | 72 | #' to use to derive the processing extent. If not NULL, the processing options
|
73 | 73 | #' which define the extent, the selected tiles and the "Full Tile / Custom"
|
74 | 74 | #' in the JSON options file are overwritten and new files are created on the
|
75 |
| -#' extent of the provided spatial file. Ignored if spatmet != "file", Default: NULL |
| 75 | +#' extent of the provided spatial file. Ignored if spatmeth != "file", Default: NULL |
76 | 76 | #' @param out_projsel `character ["Native", "User Defined`] If "Native", the
|
77 | 77 | #' outputs keep the original resolution of MODIS HDF images. Otherwise, the value
|
78 | 78 | #' set in "out_res" is used, Default:Native
|
|
110 | 110 | #' MODIStsp_process will abort, Default: 20
|
111 | 111 | #' @param verbose `logical` If FALSE, suppress processing messages,
|
112 | 112 | #' Default: TRUE
|
| 113 | +#' @param parallel `logical` If TRUE (default), the function is run using parallel |
| 114 | +#' processing, to speed-up the computation for large rasters (with a maximum |
| 115 | +#' of 8 cores). |
| 116 | +#' The number of cores is automatically determined; specifying it is also |
| 117 | +#' possible (e.g. `parallel = 4`). In this case, more than 8 cores can be |
| 118 | +#' specified. If FALSE (default), single core processing is used. |
113 | 119 | #' @param ... not used for values, forces later arguments to bind by name
|
114 | 120 | #' @return NULL
|
115 | 121 | #'
|
|
126 | 132 | #' @importFrom utils unzip
|
127 | 133 | #' @examples
|
128 | 134 | #'
|
129 |
| -#' \dontrun{ |
130 | 135 | #' #' # - Running the tool using the GUI
|
131 |
| -#' |
132 | 136 | #' # Running the tool without any option will start the GUI with the default or
|
133 | 137 | #' # last used settings, in interactive mode (i.e., with gui = TRUE).
|
134 |
| -#' |
135 |
| -#' # MODIStsp() |
| 138 | +#' \donttest{ |
| 139 | +#' if (interactive()) { |
| 140 | +#' MODIStsp() |
136 | 141 | #' }
|
137 |
| -#' \dontrun{ |
| 142 | +#' } |
| 143 | +#' |
138 | 144 | #'
|
139 | 145 | #' #' # - Running the tool specifying processing arguments in the call
|
140 | 146 | #'
|
|
143 | 149 | #' # Here we process layers __NDVI__ and __EVI__ and quality indicator __usefulness__
|
144 | 150 | #' # of product __M*D13Q1__, considering both Terra and Aqua platforms, for dates
|
145 | 151 | #' # comprised between 2020-06-01 and 2020-06-15 and saves output to R tempdir
|
146 |
| -#' # --> See name and available layers for product M*D13Q1 |
| 152 | +#' # --> See name and available layers for product M*D13Q1. |
| 153 | +#' # Note that this example (as well as the following ones) is run in single |
| 154 | +#' # core to follow CRAN policies, by setting parallel = FALSE. |
| 155 | +#' # Users can exploit multicore functionalities skipping to set this argument. |
147 | 156 | #'
|
148 | 157 | #' MODIStsp_get_prodlayers("M*D13A2")
|
149 |
| -#' |
150 |
| -#' # --> Launch the processing |
151 |
| -#' MODIStsp(gui = FALSE, |
152 |
| -#' out_folder = "$tempdir", |
153 |
| -#' selprod = "Vegetation_Indexes_16Days_1Km (M*D13A2)", |
154 |
| -#' bandsel = c("EVI", "NDVI"), |
155 |
| -#' quality_bandsel = "QA_usef", |
156 |
| -#' indexes_bandsel = "SR", |
157 |
| -#' user = "mstp_test" , |
158 |
| -#' password = "MSTP_test_01", |
159 |
| -#' start_date = "2020.06.01", |
160 |
| -#' end_date = "2020.06.15", |
161 |
| -#' verbose = FALSE) |
| 158 | +#' \donttest{ |
| 159 | +#' MODIStsp( |
| 160 | +#' gui = FALSE, |
| 161 | +#' out_folder = "$tempdir", |
| 162 | +#' selprod = "Vegetation_Indexes_16Days_1Km (M*D13A2)", |
| 163 | +#' bandsel = c("EVI", "NDVI"), |
| 164 | +#' quality_bandsel = "QA_usef", |
| 165 | +#' indexes_bandsel = "SR", |
| 166 | +#' user = "mstp_test" , |
| 167 | +#' password = "MSTP_test_01", |
| 168 | +#' start_date = "2020.06.01", |
| 169 | +#' end_date = "2020.06.15", |
| 170 | +#' verbose = FALSE, |
| 171 | +#' parallel = FALSE |
| 172 | +#' ) |
162 | 173 | #' }
|
163 | 174 | #'
|
164 |
| -#' \dontrun{ |
165 | 175 | #'
|
166 | 176 | #' #' # - Running the tool using the settings previously saved in a specific options file
|
167 | 177 | #'
|
|
173 | 183 | #' # and retrieves NDVI and EVI data, plus the Usefulness Index Quality Indicator.
|
174 | 184 | #'
|
175 | 185 | #' opts_file <- system.file("testdata/test_MOD13A2.json", package = "MODIStsp")
|
176 |
| -#' MODIStsp(gui = FALSE, opts_file = opts_file, verbose = TRUE) |
| 186 | +#' \donttest{ |
| 187 | +#' MODIStsp(gui = FALSE, opts_file = opts_file, verbose = TRUE, parallel = FALSE) |
177 | 188 | #' }
|
178 | 189 | #'
|
179 |
| -#' \dontrun{ |
180 | 190 | #'
|
181 | 191 | #' # Running the tool using the settings previously saved in a specific option file
|
182 | 192 | #' # and specifying the extent from a spatial file allows to re-use the same
|
183 | 193 | #' # processing settings to perform download and reprocessing on a different area
|
184 | 194 | #'
|
185 | 195 | #' opts_file <- system.file("testdata/test_MOD13A2.json", package = "MODIStsp")
|
186 | 196 | #' spatial_file <- system.file("testdata/lakeshapes/garda_lake.shp", package = "MODIStsp")
|
187 |
| -#' MODIStsp(gui = FALSE, opts_file = opts_file, |
| 197 | +#' \donttest{ |
| 198 | +#' MODIStsp( |
| 199 | +#' gui = FALSE, |
| 200 | +#' opts_file = opts_file, |
188 | 201 | #' spatmeth = "file",
|
189 |
| -#' spafile = spatial_file, verbose = TRUE) |
| 202 | +#' spafile = spatial_file, |
| 203 | +#' verbose = TRUE, |
| 204 | +#' parallel = FALSE |
| 205 | +#' ) |
190 | 206 | #' }
|
191 | 207 | #'
|
192 |
| -#' \dontrun{ |
193 | 208 | #'
|
194 | 209 | #' # Running the tool using the settings previously saved in a
|
195 | 210 | #' # specific options file and specifying each time the extent from a different
|
196 | 211 | #' # spatial file (e.g., to perform the same processing on several extents)
|
197 |
| -#' |
198 |
| -#' extent_list <- c(system.file("testdata/lakeshapes/garda_lake.shp", |
199 |
| -#' package = "MODIStsp"), |
200 |
| -#' system.file("testdata/lakeshapes/iseo_lake.shp", |
201 |
| -#' package = "MODIStsp")) |
202 |
| -#' extent_list |
203 |
| -#' |
204 | 212 | #' # Note that you can also put all your extent files in a specific folder and
|
205 | 213 | #' # create the extent list using for example.
|
206 |
| -#' # extent_list = list.files(system.file("testdata/lakeshapes/", package = "MODIStsp"), |
207 |
| -#' # full.names = TRUE, "\\.shp$") |
208 |
| -#' |
| 214 | +#' |
| 215 | +#' extent_list = list.files( |
| 216 | +#' system.file("testdata/lakeshapes/", package = "MODIStsp"), |
| 217 | +#' "\\.shp$", |
| 218 | +#' full.names = TRUE |
| 219 | +#' ) |
| 220 | +#' extent_list |
209 | 221 | #' opts_file <- system.file("testdata/test_MOD13A2.json", package = "MODIStsp")
|
| 222 | +#' |
| 223 | +#' \donttest{ |
210 | 224 | #' for (single_shape in extent_list) {
|
211 |
| -#' MODIStsp(gui = FALSE, opts_file = opts_file, |
212 |
| -#' spatmeth = "file", |
213 |
| -#' spafile = single_shape, verbose = TRUE) |
| 225 | +#' MODIStsp( |
| 226 | +#' gui = FALSE, |
| 227 | +#' opts_file = opts_file, |
| 228 | +#' spatmeth = "file", |
| 229 | +#' spafile = single_shape, |
| 230 | +#' verbose = TRUE, |
| 231 | +#' parallel = FALSE |
| 232 | +#' ) |
214 | 233 | #' }
|
215 | 234 | #'
|
216 | 235 | #' # output files are placed in separate folders:
|
217 |
| -#' outfiles_garda <- list.files(file.path(tempdir(), "MODIStsp/garda_lake/VI_16Days_1Km_v6/NDVI"), |
218 |
| -#' full.names = TRUE) |
| 236 | +#' outfiles_garda <- list.files( |
| 237 | +#' file.path(tempdir(), "MODIStsp/garda_lake/VI_16Days_1Km_v6/NDVI"), |
| 238 | +#' full.names = TRUE |
| 239 | +#' ) |
219 | 240 | #' outfiles_garda
|
220 |
| -#' |
221 | 241 | #' library(raster)
|
222 | 242 | #' plot(raster(outfiles_garda[1] ))
|
223 | 243 | #'
|
224 |
| -#' outfiles_iseo <- list.files(file.path(tempdir(), "MODIStsp/iseo_lake/VI_16Days_1Km_v6/NDVI"), |
225 |
| -#' full.names = TRUE) |
| 244 | +#' outfiles_iseo <- list.files( |
| 245 | +#' file.path(tempdir(), "MODIStsp/iseo_lake/VI_16Days_1Km_v6/NDVI"), |
| 246 | +#' full.names = TRUE |
| 247 | +#' ) |
226 | 248 | #' outfiles_iseo
|
227 |
| -#' |
228 | 249 | #' plot(raster(outfiles_iseo[1]))
|
| 250 | +#' } |
229 | 251 | #'
|
230 | 252 | #' # See also https://docs.ropensci.org/MODIStsp/articles/noninteractive_execution.html
|
231 |
| -#' } |
232 | 253 |
|
233 | 254 | MODIStsp <- function(...,
|
234 | 255 | gui = TRUE,
|
@@ -268,7 +289,8 @@ MODIStsp <- function(...,
|
268 | 289 | compress = NULL,
|
269 | 290 | test = NULL,
|
270 | 291 | n_retries = 5,
|
271 |
| - verbose = TRUE) { |
| 292 | + verbose = TRUE, |
| 293 | + parallel = TRUE) { |
272 | 294 |
|
273 | 295 | # Make so that "raster" functions does not automatically add extensions on
|
274 | 296 | # output files. This is automatically reset to TRUE at the end of the session
|
@@ -540,7 +562,8 @@ MODIStsp <- function(...,
|
540 | 562 |
|
541 | 563 | MODIStsp_process(proc_opts,
|
542 | 564 | n_retries = n_retries,
|
543 |
| - verbose = verbose) |
| 565 | + verbose = verbose, |
| 566 | + parallel = parallel) |
544 | 567 | }
|
545 | 568 |
|
546 | 569 | }
|
0 commit comments