Decoding the raw .bin files¶
Every analysis in this package — DCR, cross-talk, hitmap, coincidence, TDC
calibration — is built on this one decoder. It turns the raw bytes written by
Kelpie_v2.exe into per-frame, per-pixel photon counts and TDC timestamps on
the (32, 32) micropixel grid.
Frame format¶
Each frame is 4 * 64 * 8 = 2048 bytes. A pixel occupies 14 bits, packed as a
9-bit photon count (sharing its bits with a 10-bit coarse time) plus a 4-bit
fine time:
14 bits/pixel = [ 9-bit count | 1 extra coarse bit | 4-bit fine time ]
count = 9 bits (shares its bits with the coarse field)
coarse = 10 bits (count's 9 bits + one more)
fine = 4 bits
Each 32-bit word packs two pixels, MSB-first, using only bits 27..0.
The fields are pulled straight out of the assembled 32-bit words with shifts and
masks. This reproduces the reference MATLAB decoder (kelpie_data_ddr3.m)
bit-for-bit while avoiding a large intermediate bit-array, which is what makes
it fast.
photon_counts is mode-dependent¶
The photon_counts array means different things depending on which program
wrote the data, and this catches people out:
S*C/ORCprograms — a genuine per-pixel photon count.ORTprogram — not a count. Those bits are the low bits of the coarse timestamp. Validity must come fromtime_series, never fromphoton_counts. See hitmaps.
Skipping the timestamp decode¶
compute_time_series=False skips the coarse/fine time decoding, which is
roughly two thirds of the per-pixel work. Count-only consumers (DCR, cross-talk)
pass it. Inside the package this is handled for you by
core.reduce.accumulate_frames via its
need_time_series argument.
API¶
unpack ¶
Decode Kelpie v2 DDR3 binary ('.bin') data files.
The shared foundation for every analysis in the package: turns the raw bytes
written by Kelpie_v2.exe into per-frame, per-pixel photon counts and TDC
timestamps on the (32, 32) micropixel grid.
NOTE: photon_counts is a real count only for the S*C/ORC programs.
Under ORT those bits are the low bits of the coarse timestamp, so validity
must come from time_series.
Frame format, the MATLAB equivalence and the bit layout: see
docs/guide/unpack.md.
unpack ¶
unpack(filepath: str, nframes: int, compute_time_series: bool = True) -> tuple[ndarray | None, ndarray]
Read a Kelpie v2 binary file and return timestamps and photon counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the .bin file written by Kelpie_v2.exe. |
required |
nframes
|
int
|
Number of frames to decode from the file. Pass 1 for a single-frame preview even if more were captured. |
required |
compute_time_series
|
bool
|
Switch for computing the 'time_series' output. Photon-count-only consumers (e.g. DCR analysis) can set this to False to skip the coarse/fine time decoding, which is roughly two thirds of the per-pixel work. The default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
time_series |
ndarray, shape (32, 32, nframes), float64, or None
|
None if 'compute_time_series' is False. |
photon_counts |
(ndarray, shape(32, 32, nframes), float64)
|
|
Source code in src/dapkel/functions/unpack.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 | |