diff --git a/NAMESPACE b/NAMESPACE index ea061d904..359b391ce 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ S3method(bind_into_vpts,list) S3method(bind_into_vpts,vp) S3method(bind_into_vpts,vpts) S3method(c,vp) +S3method(calculate_param,ppi) S3method(calculate_param,pvol) S3method(calculate_param,scan) S3method(check_night,default) diff --git a/NEWS.md b/NEWS.md index e5ca026b6..03d355bbd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # bioRad 0.5.2.9XXX +* `calculate_param()` now also works on ppi's (#316) + * Speed up `integrate_to_ppi` and other functions by avoiding duplicate input argument checking (#358) * Warn when multiple scans with the same elevation are equally close to the requested elevation in `get_scan()`, and add option to return all (#414) diff --git a/R/calculate_param.R b/R/calculate_param.R index 40a7438dc..a85baeb7e 100644 --- a/R/calculate_param.R +++ b/R/calculate_param.R @@ -14,6 +14,7 @@ #' #' # load the file: #' example_pvol <- read_pvolfile(pvolfile) +#' data(example_scan) #' #' # calculate linear reflectivity ETA from reflectivity factor DBZH: #' radar_wavelength <- example_pvol$attributes$how$wavelength @@ -26,6 +27,11 @@ #' # calculate_param operates on both pvol and scan objects: #' calculate_param(example_scan, DR = 10 * log10((ZDR + 1 - 2 * ZDR^0.5 * RHOHV) / #' (ZDR + 1 + 2 * ZDR^0.5 * RHOHV))) +#' +#' # it also works for ppis +#' ppi <- project_as_ppi(example_scan) +#' calculate_param(ppi, exp(DBZH)) +#' #' @references #' \itemize{ #' \item Kilambi, A., Fabry, F., and Meunier, V., 2018. A simple and effective method @@ -40,15 +46,34 @@ calculate_param <- function(x, ...) { #' @describeIn calculate_param Calculate a new scan parameter for all scans in a polar volume. #' @export calculate_param.pvol <- function(x, ...) { - assert_that(class(x) == "pvol") + assert_that(is.pvol(x)) x$scans <- do.call(lapply, list(x$scans, calculate_param.scan, substitute(list(...)))) return(x) } +#' @describeIn calculate_param Calculate a new parameter for a PPI. +#' @export +calculate_param.ppi <- function(x, ...) { + assert_that(is.ppi(x)) + calc <- as.list(substitute(list(...)))[-1L] + name <- names(calc) + if (is.null(name)) { + name <- rep("", length(calc)) + } + for (i in seq_along(calc)) { + newParam <- eval(nn <- (calc[[i]]), x$data@data) + if ("" == (name[[i]])) { + name[[i]] <- deparse(nn, width.cutoff = 250L)[1] + } + x$data@data[,name[[i]]]<-newParam + } + return(x) +} + #' @describeIn calculate_param Calculate a new scan parameter for a scan #' @export calculate_param.scan <- function(x, ...) { - assert_that(class(x) == "scan") + assert_that(is.scan(x)) # check if all parameters are equal attr_to_check<-c('class','radar','datetime','geo','dim') for(i in attr_to_check){ diff --git a/man/calculate_param.Rd b/man/calculate_param.Rd index 55244d033..bc61ccf80 100644 --- a/man/calculate_param.Rd +++ b/man/calculate_param.Rd @@ -3,6 +3,7 @@ \name{calculate_param} \alias{calculate_param} \alias{calculate_param.pvol} +\alias{calculate_param.ppi} \alias{calculate_param.scan} \title{Calculate a new scan parameter} \usage{ @@ -10,6 +11,8 @@ calculate_param(x, ...) \method{calculate_param}{pvol}(x, ...) +\method{calculate_param}{ppi}(x, ...) + \method{calculate_param}{scan}(x, ...) } \arguments{ @@ -30,6 +33,8 @@ clutter corrections (CCORH) to uncorrected reflectivity moments (TH), as in TH+C \itemize{ \item \code{pvol}: Calculate a new scan parameter for all scans in a polar volume. +\item \code{ppi}: Calculate a new parameter for a PPI. + \item \code{scan}: Calculate a new scan parameter for a scan }} @@ -39,6 +44,7 @@ pvolfile <- system.file("extdata", "volume.h5", package = "bioRad") # load the file: example_pvol <- read_pvolfile(pvolfile) +data(example_scan) # calculate linear reflectivity ETA from reflectivity factor DBZH: radar_wavelength <- example_pvol$attributes$how$wavelength @@ -51,6 +57,11 @@ example_pvol <- calculate_param(example_pvol, DR = 10 * log10((ZDR + 1 - 2 * ZDR # calculate_param operates on both pvol and scan objects: calculate_param(example_scan, DR = 10 * log10((ZDR + 1 - 2 * ZDR^0.5 * RHOHV) / (ZDR + 1 + 2 * ZDR^0.5 * RHOHV))) + +# it also works for ppis +ppi <- project_as_ppi(example_scan) +calculate_param(ppi, exp(DBZH)) + } \references{ \itemize{ diff --git a/man/calculate_vp.Rd b/man/calculate_vp.Rd index a5107eb73..589b620cb 100644 --- a/man/calculate_vp.Rd +++ b/man/calculate_vp.Rd @@ -22,7 +22,7 @@ calculate_vp( azim_max = 360, range_min = 5000, range_max = 35000, - n_layer = 20L, + n_layer = 20, h_layer = 200, dealias = TRUE, nyquist_min = if (dealias) 5 else 25, diff --git a/man/sub-.ppi.Rd b/man/sub-.ppi.Rd index 8ac3e64fa..ea712b2e2 100644 --- a/man/sub-.ppi.Rd +++ b/man/sub-.ppi.Rd @@ -23,13 +23,13 @@ position indicator (\code{ppi}). # Project a scan as a ppi ppi <- project_as_ppi(example_scan) -# This ppi contains 5 parameters (VRADH DBZH ZDR RHOHV PHIDP) +# This ppi contains 5 parameters (DBZH VRADH ZDR RHOHV PHIDP) ppi -# Subset ppi to one containing only the first parameter (VRADH) +# Subset ppi to one containing only the first parameter (DBZH) ppi[1] -# Subset ppi to one containing the first three parameters (VRADH, DBZH, ZDR) +# Subset ppi to one containing the first three parameters (DBZH, VRADH, ZDR) ppi[1:3] # Subset ppi to one without the first 2 parameters (ZDR RHOHV PHIDP)