Update notebooks

This commit is contained in:
Wataru Otsubo 2025-04-15 09:05:14 +00:00
parent 2c9aaed850
commit a42bf07e7c
15 changed files with 7253 additions and 2103 deletions

View file

@ -8,7 +8,7 @@ using InteractiveUtils
begin
using Pkg
Pkg.activate(".")
Pkg.status()
# Pkg.status()
true || include("../src/PSBoardDataBase.jl")
end
@ -21,6 +21,7 @@ begin
using DBInterface
using Tables
using CairoMakie
using ColorSchemes
using Statistics
using PlutoUI
using Dates
@ -308,7 +309,8 @@ end)
combine(nrow, gdf_skews_on_psbid)
# ╔═╡ 0d3f7f0a-1713-4e22-acbb-7d370fabf5a7
combine(gdf_skews_on_psbid, :skew => (v -> all(ismissing, v)) => :hasmissing) |> (df -> sort(df, :hasmissing, rev = true))
combine(gdf_skews_on_psbid, :skew => (v -> all(ismissing, v)) => :hasmissing) |>
(df -> sort(df, :hasmissing, rev = true))
# ╔═╡ 239a808c-0411-4542-ae68-6ae6af333bd2
df_nrow_ordered = let
@ -536,7 +538,7 @@ df_skews_selected = let df
skew = sdf.skew[i],
width = sdf.width[i],
riseup = sdf.riseup[i],
runid = sdf.runid[1],
runid = sdf.runid[i],
)
end
end
@ -722,6 +724,8 @@ df_compare = let
end
# ╔═╡ 3266d1fd-b8f0-4eb0-9a8e-2050bc9a626f
# "comparison of multiple measurements of clock skew for 18 PS Boards" was deleted
# because of new measurements for all 18 boards in campaign 6.5
let
fig = Figure(size = (600, 500))
grd1 = fig[1, 1] = GridLayout()
@ -747,7 +751,8 @@ let
)
colsize!(grd1, 2, Relative(0.4))
for (key, sdf) in pairs(groupby(df_compare, :psbid))
@assert sdf.runid[2] == 382 && sdf.runid[3] == 404
@info "" sdf.runid
# @assert sdf.runid[2] == 382 && sdf.runid[3] == 404
scatterlines!(
ax1,
0:1:2,
@ -789,7 +794,7 @@ let
align = (:left, :center),
)
end
campaigns = df_compare.campaign_id |> unique |> sort! .|> Int64
campaigns = df_compare.campaign_id |> unique |> sort! .|> ceil .|> Int64
Legend(
grd1[2, 1],
[
@ -801,7 +806,7 @@ let
orientation = :horizontal,
)
fig
# fig
end
# ╔═╡ 660f2bd1-d4bc-45a8-9cf6-4e875aa9f7a2
@ -864,7 +869,8 @@ md"""
"""
# ╔═╡ 2a24c277-6679-49f3-b387-6937b7661a25
invalid_measurements = [215, 291, 442, 460, 462, 545, 799, 802, 444, 255, 435, 1213, 1215, #= TODO: remove =# 1563]
invalid_measurements =
[215, 291, 442, 460, 462, 545, 799, 802, 444, 255, 435, 1213, 1215, 1563] #= TODO: remove =#
# ╔═╡ 13b4112f-96ab-41a1-8ef1-d940771f6ece
df_skews_selected_valids = let
@ -891,6 +897,59 @@ begin
@assert all(==(1), df_skews_selected_valids.riseup)
end
# ╔═╡ 4f45c81e-df2d-481f-9d30-580e44e03c72
let
rng = Random.Xoshiro(1000)
example_results = rand(rng, eachrow(df_skews_selected_valids), 5)
fig = Figure(size = (600, 500))
ax_1 = Axis(
fig[1, 1],
title = "example clock skew measurement result",
xlabel = "offset / ns",
ylabel = "count",
limits = ((10, 16), nothing),
)
ax_2 = Axis(
fig[2, 1],
title = "example clock after substracting position contribution",
xlabel = "offset / ns",
ylabel = "count",
limits = ((-3, 3), nothing),
)
for example_result in example_results
psbid = example_result.psbid
runid = example_result.runid
single_run =
filter(
[:psboard_id, :runid] => (
(ref_psbid, ref_runid) -> begin
psbid == ref_psbid && runid == ref_runid
end
),
qaqc_single_results,
) |> first
pos_offset = qaqc_positions.rising_ns[single_run.position]
rawfilename = "../test/input/slavelogs/main/$(psbid)_$(runid)_clk.txt"
raw_points = map(eachline(rawfilename)) do line
PSBoardDataBase.ClockParser._parse_line(line)
end
stds = map(raw_points) do ((time, count))
sqrt(count * (1000 - count) / 1000)
end
collected_points = map(raw_points) do ((time, count))
(time - pos_offset, count)
end
scatterlines!(ax_1, raw_points, markersize = 6, label = basename(rawfilename))
scatterlines!(ax_2, collected_points, markersize = 6, label = basename(rawfilename))
errorbars!(ax_1, raw_points, stds, whiskerwidth = 10)
errorbars!(ax_2, collected_points, stds, whiskerwidth = 10)
end
axislegend(ax_2, position = :lt)
fig
end
# ╔═╡ 92d701aa-ab90-4c91-977d-2ce92823d130
md"""
## skew分布
@ -929,6 +988,76 @@ let
fig
end
# ╔═╡ bf62eaca-dd23-4470-9c02-20ce6f9f34d7
let
df_with_raw = leftjoin(
df_skews_selected_valids,
select(df_rawskews, [:psbid, :runid, :skew]);
on = [:psbid, :runid],
renamecols = (identity => (s -> s * "_raw")),
)
fig = Figure(size = (600, 600))
Label(
fig[0, 1],
"PS board clock skews measured in QAQC",
tellwidth = false,
fontsize = 20,
)
ax_raw = Axis(
fig[1, 1],
limits = ((10, 16), nothing),
title = "before substracting position contrib.",
)
ax_new = Axis(
fig[2, 1],
limits = ((-3, 3), nothing),
title = "after substracting position contrib.",
xlabel = "skew / ns",
)
sh1 = stephist!(
ax_raw,
df_with_raw.skew_raw,
color = Makie.wong_colors()[2],
bins = range(10, 16, step = 2 / 56),
)
sh2 = stephist!(
ax_new,
df_with_raw.skew,
color = Makie.wong_colors()[1],
bins = range(-3, 3, step = 2 / 56),
)
Legend(
fig[1, 1],
[sh1],
["""
n = $(nrow(df_with_raw))
μ = $(@sprintf "%.4g" mean(df_with_raw.skew_raw))
σ = $(@sprintf "%.2g" std(df_with_raw.skew_raw))
"""],
tellwidth = false,
tellheight = false,
halign = :right,
valign = :top,
margin = (10, 10, 10, 10),
)
Legend(
fig[2, 1],
[sh2],
["""
n = $(nrow(df_skews_selected_valids))
μ = $(@sprintf "%.2g" mean(df_skews_selected_valids.skew))
σ = $(@sprintf "%.2g" std(df_skews_selected_valids.skew))
"""],
tellwidth = false,
tellheight = false,
halign = :right,
valign = :top,
margin = (10, 10, 10, 10),
)
save("plots/skew_distrib_before_after.svg", fig)
fig
end
# ╔═╡ 82063c4b-c0cf-4524-83fe-5207bb8363d8
md"""
### skew分布のcampaign依存性
@ -949,11 +1078,12 @@ let
xlabel = "skew / ns",
)
hists = Hist1D[]
for gdf in groupby(df_skews_selected_valids, :campaign_id)
for gdf in groupby(df_skews_selected_valids, :campaign_id, sort = true)
push!(hists, Hist1D(gdf.skew, binedges = bins))
end
sh1 = stackedhist!(ax, hists, error_color = Pattern('/'))
labels = ["campaign $i" for i in 1:7]
@info "" hists |> length
sh1 = stackedhist!(ax, hists, error_color = (:black, 0), color = ColorSchemes.tab10)
labels = ["campaign $i" for i in [1:6; 6.5; 7; 7.5]]
elements =
[PolyElement(polycolor = sh1.attributes.color[][i]) for i in 1:length(labels)]
Legend(
@ -967,10 +1097,11 @@ let
"""],
tellwidth = false,
tellheight = false,
halign = :left,
halign = :right,
valign = :top,
margin = (10, 10, 10, 10),
)
save("plots/skew_distrib_campaings.svg", fig)
fig
end
@ -997,7 +1128,28 @@ let
title = "clock skew time dependency",
)
@info "" qaqc_runs
df_campaign_runlimits = let
df = combine(groupby(qaqc_runs, :campaign_id), :id => extrema)
dropmissing!(df)
df
end
@info "" df_campaign_runlimits
scatter!(ax, df_skews_selected_valids.runid, df_skews_selected_valids.skew)
rangebars!(ax,
2.2,
df_campaign_runlimits.id_extrema,
direction = :x,
color = :black,
whiskerwidth = 10,
)
text!(
ax,
df_campaign_runlimits.id_extrema .|> mean,
fill(2.3, nrow(df_campaign_runlimits)),
text = df_campaign_runlimits.campaign_id .|> string,
align = (:center, :center)
)
save("plots/skew_vs_runid.svg", fig)
fig
end
@ -1352,8 +1504,10 @@ end
# ╠═cf658de8-a4c5-413e-b5e3-56b77a80336f
# ╠═7efd380b-a976-4a86-8dff-8afd551f03fb
# ╠═6a856a55-2611-41d0-a2c7-3645c066fc3c
# ╠═4f45c81e-df2d-481f-9d30-580e44e03c72
# ╟─92d701aa-ab90-4c91-977d-2ce92823d130
# ╠═4a4ef945-b312-44ed-ab62-ce01fc33f926
# ╠═bf62eaca-dd23-4470-9c02-20ce6f9f34d7
# ╟─82063c4b-c0cf-4524-83fe-5207bb8363d8
# ╠═dff359b1-4827-40c6-86e4-0915974ef27d
# ╠═7920b03b-1d1a-4b51-bfc0-86d1361f2ff1