Data quality — check before you analyse¶
Nothing in this module contributes to a physics result. These are the checks you run first, on a fresh acquisition, to answer one question: did the TDC actually record timing?
The failure mode is silent¶
When the ring-oscillator TDC never stops — or the readout is misconfigured —
unpack still returns a full (32, 32, nframes) array of
plausible-looking integers. Every downstream analysis still runs. The delta-t
histogram still has a shape. It is simply meaningless.
There is no exception, no warning, and no obviously wrong number. The only way to catch it is to look at the raw code distribution.
What healthy data looks like¶
A working pixel's TDC codes spread over the full range for the reference clock in use — ~279 codes at 50 MHz, ~1397 at 10 MHz, ~2794 at 5 MHz, ~6985 at 2 MHz, since the ring sets the ~71.6 ps code width and the clock sets the full scale. A broken run collapses onto a handful of values — often a single code repeated across every frame.
process_time_codes
histograms every pixel's codes over all frames and saves the
(32, 32, n_codes) per-pixel code histogram to
processed/<name>_<tag>_time_codes.npy — a few tens of MB at the slowest
clock, so any pixel can then be inspected without re-reading the run.
plot_time_codes plots one
pixel from it to results/data_quality/ and returns that pixel's counts per
code:
import numpy as np
from dapkel.functions import data_quality
# a handful of files is enough to see whether the timing is populated
data_quality.process_time_codes(path, nframes=10_000, max_files=5)
hist = data_quality.plot_time_codes(path, pixel=(16, 16))
print(hist.sum(), "valid codes,", np.count_nonzero(hist), "unique")
The title gives the span of the codes as a full scale in ns. A few unique
values out of thousands of frames means the run is unusable. This mirrors the
timestamp inspection in Kelpie_run.m.
Run it on a pixel or two before spending time on coincidences.
API¶
data_quality ¶
Data-quality check to run on a fresh Kelpie acquisition.
process_time_codes raw '.bin' -> processed/<name>_<tag>_time_codes.npy
plot_time_codes that array -> results/data_quality/ one pixel's codes
Nothing here contributes to a physics result - it answers one question before you spend time on analysis: did the TDC actually record timing?
The failure mode is silent. When the TDC never stops, 'unpack' still returns a full array of plausible integers and every downstream analysis still runs on meaningless data. Healthy codes spread over the full code range of the clock in use (~279 codes at 50 MHz, ~1397 at 10 MHz, ~6985 at 2 MHz); a broken run collapses onto a handful of values.
See docs/guide/data_quality.md.
process_time_codes ¶
process_time_codes(path: str, nframes: int, tag: str = 'ORT', *, max_files: int | None = None) -> str
Histogram every pixel's TDC codes over all frames and save it.
Saves the (32, 32, n_codes) per-pixel code histogram, which is a few tens of MB at the slowest clock - so any pixel can then be inspected without re-reading the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Folder with the '.bin' data files. |
required |
nframes
|
int
|
Frames the acquisition recorded per '.bin' file. |
required |
tag
|
str
|
File tag of a timestamping program. The default is |
'ORT'
|
max_files
|
int | None
|
Use at most this many files - a handful is enough to see whether the timing is populated. The default is None (all). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the saved '.npy'. |
Source code in src/dapkel/functions/data_quality.py
plot_time_codes ¶
Plot one pixel's TDC-code histogram from the saved per-pixel histogram.
Mirrors the Kelpie_run.m timestamp inspection: the codes should span
the whole code range of the reference clock and not collapse onto a few
values. The title gives the span as a full scale in ns, the same
measurement every other analysis takes off the data
('core.timing.full_scale_from_max_code').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Data folder that 'process_time_codes' was run on. |
required |
pixel
|
tuple[int, int]
|
The |
(16, 16)
|
tag
|
str
|
The tag it was run with. The default is |
'ORT'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The pixel's counts per code. |