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

Deprecate functions: surrival --> survival #100

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/LegendSpecFitsRecipesBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

@recipe function f(report:: NamedTuple{(:wl, :min_sf, :a_grid_wl_sg, :sfs)})
xlabel := "Window Length ($(unit(first(report.a_grid_wl_sg))))"
ylabel := "SEP Surrival Fraction ($(unit(first(report.sfs))))"
ylabel := "SEP Survival Fraction ($(unit(first(report.sfs))))"

Check warning on line 130 in ext/LegendSpecFitsRecipesBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendSpecFitsRecipesBaseExt.jl#L130

Added line #L130 was not covered by tests
grid := :true
gridcolor := :black
gridalpha := 0.2
Expand Down
41 changes: 23 additions & 18 deletions src/aoe_cut.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@


"""
get_peaks_surrival_fractions(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peaks::Vector{<:T}, peak_names::Vector{Symbol}, windows::Vector{<:Tuple{T, T}}, aoe_cut::Unitful.RealOrRealQuantity,; uncertainty::Bool=true, inverted_mode::Bool=false, bin_width_window::T=2.0u"keV", sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe)), fit_funcs::Vector{Symbol}=fill(:gamma_def, length(peaks))) where T<:Unitful.Energy{<:Real}
get_peaks_survival_fractions(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peaks::Vector{<:T}, peak_names::Vector{Symbol}, windows::Vector{<:Tuple{T, T}}, aoe_cut::Unitful.RealOrRealQuantity,; uncertainty::Bool=true, inverted_mode::Bool=false, bin_width_window::T=2.0u"keV", sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe)), fit_funcs::Vector{Symbol}=fill(:gamma_def, length(peaks))) where T<:Unitful.Energy{<:Real}

Get the surrival fraction of a peak after a AoE cut value `aoe_cut` for a given `peak` and `window` size while performing a peak fit with fixed position.
Get the survival fraction of a peak after a AoE cut value `aoe_cut` for a given `peak` and `window` size while performing a peak fit with fixed position.
# Return
- `result`: Dict of results for each peak
- `report`: Dict of reports for each peak
"""
function get_peaks_surrival_fractions(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peaks::Vector{<:T}, peak_names::Vector{Symbol}, windows::Vector{<:Tuple{T, T}}, aoe_cut::Unitful.RealOrRealQuantity,; uncertainty::Bool=true, inverted_mode::Bool=false, bin_width_window::T=2.0u"keV", sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe)), fit_funcs::Vector{Symbol}=fill(:gamma_def, length(peaks))) where T<:Unitful.Energy{<:Real}
function get_peaks_survival_fractions(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peaks::Vector{<:T}, peak_names::Vector{Symbol}, windows::Vector{<:Tuple{T, T}}, aoe_cut::Unitful.RealOrRealQuantity,; uncertainty::Bool=true, inverted_mode::Bool=false, bin_width_window::T=2.0u"keV", sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe)), fit_funcs::Vector{Symbol}=fill(:gamma_def, length(peaks))) where T<:Unitful.Energy{<:Real}

Check warning on line 98 in src/aoe_cut.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_cut.jl#L98

Added line #L98 was not covered by tests
@assert length(peaks) == length(peak_names) == length(windows) "Length of peaks, peak_names and windows must be equal"
# create return and result vectors
v_result = Vector{NamedTuple}(undef, length(peak_names))
Expand All @@ -106,7 +106,7 @@
# extract peak, name and window
peak, name, window, fit_func = peaks[i], peak_names[i], windows[i], fit_funcs[i]
# fit peak
result_peak, report_peak = get_peak_surrival_fraction(aoe, e, peak, collect(window), aoe_cut; uncertainty=uncertainty, inverted_mode=inverted_mode, bin_width_window=bin_width_window, sigma_high_sided=sigma_high_sided, fit_func=fit_func)
result_peak, report_peak = get_peak_survival_fraction(aoe, e, peak, collect(window), aoe_cut; uncertainty=uncertainty, inverted_mode=inverted_mode, bin_width_window=bin_width_window, sigma_high_sided=sigma_high_sided, fit_func=fit_func)

Check warning on line 109 in src/aoe_cut.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_cut.jl#L109

Added line #L109 was not covered by tests
# save results
v_result[i] = result_peak
v_report[i] = report_peak
Expand All @@ -118,24 +118,25 @@

return result, report
end
export get_peaks_surrival_fractions
get_peaks_surrival_fractions(aoe, e, peaks, peak_names, left_window_sizes::Vector{<:Unitful.Energy{<:Real}}, right_window_sizes::Vector{<:Unitful.Energy{<:Real}}, aoe_cut; kwargs...) = get_peaks_surrival_fractions(aoe, e, peaks, peak_names, [(l,r) for (l,r) in zip(left_window_sizes, right_window_sizes)], aoe_cut; kwargs...)
get_peaks_survival_fractions(aoe, e, peaks, peak_names, left_window_sizes::Vector{<:Unitful.Energy{<:Real}}, right_window_sizes::Vector{<:Unitful.Energy{<:Real}}, aoe_cut; kwargs...) = get_peaks_survival_fractions(aoe, e, peaks, peak_names, [(l,r) for (l,r) in zip(left_window_sizes, right_window_sizes)], aoe_cut; kwargs...)

