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

Add support for LEGEND expressions #16

Merged
merged 6 commits into from
Nov 30, 2023
Merged

Add support for LEGEND expressions #16

merged 6 commits into from
Nov 30, 2023

Conversation

oschulz
Copy link
Contributor

@oschulz oschulz commented Nov 29, 2023

This add the concept of LEGEND expressions (formulas), which can be parsed from strings (both Julia- and Python/pygama-style).

We can now do things like

pf = ljl_propfunc("(0.5 + 0.13 * e_trap)")
pf.(data)

resulting in something like

...-element Vector{Float64}:
 134.3524690857239
 118.99052096163082
 144.11368517898455
...

But we can also add whole expression maps to config files:

json_string = """
{
    "e_cal": "(0.5 + 0.13 * e_trap)",
    "aoe" : "a / e_trap",
    "tail_good": "tailsigma < 12.2"
}
"""
props = convert(PropDict, json_string)

pf = ljl_propfunc(props)
pf.(data)

resulting in a StructArray (pf.(data) takes less than one millisecond for half a million rows of data):

...-element StructArray...:
 (aoe = 0.10155900911495913, e_cal = 134.3524690857239, tail_good = 0)
 (aoe = 0.10444221169888818, e_cal = 118.99052096163082, tail_good = 1)
 (aoe = 0.0958819009273352, e_cal = 144.11368517898455, tail_good = 0)
...

These broadcasts are type-stable.

Copy link

codecov bot commented Nov 29, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (63d02ca) 58.00% compared to head (870b363) 60.97%.
Report is 1 commits behind head on main.

Files Patch % Lines
src/ljl_expressions.jl 89.74% 4 Missing ⚠️
src/lpy_expressions.jl 88.88% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
+ Coverage   58.00%   60.97%   +2.97%     
==========================================
  Files          10       12       +2     
  Lines         631      697      +66     
==========================================
+ Hits          366      425      +59     
- Misses        265      272       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oschulz
Copy link
Contributor Author

oschulz commented Nov 29, 2023

CC @theHenks

@oschulz oschulz force-pushed the legend-expressions branch 2 times, most recently from ee5d3d0 to 870b363 Compare November 30, 2023 14:48
@oschulz oschulz merged commit 1f6a320 into main Nov 30, 2023
6 of 7 checks passed
@oschulz oschulz deleted the legend-expressions branch November 30, 2023 15:14
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

Successfully merging this pull request may close these issues.

1 participant