legend-exp / LegendDataManagement.jl

LegendMetadata access in Julia
Other
1 stars 5 forks source link

Add support for LEGEND expressions #16

Closed oschulz closed 8 months ago

oschulz commented 8 months ago

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.

codecov[bot] commented 8 months ago

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 :warning:
src/lpy_expressions.jl 88.88% 3 Missing :warning:
Additional details and impacted files ```diff @@ 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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

oschulz commented 8 months ago

CC @theHenks