arrayprobe 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. arrayprobe/__init__.py +219 -0
  2. arrayprobe/__main__.py +19 -0
  3. arrayprobe/_v314_lazy.py +48 -0
  4. arrayprobe/ai_ready.py +212 -0
  5. arrayprobe/attributed_export.py +1333 -0
  6. arrayprobe/authordefaults.py +267 -0
  7. arrayprobe/cli.py +3510 -0
  8. arrayprobe/combine.py +12 -0
  9. arrayprobe/compare.py +950 -0
  10. arrayprobe/config.py +1239 -0
  11. arrayprobe/constants.py +12 -0
  12. arrayprobe/count_closure.py +204 -0
  13. arrayprobe/diagnostic_views.py +769 -0
  14. arrayprobe/diode_report.py +265 -0
  15. arrayprobe/driver/__init__.py +5 -0
  16. arrayprobe/driver/_load_record.py +331 -0
  17. arrayprobe/driver/preflight_inputs.py +250 -0
  18. arrayprobe/driver/reprocess.py +553 -0
  19. arrayprobe/driver/run_flight.py +8166 -0
  20. arrayprobe/driver/tas_from_probe_housekeeping.py +124 -0
  21. arrayprobe/dropsize.py +519 -0
  22. arrayprobe/friendly.py +206 -0
  23. arrayprobe/geometry/__init__.py +77 -0
  24. arrayprobe/geometry/min_rectangle.py +92 -0
  25. arrayprobe/intarr.py +12 -0
  26. arrayprobe/intarr_analysis.py +16 -0
  27. arrayprobe/intarr_plots.py +12 -0
  28. arrayprobe/inventory.py +129 -0
  29. arrayprobe/jit_kernels.py +344 -0
  30. arrayprobe/lwc.py +44 -0
  31. arrayprobe/masks.py +349 -0
  32. arrayprobe/matio.py +410 -0
  33. arrayprobe/matlab_compat.py +13 -0
  34. arrayprobe/ncio.py +26 -0
  35. arrayprobe/particle.py +55 -0
  36. arrayprobe/particle_perimeter.py +12 -0
  37. arrayprobe/products.py +78 -0
  38. arrayprobe/profiles.py +179 -0
  39. arrayprobe/provenance.py +21 -0
  40. arrayprobe/py.typed +11 -0
  41. arrayprobe/readers/__init__.py +9 -0
  42. arrayprobe/readers/dmt.py +603 -0
  43. arrayprobe/readers/mask_csv.py +12 -0
  44. arrayprobe/readers/pms.py +12 -0
  45. arrayprobe/readers/sea.py +433 -0
  46. arrayprobe/readers/tasinfo.py +12 -0
  47. arrayprobe/regimes.py +507 -0
  48. arrayprobe/render.py +728 -0
  49. arrayprobe/reproduce_report.py +149 -0
  50. arrayprobe/review_agreement.py +135 -0
  51. arrayprobe/review_sampling.py +327 -0
  52. arrayprobe/run_page.py +624 -0
  53. arrayprobe/sample_area.py +12 -0
  54. arrayprobe/selector.py +206 -0
  55. arrayprobe/sizing.py +151 -0
  56. arrayprobe/time_convert.py +12 -0
  57. arrayprobe/timing_closure.py +141 -0
  58. arrayprobe/tools/__init__.py +27 -0
  59. arrayprobe/tools/make_demo_flight.py +1089 -0
  60. arrayprobe/tools/make_tas_file.py +760 -0
  61. arrayprobe/tools/probe_comparison.py +569 -0
  62. arrayprobe/tools/synthetic_truth.py +698 -0
  63. arrayprobe/tools/tas_sources.py +705 -0
  64. arrayprobe/triage_context.py +488 -0
  65. arrayprobe/triage_server.py +5215 -0
  66. arrayprobe/tune/__init__.py +15 -0
  67. arrayprobe/tune/diodes.py +400 -0
  68. arrayprobe/tune/distributions.py +300 -0
  69. arrayprobe/tune/sample.py +243 -0
  70. arrayprobe/tune/score.py +230 -0
  71. arrayprobe/tune/settings.py +354 -0
  72. arrayprobe/validate_by_condition.py +208 -0
  73. arrayprobe/validation_report.py +166 -0
  74. arrayprobe-0.1.0.dist-info/METADATA +260 -0
  75. arrayprobe-0.1.0.dist-info/RECORD +189 -0
  76. arrayprobe-0.1.0.dist-info/WHEEL +5 -0
  77. arrayprobe-0.1.0.dist-info/entry_points.txt +2 -0
  78. arrayprobe-0.1.0.dist-info/licenses/LICENSE +31 -0
  79. arrayprobe-0.1.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +47 -0
  80. arrayprobe-0.1.0.dist-info/licenses/NOTICE.md +369 -0
  81. arrayprobe-0.1.0.dist-info/top_level.txt +4 -0
  82. arrayprobe_soda2/__init__.py +131 -0
  83. arrayprobe_soda2/angles.py +143 -0
  84. arrayprobe_soda2/aspect_ratio.py +541 -0
  85. arrayprobe_soda2/backfill.py +100 -0
  86. arrayprobe_soda2/binary_dof.py +181 -0
  87. arrayprobe_soda2/buildindex.py +113 -0
  88. arrayprobe_soda2/decompress_dmt.py +285 -0
  89. arrayprobe_soda2/enhancement_hooks.py +275 -0
  90. arrayprobe_soda2/export_ascii.py +732 -0
  91. arrayprobe_soda2/export_ncdf.py +683 -0
  92. arrayprobe_soda2/export_ncdf_raf.py +396 -0
  93. arrayprobe_soda2/fillholes.py +161 -0
  94. arrayprobe_soda2/find_radius.py +105 -0
  95. arrayprobe_soda2/findsize.py +407 -0
  96. arrayprobe_soda2/fit_poisson.py +170 -0
  97. arrayprobe_soda2/fix2dimage.py +63 -0
  98. arrayprobe_soda2/fixraking.py +162 -0
  99. arrayprobe_soda2/fixstuckbits.py +146 -0
  100. arrayprobe_soda2/hvps4_read_frame.py +121 -0
  101. arrayprobe_soda2/jit_kernels.py +152 -0
  102. arrayprobe_soda2/label_blobs.py +177 -0
  103. arrayprobe_soda2/min_circle_fast.py +320 -0
  104. arrayprobe_soda2/particlesort.py +703 -0
  105. arrayprobe_soda2/pbp_writer.py +558 -0
  106. arrayprobe_soda2/poisson_spot_correct.py +183 -0
  107. arrayprobe_soda2/princomp.py +107 -0
  108. arrayprobe_soda2/probespecs.py +361 -0
  109. arrayprobe_soda2/process_2d.py +1364 -0
  110. arrayprobe_soda2/process_2d_parallel.py +626 -0
  111. arrayprobe_soda2/process_hk.py +512 -0
  112. arrayprobe_soda2/processbuffer_2dc.py +155 -0
  113. arrayprobe_soda2/processbuffer_cip.py +213 -0
  114. arrayprobe_soda2/processbuffer_f2dc.py +139 -0
  115. arrayprobe_soda2/processbuffer_spec.py +441 -0
  116. arrayprobe_soda2/processbuffer_tail.py +350 -0
  117. arrayprobe_soda2/pth_readers.py +245 -0
  118. arrayprobe_soda2/py.typed +11 -0
  119. arrayprobe_soda2/read2dbuffer.py +371 -0
  120. arrayprobe_soda2/reject.py +246 -0
  121. arrayprobe_soda2/reprocess_pbp.py +156 -0
  122. arrayprobe_soda2/sample_area.py +264 -0
  123. arrayprobe_soda2/save_writer.py +480 -0
  124. arrayprobe_soda2/sea.py +324 -0
  125. arrayprobe_soda2/spec_absolutepointers.py +109 -0
  126. arrayprobe_soda2/spec_decompress.py +203 -0
  127. arrayprobe_soda2/spec_index.py +476 -0
  128. arrayprobe_soda2/spec_read_frame.py +286 -0
  129. arrayprobe_soda2/spec_read_hk.py +301 -0
  130. arrayprobe_soda2/spec_readint.py +127 -0
  131. arrayprobe_soda2/timeconv.py +77 -0
  132. arrayprobe_soda2/update_op.py +101 -0
  133. arrayprobe_uiops/__init__.py +45 -0
  134. arrayprobe_uiops/combine.py +192 -0
  135. arrayprobe_uiops/combine_fork.py +359 -0
  136. arrayprobe_uiops/constants.py +830 -0
  137. arrayprobe_uiops/decode_naming.py +113 -0
  138. arrayprobe_uiops/diode_mask.py +250 -0
  139. arrayprobe_uiops/engine_absence.py +41 -0
  140. arrayprobe_uiops/export_oap.py +325 -0
  141. arrayprobe_uiops/geometry_core.py +366 -0
  142. arrayprobe_uiops/habit.py +749 -0
  143. arrayprobe_uiops/habit_core.py +248 -0
  144. arrayprobe_uiops/hollow_size_rule.py +376 -0
  145. arrayprobe_uiops/imgproc.py +2081 -0
  146. arrayprobe_uiops/imgproc_core.py +275 -0
  147. arrayprobe_uiops/intarr.py +167 -0
  148. arrayprobe_uiops/intarr_analysis.py +569 -0
  149. arrayprobe_uiops/intarr_plots.py +119 -0
  150. arrayprobe_uiops/jit_kernels.py +430 -0
  151. arrayprobe_uiops/lwc.py +70 -0
  152. arrayprobe_uiops/matlab_compat.py +860 -0
  153. arrayprobe_uiops/measure.py +346 -0
  154. arrayprobe_uiops/min_circle.py +204 -0
  155. arrayprobe_uiops/min_ellipse.py +161 -0
  156. arrayprobe_uiops/min_rectangle.py +200 -0
  157. arrayprobe_uiops/ncar_2dc_timing.py +100 -0
  158. arrayprobe_uiops/ncio.py +810 -0
  159. arrayprobe_uiops/oap_read.py +228 -0
  160. arrayprobe_uiops/particle.py +51 -0
  161. arrayprobe_uiops/particle_perimeter.py +94 -0
  162. arrayprobe_uiops/particle_physics.py +199 -0
  163. arrayprobe_uiops/pecan_params.py +134 -0
  164. arrayprobe_uiops/probe_cases.py +298 -0
  165. arrayprobe_uiops/product_sanity.py +337 -0
  166. arrayprobe_uiops/profile.py +71 -0
  167. arrayprobe_uiops/profiles.py +756 -0
  168. arrayprobe_uiops/provenance.py +804 -0
  169. arrayprobe_uiops/py.typed +11 -0
  170. arrayprobe_uiops/qc.py +169 -0
  171. arrayprobe_uiops/readers/__init__.py +8 -0
  172. arrayprobe_uiops/readers/mask_csv.py +74 -0
  173. arrayprobe_uiops/readers/pms.py +239 -0
  174. arrayprobe_uiops/readers/tasinfo.py +57 -0
  175. arrayprobe_uiops/rect_ellipse.py +129 -0
  176. arrayprobe_uiops/register_image_assisted.py +25 -0
  177. arrayprobe_uiops/reject.py +501 -0
  178. arrayprobe_uiops/reject_core.py +220 -0
  179. arrayprobe_uiops/sample_area.py +93 -0
  180. arrayprobe_uiops/sizedist.py +1923 -0
  181. arrayprobe_uiops/sizedist_core.py +814 -0
  182. arrayprobe_uiops/sizedist_tables.py +642 -0
  183. arrayprobe_uiops/spec.py +1094 -0
  184. arrayprobe_uiops/spec_core.py +703 -0
  185. arrayprobe_uiops/stray_pixel.py +103 -0
  186. arrayprobe_uiops/tas.py +191 -0
  187. arrayprobe_uiops/time_convert.py +41 -0
  188. uiops/__init__.py +402 -0
  189. uiops/py.typed +11 -0
