-
Notifications
You must be signed in to change notification settings - Fork 16
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
math and ops functions, bioRad 0.5.2.9504 #460
Conversation
Codecov Report
@@ Coverage Diff @@
## master #460 +/- ##
==========================================
+ Coverage 55.73% 57.62% +1.89%
==========================================
Files 55 57 +2
Lines 3140 3226 +86
==========================================
+ Hits 1750 1859 +109
+ Misses 1390 1367 -23
Continue to review full report at Codecov.
|
With a bit more thought we can maybe also do functions like
|
Ok, I like this a lot. Way more elegant than the convoluted methods I've used before.
I'm not sure of the use-cases, but instead of accumulating along a ray, I'd then make it accumulate along a dimension that can be user-defined
I agree, though it may be nice if there's some functionality that (optionally) checks the similarity of Is there some way to expand this to |
Thanks @barthoekstra .
What would the dimensions be your thinking about? rays, directions and across polar volumes (e.g. time). I'm not sure if that fits within what I would expect from base functions like
I think we cant add arguments for more or less checking. I'm not against leaving the responsibility with the user and only see if the dimensions make sense. If people would like to be strict they could use something like
On the expansion to |
Quick example that logical operations also work (off cause if you have more different pvols you can also identify locations where a threshold is frequently passed) plot(project_as_ppi(get_scan(example_pvol>1,3)), zlim=0:1) |
This is a nice idea. I wonder about the use case (is it common enough?) and if some of this functionality deserves a separate function:
|
Here a few things I noticed when playing around: This operation throws a complicated warning:
names of the param list is broken:
PHIDP value changed, but it's not the original value * 2:
|
The latest push now throws errors for unequal length data |
As said I think it should be paired with a function to reduce pvols to a limited set of parameters. I will make such a function but would welcome suggestions for a name.
I see these functions maybe more as a set of tools to develop functionality as described above and generating the flexibility to experiment with it more options. It is not a final solution for all users. I think also when implementing these averaging function this functionality might come in handy and make those kind of functions easier to write.
I think using the + symbol for the operations you suggest might be somewhat confusing (only ggplot uses it that way). Going by the terminology used in most other packages I would think words like |
I have now added a The other change I made it to allow flexible multiplication for length one vectors as it can come in useful when applying masks. devtools::load_all("~/bioRad")
#> ℹ Loading bioRad
#> Welcome to bioRad version 0.5.2.9419
#> Docker daemon running, Docker functionality enabled (vol2bird version 0.5.0)
require(uvaRadar)
#> Loading required package: uvaRadar
require(dplyr)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:bioRad':
#>
#> between, collapse, filter, first, lag, last
#> The following object is masked from 'package:testthat':
#>
#> matches
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
pvol<-get_pvol("NL/HRW", param='all')
scan<-get_scan(pvol, 1)
scan
#> Polar scan (class scan)
#>
#> parameters: DBZH CPAH CCORH SQIH CCORV CPAV SQIV UPHIDP VRADV WRADV TH DBZV TV VRADH WRADH RHOHV KDP PHIDP
#> elevation angle: 0.8 deg
#> dims: 832 bins x 360 rays
select(scan, 'RHOHV')
#> Polar scan (class scan)
#>
#> parameters: RHOHV
#> elevation angle: 0.8 deg
#> dims: 832 bins x 360 rays
scan%>% select(starts_with('DBZ'))
#> Polar scan (class scan)
#>
#> parameters: DBZH DBZV
#> elevation angle: 0.8 deg
#> dims: 832 bins x 360 rays
scan%>% select(contains('RAD'))
#> Polar scan (class scan)
#>
#> parameters: VRADV WRADV VRADH WRADH
#> elevation angle: 0.8 deg
#> dims: 832 bins x 360 rays
scan%>% select(ends_with('H'))
#> Polar scan (class scan)
#>
#> parameters: DBZH CPAH CCORH SQIH TH VRADH WRADH
#> elevation angle: 0.8 deg
#> dims: 832 bins x 360 rays Created on 2021-06-21 by the reprex package (v2.0.0) |
I like the approach of reusing dplyr verbs ( |
With regard to |
@bart1 I didn't really think it through, I just like the idea of using |
(some of the) time selection by |
Hi @bart1, some more feedback:
Could you add an
Really like the dplyr select you added! |
This now results in an error
I have added a bunch of warnings to this extent. I did not want to error since these warning can also occur when attributes are omitted or changed by the data provider (e.g. the den helder radar moved because coordinates were updated.
You can't really add arguments to the functions, but i retains attributes from the first object (now documented).
Thanks! I have also added some tests for multiplying with vectors (along rays) or matrixes. This might for example be useful when implementing noise filters. Pvols can now be multiplied with lists then one list element is taken per scan. |
… optimize. This is now tested
Merge remote-tracking branch 'origin/master' into math_new
Hi @bart1, thanks for adding the tests, which is also helpful for understanding the operators. Here a few more thoughts and questions:
It seems a solution to 2) and 3) is to not allow operations on scans with different sets of quantities
|
This has to do with the fact that the first object takes priority in copying of attributes. So the values are exactly the same only the name of the scan is taken from the first object. So in this case only the names of the param differ otherwise everything is exactly the same: require(bioRad)
#> Loading required package: bioRad
#> Welcome to bioRad version 0.5.2.9419
#> Docker daemon running, Docker functionality enabled (vol2bird version 0.5.0)
data("example_scan")
a<-dplyr::select(example_scan,"VRADH") + dplyr::select(example_scan,"DBZH")
b<-dplyr::select(example_scan,"DBZH") + dplyr::select(example_scan,"VRADH")
all.equal(a,b)
#> [1] "Component \"params\": Names: 1 string mismatch"
#> [2] "Component \"params\": Component 1: Attributes: < Component \"param\": 1 string mismatch >" Created on 2021-07-16 by the reprex package (v2.0.0)
This is by design to as I think you might want to do operations with a mask for example to multiple parameters. Therefore I did not want to ban these one to many or many to one operations.
This is an interesting point. I'm not sure what is right here as it might also produce some quite tricky names (spaces, special characters usw). If you would change names it would also mean that for operations that keep the quantity valid you would need to rename to get things working again. My though was that if you are a power user and use this kind of functionality it is up to you to keep it sensible. I'm now online would it maybe make sense to quickly call to coordinate this? |
Note that the attribute behavior is now fairly similar to the way sum works in R (first takes priority) a<-1
b<-2
attr(a,'g')<-'g'
attr(b,'g')<-'b'
a+b
#> [1] 3
#> attr(,"g")
#> [1] "g"
b+a
#> [1] 3
#> attr(,"g")
#> [1] "b"
1+a
#> [1] 2
#> attr(,"g")
#> [1] "g" Created on 2021-07-16 by the reprex package (v2.0.0) |
Quick update to see if the branch is still mergable with master |
@adokter @barthoekstra @CeciliaNilsson709 @peterdesmet
I have started looking into how we could more easily work with the bioRad objects, among others to address #404 . In this pull request I made a first draft how this could work. It should make it possible to more easily work with multiple pvols/scans. This could be an example operation (e.g. to accumulate pvols for generating masks):
In this way you could combine a list of pvols. This request is certainly still a draft but I think it would be good do discuss some possible design choices. I have not added the test for the errors but some example calculations can be seen in the test file.
Some discussion points:
cumsum
. Currently I just warn that they are not very logical. We could accumulate along the rays or just error?param
dimensions? Differences in range gate size?scans
? How about elevation angles, should they match?get_pvol