Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate_param accepting ifelse statement for ppi but not scan #672

Closed
adokter opened this issue Sep 11, 2024 · 2 comments
Closed

calculate_param accepting ifelse statement for ppi but not scan #672

adokter opened this issue Sep 11, 2024 · 2 comments
Assignees

Comments

@adokter
Copy link
Owner

adokter commented Sep 11, 2024

# start a tempfile
tempfile=tempfile("KBGM_example")
# Download a NEXRAD file and save as KBGM_example
download.file(
    "https://noaa-nexrad-level2.s3.amazonaws.com/2019/10/01/KBGM/KBGM20191001_000542_V06",
    method="libcurl", mode="wb", tempfile
)
# Calculate MistNet segmentation
mistnet_pvol <- apply_mistnet(tempfile)
# Replace DBZH values with NA when CELL >=1
# produces an error:
calculate_param(mistnet_pvol$scans[[1]], DBZH = ifelse(CELL >=1, NA, DBZH))

Last statement produces:

Error in Ops.param(test) : argument "e2" is missing, with no default

If we convert the scan to a ppi, the operation does succeed:

# convert scan to ppi:
my_ppi <- project_as_ppi(mistnet_pvol$scans[[1]])
# Replace DBZH values with NA when CELL >=1
# Succeeds where operations failed earlier for scan:
calculate_param(my_ppi, DBZH = ifelse(CELL >=1, NA, DBZH))

@bart1 as the original author of calculate_param() would you be able to generalize this to work also on scan and pvol objects? Brushing out weather like this is quite a common operation people want to use, so would be great if we can support it. If not, we need a more informative error message for why this isn't possible.

@bart1
Copy link
Collaborator

bart1 commented Sep 13, 2024

I quickly checked, the first problem is that ifelse is not vectored contrasting to if_else from dplyr, here are some examples:

require(bioRad)
#> Loading required package: bioRad
#> Welcome to bioRad version 0.7.3.9000
#> Attempting to load MistNet from: /home/bart/R/x86_64-pc-linux-gnu-library/4.4/vol2birdR/lib 
#> MistNet successfully initialized.
#> using vol2birdR version 1.0.2 (MistNet installed)
require(dplyr)
#> Loading required package: dplyr
#> ...
#>     intersect, setdiff, setequal, union
tempfile=tempfile("KBGM_example")
download.file(
  "https://noaa-nexrad-level2.s3.amazonaws.com/2019/10/01/KBGM/KBGM20191001_000542_V06",
  method="libcurl", mode="wb", tempfile
)
mistnet_pvol <- apply_mistnet(tempfile)
#> Checking file before processing: /tmp/RtmpcW1oyE/KBGM_examplef9d6935579c 
#> ...
#> Running MistNet...done
calculate_param(get_scan(mistnet_pvol,0),
                DBZH = if_else(c(CELL) >=1, NA, c(DBZH)))
#>                   Polar scan (class scan)
#> 
#>      parameters:  DBZH VRADH RHOHV WRADH WEATHER BACKGROUND CELL PHIDP BIOLOGY ZDR 
#> elevation angle:  0.483395 deg
#>            dims:  1201 bins x 720 rays
calculate_param(mistnet_pvol, 
                DBZH = if_else(c(CELL) >=1, NA, c(DBZH)))
#>                Polar volume (class pvol)
#> 
#>      # scans:  9 
#>        radar:  KBGM 
#>       source:  RAD:KBGM,PLC:BINGHAMTON,state:NY,radar_name:KBGM 
#> nominal time:  2019-10-01 00:05:42
calculate_param(get_scan(mistnet_pvol,0),
                DBZH = dplyr::if_else(c(CELL) >=1, NA, c(DBZH)))
#> Error in if (as.character(as.list(substitute(...))[[1L]]) == "list") {: the condition has length > 1

The later error is one I need to fix. I guess for the other problem it might be mostly important to clarify the documentation and explain why c and if_else is needed.

Created on 2024-09-13 with reprex v2.1.0

@bart1
Copy link
Collaborator

bart1 commented Sep 13, 2024

I will make a pull request later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants