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.
from dapkel.functions import data_quality
fig, codes = data_quality.plot_time_code_histogram(
folder, pixel=(16, 16), nframes=10_000
)
print(codes.size, "valid codes,", len(set(codes)), "unique")
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 checks to run on a fresh Kelpie acquisition.
Nothing here contributes to a physics result - these answer 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.
collect_time_mat ¶
collect_time_mat(folder: str, pixels: Pixel | Sequence[Pixel], *, nframes: int, tag: str = 'ORT', max_files: int | None = None) -> dict[Pixel, ndarray]
Collect the per-frame TDC codes (time_mat) for given pixels.
Returns, per requested pixel, the stack of its per-frame TDC codes over
every file, keeping only frames with a valid timestamp - 'unpack' leaves
non-fired slots at <= 0, so that is time_series > 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Path to the folder with the '.bin' data files. |
required |
pixels
|
tuple[int, int] | Sequence[tuple[int, int]]
|
A single |
required |
nframes
|
int
|
Number of frames stored in each '.bin' file. |
required |
tag
|
str
|
Filename fragment selecting the files. The default is |
'ORT'
|
max_files
|
int | None
|
Process at most this many files. The default is None. |
None
|
Returns:
| Type | Description |
|---|---|
dict[tuple[int, int], ndarray]
|
Mapping |
Source code in src/dapkel/functions/data_quality.py
plot_time_code_histogram ¶
plot_time_code_histogram(folder: str, pixel: Pixel, *, nframes: int, tag: str = 'ORT', bins: int | ndarray = 256, time_unit_s: float | None = None, max_files: int | None = None) -> tuple[Figure, ndarray]
Histogram one pixel's TDC codes over all frames (QA / jitter view).
Mirrors the Kelpie_run.m timestamp inspection. Useful to confirm, on a
fresh acquisition, that the timing is populated (codes should span the full
full code range for the reference clock in use - ~279 codes at 50 MHz,
~1397 at 10 MHz, ~6985 at 2 MHz - not collapse onto a few values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Path to the folder with the '.bin' data files. |
required |
pixel
|
tuple[int, int]
|
The |
required |
nframes
|
int
|
Number of frames stored in each '.bin' file. |
required |
tag
|
str
|
Filename fragment selecting the files. The default is |
'ORT'
|
bins
|
int | ndarray
|
Bins for |
256
|
time_unit_s
|
float | None
|
Seconds per code for the x-axis (the axis itself is drawn in ps); None (default) keeps raw codes. |
None
|
max_files
|
int | None
|
Process at most this many files. The default is None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
The generated figure. |
codes |
ndarray
|
The pixel's valid TDC codes over all frames. |