-
Notifications
You must be signed in to change notification settings - Fork 11
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
Generic simple_calibration #108
base: main
Are you sure you want to change the base?
Changes from 11 commits
a0b628f
fa21052
1639f38
888996b
421e2c3
692c1de
b8dda3f
8e924d9
13a85f9
4851690
da82248
a84f399
8ff7002
db57f33
35f9b55
cace095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,24 +456,25 @@ end | |
end | ||
end | ||
|
||
@recipe function f(report::NamedTuple{(:h_calsimple, :h_uncal, :c, :fep_guess, :peakhists, :peakstats)}; cal=true) | ||
@recipe function f(report::NamedTuple{(:h_calsimple, :h_uncal, :c, :peak_guess, :peakhists, :peakstats)}; cal=true) | ||
ylabel := "Counts" | ||
legend := :topright | ||
yscale := :log10 | ||
fill := false | ||
if cal | ||
h = LinearAlgebra.normalize(report.h_calsimple, mode = :density) | ||
xlabel := "Energy (keV)" | ||
xlims := (0, 3000) | ||
xticks := (0:200:3000, ["$i" for i in 0:200:3000]) | ||
xticks := (0:500:3000, ["$i" for i in 0:500:3000]) | ||
ylims := (0.2, maximum(h.weights)*1.1) | ||
fep_guess = 2614.5 | ||
peak_guess = ustrip(report.c * report.peak_guess) | ||
else | ||
h = LinearAlgebra.normalize(report.h_uncal, mode = :density) | ||
xlabel := "Energy (ADC)" | ||
xlims := (0, 1.2*report.fep_guess) | ||
xticks := (0:3000:1.2*report.fep_guess, ["$i" for i in 0:3000:1.2*report.fep_guess]) | ||
xlims := (0, 1.2*report.peak_guess) | ||
# xticks := (0:3000:1.2*report.peak_guess, ["$i" for i in 0:3000:1.2*report.peak_guess]) | ||
ylims := (0.2, maximum(h.weights)*1.1) | ||
fep_guess = report.fep_guess | ||
peak_guess = report.peak_guess | ||
end | ||
@series begin | ||
seriestype := :stepbins | ||
|
@@ -483,10 +484,10 @@ end | |
y_vline = 0.2:1:maximum(h.weights)*1.1 | ||
@series begin | ||
seriestype := :line | ||
label := "FEP Guess" | ||
color := :red | ||
label := "Peak estimate"#: $(round(peak_guess, digits = 1))" | ||
color := :red2 | ||
linewidth := 1.5 | ||
fill(fep_guess, length(y_vline)), y_vline | ||
fill(peak_guess, length(y_vline)), y_vline | ||
end | ||
end | ||
|
||
|
@@ -820,7 +821,8 @@ end | |
if plot_ribbon | ||
ribbon := uncertainty.(report.f_fit.(0:1:1.2*value(maximum(report.x)))) | ||
end | ||
0:1:1.2*value(maximum(report.x)), value.(report.f_fit.(0:1:1.2*value(maximum(report.x)))) | ||
xstep = value(maximum(report.x))/100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this also work for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested it today on |
||
0:xstep:1.2*value(maximum(report.x)), value.(report.f_fit.(0:xstep:1.2*value(maximum(report.x)))) | ||
end | ||
@series begin | ||
seriestype := :scatter | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This file is a part of LegendSpecFits.jl, licensed under the MIT License (MIT). | ||
using LegendSpecFits | ||
using Test | ||
using LegendDataTypes: fast_flatten | ||
using Measurements: value as mvalue | ||
using Distributions | ||
using StatsBase | ||
using Interpolations | ||
using Unitful | ||
using IntervalSets | ||
include("test_utils.jl") | ||
|
||
@testset "simplecal" begin | ||
# generate fake data - very simplified | ||
energy_test, th228_lines = generate_mc_spectrum(200000) | ||
m_cal_simple = 0.123u"keV" | ||
e_uncal = energy_test ./ m_cal_simple | ||
|
||
# binning and peak-finder settings that should work for this fake data set | ||
window_sizes = vcat([(25.0u"keV",25.0u"keV") for _ in 1:6], (30.0u"keV",30.0u"keV")) | ||
quantile_perc=NaN | ||
peakfinder_σ = 2.0 | ||
peakfinder_threshold = 6.0 | ||
peak_quantile = 0.7..1.0 | ||
bin_quantile = 0.05..0.5 | ||
quantile_perc = NaN | ||
kwargs = (peakfinder_σ=peakfinder_σ, peakfinder_threshold=peakfinder_threshold, peak_quantile=peak_quantile, bin_quantile=bin_quantile, quantile_perc = quantile_perc) | ||
|
||
# simple calibration | ||
result_simple, report_simple = simple_calibration(e_uncal, th228_lines, window_sizes,; calib_type= :th228, kwargs...); | ||
@test isapprox(result_simple.c, m_cal_simple, atol = 0.05.*(m_cal_simple)) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this is a new recipe. Was this not here already before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost a duplicate of the existing recipe. However, the old one has some stuff hardcoded, e.g. "FEP" in the plot label. I didn't want to mess with the existing one, since we're int he middle of the processing.