Skip to content

Commit 2bc5ba2

Browse files
committed
Merge branch 'feature/cran_resubmission' into devel
2 parents ed03253 + e1c1609 commit 2bc5ba2

File tree

105 files changed

+5779
-557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+5779
-557
lines changed

.Rbuildignore

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
^pkgdown$
1616
^codecov\.yml$
1717
^utils
18-
^vignettes/faq\.Rmd$
19-
^vignettes/discovered_bug\.Rmd$
20-
^vignettes/lorenzo\.Rmd$
21-
^vignettes/MODIStsp\.Rmd$
18+
^vignettes/analyze\.Rmd
19+
^vignettes/discovered_bug\.Rmd
20+
^vignettes/examples\.Rmd
21+
^vignettes/faq\.Rmd
22+
^vignettes/installation\.Rmd
23+
^vignettes/interactive_execution\.Rmd
24+
^vignettes/lorenzo\.Rmd
25+
^vignettes/noninteractive_execution\.Rmd
26+
^vignettes/output\.Rmd
27+
^vignettes/products_list\.Rmd
28+
^vignettes/standalone_execution\.Rmd
2229
^CONDUCT\.md$

DESCRIPTION

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: MODIStsp
2-
Title: A Tool for Automating Download and Preprocessing of MODIS Land Products
2+
Title: Find, Download and Process MODIS Land Products
33
Data
44
Type: Package
55
Version: 2.0.5
@@ -17,22 +17,28 @@ Authors@R: c(person("Lorenzo", "Busetto",
1717
person("Jeff", "Hanson",
1818
role = "rev",
1919
comment = "Jeff Hanson reviewed the package for rOpenSci, see
20-
https://github.com/ropensci/software-review/issues/184"))
20+
https://github.com/ropensci/software-review/issues/184"),
21+
person("Babak", "Naimi",
22+
role = "ctb",
23+
comment = "Babak Naimi wrote the function ModisDownload(),
24+
on which some MODIStsp internal functions are based"))
2125
Description: Allows automating the creation of time series of rasters derived
22-
from MODIS Satellite Land Products data. It performs several typical
23-
preprocessing steps such as download, mosaicking, reprojection and resize
24-
of data acquired on a specified time period. All processing parameters
26+
from MODIS satellite land products data. It performs several typical
27+
preprocessing steps such as download, mosaicking, reprojecting and resizing
28+
data acquired on a specified time period. All processing parameters
2529
can be set using a user-friendly GUI. Users can select which layers of
2630
the original MODIS HDF files they want to process, which additional
27-
Quality Indicators should be extracted from aggregated MODIS Quality
28-
Assurance layers and, in the case of Surface Reflectance products
29-
, which Spectral Indexes should be computed from the original reflectance
31+
quality indicators should be extracted from aggregated MODIS quality
32+
assurance layers and, in the case of surface reflectance products,
33+
which spectral indexes should be computed from the original reflectance
3034
bands. For each output layer, outputs are saved as single-band raster
3135
files corresponding to each available acquisition date. Virtual files
3236
allowing access to the entire time series as a single file are also created.
3337
Command-line execution exploiting a previously saved processing options
34-
file is also possible, allowing to automatically update time series
38+
file is also possible, allowing users to automatically update time series
3539
related to a MODIS product whenever a new image is available.
40+
For additional documentation refer to the following article:
41+
Busetto and Ranghetti (2016) <doi:10.1016/j.cageo.2016.08.020>.
3642
License: GPL-3
3743
Depends:
3844
R (>= 3.5.0)
@@ -63,9 +69,7 @@ Suggests:
6369
leaflet,
6470
magrittr,
6571
mapedit (>= 0.6.0),
66-
markdown,
6772
png,
68-
qpdf,
6973
rappdirs,
7074
rgdal,
7175
rmarkdown,
@@ -77,7 +81,6 @@ Suggests:
7781
spelling,
7882
testthat,
7983
tibble,
80-
tibbletime,
8184
tidyr,
8285
xtable
8386
SystemRequirements:

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- Edit documentation related to the change of maintainer
66
(see https://docs.ropensci.org/MODIStsp/articles/lorenzo).
77

8+
- Add the argument `parallel` to function `MODIStsp()` and `MODSIStsp_process()`
9+
to allow running the processing in single core modality.
10+
811
### Minor changes
912

1013
- Fix Travis tests

R/MODIStsp.R

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
#' to use to derive the processing extent. If not NULL, the processing options
7373
#' which define the extent, the selected tiles and the "Full Tile / Custom"
7474
#' 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
7676
#' @param out_projsel `character ["Native", "User Defined`] If "Native", the
7777
#' outputs keep the original resolution of MODIS HDF images. Otherwise, the value
7878
#' set in "out_res" is used, Default:Native
@@ -110,6 +110,12 @@
110110
#' MODIStsp_process will abort, Default: 20
111111
#' @param verbose `logical` If FALSE, suppress processing messages,
112112
#' 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.
113119
#' @param ... not used for values, forces later arguments to bind by name
114120
#' @return NULL
115121
#'
@@ -126,15 +132,15 @@
126132
#' @importFrom utils unzip
127133
#' @examples
128134
#'
129-
#' \dontrun{
130135
#' #' # - Running the tool using the GUI
131-
#'
132136
#' # Running the tool without any option will start the GUI with the default or
133137
#' # last used settings, in interactive mode (i.e., with gui = TRUE).
134-
#'
135-
#' # MODIStsp()
138+
#' \donttest{
139+
#' if (interactive()) {
140+
#' MODIStsp()
136141
#' }
137-
#' \dontrun{
142+
#' }
143+
#'
138144
#'
139145
#' #' # - Running the tool specifying processing arguments in the call
140146
#'
@@ -143,25 +149,29 @@
143149
#' # Here we process layers __NDVI__ and __EVI__ and quality indicator __usefulness__
144150
#' # of product __M*D13Q1__, considering both Terra and Aqua platforms, for dates
145151
#' # 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.
147156
#'
148157
#' 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+
#' )
162173
#' }
163174
#'
164-
#' \dontrun{
165175
#'
166176
#' #' # - Running the tool using the settings previously saved in a specific options file
167177
#'
@@ -173,62 +183,73 @@
173183
#' # and retrieves NDVI and EVI data, plus the Usefulness Index Quality Indicator.
174184
#'
175185
#' 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)
177188
#' }
178189
#'
179-
#' \dontrun{
180190
#'
181191
#' # Running the tool using the settings previously saved in a specific option file
182192
#' # and specifying the extent from a spatial file allows to re-use the same
183193
#' # processing settings to perform download and reprocessing on a different area
184194
#'
185195
#' opts_file <- system.file("testdata/test_MOD13A2.json", package = "MODIStsp")
186196
#' 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,
188201
#' spatmeth = "file",
189-
#' spafile = spatial_file, verbose = TRUE)
202+
#' spafile = spatial_file,
203+
#' verbose = TRUE,
204+
#' parallel = FALSE
205+
#' )
190206
#' }
191207
#'
192-
#' \dontrun{
193208
#'
194209
#' # Running the tool using the settings previously saved in a
195210
#' # specific options file and specifying each time the extent from a different
196211
#' # 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-
#'
204212
#' # Note that you can also put all your extent files in a specific folder and
205213
#' # 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
209221
#' opts_file <- system.file("testdata/test_MOD13A2.json", package = "MODIStsp")
222+
#'
223+
#' \donttest{
210224
#' 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+
#' )
214233
#' }
215234
#'
216235
#' # 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+
#' )
219240
#' outfiles_garda
220-
#'
221241
#' library(raster)
222242
#' plot(raster(outfiles_garda[1] ))
223243
#'
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+
#' )
226248
#' outfiles_iseo
227-
#'
228249
#' plot(raster(outfiles_iseo[1]))
250+
#' }
229251
#'
230252
#' # See also https://docs.ropensci.org/MODIStsp/articles/noninteractive_execution.html
231-
#' }
232253

233254
MODIStsp <- function(...,
234255
gui = TRUE,
@@ -268,7 +289,8 @@ MODIStsp <- function(...,
268289
compress = NULL,
269290
test = NULL,
270291
n_retries = 5,
271-
verbose = TRUE) {
292+
verbose = TRUE,
293+
parallel = TRUE) {
272294

273295
# Make so that "raster" functions does not automatically add extensions on
274296
# output files. This is automatically reset to TRUE at the end of the session
@@ -540,7 +562,8 @@ MODIStsp <- function(...,
540562

541563
MODIStsp_process(proc_opts,
542564
n_retries = n_retries,
543-
verbose = verbose)
565+
verbose = verbose,
566+
parallel = parallel)
544567
}
545568

546569
}

R/MODIStsp_process.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#' In case any download function fails more than `n_retries` times consecutively,
2424
#' MODIStsp_process will abort, Default: 20
2525
#' @param verbose `logical` If FALSE, suppress processing messages, Default: TRUE
26+
#' @param parallel `logical` If TRUE (default), the function is run using parallel
27+
#' processing, to speed-up the computation for large rasters (with a maximum
28+
#' of 8 cores).
29+
#' The number of cores is automatically determined; specifying it is also
30+
#' possible (e.g. `parallel = 4`). In this case, more than 8 cores can be
31+
#' specified. If FALSE (default), single core processing is used.
2632
#' @return The function is called for its side effects.
2733
#' @author Lorenzo Busetto, phD (2014-2017)
2834
#' @author Luigi Ranghetti, phD (2015) \email{luigi@@ranghetti.info}
@@ -36,7 +42,8 @@
3642

3743
MODIStsp_process <- function(proc_opts,
3844
n_retries,
39-
verbose = TRUE) {
45+
verbose = TRUE,
46+
parallel = TRUE) {
4047

4148
# Based on sel_prod, retrieve needed variables from prod_opts file
4249

@@ -425,7 +432,7 @@ MODIStsp_process <- function(proc_opts,
425432
proc_opts$out_format, outrep_file, proc_opts$compress,
426433
proc_opts$out_res_sel, proc_opts$out_res, proc_opts$resampling,
427434
proc_opts$nodata_change,
428-
gui, verbose
435+
gui, verbose, parallel
429436
)
430437
}
431438
} # END Cycle on available MODIS Bands

R/MODIStsp_process_QA_bits.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#' @author Lorenzo Busetto, phD (2017)
2424
#' @author Luigi Ranghetti, phD (2017) \email{luigi@@ranghetti.info}
2525
#' @note License: GPL 3.0
26-
#' Based on the "modis.qc.R" script by Yann Chemin (2008) (https://goo.gl/7Fhreo)
26+
#' Based on the `modis.qc.R` script by Yann Chemin (2008) (\url{https://goo.gl/7Fhreo})
2727
#' license GPL 3.0
2828
#' @importFrom raster raster NAvalue calc
2929
#' @importFrom bitops bitShiftR bitAnd

R/MODIStsp_process_bands.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
#' @param outrep_file `character` Full path of the file where results of the
3030
#' processing are to be stored (created in `MODIStsp_process`)
3131
#' @param verbose `logical` If FALSE, suppress processing messages, Default: TRUE
32+
#' @param parallel `logical` If TRUE, the function is run using parallel
33+
#' processing, to speed-up the computation for large rasters (with a maximum
34+
#' of 8 cores).
35+
#' The number of cores is automatically determined; specifying it is also
36+
#' possible (e.g. `parallel = 4`). In this case, more than 8 cores can be
37+
#' specified. If FALSE (default), single core processing is used.
3238
#' @return The function is called for its side effects
3339
#' @rdname MODIStsp_process_bands
3440
#' @author Lorenzo Busetto, phD (2014-2017)
@@ -50,7 +56,7 @@ MODIStsp_process_bands <- function(out_folder_mod, modislist,
5056
out_format, outrep_file, compress,
5157
out_res_sel, out_res, resampling,
5258
nodata_change,
53-
gui, verbose) {
59+
gui, verbose, parallel) {
5460

5561
tmpdir <- file.path(tempdir(), "mstp_temp")
5662
dir.create(tmpdir, showWarnings = FALSE)
@@ -62,7 +68,13 @@ MODIStsp_process_bands <- function(out_folder_mod, modislist,
6268
# number of available cpus > 8 (this to avoid overloading servers with high
6369
# number of cpus)
6470

65-
ncores <- min(c(8, parallel::detectCores() - 2))
71+
ncores <- if (is.numeric(parallel)) {
72+
as.integer(parallel)
73+
} else if (parallel == FALSE) {
74+
1
75+
} else {
76+
min(c(8, parallel::detectCores() - 2))
77+
}
6678

6779
# check to see if the patch to correct wrong resolution/bbox in some HDF4 ----
6880
# original layers (e.g. albedo) is needed
@@ -316,7 +328,7 @@ MODIStsp_process_bands <- function(out_folder_mod, modislist,
316328
outproj_str,
317329
mod_proj_str,
318330
enlarge = TRUE)
319-
# Create a resized and (if needed) mosaiced GDAL vrt file
331+
# Create a resized and (if needed) mosaicked GDAL vrt file
320332

321333
if (datatype == "UInt32") {
322334
# fix to avoid bug on gdalbuildvrt for UInt32 datasets;

R/get_mod_dirs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' environment or not. If not, processing messages are sent to a log file
1717
#' instead than to the console/GTK progress windows.
1818
#' @param out_folder_mod `character` output folder for MODIS HDF storage
19-
#' @return `character arraay` listing all available folders (a.k.a. dates) for
19+
#' @return `character array` listing all available folders (a.k.a. dates) for
2020
#' the requested MODIS product on lpdaac http archive, for the years
2121
#' included in the time range selected for processing.
2222
#' @author Original code by Babak Naimi (\code{.getModisList}, in

0 commit comments

Comments
 (0)