Optical cross-talk¶
Cross-talk is measured on the Kelpie v2 sensor by reading, for each 2×2 macropixel, two on-chip counters over the same set of frames:
coinc— frames in which both micropixels of the pair fired (logical AND)OR— frames in which at least one of the pair fired (logical union)
The per-macropixel cross-talk metric is the ratio of the accumulated counts:
which is dimensionless (a probability), so the frame time cancels and no exposure time is needed.
This slightly overestimates true optical cross-talk
The raw ratio includes accidental coincidences from independent dark counts landing in the same frame.
Macropixels where OR = 0 are undefined and come back as NaN. Everything in
core.plots is NaN-aware, so those pixels are dropped from
the statistics rather than poisoning them.
SPAD geometry — the indices run clockwise¶
This is the single most important fact in this module, and it is not the convention you would guess. Inside one 2×2 macropixel the four SPADs are indexed clockwise, not row-major:
So relative to S0:
| pairing | neighbour | direction | cell offset |
|---|---|---|---|
S0S1 |
right | horizontal | (0, 1) |
S0S3 |
below | vertical | (1, 0) |
S0S2 |
corner | diagonal | (1, 1) |
Note that S0S2 is the diagonal pairing and S0S3 the vertical one — the
reverse of what a row-major reading gives. Vertical and diagonal cross-talk are
physically different magnitudes (diagonal SPADs sit further apart), so swapping
them silently mislabels two real measurements.
This layout is asserted in tests/test_spad_geometry.py, which ties
crosstalk_analysis._DIRECTIONS to the _SPAD_LAYOUT used by
DCR and hitmap for their (64, 64) assembly, so the three
encodings cannot drift apart.
Data layout¶
One folder per micropixel pairing, e.g. S0S1, S0S2, S0S3. Each folder holds
many repeated .bin acquisitions per counter, named like
CT_coincS0S1<n>.bin / CT_ORS0S1<n>.bin; the counts are summed across every
acquisition for statistics.
The 01 preliminary batches use a CT01_ / CT02_ prefix and are excluded by
the default file_prefix="CT_", so the two acquisitions are never silently
mixed.
The combined 64×64 map¶
combine_directional_crosstalk scans a parent folder holding one sub-folder per
pairing, computes each (32, 32) directional map, and lays them onto a single
(64, 64) micropixel grid. Within each 2×2 block the neighbour cells carry S0's
cross-talk in that direction, and the S0 cell carries the mean of the available
directions:
API¶
crosstalk_analysis ¶
Optical cross-talk (CT) maps from the on-chip coinc/OR counters.
CT = sum(coinc) / sum(OR) per macropixel - dimensionless, so the frame time
cancels and no exposure time is needed. NaN where OR = 0.
NOTE: the SPAD indices run CLOCKWISE inside a 2x2 macropixel::
S0 (0,0) S1 (0,1)
S3 (1,0) S2 (1,1)
so S0S1 is horizontal, S0S3 VERTICAL and S0S2 DIAGONAL - the reverse
of a row-major reading. See docs/guide/crosstalk.md.
compute_crosstalk ¶
compute_crosstalk(folder: str, nframes: int, file_prefix: str = _DEFAULT_PREFIX) -> tuple[ndarray, ndarray, ndarray, str]
Unpack the coinc/OR data and compute the (32, 32) cross-talk map.
Returns the per-macropixel ratio sum(coinc) / sum(OR) accumulated
over every matching '.bin' file. Macropixels with OR = 0 are NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
str
|
Path to the folder with the coinc/OR '.bin' data files. |
required |
nframes
|
int
|
Number of frames stored in each '.bin' file. |
required |
file_prefix
|
str
|
Filename prefix selecting the measurement batch. The default is
|
_DEFAULT_PREFIX
|
Returns:
| Name | Type | Description |
|---|---|---|
ct_map |
ndarray
|
The (32, 32) cross-talk map (dimensionless ratio, NaN where OR=0). |
coinc_sum |
ndarray
|
The (32, 32) accumulated coincidence counts. |
or_sum |
ndarray
|
The (32, 32) accumulated OR counts. |
pair |
str
|
The detected micropixel-pair tag (e.g. |
Source code in src/dapkel/functions/crosstalk_analysis.py
plot_ct_heatmap ¶
Plot a cross-talk map as a 2D heatmap (values in percent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ct_map
|
ndarray
|
Cross-talk map from 'compute_crosstalk' (dimensionless ratio). |
required |
pair
|
str
|
Micropixel-pair tag for the title (e.g. |
''
|
cmap
|
str | None
|
Matplotlib colormap name. The default is None — use the active
style's |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The generated figure. |
Source code in src/dapkel/functions/crosstalk_analysis.py
plot_ct_distribution ¶
Plot the sorted per-macropixel cross-talk distribution (percent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ct_map
|
ndarray
|
Cross-talk map from 'compute_crosstalk' (dimensionless ratio). |
required |
pair
|
str
|
Micropixel-pair tag for the title/label. The default is "". |
''
|
Returns:
| Type | Description |
|---|---|
Figure
|
The generated figure. |
Source code in src/dapkel/functions/crosstalk_analysis.py
compute_and_save_crosstalk ¶
Compute the (32, 32) cross-talk map and save it under processed/.
The stage-1 half of the cross-talk analysis: unpack the coinc/OR files
once, write the array plus a '.meta.json' sidecar, and return the path.
'collect_and_plot_crosstalk' can then replot it with from_saved=True
without re-unpacking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the folder with the coinc/OR '.bin' data files. |
required |
nframes
|
int
|
Number of frames stored in each '.bin' file. |
required |
file_prefix
|
str
|
Filename prefix selecting the measurement batch. The default is
|
_DEFAULT_PREFIX
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the saved '.npy'. |
Source code in src/dapkel/functions/crosstalk_analysis.py
collect_and_plot_crosstalk ¶
collect_and_plot_crosstalk(path: str, nframes: int, file_prefix: str = _DEFAULT_PREFIX, cmap: str | None = None, *, from_saved: bool = False) -> ndarray
Unpack, compute, and plot the (32, 32) cross-talk map for a folder.
Computes (and saves) the map, then writes both the heatmap and the
sorted distribution to results/crosstalk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the folder with the coinc/OR '.bin' data files. |
required |
nframes
|
int
|
Number of frames stored in each '.bin' file. Ignored when
|
required |
file_prefix
|
str
|
Filename prefix selecting the measurement batch. The default is
|
_DEFAULT_PREFIX
|
cmap
|
str | None
|
Matplotlib colormap name for the heatmap. The default is None —
use the active style's |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The (32, 32) cross-talk map (dimensionless ratio, NaN where OR=0). |
Source code in src/dapkel/functions/crosstalk_analysis.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
plot_combined_ct_heatmap ¶
Plot the combined (64, 64) directional cross-talk map (percent).
Each 2x2 block is one macropixel: the top-left cell holds the mean cross-talk of pixel S0, and the other three cells hold S0's cross-talk towards its horizontal (S1), vertical (S3) and diagonal (S2) neighbours - the SPAD indices run clockwise, see '_DIRECTIONS'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
combined
|
ndarray
|
The (64, 64) map from 'combine_directional_crosstalk' (dimensionless ratio, NaN where a direction is missing/OR=0). |
required |
cmap
|
str | None
|
Matplotlib colormap name. The default is None — use the active
style's |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The generated figure. |
Source code in src/dapkel/functions/crosstalk_analysis.py
plot_ct_direction_summary ¶
Bar-chart the median cross-talk per direction (percent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
medians
|
dict[str, float]
|
Ordered |
required |
Returns:
| Type | Description |
|---|---|
Figure
|
The generated figure. |
Source code in src/dapkel/functions/crosstalk_analysis.py
combine_directional_crosstalk ¶
combine_directional_crosstalk(parent_path: str, nframes: int, file_prefix: str = _DEFAULT_PREFIX, cmap: str | None = None) -> ndarray
Combine the per-direction cross-talk of pixel S0 into a (64, 64) map.
Scans the sub-folders of parent_path (one folder per micropixel
pairing: S0S1 horizontal, S0S3 vertical, S0S2 diagonal), computes each
(32, 32) directional cross-talk map via 'compute_crosstalk', and lays
them onto a single (64, 64) micropixel grid. In each 2x2 macropixel
block the neighbour cells carry S0's cross-talk in that direction and
the S0 cell carries the mean of the available directions.
Both a combined (64, 64) heatmap and a per-direction median bar chart
are saved into parent_path/results/crosstalk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_path
|
str
|
Folder holding one sub-folder per pairing (e.g. '01'/'02'/'03').
Sub-folders named 'results' and any without a recognisable
|
required |
nframes
|
int
|
Number of frames stored in each '.bin' file. The pairings are acquired with the same setting, so one value covers every sub-folder. |
required |
file_prefix
|
str
|
Filename prefix selecting the measurement batch, passed through to
'compute_crosstalk'. The default is |
_DEFAULT_PREFIX
|
cmap
|
str | None
|
Matplotlib colormap name for the heatmap. The default is None —
use the active style's |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The (64, 64) combined cross-talk map (dimensionless ratio, NaN where a direction is missing or OR=0). |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
Raised when no sub-folder yields a recognisable directional map. |
Source code in src/dapkel/functions/crosstalk_analysis.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |