Dark count rate (DCR)¶
The DCR map is the per-pixel dark-count rate in counts per second: accumulated dark counts divided by the time the sensor was actually collecting.
Two calls, like every analysis:
process_dcr unpacks the dark
.bin files and saves the map in cps to processed/<name>_<tag>_dcr.npy;
plot_dcr loads it, saves
<name>_<tag>_dcr_heatmap.png and <name>_<tag>_dcr_distribution.png to
results/dcr/, and returns the map.
from dapkel.functions import dcr_analysis
# one quadrant, counting mode, 100 ns open shutter
dcr_analysis.process_dcr(path, 1000, "S0C", open_shutter_time_s=100e-9)
dcr = dcr_analysis.plot_dcr(path, "S0C")
# timestamping mode, Poisson-corrected
dcr_analysis.process_dcr(
path, 1000, "S0T", open_shutter_time_s=8e-6, pileup_correct=True
)
dcr_analysis.plot_dcr(path, "S0T")
Counting mode vs timestamping mode¶
What "a count" is depends on the acquisition program, and it decides which
field of the unpacked data is read. There is no mode argument: the mode comes
from the last letter of the tag
(core.reduce.readout_mode), so tag is
required.
- Count mode —
...Ctags (S0C,ORC). Each pixel has a real 9-bit photon counter per frame, and the map is its sum. - Timestamp mode —
...Ttags (S0T,ORT). There is no counter: the chip timestamps the first hit instead, andunpackreturns the low bits of the coarse timestamp in thephoton_countsslot. The count is therefore the number of frames carrying a valid timestamp,(ts > 0).sum(axis=2)— the same definitionhitmap_analysisuses.
Summing the counter field on *T data inflates the DCR ~40-50×
Those bits are coarse >> 1, so a fired pixel contributes a few hundred
instead of 1, and the result still looks like a plausible DCR map. On real
24 V S0T data the median came out at 247 kcps — nearly twice the 125 kcps
that one-hit-per-8-µs-frame physically allows. Because the mode is read off
the tag rather than passed beside it, S0T data can no longer be summed as
counts by mistake.
Saturation and pileup_correct¶
Timestamping records at most one count per pixel per frame, so the raw rate
is really an occupancy and it saturates at 1 / open_shutter_time_s — 125 kcps
at an 8 µs shutter. It under-reports well before the ceiling: at 50 % occupancy
it reads ~30 % low.
pileup_correct=True inverts the censoring under Poisson statistics, since a
frame fires with probability p = 1 - exp(-r·w):
It is off by default — the raw occupancy rate is what the sensor measured — and
process_dcr prints a warning naming the ceiling whenever the hottest pixel
gets past 5 % of it. Counting mode has no such ceiling and ignores the flag.
Live time is not frame time¶
The normalisation uses the live time per frame, which depends on the
firmware — see core.timing.resolve_live_time.
short_exposure(current firmware, the default) — each ~9 µs frame is mostly readout and only the user-setopen_shutter_time_sis photon-sensitive. That window sits inside the cycle without extending it and is settable from ~50 ns up to the full 9 µs, so a wrong guess is a rate error of up to two decades. Pass theopen_shutter_time_sthe run used (the default is500e-9);resolve_live_timeraises onNonerather than guessing. Nothing in the data reveals it, which is why it is one of the few timescales still asked for — and note it is not the TDC full scale, which the coincidence pipeline measures for itself.long_exposure(legacy) — the whole frame is live, so the per-frame time isexp_time_s+ 9 µs overhead, or the 9 µs free-running cycle whenexp_time_sis None.
Under the legacy firmware the exposure argument passed to Kelpie_v2.exe maps
to an actual frame period with 9 µs of overhead: 0 → 9 µs, 10 µs → 19 µs.
Quadrants¶
Every program gives a (32, 32) map: a SPAD quadrant tag — S0C...S3C in
counting mode, S0T...S3T in timestamping mode — reads one micropixel per 2×2
macropixel, ORC / ORT all four at once. Interleaving the four quadrant maps
onto the (64, 64) micropixel grid is archived (archive/core/reduce.py), since
no current measurement needs it.
The SPAD indices run clockwise (S0 S1 / S3 S2), not row-major; the layout
is documented under cross-talk
and enforced by tests/test_spad_geometry.py.
Pixel masking¶
Hot/warm pixel masking is not implemented yet. When per-board mask files
become available, masked pixels will read as NaN — which is why every
statistic in core.plots is already NaN-aware. Plain
np.median / np.percentile propagate NaN, and a single masked pixel would
otherwise turn vmax into NaN and flatten the entire heatmap to one colour
with no error raised.
API¶
dcr_analysis ¶
Dark count rate (DCR) maps, per quadrant or for the full sensor.
process_dcr raw '.bin' -> processed/<name>_<tag>_dcr.npy (cps)
plot_dcr that array -> results/dcr/ heatmap and sorted distribution
DCR is accumulated dark counts divided by the time the sensor was actually
collecting. That live time is NOT the frame period: under the current
short_exposure firmware only the user-set open_shutter_time_s of each
~9 us frame is photon-sensitive.
What a count is follows from the tag ('core.reduce'): the photon counter for
...C programs, frames carrying a valid timestamp for ...T ones.
In timestamp mode only the first dark count of a frame is recorded, so the
rate saturates at one per open_shutter_time_s (125 kcps at an 8 µs window)
and under-reports below it; pileup_correct=True inverts that censoring
under Poisson statistics.
See docs/guide/dcr.md.
process_dcr ¶
process_dcr(path: str, nframes: int, tag: str, *, pileup_correct: bool = False, firmware_version: str = 'short_exposure', open_shutter_time_s: float | None = 5e-07, exp_time_s: float | None = None, max_files: int | None = None) -> str
Unpack the dark '.bin' files, compute the DCR map in cps and save it.
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: |
required |
pileup_correct
|
bool
|
Timestamp tags only. Each frame is a Bernoulli trial - a frame fires
with |
False
|
firmware_version
|
str
|
|
'short_exposure'
|
open_shutter_time_s
|
float | None
|
Photon-sensitive window per frame, in seconds. The default is
|
5e-07
|
exp_time_s
|
float | None
|
Exposure requested of |
None
|
max_files
|
int | None
|
Use at most this many files. The default is None (all). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the saved '.npy'. |
Source code in src/dapkel/functions/dcr_analysis.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
plot_dcr ¶
Load a saved DCR map and save its heatmap and sorted distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Data folder that 'process_dcr' was run on. |
required |
tag
|
str
|
The tag it was run with. |
required |
cmap
|
str | None
|
Matplotlib colormap name for the heatmap. The default is None - the active style's. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The DCR map, in counts per second. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
Raised when no saved DCR map exists for |