Skip to content

Commit

Permalink
Merge pull request #640 from adokter/bugfix/dbzh
Browse files Browse the repository at this point in the history
drop DBZH column in cases where it is created
  • Loading branch information
adokter authored Oct 20, 2023
2 parents 0582320 + 15bc256 commit ab2550e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ pkgdown/*
/doc/
/Meta/

#ROSM basemaps
rosm.cache
# rosm cache
rosm.cache
7 changes: 7 additions & 0 deletions R/as.vpts.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
as.vpts <- function(data) {
assertthat::assert_that(inherits(data,"data.frame"))

# if dbz_all is a column name, rename to bioRad naming DBZH
if("dbz_all" %in% names(data)){
data <- data %>%
dplyr::rename(DBZH = "dbz_all")
}

height <- datetime <- source_file <- radar <- NULL

# Throw error if nrows per height are not identical
Expand Down Expand Up @@ -81,6 +87,7 @@ as.vpts <- function(data) {
# Convert dataframe
maskvars <- c("radar", "rcs", "sd_vvp_threshold", "radar_latitude", "radar_longitude", "radar_height", "radar_wavelength", "source_file", "datetime", "height", "sunrise", "sunset", "day")


data <- df_to_mat_list(data, maskvars, cached_schema)

# Create vpts object
Expand Down
5 changes: 1 addition & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ guess_file_type <- function(file_path, n_lines = 5) {
}

if(tools::file_ext(file_path) == "txt"){
return("txt")
return("txt")
} else {
message("No extension detected; assuming file type .txt which maps to stdout format")
return("txt")
Expand Down Expand Up @@ -296,11 +296,8 @@ df_to_mat_list <- function(data, maskvars, schema) {
alt_radvar <- "DBZH"
insert_index <- which(radvars == "dbz_all") + 1
radvars <- append(radvars, alt_radvar, after = insert_index)

tbls_lst <- data %>%
dplyr::select(c(setdiff(colnames(data), maskvars), "datetime", "height")) %>%
dplyr::mutate(DBZH = ifelse("dbz_all" %in% colnames(data), dbz_all, DBZH),
dbz_all = ifelse("DBZH" %in% colnames(data), DBZH, dbz_all)) %>%
tidyr::pivot_longer(-c(datetime, height), names_to = "variable", values_to = "value") %>%
dplyr::group_by(variable) %>%
dplyr::group_split()
Expand Down
3 changes: 2 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## bioRad 0.7.2
## bioRad 0.7.3

Updates to external links and tests. Errors addressed from CRAN package check.

Expand All @@ -7,3 +7,4 @@ Updates to external links and tests. Errors addressed from CRAN package check.
2. Fixes an issue where flight altitude quantiles were incorrectly shifted down by up to one height bin in integrate_profile().

3. Tests brought to date with the latest version of the `testthat` package, which requires handling each indvidual warning and deprecates expect_equivalent()

17 changes: 17 additions & 0 deletions tests/testthat/test-as.vpts.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ test_that("as.vpts() returns error message for incorrect data", {

expect_error(as.vpts(df),"identical")
})


test_that("as.vpts() converts reflectivity `dbz_all` into 'DBZH'", {

file <- system.file("extdata", "example_vpts.csv", package = "bioRad")

# When as.vpts() is called via read_vpts(), the reflectivity variable is named dbz_all in the resulting data.frame
vpts_df <- read_vpts(file, data_frame=TRUE)
expect_true(!"DBZH" %in% colnames(vpts_df))
expect_true("dbz_all" %in% colnames(vpts_df))

# When as.vpts() is called on a dataframe, the reflectivity variable will be renamed DBZH in the resulting vpts object
vpts_obj <- as.vpts(vpts_df)
expect_true("DBZH" %in% names(vpts_obj$data))
expect_true(!"dbz_all" %in% names(vpts_obj$data))

})

0 comments on commit ab2550e

Please sign in to comment.