Commit 00562d9
committed
Normalize PSF in locate so min_contrast thresholds the fitted contrast
The ``min_contrast`` parameter and the ``contrast`` output column were
not on the same scale: ``min_contrast`` thresholded the raw matched-filter
score (which mixes contrast, PSF energy, and background), while
``contrast`` was the fitted amplitude of the PSF template. A user
setting ``min_contrast=1.0`` could not predict which emitters would
survive the threshold without knowing the PSF's L2 norm and DC offset.
Fix: normalize the PSF in ``_canonicalize_psf`` (mean-subtract to kill
the background contribution, L2-normalize so a unit-contrast emitter
scores 1.0). After normalization, the peak matched-filter score of an
emitter with true contrast C is exactly C, so ``min_contrast`` becomes
a direct threshold on the fitted ``contrast`` column. The fitted
``contrast`` is now relative to the normalized PSF; the fitted
``background`` absorbs the DC component removed by mean subtraction
(for an all-positive PSF it is biased high by ``contrast * mean(psf)``).
The normalization is a canonicalization step, so it lives in
``_canonicalize_psf`` (called only by ``locate``). ``_locate_in_chunk``
remains a pure primitive whose docstring now notes that the PSF must be
pre-normalized. A precision-relative floor on the L2 norm guards
against divide-by-zero for constant PSFs.
Test changes:
- Migrate result-checking tests from ``_locate_in_chunk`` to ``locate``
(the public API that normalizes the PSF). ``_locate_in_chunk`` is now
only tested for its own contracts (validation, padding, noise estimation).
- Recalibrate value-asserting tests for the new contrast scale (fitted
contrast = true_contrast * L2_norm). The background test moves to a
20x20 frame and checks the nearest detection, since the mean-zero PSF
produces edge artifacts on constant-background frames.
- Add ``sign="positive"`` to tests with positive-only emitters to avoid
Mexican-hat ring detections.
- Add ``test_canonicalize_psf_normalizes`` to verify mean-zero and
unit-L2 properties, plus the constant-PSF floor.
- Fix ``bench_locate.py``: the dense case used ``min_contrast=0.0``,
which is now rejected (must be strictly positive).1 parent e2cdc73 commit 00562d9
5 files changed
Lines changed: 186 additions & 162 deletions
File tree
- benchmarks
- src/toolsandogh
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
| 106 | + | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
| |||
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
106 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
107 | 115 | | |
108 | 116 | | |
109 | 117 | | |
| |||
148 | 156 | | |
149 | 157 | | |
150 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
151 | 167 | | |
152 | 168 | | |
153 | 169 | | |
| |||
302 | 318 | | |
303 | 319 | | |
304 | 320 | | |
305 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
306 | 327 | | |
307 | 328 | | |
308 | 329 | | |
| |||
318 | 339 | | |
319 | 340 | | |
320 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
321 | 345 | | |
322 | 346 | | |
323 | 347 | | |
| |||
939 | 963 | | |
940 | 964 | | |
941 | 965 | | |
942 | | - | |
| 966 | + | |
943 | 967 | | |
944 | 968 | | |
945 | | - | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
946 | 975 | | |
947 | 976 | | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
948 | 987 | | |
949 | 988 | | |
950 | 989 | | |
| |||
955 | 994 | | |
956 | 995 | | |
957 | 996 | | |
958 | | - | |
| 997 | + | |
959 | 998 | | |
960 | 999 | | |
961 | 1000 | | |
| |||
969 | 1008 | | |
970 | 1009 | | |
971 | 1010 | | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
972 | 1018 | | |
973 | 1019 | | |
974 | 1020 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
| 213 | + | |
212 | 214 | | |
213 | 215 | | |
214 | 216 | | |
| |||
0 commit comments