@@ -0,0 +1,129 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """``imgProc_sm.m:1293-1301,1361-1374`` (v3.5) -- the ``iRectEllipse`` unit (Part D).
3
+
4
+ Computed once per particle, right after ``axis_ratio`` (``measure.py``'s
5
+ ``:1287-1291``) and before the area-ratio recomputation (``:1302-1309``,
6
+ already inside :func:`arrayprobe_uiops.measure.measure_record` as
7
+ :func:`arrayprobe_uiops.imgproc._percent_shadow`)::
8
+
9
+ if 1==iRectEllipse
10
+ [images.RectangleL(kk), images.RectangleW(kk), ...
11
+ images.RectangleAngle(kk)] = CGAL_RectSize(c);
12
+ if hasExtendedOutputs
13
+ [images.EllipseL(kk), images.EllipseW(kk), images.EllipseAngle(kk), ...
14
+ images.EllipseY(kk), images.EllipseX(kk)] = CGAL_EllipseSize(c);
15
+ else
16
+ [images.EllipseL(kk), images.EllipseW(kk), ...
17
+ images.EllipseAngle(kk)] = CGAL_EllipseSize(c);
18
+ end
19
+ end
20
+
21
+ ``c`` is the record loop's post-QC particle image (``imgproc.py:590``, or its
22
+ :func:`arrayprobe_uiops.qc.qc_image` replacement under ``iQC==1``) -- the SAME
23
+ ``c`` the reject call and the habit call already consume, **not** a
24
+ TAS-rescaled copy (only ``CGAL_minR`` gets ``tasRatio``, ``:1275-1280`` /
25
+ :func:`arrayprobe_uiops.min_circle.cgal_min_r_v35`). It is passed to
26
+ ``CGAL_RectSize``/``CGAL_EllipseSize`` completely unconverted -- both ported
27
+ routines read it through :func:`arrayprobe.particle.shadow_mask`, which
28
+ already accepts the raw ASCII ``'0'``/``'1'`` (48/49) form
29
+ :func:`arrayprobe.matlab_compat.dec2bin_concat` produces, so no ``codes``
30
+ array needs to be built here the way
31
+ :func:`arrayprobe_uiops.measure._ascii` builds one for the reject/habit calls --
32
+ pinned by ``tests/test_v35_rect_ellipse.py``'s two Step-1 MEX cases either way.
33
+
34
+ **Two CGAL sources, two fidelity stories:**
35
+
36
+ * ``CGAL_RectSize.cpp`` is SHA-256 **identical** between v3.1.4 and v3.5 (the
37
+ same file the v3.1.4 port already goldens against the real MEX,
38
+ ``tests/test_cgal_mex_oracle.py``), so
39
+ :func:`arrayprobe_uiops.min_rectangle.cgal_rect_size` serves both
40
+ releases -- **reused, not reimplemented**, following the
41
+ ``FORK_ONLY``/``SHARED`` distinction in ``uiops.CATALOGUE``.
42
+ * ``CGAL_EllipseSize.cpp`` **differs**: v3.5 drops v3.1.4's ``major``/``minor``
43
+ ``+1.`` bias, adds the two centre outputs (their own ``+1``), a sign
44
+ normalisation, and two near-circular tie-break angle branches (see
45
+ :mod:`arrayprobe_uiops.min_ellipse`'s own module docstring for the full diff).
46
+ ``hasExtendedOutputs`` (``imgProc_sm.m:255-272``) selects which binary is on
47
+ the MATLAB path and therefore which of the two output schemas is written --
48
+ recorded here as the caller-supplied ``extended`` flag rather than probed at
49
+ run time (the binary-dependent output schema). ``extended=True`` calls
50
+ :func:`arrayprobe_uiops.min_ellipse.cgal_ellipse_size` (5 outputs, the
51
+ ``CGAL_EllipseSize_v35.mex`` binary this stage compiled);
52
+ ``extended=False`` calls
53
+ :func:`arrayprobe.geometry.min_ellipse.cgal_ellipse_size` (3 outputs, the
54
+ ``+1``-biased v3.1.4 form -- what an *old* binary left on the path actually
55
+ writes for a v3.5 run, ``:1299``).
56
+
57
+ **Y before X is correct, not a defect** (``:1297``). ``CGAL_EllipseSize.cpp``
58
+ pushes ``Point(i, j)`` with ``i`` the MATLAB **column** (diode) index and
59
+ ``j`` the **row** (slice/time) index (``:79-88``), so its 4th output (C++
60
+ "x", ``:154``) is the diode-direction centre and its 5th ("y", ``:155``) is
61
+ the time-direction centre -- matching the netCDF descriptions
62
+ (``imgProc_sm.m:547-557``): ``image_EllipseX`` is "time direction",
63
+ ``image_EllipseY`` is "photodiode direction". MATLAB's destructuring
64
+ assigns the 4th output to the variable named ``EllipseY`` and the 5th to
65
+ ``EllipseX``, i.e. it un-swaps the C++'s x/y naming back onto its own
66
+ axis-labelled variables. :func:`arrayprobe_uiops.min_ellipse.cgal_ellipse_size`
67
+ returns ``(major, minor, angle, 1+cx, 1+cy)`` in that same C++ (diode, time)
68
+ order, so here too the 4th value goes to ``ell_y`` and the 5th to ``ell_x``.
69
+
70
+ **MATLAB's collinear-particle ellipse abort does not happen in this port.**
71
+ ``CGAL_EllipseSize.cpp`` has no degeneracy guard -- CGAL's
72
+ ``Optimisation_ellipse_2.h:250`` precondition ``!is_degenerate()`` fires on a
73
+ collinear point set (a one-diode-wide or one-slice-tall particle, common in
74
+ real 2D-S data) and ``std::terminate`` kills the whole MATLAB session,
75
+ uncatchable from ``.m`` code (``tests/test_cgal_mex_oracle.py:113-134``).
76
+ Both Python ellipse routines instead return a finite degenerate-segment
77
+ answer (:func:`arrayprobe.geometry.min_ellipse._degenerate_segment_ellipse`)
78
+ -- the same "a port must not reproduce a silent or fatal failure quietly"
79
+ call already made for :class:`arrayprobe.imgproc.ImageWidthMismatch`.
80
+ """
81
+
82
+ from __future__ import annotations
83
+
84
+ from dataclasses import dataclass
85
+ from typing import Any
86
+
87
+ from .geometry_core import cgal_ellipse_size as _cgal_ellipse_size_v314
88
+ from .min_ellipse import cgal_ellipse_size as _cgal_ellipse_size_v35
89
+ from .min_rectangle import cgal_rect_size
90
+
91
+ __all__ = ["RectEllipse", "rect_ellipse_for_image"]
92
+
93
+
94
+ @dataclass(frozen=True)
95
+ class RectEllipse:
96
+ """One particle's ``:1293-1301`` outputs, diode units / radians (unscaled
97
+ by ``diode_size`` -- the caller applies that at the ``:1364-1373`` writer,
98
+ the same split :func:`arrayprobe_uiops.measure.ParticleMeasurement` uses for
99
+ ``minR``/``AreaR``/``Perimeter``).
100
+
101
+ Source: ``imgProc_sm.m:1293-1301`` (UIOOPS v3.5)."""
102
+
103
+ rect_l: float
104
+ rect_w: float
105
+ rect_angle: float
106
+ ell_l: float
107
+ ell_w: float
108
+ ell_angle: float
109
+ ell_x: float | None #: time direction; ``None`` unless ``extended``
110
+ ell_y: float | None #: photodiode direction; ``None`` unless ``extended``
111
+
112
+
113
+ def rect_ellipse_for_image(c: Any, *, extended: bool) -> RectEllipse:
114
+ """``:1293-1301`` for one particle image ``c``.
115
+
116
+ Source: ``imgProc_sm.m:1293-1301`` (UIOOPS v3.5).
117
+
118
+ ``extended`` is the recorded ``hasExtendedOutputs`` flag (module
119
+ docstring) -- ``True`` selects the 5-output v3.5 ``CGAL_EllipseSize``
120
+ schema, ``False`` the 3-output v3.1.4-binary schema a v3.5 run gets when
121
+ an old ``.mex`` is on the MATLAB path.
122
+ """
123
+ rect_l, rect_w, rect_angle = cgal_rect_size(c)
124
+ if extended:
125
+ ell_l, ell_w, ell_angle, out4, out5 = _cgal_ellipse_size_v35(c)
126
+ ell_y, ell_x = out4, out5 # :1297 -- Y<-output4 (diode), X<-output5 (time)
127
+ return RectEllipse(rect_l, rect_w, rect_angle, ell_l, ell_w, ell_angle, ell_x, ell_y)
128
+ ell_l, ell_w, ell_angle = _cgal_ellipse_size_v314(c)
129
+ return RectEllipse(rect_l, rect_w, rect_angle, ell_l, ell_w, ell_angle, None, None)
@@ -0,0 +1,25 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Import-time side effect: registers ``stock-v3.5-image-assisted`` (label-based hollow setting).
3
+
4
+ Meant to be named as ``[fidelity].profile_module`` (``config.py``) or
5
+ ``run_flight.PROFILE_MODULE`` (the CIP lane scripts under
6
+ ``_decoded/cip160906/``), never imported for any symbol of its own. Both call
7
+ sites exist for exactly one reason, spelled out in ``config.py``'s own
8
+ ``[fidelity].profile_module`` docstring: a profile reached through
9
+ :func:`arrayprobe.profiles.register_profile` (which is how
10
+ :func:`arrayprobe.profiles.register_stock_v35_image_assisted` adds this one --
11
+ see its docstring for why this profile is registered rather than shipped as a
12
+ module-level constant) lives only in the ``_REGISTRY`` of the process that
13
+ registered it. A chunk worker (``scripts/run_flight.py --_run-chunk``) is a
14
+ *fresh* subprocess that re-imports ``arrayprobe.profiles`` from scratch and so
15
+ starts with an empty registry for anything not shipped -- ``PROFILE.name``
16
+ alone does not survive the re-exec, only ``PROFILE_MODULE`` does. Importing
17
+ this module is what makes ``PROFILES["stock-v3.5-image-assisted"]`` resolve
18
+ there too.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from arrayprobe_uiops.profiles import register_stock_v35_image_assisted
24
+
25
+ register_stock_v35_image_assisted()
@@ -0,0 +1,501 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """``calculate_reject_unified.m`` (UIOOPS v3.5) -- reject-code logic, CHANGED
3
+ from v3.1.4 (:func:`arrayprobe.reject.calculate_reject_unified`).
4
+
5
+ Measured directly from `UIOPS-v3.5/joefinlon-UIOPS-039be82/calculate_reject_unified.m`
6
+ against the v3.1.4 source, not assumed. Real differences found:
7
+
8
+ 1. **New required 4th argument, ``ihollow``.** v3.1.4 computes hollow status
9
+ internally from a four-call ensemble vote (``is_it_hollow`` forward and
10
+ reverse, ``is_it_hollow_sidescan`` forward and reverse) with elaborate
11
+ habit-dependent tie-breaking (:297-309 of the v3.1.4 source). v3.5 drops
12
+ that ensemble entirely: the caller (``imgProc_sm.m``, V8's scope --
13
+ presumably the ungated experimental hollow rule documented elsewhere in the package,
14
+ beside the whole-set sphericity computation) now decides hollow status itself, passing it in
15
+ as ``ihollow``; this function just does ``is_hollow = ihollow`` and, if
16
+ that came in true, calls ``is_it_hollow`` ONCE for the diameter/edge
17
+ measurement the size correction needs.
18
+ 2. **New output, ``center_in``.** ``center_in = 1`` unless
19
+ ``p_length <= max(max_bottom, max_top)``, in which case ``center_in = 0``.
20
+ This has no v3.1.4 equivalent; the note that habit ``'C'`` is
21
+ reassigned in ``imgProc_sm.m`` when ``center_in == 0`` reads this output,
22
+ external to this function and to ``holroyd``/``holroyd_new`` (V8's scope,
23
+ not this one's).
24
+ 3. **``is_it_hollow`` itself changed.** v3.1.4's version restricts the
25
+ diameter scan to the middle third of the particle
26
+ (``i > slices_third and i < slices - slices_third``); v3.5 removed that
27
+ restriction entirely -- the "32-diode hollow packing,
28
+ genuinely fixed" refers to this file's OTHER hollow routine
29
+ (``is_it_hollow_sidescan``, no longer even called from here in v3.5); this
30
+ is a separate, additional change to the un-sided scan. v3.1.4's bit-overlap
31
+ test reconstructs 32-bit integers via ``bin2dec``/``bitshift`` across two
32
+ 16-bit halves; v3.5 replaces that with a direct elementwise
33
+ ``bitand(image_buf(i,:)=='1', old=='1')`` on the character rows themselves.
34
+
35
+ **A second real MATLAB defect found while reading, not fixed:** the "side"
36
+ recompute of ``is_it_hollow`` on the transposed buffer assigns its status to
37
+ ``hollow_status_side1``, a variable never read again -- ``hollow_status``
38
+ itself keeps whatever ``ihollow`` gave it. Only ``edge_at_max_hole`` and
39
+ ``max_hole_diameter`` (genuine side effects the caller does use) come from
40
+ the second call; the recompute's own hollow/not-hollow verdict is dead code.
41
+ Preserved verbatim: this port never writes the recompute's status back into
42
+ ``hollow_status``.
43
+
44
+ **A real MATLAB defect found while reading, not fixed:** the row-coverage
45
+ test at (the diff's) ``elseif n_lite > 0`` branch computes
46
+ ``bufandold = bitand(image_buf(i,:)=='1', old=='1')`` -- an ARRAY, not a
47
+ scalar -- and then tests ``if bufandold > 0``. MATLAB's ``if`` on a
48
+ non-scalar array is true only when **every** element is nonzero, so this
49
+ branch (probably intended as "any bit overlaps") is true only when the ENTIRE
50
+ row overlaps the stored mask, which real diode data essentially never does.
51
+ Preserved here exactly, verified against a real Octave run rather than
52
+ "fixed" to the evidently-intended ``any(...)``.
53
+
54
+ **A genuine gap, not silently patched:** ``center_in`` is left UNASSIGNED by
55
+ the real MATLAB on the ``n_slices == 0`` early-return path -- measured
56
+ directly (Octave raises ``"element number 16 undefined in return list"`` on
57
+ a zero-slice case) -- the same shape of quirk V2 found in
58
+ ``holroyd_new``/``holroyd_new_HVPS`` on zero-slice images. This port raises
59
+ :class:`ZeroSlicesUnassignedOutputs` on that path rather than inventing a
60
+ value for ``center_in``.
61
+
62
+ Confirmed against a real Octave 11.3.0 run of the unmodified v3.5 source,
63
+ 210 cases (the earlier translation's own 105-particle reject bank, both ``ihollow``
64
+ values) -- see ``octave_oracle/run_v35_reject_oracle.m`` and
65
+ ``tests/test_v35_reject.py``.
66
+ """
67
+ from __future__ import annotations
68
+
69
+ from dataclasses import dataclass
70
+ from typing import Any
71
+
72
+ import numpy as np
73
+
74
+ from arrayprobe_uiops.reject_core import _vertical_split, mask_start_end, scan_slice
75
+
76
+ from .particle import shadow_mask
77
+
78
+ #: The module's honesty boundary, and the one place in either new port that
79
+ #: had none (found 2026-09-12, generating the API reference). The three
80
+ #: lookup helpers below are deliberately out: ``_z_d_lookup`` and
81
+ #: ``_edge_0_lookup`` read the Korolev tables, which are v3.5's data and not
82
+ #: an interface, and ``_Z_D``/``_SPOT_EDGE`` are those tables themselves.
83
+ __all__ = [
84
+ "ZeroSlicesUnassignedOutputs",
85
+ "RejectResultV35",
86
+ "is_it_hollow",
87
+ "calculate_reject_unified",
88
+ ]
89
+
90
+
91
+ class ZeroSlicesUnassignedOutputs(RuntimeError):
92
+ """The real MATLAB leaves ``center_in`` unassigned for a zero-slice image
93
+ (measured: Octave errors "undefined in return list" on this path) --
94
+ raised to match that refusal rather than inventing a value, the same
95
+ rule already applied for ``holroyd_new``/``holroyd_new_HVPS``."""
96
+
97
+
98
+ @dataclass(frozen=True)
99
+ class RejectResultV35:
100
+ """The result of :func:`calculate_reject_unified`. Adds ``center_in`` to
101
+ the earlier translation's ``RejectResult`` fields; ``handles``
102
+ is not a return value in v3.5 (its two fields are direct outputs
103
+ instead), so this dataclass has no ``handles`` analogue.
104
+
105
+ Source: the output list of ``calculate_reject_unified.m:1`` (UIOOPS v3.5)."""
106
+
107
+ p_length: float
108
+ width: float
109
+ area: float
110
+ longest_y: int
111
+ max_top: int
112
+ max_bottom: int
113
+ touching_edge: object
114
+ reject_status: str
115
+ is_hollow: int
116
+ percent_shadow_area: float
117
+ part_z: float
118
+ size_factor: float
119
+ area_hole_ratio: float
120
+ max_hole_diameter: float
121
+ edge_at_max_hole: float
122
+ center_in: int
123
+
124
+
125
+ def is_it_hollow(shadow: Any, slices: int, jit: bool = False) -> Any:
126
+ """``calculate_reject_unified.m``'s v3.5 ``is_it_hollow`` -- CHANGED from
127
+ the earlier translation's ``is_it_hollow``: no
128
+ middle-third restriction on the diameter scan, and the row-overlap test
129
+ is a direct elementwise ``bitand`` on the character rows rather than a
130
+ ``bin2dec``/``bitshift`` reconstruction. See this module's docstring for
131
+ the array-truthiness defect preserved in the coverage test below.
132
+
133
+ The real MATLAB derives its own row width from ``size(image_buf)``
134
+ rather than taking it as an argument (``im_width = size(image_buf)``,
135
+ used only for ``mask_start_end``'s modulus) -- the caller passes the
136
+ *same* buffer transposed for the "side" scan, so the width genuinely
137
+ differs between the two calls this function receives, and a fixed
138
+ ``bits_per_slice`` parameter (this port's first draft) breaks on the
139
+ transposed call with a shape mismatch. ``bits_per_slice`` here is
140
+ therefore read from ``shadow.shape[1]``, matching ``im_width(2))``.
141
+
142
+ ``jit=True`` (opt-in, default off) dispatches to
143
+ :func:`arrayprobe_uiops.jit_kernels.V35JitKernels.is_it_hollow`, a numba
144
+ compilation of the exact body below (same state machine, same
145
+ preserved ``bufandold.all()`` defect), fusing what would otherwise be
146
+ one Python-level ``scan_slice`` dispatch per slice
147
+ into one compiled call for the whole particle. Proven byte-identical to
148
+ this body by a JIT identity test; requires numba
149
+ (an optional extra), imported lazily only when ``jit=True`` is actually
150
+ requested.
151
+ """
152
+ if jit:
153
+ from . import jit_kernels
154
+ return jit_kernels.load().is_it_hollow(shadow, slices)
155
+
156
+ shadow = np.asarray(shadow)
157
+ bits_per_slice = shadow.shape[1]
158
+
159
+ start_img = 0 # 0 means "not yet found", matching MATLAB's 1-based sentinel
160
+ end_img = 0
161
+ for i in range(1, slices + 1):
162
+ zero_amt = int(np.count_nonzero(shadow[i - 1]))
163
+ if zero_amt > 0 and start_img == 0:
164
+ start_img = i
165
+ if zero_amt == 0 and start_img > 0:
166
+ end_img = i
167
+ if i == slices and end_img == 0:
168
+ if start_img == 0:
169
+ start_img = 1
170
+ end_img = slices
171
+
172
+ max_hole_diameter = 0
173
+ edge_at_max_hole = 0
174
+ status = 0
175
+ old = None
176
+ possibly_hollow = 0
177
+
178
+ for i in range(start_img, end_img + 1):
179
+ scan = scan_slice(shadow[i - 1])
180
+ num_empty = scan.max_pos_lite - scan.min_pos_lite + 1 - scan.n_lite
181
+
182
+ if num_empty > max_hole_diameter:
183
+ max_hole_diameter = num_empty
184
+ edge_at_max_hole = scan.max_pos_lite - scan.min_pos_lite + 1
185
+
186
+ if possibly_hollow == 1 and status == 0:
187
+ # `old` is set wherever `possibly_hollow` first becomes 1 (below), so by
188
+ # construction it is never None here -- asserted rather than left for mypy
189
+ # to (incorrectly) flag as possibly-None, and to document the invariant.
190
+ assert old is not None
191
+ lit_row = ~shadow[i - 1] # image_buf(i,:) == '1'
192
+ if scan.n_lite > 0 and scan.n_lite != scan.max_pos_lite - scan.min_pos_lite + 1:
193
+ newandold = lit_row & old
194
+ if not newandold.any():
195
+ status = 1
196
+ else:
197
+ old = mask_start_end(scan.max_pos_lite, scan.min_pos_lite,
198
+ shadow[i - 1], bits_per_slice)
199
+ elif scan.n_lite > 0:
200
+ bufandold = lit_row & old
201
+ hole_size = int(old.sum())
202
+ cover_size = int(bufandold.sum())
203
+ # PRESERVED DEFECT (see module docstring): MATLAB's
204
+ # `if bufandold > 0` on an array is "every element nonzero",
205
+ # not "any element nonzero" -- replicated with `.all()`.
206
+ if bufandold.size > 0 and bool(bufandold.all()):
207
+ if cover_size <= 0.65 * hole_size:
208
+ status = 1
209
+ possibly_hollow = 0
210
+ old = None
211
+ elif i > 1:
212
+ status = 1
213
+ else:
214
+ possibly_hollow = 0
215
+ old = None
216
+ else:
217
+ possibly_hollow = 0
218
+ elif status == 0:
219
+ if scan.n_lite > 0 and scan.n_lite != scan.max_pos_lite - scan.min_pos_lite + 1:
220
+ old = mask_start_end(scan.max_pos_lite, scan.min_pos_lite,
221
+ shadow[i - 1], bits_per_slice)
222
+ possibly_hollow = 1
223
+
224
+ return status, edge_at_max_hole, max_hole_diameter
225
+
226
+
227
+ def calculate_reject_unified(
228
+ image_buffer: Any,
229
+ habit: str,
230
+ ihollow: int,
231
+ config: Any,
232
+ jit: bool = False,
233
+ ) -> RejectResultV35:
234
+ """v3.5's ``calculate_reject_unified.m``. ``config`` is a
235
+ :class:`arrayprobe_uiops.reject_core.RejectConfig` (the same dataclass the v3.1.4
236
+ port uses -- ``rej_zero_area``/``rej_split``/``rej_hollow``,
237
+ ``shadowed_area``, ``max_edge_img_ar``, ``max_comp_img_ar`` are unchanged
238
+ fields in the v3.5 source's own ``handles.*`` defaults).
239
+
240
+ ``jit=True`` (opt-in, default off;
241
+ ``_decoded/cip160906/V35_REJECT_JIT.md``) fuses the per-slice scanning
242
+ loop below, and both :func:`is_it_hollow` calls in the hollow branch,
243
+ into numba-compiled kernels (:mod:`arrayprobe_uiops.jit_kernels`) instead
244
+ of one Python-level ``scan_slice`` dispatch per
245
+ slice -- measured as this function's own dominant cost
246
+ (``_decoded/cip160906/V35_JIT.md``: 7.367 s cumulative over 3,085 real
247
+ CIP particles, 6.610 s of it inside ``scan_slice``). Writes the
248
+ identical :class:`RejectResultV35` either way
249
+ (checked by a JIT identity test); numba is imported lazily,
250
+ only when ``jit=True`` is actually requested.
251
+ """
252
+ shadow = shadow_mask(image_buffer)
253
+ if shadow.size == 0:
254
+ # An empty image_buffer (no rows at all) -- np.atleast_2d would turn
255
+ # this into a bogus one-row, zero-column shape, hiding the real
256
+ # n_slices == 0 case the MATLAB source leaves center_in unassigned on.
257
+ n_slices, bits_per_slice = 0, 0
258
+ else:
259
+ if shadow.ndim != 2:
260
+ shadow = np.atleast_2d(shadow)
261
+ n_slices, bits_per_slice = shadow.shape
262
+
263
+ max_hole_diameter = 0.0
264
+ edge_at_max_hole = 0.0
265
+ min_length = -1
266
+ max_length = -1
267
+ max_width = 1
268
+ min_width = bits_per_slice
269
+ total_area = 0
270
+ touch = 0
271
+ width = 0.0
272
+ ndrops = 0
273
+ split = 0
274
+ met_image = 0
275
+ is_hollow = 0
276
+ aspect_ratio = 0.0
277
+ percent_shadow_area = 0.0
278
+ area_hole_ratio = 0.0
279
+ area = 0.0
280
+ max_top = 0
281
+ max_bottom = 0
282
+ longest_y = 0
283
+ part_z = -1.0
284
+ size_factor = 1.0
285
+ touching_edge: object = 0
286
+ top_min_x = top_max_x = -1
287
+ bottom_min_x = bottom_max_x = -1
288
+ center_in = None # unassigned unless the main branch below runs
289
+
290
+ def result(p_length: Any, reject_status: Any) -> RejectResultV35:
291
+ if center_in is None:
292
+ raise ZeroSlicesUnassignedOutputs(
293
+ "center_in is never assigned on the n_slices==0 path -- "
294
+ "measured directly against the real v3.5 MATLAB source")
295
+ return RejectResultV35(
296
+ p_length=float(p_length), width=float(width), area=float(area),
297
+ longest_y=longest_y, max_top=max_top, max_bottom=max_bottom,
298
+ touching_edge=touching_edge, reject_status=reject_status,
299
+ is_hollow=is_hollow, percent_shadow_area=float(percent_shadow_area),
300
+ part_z=float(part_z), size_factor=float(size_factor),
301
+ area_hole_ratio=float(area_hole_ratio),
302
+ max_hole_diameter=float(max_hole_diameter),
303
+ edge_at_max_hole=float(edge_at_max_hole), center_in=center_in,
304
+ )
305
+
306
+ if n_slices == 0:
307
+ # center_in stays None: the real MATLAB never assigns it on this path
308
+ # either, whichever reject_status it would have returned.
309
+ raise ZeroSlicesUnassignedOutputs(
310
+ "center_in is never assigned on the n_slices==0 path -- "
311
+ "measured directly against the real v3.5 MATLAB source")
312
+
313
+ if jit:
314
+ from . import jit_kernels
315
+ (longest_y, touch, bottom_min_x, bottom_max_x, top_min_x, top_max_x,
316
+ max_width, min_width, min_length, max_length, total_area, split) = (
317
+ jit_kernels.load().reject_scan_pass(shadow, n_slices, bits_per_slice,
318
+ config.rej_split)
319
+ )
320
+ else:
321
+ for i in range(1, n_slices + 1):
322
+ scan = scan_slice(shadow[i - 1])
323
+ longest_y = max(longest_y, scan.n_lite)
324
+
325
+ if scan.n_lite > 0:
326
+ if touch == 0:
327
+ if scan.max_pos_lite == bits_per_slice or scan.min_pos_lite == 1:
328
+ touch = 1
329
+ if scan.min_pos_lite == 1:
330
+ if bottom_min_x == -1:
331
+ bottom_min_x = i
332
+ if bottom_max_x < i:
333
+ bottom_max_x = i
334
+ if scan.max_pos_lite == bits_per_slice:
335
+ if top_min_x == -1:
336
+ top_min_x = i
337
+ if top_max_x < i:
338
+ top_max_x = i
339
+ max_width = max(max_width, scan.max_pos_lite)
340
+ min_width = min(min_width, scan.min_pos_lite)
341
+ if min_length == -1:
342
+ min_length = i
343
+ max_length = i
344
+ else:
345
+ max_length = i
346
+ total_area += scan.n_lite
347
+
348
+ if met_image == 0 and scan.n_lite > 0:
349
+ met_image = 1
350
+ ndrops += 1
351
+ if ndrops > 1 and config.rej_split:
352
+ split = 1
353
+ elif met_image == 1 and scan.n_lite == 0:
354
+ met_image = 0
355
+
356
+ area = total_area
357
+ max_top = 0 if top_min_x == -1 else (top_max_x - top_min_x) + 1
358
+ max_bottom = 0 if bottom_min_x == -1 else (bottom_max_x - bottom_min_x) + 1
359
+ touching_edge = "t" if touch == 1 else "0"
360
+
361
+ if total_area == 0:
362
+ p_length = 0
363
+ width = 0.0
364
+ else:
365
+ p_length = max_length - min_length + 1
366
+ width = float(max_width - min_width + 1)
367
+ # center_in is computed from p_length itself, after it is final -- matches
368
+ # the real source's own order (this is the only assignment).
369
+ center_in = 1
370
+ if p_length <= max(max_bottom, max_top):
371
+ center_in = 0
372
+
373
+ if total_area > 0.8 * bits_per_slice * n_slices:
374
+ return result(p_length, "A")
375
+ if split == 1:
376
+ return result(p_length, "s")
377
+
378
+ vscan = scan_slice(_vertical_split(shadow[:n_slices]))
379
+ v_n_lite = vscan.n_lite
380
+ v_span = vscan.max_pos_lite - vscan.min_pos_lite + 1
381
+ if v_n_lite == 1 and v_n_lite != v_span and not config.rej_split:
382
+ return result(p_length, "s")
383
+
384
+ if total_area > 0 and p_length > 0 and width > 0:
385
+ aspect_ratio = p_length / width
386
+ percent_shadow_area = total_area / (p_length * width) * 100
387
+ else:
388
+ aspect_ratio = 0.0
389
+ percent_shadow_area = 0.0
390
+
391
+ if total_area == 0 and config.rej_zero_area:
392
+ return result(p_length, "z")
393
+ if total_area == 0 and not config.rej_zero_area:
394
+ return result(p_length, "0")
395
+ if aspect_ratio > config.max_comp_img_ar or aspect_ratio < 1 / config.max_comp_img_ar:
396
+ return result(p_length, "a")
397
+ if touch == 1 and aspect_ratio > config.max_edge_img_ar:
398
+ return result(p_length, "t")
399
+ if percent_shadow_area < config.shadowed_area:
400
+ return result(p_length, "p")
401
+ if config.rej_hollow:
402
+ hollow_status, edge_at_max_hole, max_hole_diameter = is_it_hollow(
403
+ shadow[:n_slices], n_slices, jit=jit)
404
+ is_hollow = int(ihollow)
405
+ hollow_status = is_hollow
406
+ if center_in == 1 and touching_edge != "0" and is_hollow == 1:
407
+ # PRESERVED DEFECT: the real MATLAB assigns this call's status to
408
+ # a DIFFERENT variable, `hollow_status_side1`, which is never
409
+ # read again -- hollow_status itself keeps the `is_hollow` value
410
+ # assigned above, untouched by this recompute. Only
411
+ # edge_at_max_hole/max_hole_diameter (side effects the caller
412
+ # does use) come from this second call.
413
+ _hollow_status_side1, edge_at_max_hole, max_hole_diameter = is_it_hollow(
414
+ shadow[:n_slices].T, bits_per_slice, jit=jit)
415
+ del _hollow_status_side1
416
+ if hollow_status == 1:
417
+ ratio = 0.0 if edge_at_max_hole <= 0 else max_hole_diameter / edge_at_max_hole
418
+ if ratio == 0:
419
+ part_z, size_factor, reject_status, area_hole_ratio = 0.0, 1.0, "h", 0.0
420
+ elif max_hole_diameter <= 1:
421
+ part_z, size_factor, area_hole_ratio, reject_status = 0.0, 1.0, 0.0, "0"
422
+ else:
423
+ part_z = _z_d_lookup(ratio)
424
+ size_factor = _edge_0_lookup(part_z)
425
+ reject_status = "H"
426
+ area_hole_ratio = area / max_hole_diameter
427
+ if area_hole_ratio > 20 and habit == "i":
428
+ part_z, size_factor, reject_status = 0.0, 1.0, "u"
429
+ elif area_hole_ratio > 35 and habit == "h":
430
+ part_z, size_factor, reject_status = 0.0, 1.0, "u"
431
+ elif area_hole_ratio > 40 and habit != "s":
432
+ part_z, size_factor, reject_status = 0.0, 1.0, "u"
433
+ return result(p_length, reject_status)
434
+ part_z, size_factor, area_hole_ratio = -1.0, 1.0, 0.0
435
+
436
+ return result(p_length, "0")
437
+
438
+
439
+ #: ``z_d = 0:.05:8.15`` and its two lookup tables, verbatim from the MATLAB
440
+ #: source (unchanged between v3.1.4 and v3.5) -- see
441
+ #: ``arrayprobe.reject`` for the same tables under the v3.1.4 port, kept as a
442
+ #: second copy here rather than imported, because :func:`calculate_reject_unified`
443
+ #: above is a from-scratch translation of a changed function, not a re-export.
444
+ # MATLAB's colon `0 : .05 : 8.15` is base + i*step (Octave 8.4 measured: all
445
+ # 164 entries equal i * 0.05, as in arrayprobe.reject.Z_D). The earlier
446
+ # round(i*0.05, 10) differed in 59 of 164 entries, and part_z is written to
447
+ # the file. Applied pass 6 (pass 5 item 4).
448
+ _Z_D = [i * 0.05 for i in range(164)]
449
+ _EDGE_0 = [
450
+ 1.000, 1.054, 1.083, 1.101, 1.095, 1.110, 1.148, 1.162, 1.155, 1.123,
451
+ 1.182, 1.121, 1.162, 1.210, 1.242, 1.134, 1.166, 1.202, 1.238, 1.270,
452
+ 1.294, 1.278, 1.130, 1.148, 1.170, 1.194, 1.218, 1.242, 1.265, 1.288,
453
+ 1.310, 1.331, 1.351, 1.369, 1.386, 1.400, 1.411, 1.416, 1.407, 1.074,
454
+ 1.080, 1.087, 1.096, 1.106, 1.117, 1.127, 1.139, 1.150, 1.162, 1.173,
455
+ 1.185, 1.197, 1.208, 1.220, 1.232, 1.243, 1.255, 1.266, 1.277, 1.289,
456
+ 1.300, 1.311, 1.322, 1.333, 1.344, 1.355, 1.366, 1.376, 1.387, 1.397,
457
+ 1.407, 1.418, 1.428, 1.438, 1.448, 1.458, 1.467, 1.477, 1.486, 1.496,
458
+ 1.505, 1.515, 1.524, 1.533, 1.542, 1.551, 1.559, 1.568, 1.577, 1.585,
459
+ 1.594, 1.602, 1.610, 1.618, 1.626, 1.634, 1.642, 1.650, 1.657, 1.665,
460
+ 1.673, 1.680, 1.687, 1.694, 1.702, 1.709, 1.716, 1.722, 1.729, 1.736,
461
+ 1.742, 1.749, 1.755, 1.761, 1.768, 1.774, 1.780, 1.786, 1.791, 1.797,
462
+ 1.803, 1.808, 1.813, 1.819, 1.824, 1.829, 1.834, 1.839, 1.843, 1.848,
463
+ 1.852, 1.857, 1.861, 1.865, 1.869, 1.872, 1.876, 1.880, 1.883, 1.886,
464
+ 1.889, 1.892, 1.895, 1.897, 1.899, 1.901, 1.903, 1.905, 1.906, 1.907,
465
+ 1.908, 1.908, 1.908, 1.908, 1.907, 1.905, 1.903, 1.900, 1.897, 1.892,
466
+ 1.885, 1.877, 1.865, 1.845,
467
+ ]
468
+ _SPOT_EDGE = [
469
+ 0.003, 0.008, 0.017, 0.024, 0.033, 0.040, 0.047, 0.054, 0.062, 0.072,
470
+ 0.076, 0.088, 0.093, 0.096, 0.101, 0.119, 0.123, 0.127, 0.130, 0.134,
471
+ 0.139, 0.148, 0.175, 0.180, 0.184, 0.188, 0.192, 0.195, 0.199, 0.202,
472
+ 0.206, 0.209, 0.213, 0.217, 0.221, 0.225, 0.230, 0.235, 0.243, 0.327,
473
+ 0.334, 0.340, 0.345, 0.351, 0.355, 0.360, 0.365, 0.369, 0.373, 0.377,
474
+ 0.381, 0.385, 0.389, 0.393, 0.397, 0.400, 0.404, 0.408, 0.411, 0.415,
475
+ 0.419, 0.422, 0.426, 0.429, 0.433, 0.436, 0.439, 0.443, 0.446, 0.450,
476
+ 0.453, 0.457, 0.460, 0.463, 0.467, 0.470, 0.473, 0.477, 0.480, 0.484,
477
+ 0.487, 0.490, 0.494, 0.497, 0.501, 0.504, 0.507, 0.511, 0.514, 0.518,
478
+ 0.521, 0.525, 0.528, 0.532, 0.535, 0.539, 0.543, 0.547, 0.550, 0.554,
479
+ 0.558, 0.562, 0.566, 0.569, 0.572, 0.575, 0.578, 0.581, 0.584, 0.587,
480
+ 0.590, 0.593, 0.596, 0.598, 0.601, 0.605, 0.610, 0.614, 0.618, 0.623,
481
+ 0.627, 0.631, 0.635, 0.640, 0.644, 0.648, 0.653, 0.657, 0.662, 0.666,
482
+ 0.671, 0.676, 0.680, 0.685, 0.690, 0.695, 0.700, 0.705, 0.711, 0.716,
483
+ 0.721, 0.727, 0.733, 0.738, 0.744, 0.751, 757, 0.763, 0.770, 0.777,
484
+ 0.784, 0.792, 0.800, 0.808, 0.817, 0.826, 0.836, 0.846, 0.858, 0.870,
485
+ 0.884, 0.901, 0.921, 0.950,
486
+ ]
487
+
488
+
489
+ def _z_d_lookup(ratio: float) -> float:
490
+ """``z_d(find(spot_edge < ratio, 1, 'last'))`` -- the last index where
491
+ ``spot_edge`` is strictly less than ``ratio``. Preserves ``0757`` (an
492
+ unquoted literal 757, a missing-decimal-point typo already documented for
493
+ v3.1.4 at ``calculate_reject_unified.m:54``) verbatim."""
494
+ idx = [i for i, v in enumerate(_SPOT_EDGE) if v < ratio]
495
+ return _Z_D[idx[-1]]
496
+
497
+
498
+ def _edge_0_lookup(part_z: float) -> float:
499
+ """``edge_0(find(z_d <= part_z, 1, 'last'))``."""
500
+ idx = [i for i, v in enumerate(_Z_D) if v <= part_z]
501
+ return _EDGE_0[idx[-1]]