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

Add lplot! for A/E optimization plot #21

Merged
merged 2 commits into from
Mar 5, 2025
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
28 changes: 26 additions & 2 deletions ext/LegendMakieMeasurementsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ module LegendMakieMeasurementsExt
Makie.axislegend(ax)

Makie.current_axis!(ax)
LegendMakie.add_watermarks!(; final, kwargs...)
watermark && LegendMakie.add_watermarks!(; final, kwargs...)
fig
end

Expand All @@ -323,7 +323,31 @@ module LegendMakieMeasurementsExt
Makie.axislegend(ax)

Makie.current_axis!(ax)
LegendMakie.add_watermarks!(; final, kwargs...)
watermark && LegendMakie.add_watermarks!(; final, kwargs...)
fig
end

function LegendMakie.lplot!(
report::NamedTuple{(:wl, :min_sf, :a_grid_wl_sg, :sfs)};
title::AbstractString = "", xunit = Unitful.unit(first(report.a_grid_wl_sg)), yunit = Unitful.unit(first(report.sfs)),
xlims = Unitful.ustrip.(xunit, extrema(report.a_grid_wl_sg) .+ (-1, 1) .* (report.a_grid_wl_sg[2] - report.a_grid_wl_sg[1])),
legend_position = :lt, watermark::Bool = true, final::Bool = !isempty(title), kwargs...
)

fig = Makie.current_figure()

ax = Makie.Axis(fig[1,1],
title = title,
limits = (xlims, nothing),
xlabel = "Window length ($xunit)", ylabel = "SEP survival fraction ($yunit)")

Makie.errorbars!(ax, Unitful.ustrip.(xunit, report.a_grid_wl_sg), Unitful.ustrip.(yunit, Measurements.value.(report.sfs)), Unitful.ustrip.(yunit, Measurements.uncertainty.(report.sfs)))
Makie.scatter!(ax, Unitful.ustrip.(xunit, report.a_grid_wl_sg), Unitful.ustrip.(yunit, Measurements.value.(report.sfs)), label = "SF")
Makie.hlines!(ax, [Unitful.ustrip(yunit, Measurements.value(report.min_sf))], color = :red, label = "Min. SF $(round(yunit, Measurements.value(report.min_sf), digits = 2)) (WL: $(report.wl))")
legend_position != :none && Makie.axislegend(ax, position = legend_position)

Makie.current_axis!(ax)
watermark && LegendMakie.add_watermarks!(; final, kwargs...)
fig
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_lplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ end
@testset "FWHM vs. Flat-Top Time" begin
@test_nowarn LegendMakie.lplot(report_ft, title = "Test")
end
a_grid_wl_sg = (30:32.:350)u"ns"
sfs = Measurements.measurement.(rand(length(a_grid_wl_sg)), NaN) .* 100u"percent"
min_sf, idx = findmin(sfs)
wl = Measurements.measurement(a_grid_wl_sg[idx], step(a_grid_wl_sg))
report_wl = (; wl, min_sf, a_grid_wl_sg, sfs)
@testset "A/E: SEP SF vs. Window length" begin
@test_nowarn LegendMakie.lplot(report_wl, title = "Test")
end
end

@testset "Energy calibration" begin
Expand Down