diff --git a/DESCRIPTION b/DESCRIPTION index cec213f3b..b32ad0337 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,15 +46,14 @@ Imports: utils, viridisLite, viridis, - vol2birdR + rlang Remotes: - adokter/vol2birdR, bioc::rhdf5 Suggests: + vol2birdR, aws.s3, ggmap (>= 3.0.0), knitr, - rlang, tidyselect, rmarkdown, testthat, diff --git a/R/apply_mistnet.R b/R/apply_mistnet.R index 8753e6731..9e9559d14 100644 --- a/R/apply_mistnet.R +++ b/R/apply_mistnet.R @@ -132,7 +132,7 @@ apply_mistnet_body <- function(file, pvolfile_out, verbose = FALSE, local_install, local_mistnet) { assert_that(file.exists(file)) - + rlang::check_installed('vol2birdR',format_reason_vol2bird("to run `apply_mist`.")) if (!vol2birdR::mistnet_exists()) { stop("MistNet has not been installed, see vol2birdR package documentation for install instructions") } diff --git a/R/bioRad-deprecated.R b/R/bioRad-deprecated.R index 600bf6c24..973a86fca 100644 --- a/R/bioRad-deprecated.R +++ b/R/bioRad-deprecated.R @@ -34,6 +34,7 @@ update_docker <- function(...) { #' @export vol2bird_version <- function(...) { .Deprecated("vol2birdR::vol2bird_version") + rlang::check_installed('vol2birdR',format_reason_vol2bird("to run `vol2bird_version`.")) warning("vol2bird_version has been moved to package vol2birdR") vol2birdR::vol2bird_version() } diff --git a/R/calculate_vp.R b/R/calculate_vp.R index 95e82bcc6..23d64fe9c 100644 --- a/R/calculate_vp.R +++ b/R/calculate_vp.R @@ -204,7 +204,7 @@ calculate_vp <- function(file, vpfile = "", pvolfile_out = "", vpfile = vpfile, pvolfile_out = pvolfile_out, autoconf = autoconf, verbose = verbose, warnings = warnings, mount = mount, sd_vvp_threshold = sd_vvp_threshold, - rcs = rcs, dual_pol = dual_pol, rho_hv = rho_hv, single_pol=single_pol, + rcs = rcs, dual_pol = dual_pol, rho_hv = rho_hv, single_pol = single_pol, elev_min = elev_min, elev_max = 90, azim_min = 0, azim_max = 360, range_min = range_min, range_max = range_max, n_layer = n_layer, h_layer = h_layer, dealias = dealias, @@ -219,7 +219,7 @@ calculate_vp <- function(file, vpfile = "", pvolfile_out = "", file.remove(tmp_pvol_file) return(res) } - + rlang::check_installed("vol2birdR", format_reason_vol2bird("to run `calculate_vp`.")) # check input arguments assert_that( is.character(file), @@ -237,25 +237,24 @@ calculate_vp <- function(file, vpfile = "", pvolfile_out = "", if (!is.logical(mistnet)) { stop("`mistnet` must be a logical value.") } - if (mistnet){ - if(missing(local_mistnet)){ + if (mistnet) { + if (missing(local_mistnet)) { if (!vol2birdR::mistnet_exists()) { stop("MistNet has not been installed, see vol2birdR package documentation for install instructions.") } - } - else{ - if(!file.exists(local_mistnet)){ - stop(paste0("'",local_mistnet,"' does not exist, `local_mistnet` should specify the path of MistNet segmentation model")) + } else { + if (!file.exists(local_mistnet)) { + stop(paste0("'", local_mistnet, "' does not exist, `local_mistnet` should specify the path of MistNet segmentation model")) } } } if (!is.logical(dealias)) { stop("`dealias` must be a logical value.") } - if(!missing(mount)) { + if (!missing(mount)) { warning("mount argument is deprecated") } - if(!missing(local_install)){ + if (!missing(local_install)) { warning("local_install argument is deprecated") } @@ -333,7 +332,8 @@ calculate_vp <- function(file, vpfile = "", pvolfile_out = "", assert_that(is.flag(mistnet)) assert_that( !(mistnet && !vol2birdR::mistnet_exists() && missing(local_mistnet)), - msg = "Can't find MistNet installation, see vol2birdR package for install instructions.") + msg = "Can't find MistNet installation, see vol2birdR package for install instructions." + ) assert_that(is.flag(dealias)) filedir <- dirname(normalizePath(file[1], winslash = "/")) @@ -342,7 +342,7 @@ calculate_vp <- function(file, vpfile = "", pvolfile_out = "", profile.tmp <- tempfile() config <- vol2birdR::vol2bird_config() - if(!autoconf){ + if (!autoconf) { config$birdRadarCrossSection <- rcs config$rhohvThresMin <- rho_hv config$elevMin <- elev_min @@ -358,16 +358,16 @@ calculate_vp <- function(file, vpfile = "", pvolfile_out = "", config$dualPol <- dual_pol config$dealiasVrad <- dealias if (!missing(sd_vvp_threshold)) config$stdDevMinBird <- sd_vvp_threshold - } else{ + } else { # setting stdDevMinBird triggers it to be set according to wavelength (1 m/s for S-band, 2 m/s for C-band) config$stdDevMinBird <- -1 } config$mistNetElevs <- mistnet_elevations config$useMistNet <- mistnet - if(!missing(local_mistnet) & mistnet) config$mistNetPath <- local_mistnet + if (!missing(local_mistnet) & mistnet) config$mistNetPath <- local_mistnet # run vol2bird - vol2birdR::vol2bird(file=file, config=config, vpfile=profile.tmp, pvolfile_out=pvolfile_out, verbose = verbose) + vol2birdR::vol2bird(file = file, config = config, vpfile = profile.tmp, pvolfile_out = pvolfile_out, verbose = verbose) # read output into a vp object output <- read_vpfiles(profile.tmp) @@ -380,3 +380,13 @@ calculate_vp <- function(file, vpfile = "", pvolfile_out = "", output } + +format_reason_vol2bird <- function(x) { + on_intel_mac <- Sys.info()[["sysname"]]=="Darwin" & Sys.info()[["machine"]] == "x86_64" + if (.Platform$OS.type == "unix" & !on_intel_mac) { + return(paste(x, "Installation may require pre-installation of additional system libraries, see https://github.com/adokter/vol2birdR#install for instructions.")) + } else { + # platform is Windows or Intel Mac, pre-compiled binaries are available on CRAN + return(x) + } +} diff --git a/R/hooks.R b/R/hooks.R index 0cea6c3a5..decf3fc65 100644 --- a/R/hooks.R +++ b/R/hooks.R @@ -1,9 +1,10 @@ .onLoad <- function(libname, pkgname) { register_all_s3_methods() # dynamically registers non-imported pkgs (tidyverse) # nocov - assert_that(is.string(find.package("vol2birdR", verbose=F, quiet=T)),msg="package vol2birdR not found. See https://adokter.github.io/vol2birdR/ for install instructions") } .onAttach <- function(libname, pkgname) { packageStartupMessage(paste("Welcome to", pkgname, "version", packageVersion(pkgname))) - packageStartupMessage(paste("using vol2birdR version ", packageVersion("vol2birdR"), ifelse(vol2birdR::mistnet_exists(), " (MistNet installed)", " (MistNet not installed)"), sep = "")) + if (rlang::is_installed("vol2birdR")) { + packageStartupMessage(paste("using vol2birdR version ", packageVersion("vol2birdR"), ifelse(vol2birdR::mistnet_exists(), " (MistNet installed)", " (MistNet not installed)"), sep = "")) + } } diff --git a/R/nexrad_odim.R b/R/nexrad_odim.R index debab82b9..5c7df875a 100644 --- a/R/nexrad_odim.R +++ b/R/nexrad_odim.R @@ -37,6 +37,7 @@ nexrad_to_odim <- function(pvolfile_nexrad, pvolfile_odim, verbose = FALSE) { assert_that(dir.exists(dirname(pvolfile_odim)),msg=paste("output directory", dirname(pvolfile_odim), "not found")) assert_that(is.writeable(dirname(pvolfile_odim))) + rlang::check_installed('vol2birdR',format_reason_vol2bird('to run `nexrad_to_odim`.')) config <- vol2birdR::vol2bird_config() vol2birdR::rsl2odim(file=pvolfile_nexrad, config=config, pvolfile_out=pvolfile_odim, verbose=verbose) diff --git a/R/read_pvolfile.R b/R/read_pvolfile.R index 393528a7a..2521312d6 100644 --- a/R/read_pvolfile.R +++ b/R/read_pvolfile.R @@ -72,19 +72,20 @@ read_pvolfile <- function(file, param = c( sort = TRUE, lat, lon, height, elev_min = 0, elev_max = 90, verbose = TRUE, mount = dirname(file), local_install) { - if(!missing(local_install)) warning("argument 'local_install' has been deprecated") - if(!file.exists(file)){ - stop(paste0("'",file,"' does not exist in current working directory ('",getwd(),"').")) - } - tryCatch(read_pvolfile_body( - file, param, sort, lat, lon, - height, elev_min, elev_max, - verbose, mount, local_install - ), - error = function(err) { - rhdf5::h5closeAll() - stop(err) + if (!missing(local_install)) warning("argument 'local_install' has been deprecated") + if (!file.exists(file)) { + stop(paste0("'", file, "' does not exist in current working directory ('", getwd(), "').")) } + tryCatch( + read_pvolfile_body( + file, param, sort, lat, lon, + height, elev_min, elev_max, + verbose, mount, local_install + ), + error = function(err) { + rhdf5::h5closeAll() + stop(err) + } ) } @@ -125,9 +126,9 @@ read_pvolfile_body <- function(file, param = c( } } else { pvol_tmp <- tempfile() - + rlang::check_installed("vol2birdR", format_reason_vol2bird("to read `NEXRAD` files.")) config <- vol2birdR::vol2bird_config() - vol2birdR::rsl2odim(file=file, config=config, pvolfile_out=pvol_tmp, verbose=verbose) + vol2birdR::rsl2odim(file = file, config = config, pvolfile_out = pvol_tmp, verbose = verbose) if (!is.pvolfile(pvol_tmp)) { file.remove(pvol_tmp) @@ -168,9 +169,9 @@ read_pvolfile_body <- function(file, param = c( } # construct wavelength attribute from frequency attribute if possible: - if(is.null(attribs.how$wavelength) & !is.null(attribs.how$frequency)){ - speed_of_light = 299792458 - attribs.how$wavelength = 100*speed_of_light/attribs.how$frequency + if (is.null(attribs.how$wavelength) & !is.null(attribs.how$frequency)) { + speed_of_light <- 299792458 + attribs.how$wavelength <- 100 * speed_of_light / attribs.how$frequency } vol.lat <- c(attribs.where$lat) # need the c() to convert single element matrix to single element vector @@ -218,7 +219,7 @@ read_pvolfile_body <- function(file, param = c( datetime <- as.POSIXct(paste(attribs.what$date, attribs.what$time), format = "%Y%m%d %H%M%S", tz = "UTC" ) - if(is.null(attribs.what$source)) attribs.what$source="" + if (is.null(attribs.what$source)) attribs.what$source <- "" sources <- strsplit(attribs.what$source, ",")[[1]] radar <- gsub("NOD:", "", sources[which(grepl("NOD:", sources))]) if (length(radar) == 0) { @@ -254,8 +255,8 @@ read_pvolfile_body <- function(file, param = c( # filter out NULL output from read_pvolfile_scan valid_scans <- which(!sapply(data, is.null)) assert_that(length(valid_scans) > 0, msg = paste("none of the requested scan parameters found in file", file)) - if(length(valid_scans) < length(scans)){ - warning(paste("ignoring",length(scans)-length(valid_scans),"scan(s) in file",file,"because requested scan parameter(s) are missing.")) + if (length(valid_scans) < length(scans)) { + warning(paste("ignoring", length(scans) - length(valid_scans), "scan(s) in file", file, "because requested scan parameter(s) are missing.")) } data <- data[valid_scans] @@ -349,7 +350,7 @@ read_pvolfile_scan <- function(file, scan, param, radar, datetime, geo, attribut names(quantities) <- quantityNames # if wavelength is attribute is missing at the scan level, copy it from the pvol level - if(is.null(attribs.how$wavelength)) attribs.how$wavelength = attributes$how$wavelength + if (is.null(attribs.how$wavelength)) attribs.how$wavelength <- attributes$how$wavelength output <- list( radar = radar, datetime = datetime, params = quantities, @@ -370,12 +371,14 @@ read_pvolfile_quantity <- function(file, quantity, radar, datetime, geo, dtype) data <- replace(data, data == as.numeric(attr$nodata), NA) data <- replace(data, data == as.numeric(attr$undetect), NaN) data <- as.numeric(attr$offset) + as.numeric(attr$gain) * data - if(attr$quantity == "RHOHV"){ + if (attr$quantity == "RHOHV") { data <- replace(data, data > 10, NaN) } - conversion <- list(gain = as.numeric(attr$gain), offset = as.numeric(attr$offset), - nodata = as.numeric(attr$nodata), undetect = as.numeric(attr$undetect), - dtype = dtype) + conversion <- list( + gain = as.numeric(attr$gain), offset = as.numeric(attr$offset), + nodata = as.numeric(attr$nodata), undetect = as.numeric(attr$undetect), + dtype = dtype + ) class(data) <- c("param", class(data)) attributes(data)$radar <- radar attributes(data)$datetime <- datetime diff --git a/R/zzz.R b/R/zzz.R index 821fc6116..766ca4b6b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -19,9 +19,11 @@ is.nan.data.frame <- function(x) do.call(cbind, lapply(x, is.nan)) #' Inspired by . #' #' @keywords internal -skip_if_no_mistnet <- function() { - if (vol2birdR::mistnet_exists()) { - return(invisible(TRUE)) +skip_if_no_mistnet <- function(){ + if(rlang::is_installed('vol2birdR')){ + if (vol2birdR::mistnet_exists()) { + return(invisible(TRUE)) + } } testthat::skip("No MistNet") }