Check warning on line 121 in src/aoe_cut.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_cut.jl#L121

Added line #L121 was not covered by tests

Base.@deprecate get_peaks_surrival_fractions(args...; kwargs...) get_peaks_survival_fractions(args...; kwargs...)
export get_peaks_survival_fractions, get_peaks_surrival_fractions

"""
get_peak_surrival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peak::T, window::Vector{T}, aoe_cut::Unitful.RealOrRealQuantity,;
get_peak_survival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peak::T, window::Vector{T}, aoe_cut::Unitful.RealOrRealQuantity,;
uncertainty::Bool=true, inverted_mode::Bool=false, bin_width_window::T=2.0u"keV", sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe)), fit_func::Symbol=:gamma_def) where T<:Unitful.Energy{<:Real}

Get the surrival fraction of a peak after a AoE cut value `aoe_cut` for a given `peak` and `window` size while performing a peak fit with fixed position.
Get the survival fraction of a peak after a AoE cut value `aoe_cut` for a given `peak` and `window` size while performing a peak fit with fixed position.

# Returns
- `peak`: Peak position
- `n_before`: Number of counts before the cut
- `n_after`: Number of counts after the cut
- `sf`: Surrival fraction
- `sf`: Survival fraction
- `err`: Uncertainties
"""
function get_peak_surrival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peak::T, window::Vector{T}, aoe_cut::Unitful.RealOrRealQuantity,;
function get_peak_survival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peak::T, window::Vector{T}, aoe_cut::Unitful.RealOrRealQuantity,;

Check warning on line 139 in src/aoe_cut.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_cut.jl#L139

Added line #L139 was not covered by tests
uncertainty::Bool=true, inverted_mode::Bool=false, bin_width_window::T=2.0u"keV", sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe)), fit_func::Symbol=:gamma_def) where T<:Unitful.Energy{<:Real}
# estimate bin width
bin_width = get_friedman_diaconis_bin_width(e[e .> peak - bin_width_window .&& e .< peak + bin_width_window])
Expand All @@ -162,7 +163,7 @@
cut = fit(Histogram, ustrip(e_cut), ustrip(peak-first(window):bin_width:peak+last(window)))
# fit peak and return number of signal counts
result_after, report_after = fit_subpeaks_th228(survived, cut, result_before; uncertainty=uncertainty, fit_func=fit_func)
# calculate surrival fraction
# calculate survival fraction
sf = result_after.sf * 100u"percent"
result = (
peak = peak,
Expand All @@ -182,21 +183,23 @@
)
return result, report
end
export get_peak_surrival_fraction

Base.@deprecate get_peak_surrival_fraction(args...; kwargs...) get_peak_survival_fraction(args...; kwargs...)
export get_peak_survival_fraction, get_peak_surrival_fraction


"""
get_continuum_surrival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, center::T, window::T, aoe_cut::Unitful.RealOrRealQuantity,; inverted_mode::Bool=false, sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe))) where T<:Unitful.Energy{<:Real}
Get the surrival fraction of a continuum after a AoE cut value `aoe_cut` for a given `center` and `window` size.
get_continuum_survival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, center::T, window::T, aoe_cut::Unitful.RealOrRealQuantity,; inverted_mode::Bool=false, sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe))) where T<:Unitful.Energy{<:Real}
Get the survival fraction of a continuum after a AoE cut value `aoe_cut` for a given `center` and `window` size.

# Returns
- `center`: Center of the continuum
- `window`: Window size
- `n_before`: Number of counts before the cut
- `n_after`: Number of counts after the cut
- `sf`: Surrival fraction
- `sf`: Survival fraction
"""
function get_continuum_surrival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, center::T, window::T, aoe_cut::Unitful.RealOrRealQuantity,; inverted_mode::Bool=false, sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe))) where T<:Unitful.Energy{<:Real}
function get_continuum_survival_fraction(aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, center::T, window::T, aoe_cut::Unitful.RealOrRealQuantity,; inverted_mode::Bool=false, sigma_high_sided::Unitful.RealOrRealQuantity=Inf*unit(first(aoe))) where T<:Unitful.Energy{<:Real}

Check warning on line 202 in src/aoe_cut.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_cut.jl#L202

Added line #L202 was not covered by tests
# scale unit
e_unit = u"keV"
# get energy around center
Expand All @@ -216,7 +219,7 @@
end
n_after = length(e_survived)

