Skip to content

Commit 110ae2a

Browse files
committed
lights updates on the documentations of the functions + adding the cli package for messages when verbose
1 parent d77f8b4 commit 110ae2a

10 files changed

+33
-26
lines changed

R/mf_download_data.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#' @param parallel boolean. Parallelize the download ? Default to FALSE
1313
#' @param num_workers integer. Number of workers in case of parallel download. Default to number of workers available in the machine minus one.
1414
#' @param min_filesize integer. Minimum file size expected (in bites) for one file downloaded. If files downloaded are less that this value, the files will be downloaded again. Default 5000.
15-
#' @param ... not used
1615
#'
1716
#' @return a data.frame with the same structure of the input data.frame \code{df_to_dl} + columns providing details of the data downloaded. The additional columns are :
1817
#' \describe{
@@ -73,7 +72,7 @@
7372
#' ### Plot the data
7473
#' terra::plot(modis_ts)
7574
#' }
76-
mf_download_data <- function(df_to_dl, path = tempfile("modisfast_"), parallel = FALSE, num_workers = parallel::detectCores() - 1, credentials = NULL, verbose = TRUE, min_filesize = 5000, ...) {
75+
mf_download_data <- function(df_to_dl, path = tempfile("modisfast_"), parallel = FALSE, num_workers = parallel::detectCores() - 1, credentials = NULL, verbose = TRUE, min_filesize = 5000) {
7776
fileSize <- destfile <- fileDl <- folders <- readme_files <- source <- NULL
7877

7978
source <- "earthdata"
@@ -189,16 +188,16 @@ mf_download_data <- function(df_to_dl, path = tempfile("modisfast_"), parallel =
189188

190189
if (!(identical(data_dl, data_downloaded))) {
191190
if (verbose) {
192-
cli_alert_warning("Only part of the data has been downloaded. Downloading the remaining datasets one by one...\n")
191+
cli::cli_alert_warning("Only part of the data has been downloaded. Downloading the remaining datasets one by one...\n")
193192
}
194193
mf_download_data(df_to_dl = df_to_dl, path = path, parallel = FALSE, credentials = credentials) # ,source=source)
195194
} else {
196195
# 1 : download ok
197196
# 2 : download error
198197
# 3 : data already existing in output folder
199198
if (verbose) {
200-
cli_alert_success("\nData were all properly downloaded under the folder(s) ", paste(as.character(unique(dirname(df_to_dl$destfile))), collapse = " and "))
201-
cli_alert_info("\nTo import the data in R, use the function modisfast::mf_import_data() rather than terra::rast() or stars::read_stars(). More info at help(mf_import_data)\n")
199+
cli::cli_alert_success("\nData were all properly downloaded under the folder(s) ", paste(as.character(unique(dirname(df_to_dl$destfile))), collapse = " and "))
200+
cli::cli_alert_info("\nTo import the data in R, use the function modisfast::mf_import_data() rather than terra::rast() or stars::read_stars(). More info at help(mf_import_data)\n")
202201
}
203202
}
204203

R/mf_get_url.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#' @param opt_param list of optional arguments. optional. (see details).
1414
#' @param credentials vector string of length 2 with username and password. optional if the function \link{mf_login} was previously executed.
1515
#' @param verbose boolean. optional. Verbose (default TRUE)
16-
#' @param ... not used
1716
#'
1817
#' @return a data.frame with one row for each dataset to download and 5 columns :
1918
#' \describe{
@@ -43,6 +42,7 @@
4342
#'
4443
#' @importFrom stringr str_replace
4544
#' @importFrom stats ave
45+
#' @importFrom cli cli_alert_success
4646
#' @import dplyr
4747
#'
4848
#' @examples
@@ -97,8 +97,7 @@ mf_get_url <- function(collection,
9797
single_netcdf = TRUE,
9898
opt_param = NULL,
9999
credentials = NULL,
100-
verbose = TRUE,
101-
...) {
100+
verbose = TRUE) {
102101
existing_variables <- odap_coll_info <- odap_timeDimName <- odap_lonDimName <- odap_latDimName <- . <- name <- destfile <- roi_id <- NULL
103102

104103
## tests :
@@ -142,7 +141,7 @@ mf_get_url <- function(collection,
142141

143142
# test variables
144143
# if(verbose){cat("Checking if specified variables exist for the collection specified...\n")}
145-
available_variables <- opt_param$availableVariables$name[which(opt_param$availableVariables$extractable_w_opendapr == "extractable")]
144+
available_variables <- opt_param$availableVariables$name[which(opt_param$availableVariables$extractable_with_modisfast == "extractable")]
146145
if (is.null(variables)) {
147146
variables <- available_variables
148147
} else {
@@ -172,7 +171,7 @@ mf_get_url <- function(collection,
172171
dplyr::rename(time_start = date, id_roi = roi_id)
173172

174173
if (verbose) {
175-
cat("OK\n")
174+
cli::cli_alert_success("URL(s) built\n")
176175
}
177176

178177
return(table_urls)

R/mf_import_data.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#' @param proj_epsg numeric. EPSG of the desired projection for the output raster (default : source projection of the data).
99
#' @param roi_mask \code{SpatRaster} or \code{SpatVector} or \code{sf}. Area beyond which data will be masked. Typically, the input ROI of \link{mf_get_url} (default : NULL (no mask))
1010
#' @param vrt boolean. Import virtual raster instead of SpatRaster. Useful for very large files. (default : FALSE)
11+
#' @param verbose boolean. optional. Verbose (default TRUE)
1112
#' @inheritParams mf_get_url
1213
#' @param ... not used
1314
#'
@@ -28,6 +29,7 @@
2829
#' @import purrr
2930
#' @importFrom terra rast t merge flip
3031
#' @importFrom magrittr %>%
32+
#' @importFrom cli cli_alert_success
3133
#' @export
3234
#'
3335
#' @examples
@@ -74,6 +76,7 @@ mf_import_data <- function(path,
7476
proj_epsg = NULL,
7577
roi_mask = NULL,
7678
vrt = FALSE,
79+
verbose = TRUE,
7780
...) {
7881
rasts <- NULL
7982

@@ -89,11 +92,19 @@ mf_import_data <- function(path,
8992
stop("paramater 'output_class' must be SpatRaster.")
9093
}
9194

95+
if (verbose) {
96+
cat("Importing the dataset as a",output_class,"object...\n")
97+
}
98+
9299
if (odap_coll_info$source %in% c("MODIS", "VIIRS")) {
93100
rasts <- .import_modis_viirs(path, output_class, proj_epsg, roi_mask, vrt)
94101
} else if (odap_coll_info$source == "GPM") {
95102
rasts <- .import_gpm(path, output_class, proj_epsg, roi_mask)
96103
}
97104

105+
if (verbose) {
106+
cli_alert_success("Dataset imported")
107+
}
108+
98109
return(rasts)
99110
}

R/mf_list_variables.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @inheritParams mf_get_url
77
#'
88
#' @return A data.frame with the variables available for the collection, and a set of related information for each variable.
9-
#' The variables marked as "extractable" in the column "extractable_w_opendapr" can be provided as input parameter \code{variables} of the function \link{mf_get_url}
9+
#' The variables marked as "extractable" in the column "extractable_with_modisfast" can be provided as input parameter \code{variables} of the function \link{mf_get_url}
1010
#'
1111
#' @export
1212
#'
@@ -83,20 +83,20 @@ mf_list_variables <- function(collection, credentials = NULL) { # for a given co
8383
dim_proj <- opendapMetadata$dim_proj
8484

8585
tab <- tab %>%
86-
dplyr::mutate(extractable_w_opendapr = dplyr::case_when(
86+
dplyr::mutate(extractable_with_modisfast = dplyr::case_when(
8787
name %in% c(dim_lon, dim_lat, dim_time, dim_proj) ~ "automatically extracted",
8888
grepl(dim_lon, tab$indices) & grepl(dim_lat, tab$indices) & grepl(dim_time, tab$indices) & !is.na(dim_time) ~ "extractable",
8989
grepl(dim_lon, tab$indices) & grepl(dim_lat, tab$indices) & is.na(dim_time) ~ "extractable"
9090
))
9191

92-
tab$extractable_w_opendapr[which(is.na(tab$extractable_w_opendapr))] <- "not extractable"
92+
tab$extractable_with_modisfast[which(is.na(tab$extractable_with_modisfast))] <- "not extractable"
9393

9494
if (opendapMetadata$source == "SMAP") {
95-
tab$extractable_w_opendapr[which(tab$extractable_w_opendapr == "not extractable")] <- "extractable"
95+
tab$extractable_with_modisfast[which(tab$extractable_with_modisfast == "not extractable")] <- "extractable"
9696
}
9797

9898

99-
tab <- tab[c("name", "long_name", "units", "indices", "all_info", "extractable_w_opendapr")]
99+
tab <- tab[c("name", "long_name", "units", "indices", "all_info", "extractable_with_modisfast")]
100100

101101
return(tab)
102102
}

R/mf_login.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#'
55
#' @inheritParams mf_get_url
66
#'
7+
#' @importFrom cli cli_alert_success
8+
#'
79
#' @return None.
810
#' @export
911
#'
@@ -39,6 +41,6 @@ mf_login <- function(credentials, verbose = TRUE) {
3941
# }
4042
# if(verbose){cat("Successfull login to",source,"\n")}
4143
if (verbose) {
42-
cat("Successfull login to Earthdata\n")
44+
cli::cli_alert_success("Successfull login to Earthdata\n")
4345
}
4446
}

man/mf_download_data.Rd

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mf_get_url.Rd

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mf_import_data.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mf_list_variables.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/modisfast-package.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)