Skip to content

Commit

Permalink
Support plus-minus in ljl-expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
oschulz committed Mar 18, 2024
1 parent 122fc47 commit a9db203
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/LegendDataManagement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using PropertyDicts
using StructArrays
using Unitful
using Measurements
using Measurements: ±

using Printf: @printf

Expand Down
3 changes: 2 additions & 1 deletion src/ljl_expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const ljl_expr_allowed_funcs = Set([
:abs, :abs2, :normalize, :norm,
:exp, exp2, :exp10, :log, :log2, :log10,
:sin, :cos, :tan, :asin, :acos, :atan,
:isnan, :isinf
:isnan, :isinf,
:±
])

const _ljlexpr_units = IdDict([
Expand Down
10 changes: 10 additions & 0 deletions test/test_ljl_expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using LegendDataManagement
using Test

using PropertyFunctions, StructArrays
import Measurements

include("testing_utils.jl")

Expand Down Expand Up @@ -32,6 +33,15 @@ include("testing_utils.jl")
@test num_pf === ljl_propfunc(num_expr_string)
@test @inferred(broadcast(num_pf, data)) == ref_numfunc.(data)

meas_expr_string = "(offs + slope * abs(E_trap) / 1000) - (5.2 ± 0.1)"
meas_expr = parse_ljlexpr(meas_expr_string)
@test meas_expr == :((offs + (slope * abs(E_trap)) / 1000) - (5.2 ± 0.1))
ref_measfunc(x) = (x.offs + (x.slope * abs(x.E_trap)) / 1000) - Measurements.:(±)(5.2, 0.1)
meas_pf = ljl_propfunc(meas_expr)
@test meas_pf isa PropertyFunctions.PropertyFunction
@test meas_pf === ljl_propfunc(meas_expr_string)
@test @inferred(broadcast(meas_pf, data)) == ref_measfunc.(data)

expr_map = props = PropDict(:e_flag => bool_expr_string, :e_cal => num_expr_string)
multi_pf = ljl_propfunc(expr_map)
@test multi_pf isa PropertyFunctions.PropertyFunction
Expand Down

0 comments on commit a9db203

Please sign in to comment.