# calculate surrival fraction
# calculate survival fraction
sf = n_after / n_before
result = (
window = measurement(center, window),
Expand All @@ -238,4 +241,6 @@
)
return result, report
end
export get_continuum_surrival_fraction

Base.@deprecate get_continuum_surrival_fraction(args...; kwargs...) get_continuum_survival_fraction(args...; kwargs...)
export get_continuum_survival_fraction, get_continuum_surrival_fraction
4 changes: 2 additions & 2 deletions src/aoe_filter_optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
aoe_sep_i = flatview(aoe_sep)[i_aoe, :][isfinite.(flatview(aoe_sep)[i_aoe, :])] ./ result_sep.m_calib
e_sep_i = e_sep_calib[isfinite.(flatview(aoe_sep)[i_aoe, :])]

result_sep_sf, _ = get_peak_surrival_fraction(aoe_sep_i, e_sep_i, sep, sep_window, psd_cut.lowcut; uncertainty=uncertainty, fit_func=sep_cut_search_fit_func)
result_sep_sf, _ = get_peak_survival_fraction(aoe_sep_i, e_sep_i, sep, sep_window, psd_cut.lowcut; uncertainty=uncertainty, fit_func=sep_cut_search_fit_func)

Check warning on line 86 in src/aoe_filter_optimization.jl

View check run for this annotation

Codecov / codecov/patch

src/aoe_filter_optimization.jl#L86

Added line #L86 was not covered by tests

sep_sfs[i_aoe] = result_sep_sf.sf
wls[i_aoe] = wl
Expand All @@ -98,7 +98,7 @@
sep_sfs = sep_sfs[fts_success]
wls = wls[fts_success]

# get minimal surrival fraction and window length
# get minimal survival fraction and window length
sep_sfs_cut = 1.0u"percent" .< sep_sfs .< 100u"percent"
if isempty(sep_sfs[sep_sfs_cut])
@error "No valid SEP SF found"
Expand Down
6 changes: 3 additions & 3 deletions src/qc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
# get bl mean cut
result_blmean, report_blmean = get_centered_gaussian_window_cut(data.blmean, qc_config.blmean.min, qc_config.blmean.max, qc_config.blmean.sigma, ; n_bins_cut=convert(Int64, round(length(data) * qc_config.blmean.n_bins_fraction)), relative_cut=qc_config.blmean.relative_cut, fixed_center=false, left=true)
blmean_qc = result_blmean.low_cut .< data.blmean .< result_blmean.high_cut
@debug format("Baseline Mean cut surrival fraction {:.2f}%", count(blmean_qc) / length(data) * 100)
@debug format("Baseline Mean cut survival fraction {:.2f}%", count(blmean_qc) / length(data) * 100)

Check warning on line 13 in src/qc.jl

View check run for this annotation

Codecov / codecov/patch

src/qc.jl#L13

Added line #L13 was not covered by tests
# get bl slope cut
result_blslope, report_blslope = get_centered_gaussian_window_cut(data.blslope, qc_config.blslope.min, qc_config.blslope.max, qc_config.blslope.sigma, ; n_bins_cut=convert(Int64, round(length(data) * qc_config.blslope.n_bins_fraction)), relative_cut=qc_config.blslope.relative_cut, fixed_center=true, left=false, center=zero(data.blslope[1]))
blslope_qc = result_blslope.low_cut .< data.blslope .< result_blslope.high_cut
@debug format("Baseline Slope cut surrival fraction {:.2f}%", count(blslope_qc) / length(data) * 100)
@debug format("Baseline Slope cut survival fraction {:.2f}%", count(blslope_qc) / length(data) * 100)

Check warning on line 17 in src/qc.jl

View check run for this annotation

Codecov / codecov/patch

src/qc.jl#L17

Added line #L17 was not covered by tests
# get blsigma cut
result_blsigma, report_blsigma = get_centered_gaussian_window_cut(data.blsigma, qc_config.blsigma.min, qc_config.blsigma.max, qc_config.blsigma.sigma, ; n_bins_cut=convert(Int64, round(length(data) * qc_config.blsigma.n_bins_fraction)), relative_cut=qc_config.blsigma.relative_cut, fixed_center=false, left=true)
blsigma_qc = result_blsigma.low_cut .< data.blsigma .< result_blsigma.high_cut
@debug format("Baseline Sigma cut surrival fraction {:.2f}%", count(blsigma_qc) / length(data) * 100)
@debug format("Baseline Sigma cut survival fraction {:.2f}%", count(blsigma_qc) / length(data) * 100)

Check warning on line 21 in src/qc.jl

View check run for this annotation

Codecov / codecov/patch

src/qc.jl#L21

Added line #L21 was not covered by tests

result = (blmean = result_blmean, blslope = result_blslope, blsigma = result_blsigma)
report = (blmean = report_blmean, blslope = report_blslope, blsigma = report_blsigma)
Expand Down
Loading