Skip to content

Commit

Permalink
Merge pull request #453 from adokter/scan_wavelength_attribute
Browse files Browse the repository at this point in the history
fix issue #298
  • Loading branch information
adokter authored Jun 10, 2021
2 parents 035a5b4 + 97cfd37 commit 6b22288
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions R/ppi.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ dim.ppi <- function(x) {
#' # 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)
Expand Down
18 changes: 12 additions & 6 deletions R/read_pvolfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,17 @@ read_pvolfile_body <- function(file, param = c(
attribs.where$lat <- vol.lat
attribs.where$lon <- vol.lon

# assemble attributes in list
attributes <- list(
how = attribs.how, what = attribs.what,
where = attribs.where
)

# read scan groups
data <- lapply(
scans,
function(x) {
read_pvolfile_scan(file, x, param, radar, datetime, geo)
read_pvolfile_scan(file, x, param, radar, datetime, geo, attributes)
}
)

Expand All @@ -249,10 +255,7 @@ read_pvolfile_body <- function(file, param = c(
# prepare output
output <- list(
radar = radar, datetime = datetime, scans = data,
attributes = list(
how = attribs.how, what = attribs.what,
where = attribs.where
), geo = geo
attributes = attributes, geo = geo
)
class(output) <- "pvol"
if (cleanup) {
Expand All @@ -261,7 +264,7 @@ read_pvolfile_body <- function(file, param = c(
output
}

read_pvolfile_scan <- function(file, scan, param, radar, datetime, geo) {
read_pvolfile_scan <- function(file, scan, param, radar, datetime, geo, attributes) {
h5struct <- h5ls(file)
h5struct <- h5struct[h5struct$group == paste("/", scan, sep = ""), ]$name
groups <- h5struct[grep("data", h5struct)]
Expand Down Expand Up @@ -327,6 +330,9 @@ read_pvolfile_scan <- function(file, scan, param, radar, datetime, geo) {
quantities <- lapply(quantities, "[[", "quantity")
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

output <- list(
radar = radar, datetime = datetime, params = quantities,
attributes = list(
Expand Down
Binary file modified data/example_scan.rda
Binary file not shown.
8 changes: 4 additions & 4 deletions tests/testthat/test-ppi.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test_that("dim.ppi() returns number of params, x, y", {
})

test_that("[.ppi subsets by param", {
# parameters: VRADH DBZH ZDR RHOHV PHIDP
expect_equal(names(ppi[1]$data), c("VRADH"))
expect_equal(names(ppi[2:4]$data), c("DBZH", "ZDR", "RHOHV"))
expect_equal(names(ppi[-2:-4]$data), c("VRADH", "PHIDP")) # All except 2 to 4
# parameters: DBZH VRADH RHOHV ZDR PHIDP
expect_equal(names(ppi[1]$data), c("DBZH"))
expect_equal(names(ppi[2:4]$data), c("VRADH", "RHOHV", "ZDR"))
expect_equal(names(ppi[-2:-4]$data), c("DBZH", "PHIDP")) # All except 2 to 4
})

0 comments on commit 6b22288

Please sign in to comment.