-
Notifications
You must be signed in to change notification settings - Fork 10
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
Open
LisaSchlueter
wants to merge
10
commits into
main
Choose a base branch
from
co60
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a0b628f
add more generic verison of simple calibration, e.g. for co60 data
LisaSchlueter fa21052
take most prominent peak not not largest energy
LisaSchlueter 1639f38
add minimal peakshape without tail
LisaSchlueter 888996b
update docstring and add fall-back solution for fwhm calculation
LisaSchlueter 421e2c3
add e_unit as kwarg
LisaSchlueter 692c1de
merge commong function for th228 and generic gamma
LisaSchlueter b8dda3f
clean up th228 remainders and docstrings
LisaSchlueter 8e924d9
merge simple calibration plto recipes
LisaSchlueter 13a85f9
add simple calibration test
LisaSchlueter 4851690
bug fix tests
LisaSchlueter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.