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,756 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """The fidelity-profile type and the one shared profile registry.
3
+
4
+ Moved here from :mod:`arrayprobe.profiles`. The
5
+ v3.1.4 variants, the v3.5 builders and the ``register_*_v35`` functions still
6
+ live there and register into the registry defined here, so
7
+ ``arrayprobe.profiles.PROFILES is arrayprobe_uiops.profiles.PROFILES``. This
8
+ module never imports ``arrayprobe``.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from collections.abc import Callable, Mapping
14
+ from dataclasses import dataclass, replace
15
+
16
+ from arrayprobe_uiops.reject_core import ORACLES_PRODUCTION_REJECT_CONFIG, RejectConfig
17
+
18
+ __all__ = [
19
+ "FidelityProfile",
20
+ "PROFILES",
21
+ "profile",
22
+ "register_profile",
23
+ "is_v35_flavoured",
24
+ "register_stock_v35_image_assisted",
25
+ ]
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class FidelityProfile:
30
+ """A named MATLAB variant, plus the switches that distinguish it."""
31
+
32
+ name: str
33
+ description: str
34
+
35
+ spec_buffer_guard: bool
36
+ """Whether ``read_binary_SPEC``'s image decoder carries the 2017 bounds guards.
37
+
38
+ Stock v3.1.4 ``read_binary_SPEC.m:222,226,233,256,260,267`` tests
39
+ ``iii+nH-1<=length(buf)`` and ``iii+kkk<=length(buf)`` before decoding, so a
40
+ packet whose declared word count runs past the two-record window is skipped
41
+ and the file keeps processing. The ORACLES variant
42
+ (``OptArrProbDataProcessing/read_binary_SPEC.m:215,218,224``) has none of
43
+ them -- those exact lines are the whole diff between the two files, aside
44
+ from four commented-out debug prints -- so MATLAB raises
45
+ ``Index exceeds matrix dimensions`` and the run dies there.
46
+
47
+ ``False`` therefore means "let it raise", which is the honest reproduction of
48
+ what produced the reference data. It is not a bug we are free to fix: a run
49
+ that would have died in MATLAB must not quietly return a shorter file here.
50
+ """
51
+
52
+ hvps_reader: str
53
+ """Which decoder handles a raw ``.HVPS`` file: ``'spec'`` or ``'hvps'``.
54
+
55
+ Stock v3.1.4 has only ``read_binary_SPEC``. The ORACLES variant also ships
56
+ ``read_binary_hvps.m``, a single-block decoder with a different packet walk,
57
+ and the surviving one-line run scripts show *both* were pointed at the same
58
+ file: ``read_binary_SPEC_oracles.m`` calls ``read_binary_SPEC`` on
59
+ ``base160906064343.HVPS`` and ``read_binary_hvps_20160906_1.m`` calls
60
+ ``read_binary_hvps`` on it.
61
+
62
+ **The steps script resolves this, and it points at ``'spec'``**
63
+ (``archive/staging_variant_raw/steps_scr_1.m.raw.txt``, a ``switch probe``
64
+ naming every step's input and output filename per probe; author-identified
65
+ 2026-09-03 as the script actually used). Its HVPS branch is internally
66
+ inconsistent, and the inconsistency is the evidence:
67
+
68
+ * **Step 1** names ``read_binary_hvps([filename '.HVPS'], filename)``. That
69
+ function writes a netCDF at the literal ``outfilename`` holding one
70
+ ``data`` variable -- **no channel split and no sidecars** (one ``fopen``,
71
+ the input).
72
+ * **Step 2** then reads ``[filename '.V.cdf']``.
73
+ * **Step 3** reads TAS from ``[filename '.tas.csv']`` -- the **HVPS file's
74
+ own basename** -- and feeds ``[filename '.V_1.cdf']`` to ``sizeDist``.
75
+
76
+ Step 1 as written cannot produce what steps 2 and 3 consume.
77
+ ``read_binary_SPEC`` produces exactly both: ``.H.cdf``/``.V.cdf`` at
78
+ ``:30-31`` and ``.tas.csv`` at ``:289``. So the inputs the HVPS
79
+ ``sizeDist`` actually consumed came from ``read_binary_SPEC`` run on the
80
+ **HVPS raw file**, and the ``read_binary_hvps`` line is a stale branch.
81
+
82
+ **What this does and does not overturn** -- one of each, and the boundary
83
+ was drawn wrongly here once before it was corrected.
84
+
85
+ *Overturned:* the claim that the HVPS decode writes no ``.tas.csv`` so the
86
+ archived product's airspeed must have come from the 2D-S sidecar. It has
87
+ its own. Measured on two flights, the HVPS's own sidecar ends at exactly
88
+ the archived product's last second (170813: 16:55:21; 160906: 14:40:13),
89
+ and it explains the 18-second overrun the 2D-S-sidecar run carried.
90
+
91
+ *NOT overturned:* the ``.V.`` in the product name. **The HVPS is a
92
+ single-channel instrument** -- unlike the 2D-S, it has no second optical
93
+ channel -- and it was **mounted in a vertical orientation**, which is what
94
+ the ``V`` records. So ``.V.`` is a label for the
95
+ probe's mounting, exactly as this project originally had it, and a claim
96
+ made here that it was "a real channel" was wrong. Running
97
+ ``read_binary_SPEC`` over an HVPS file does emit an ``.H.cdf``, but that
98
+ output is an artefact of a two-channel reader meeting a one-channel
99
+ instrument, not a second channel: on 170813 it holds 15,947 records against
100
+ the V side's 19,700, and nothing downstream should read it.
101
+
102
+ **The measurement is in, and it is a clean negative** (flight 170813,
103
+ 2026-09-03, both arms run end to end and compared against the archived
104
+ product):
105
+
106
+ ========================== ========== ==========
107
+ .. ``'hvps'`` ``'spec'``
108
+ ========================== ========== ==========
109
+ particles out of S3 39,241 49,964
110
+ ``DMT_DOF_SPEC_OVERLOAD`` set 0 10,722
111
+ accepted particles 22,497 22,497
112
+ ``Counts`` total 17,470 17,470
113
+ ========================== ========== ==========
114
+
115
+ ``Counts`` is **element-wise identical** between the two arms -- not merely
116
+ equal in total -- and so is the accepted-particle count. The archive holds
117
+ 16,094, so **both arms miss it by the same 1.0855**. Switching decoder
118
+ changes only ``Size Distribution`` (2 cells, 5.9e-6), ``Number
119
+ Concentration`` (1 cell) and ``Reject Ratio`` (2 cells), via the DOF
120
+ dead time that the overload vector now drives.
121
+
122
+ So the decoder was genuinely misidentified, and correcting it does **not**
123
+ explain the HVPS count excess. Both readers reach the same single physical
124
+ channel, which is why they agree; ``'spec'`` additionally populates
125
+ ``SliceCount``, ``DMT_DOF_SPEC_OVERLOAD`` and ``Particle_number_all``, which
126
+ ``'hvps'`` leaves identically zero for every particle -- the "a variable
127
+ uniform across every particle" signature, here with a definite cause.
128
+
129
+ **The default stays ``'hvps'`` for now**, because nothing output-pinned
130
+ argues for moving it: the counts are identical either way, and the archived
131
+ products cannot adjudicate between them. ``'spec'`` is nonetheless the more
132
+ faithful reproduction of the chain the steps script describes, and is what a
133
+ future flip should adopt once something depends on those three variables.
134
+ Build the test profile with
135
+ ``dataclasses.replace(ORACLES_PRODUCTION, hvps_reader='spec')``.
136
+ """
137
+
138
+ # ------------------------------------------------------------------
139
+ # S3 axes. ``imgProc_sm.m`` is where the two trees part company hardest:
140
+ # 949 lines in stock against 521 in the variant, and unlike the reject/sizing files -- where
141
+ # every shared file turned out byte-identical -- five of those differences
142
+ # change written output for probetype 2.
143
+ # ------------------------------------------------------------------
144
+
145
+ diode_stats_counts_shadowed: bool
146
+ """Whether ``bin_stats`` counts shadowed diodes or lit ones.
147
+
148
+ Stock ``imgProc_sm.m:804-805`` accumulates ``sum(c=='0',1)``; the variant at
149
+ ``:387-388`` accumulates ``sum(c=='1',1)``. In UIOOPS's char image ``'0'`` is
150
+ a **shadowed** diode (``CGAL_minR.cpp:63`` selects on 48, ``holroyd.m:139``,
151
+ ``calculate_reject_unified.m:386``), so the two are exact complements and the
152
+ variant counts *illuminated* diodes.
153
+
154
+ This is not an ambiguity -- stock's own changelog names it as a repair:
155
+ "Updated by Dan Stechman, 11/28/2016 -- Changed definition of diode_stats
156
+ variable to sum instances of *shadowed* particles (old version summed
157
+ illuminated particles)" (``imgProc_sm.m:48-50``). The ORACLES variant is
158
+ dated November 2016 and sits on the near side of that fix, so ``bin_stats``
159
+ in the reference product is a lit-diode count. ``False`` reproduces it.
160
+
161
+ Consequence is bounded but real: ``bin_stats`` is a per-flight diagnostic of
162
+ which photodiodes are working, and read as a shadow count it inverts --
163
+ a dead (never-shadowed) diode reads as the *most* active one.
164
+ """
165
+
166
+ zero_image_particle_recovery: bool
167
+ """What happens when a particle frames to zero slices.
168
+
169
+ Both trees detect the condition the same way (``start > (j-1)`` for
170
+ probetype 2), and then diverge completely:
171
+
172
+ * stock ``imgProc_sm.m:541-546`` sets ``start = j + 2``, advances ``j`` and
173
+ ``continue``\\ s -- the empty particle is skipped and the record keeps
174
+ being scanned;
175
+ * the variant at ``:249-251`` executes ``break``, abandoning **the entire
176
+ rest of the image record**.
177
+
178
+ Stock's changelog dates the change: "Updated by Joe Finlon (w/ contribution
179
+ from Adam Majewski), 11/06/17 -- Improved handling of image buffers when
180
+ zero-image particles are detected" (``:66-68``), and the old ``break`` is
181
+ left in place commented out at ``:538``/``:545`` beside its replacement.
182
+
183
+ This is the highest-consequence S3 divergence, because it is silent and
184
+ unbounded: every particle after the first zero-image particle in a record is
185
+ simply absent from the reference product, with nothing recorded to say so.
186
+ ``False`` reproduces that loss, which is required -- a port that recovered
187
+ here would emit particles that are not in the file it is validated against.
188
+ """
189
+
190
+ time_in_seconds_from_tas: bool
191
+ """How ``Time_in_seconds`` is built for probetype 2 (2D-S / HVPS).
192
+
193
+ The variant, ``imgProc_sm.m:365``, is one line that scales the particle's own
194
+ clock count by the diode size: an absolute value, with true air speed
195
+ hard-wired to 170 m/s.
196
+
197
+ Stock ``:724-778`` is Joe Finlon's 2017-03-03 replacement: it reads TAS from
198
+ an aircraft data file passed as ``varargin{1}``, converts each *inter-particle*
199
+ clock difference at the TAS for that image record's time, and accumulates --
200
+ falling back to the same ``/170`` only when the lookup is empty or NaN
201
+ (``:730``, Finlon 2018-02-09). It also carries the rollback correction at
202
+ ``:737``/``:752``: a negative difference below ``-250`` s is treated as the
203
+ 32-bit clock wrapping, and ``2^32-1`` is added back.
204
+
205
+ The two therefore differ in kind, not degree: an absolute clock reading
206
+ against an accumulated sum of TAS-corrected differences. ``False`` also
207
+ means no aircraft file is required, which is why the variant's signature has
208
+ no ``varargin``.
209
+ """
210
+
211
+ inter_arrival_in_seconds: bool
212
+ """The units of the written ``inter_arrival`` variable, for probetype 2.
213
+
214
+ Stock ``imgProc_sm.m:769-773`` differences ``time_in_seconds``, so the
215
+ variable is in **seconds** as its own attribute claims. The variant at
216
+ ``:366-370`` computes ``part_time - part_micro(kk-1)`` -- a difference of raw
217
+ clock counts, never scaled -- so the reference product's ``inter_arrival`` is
218
+ in **clock cycles**. Measured on the fixture: the variant writes 3129, 11,
219
+ 19, 71 where the seconds reading would be of order 1e-5.
220
+
221
+ Two further consequences of the variant's form, both reproduced:
222
+
223
+ * ``part_micro`` is reset to a fresh array at every image record
224
+ (``:513`` ``clear ... part_micro ...``) and ``kk`` returns to 1, so the
225
+ ``if(kk>1)`` test at ``:366`` fails for the first particle of *every*
226
+ record and writes 0 -- not just for the first particle of the file.
227
+ * because it differences the clock rather than the time, it is unaffected by
228
+ the ``/170`` TAS assumption above -- which makes it the more transferable
229
+ of the two quantities, not the less.
230
+ """
231
+
232
+ shadow_diode_reillumination: bool
233
+ """Whether ``imgProc_sm`` re-illuminates stuck photodiodes before measuring.
234
+
235
+ A third source variant, and the one that actually produced the ORACLES
236
+ products. Both trees on disk take six arguments (variant) or eight-plus
237
+ (stock); the production file takes **nine** -- ``(..., projectname, path,
238
+ flight, file)`` -- and uses the three extras for one guarded block, at
239
+ extraction ``:286-292``::
240
+
241
+ if exist([path '/' 'diode.' flight file '.' infile(end-4) '.mat'],'file')==2;
242
+ load([... ],'shadow_diode');
243
+ c(:,shadow_diode)='1';
244
+ end
245
+
246
+ It sits between the ``c`` construction (``:266-268``) and the image-width
247
+ guard (``:272``), so it precedes habit, rejection, sizing and the enclosing
248
+ circle: it reaches all 41 written variables. ``find_shadow_diodes.m``
249
+ supplies the list, calling a diode stuck when ``bin_stats`` shows it lit for
250
+ under 80% of the array mean.
251
+
252
+ Established by normalized diff of the Appendix-B extraction against the real
253
+ variant tree file: the *entire* delta is this block, the ``mod(i,100)``
254
+ progress ``disp`` that reports it, the three-argument signature, and two
255
+ spelling repairs in comments (``Variabels``, ``doide``). Nothing else
256
+ differs, so the production file is the variant file plus this axis.
257
+
258
+ ``True`` only enables the branch. Whether it does anything depends on the
259
+ mask, which is passed separately (:mod:`arrayprobe.masks`) rather than
260
+ discovered by filename, so a run states what it applied instead of
261
+ depending on the working directory. ``False`` makes passing a mask an
262
+ error, because neither tree file can consume one.
263
+
264
+ Note what this does *not* settle: the mask files recovered for 09/06/2016
265
+ 2D-S are empty, so for that product the branch is inert whether or not it
266
+ was compiled in. The 09/06 HVPS mask is not empty (diodes 2 and 128).
267
+ """
268
+
269
+ imgproc_output_typing: str
270
+ """The proc-file variable contract: ``'typed'`` or ``'all-double'``.
271
+
272
+ Stock ``imgProc_sm.m:218-448`` declares each variable at its natural width
273
+ -- ``'int'`` for ``Date``/``Time``/``parent_rec_num``, ``'short'`` for
274
+ ``msec``/``position``/``image_length``/``holroyd_habit``, ``'byte'`` for the
275
+ three flags -- casts on write (``int16(images.auto_reject)`` at ``:898``,
276
+ ``int16(images.holroyd_habit)`` at ``:923``), and attaches ``Units`` and
277
+ ``Description`` to every one, plus eight global attributes.
278
+
279
+ The variant ``:135-186`` declares **every** variable ``'double'``, writes
280
+ ``double(...)`` where stock writes ``int16(...)``, and calls ``endDef`` at
281
+ ``:187`` having issued **no ``putAtt`` at all** -- no variable attributes and
282
+ no global attributes. Confirmed by executing it: the proc file it writes has
283
+ 41 variables, all ``float64``, and ``ncattrs()`` empty on every one, against
284
+ the same 41 variables carrying eight global and two per-variable attributes
285
+ from stock on the identical input.
286
+
287
+ So the reference product is self-describing to a much smaller degree than
288
+ stock's, and nothing in it records the probe, the project, or the source
289
+ file. It also means the variant cannot round-trip a value through a narrower
290
+ type -- worth knowing, because it makes ``holroyd_habit`` and
291
+ ``image_auto_reject`` exact ASCII codes in the reference where stock's
292
+ ``int16`` cast is a genuine (if here harmless) narrowing.
293
+ """
294
+
295
+ nan_tas_substitution: bool
296
+ """Whether ``sizeDist`` replaces a NaN TAS before the sample volume.
297
+
298
+ Stock ``UIOPS-v3.1.4/joefinlon-UIOPS-ba5e67c/sizeDist.m:1729-1741``
299
+ ("Correct NaN TAS values where appropriate (rare issue) ~ Joe Finlon
300
+ 02/26/18") walks ``tas`` in order and sets each NaN ``tas(i)`` to the last
301
+ valid value in ``tas(1:i-1)`` -- already substituted, so earlier NaNs count
302
+ as valid once replaced -- or to 100 m/s when there is none; ``svol2`` at
303
+ ``:1748`` then uses the repaired vector. The ORACLES-variant ``sizeDist.m``, the
304
+ ORACLES production tree, has no such block: its ``svol2`` line (``:1605``)
305
+ follows the probetype-1 block (``:1596``) directly, so a NaN TAS writes a NaN
306
+ sample volume and every concentration derived from it. The v3.5 tree keeps
307
+ the block (``UIOPS-v3.5/joefinlon-UIOPS-039be82/sizeDist.m:1959-1971``).
308
+ ``True`` reproduces stock; ``False`` the ORACLES products. Implemented by
309
+ :func:`arrayprobe.sizedist.substitute_nan_tas`, selected in
310
+ :func:`arrayprobe.sizedist.run` by ``nan_tas_substitution=`` (which follows
311
+ ``tree`` when not given); pinned against Octave in
312
+ ``tests/test_sizedist_nan_tas.py``.
313
+ """
314
+
315
+ reject_thresholds: RejectConfig
316
+ """The ``calculate_reject_unified.m:71-77`` thresholds this tree runs with.
317
+
318
+ Stock and the named ORACLES variant tree share a byte-identical
319
+ ``calculate_reject_unified.m`` and take :data:`~arrayprobe.reject.DEFAULT_REJECT_CONFIG`.
320
+ The ORACLES variant -- the file that made the archived products -- carries
321
+ three dated edits (``rej_hollow 1->0``, ``max_edge_img_ar 6->4``,
322
+ ``max_comp_img_ar 5->4``) and takes
323
+ :data:`~arrayprobe.reject.ORACLES_PRODUCTION_REJECT_CONFIG`.
324
+
325
+ Carried on the profile because the alternative -- the call site reaching for
326
+ a module default -- is exactly what happened until 2026-08-28: every ORACLES
327
+ file was rejected on the stock thresholds, which drops ~40% of large
328
+ particles on a dense file, and the proc files looked plausible throughout.
329
+ The measurement that settled which thresholds made the product is in
330
+ ``reject.py``.
331
+ """
332
+
333
+
334
+ #: Fields that describe which MATLAB tree's *behaviour* a run reproduces, as
335
+ #: opposed to ``reject_thresholds``, which is configuration the v3.5 engine
336
+ #: reads. :func:`is_v35_flavoured` compares exactly these.
337
+ _BEHAVIOUR_FIELDS: tuple[str, ...] = (
338
+ "spec_buffer_guard", "hvps_reader", "diode_stats_counts_shadowed",
339
+ "zero_image_particle_recovery", "time_in_seconds_from_tas",
340
+ "inter_arrival_in_seconds", "shadow_diode_reillumination",
341
+ "imgproc_output_typing", "nan_tas_substitution",
342
+ )
343
+
344
+
345
+ #: Names whose *citations* point at the v3.5 tree. Populated by the two v3.5
346
+ #: builders below and by ``register_profile(..., cites_tree="v3.5")``.
347
+ #:
348
+ #: **Why a declaration and not only a field comparison.** The first version of
349
+ #: :func:`is_v35_flavoured` compared the behaviour fields alone and returned
350
+ #: **True for ``stock-v3.1.4``** -- correctly, and uselessly. ``STOCK_V35`` was
351
+ #: built precisely by measuring that *every* field holds the same value as
352
+ #: ``stock-v3.1.4`` (see its description), so the two are field-identical and no
353
+ #: comparison of fields can ever separate them. What separates them is which tree
354
+ #: their citations name, and that is not derivable from the values. Running the
355
+ #: v3.5 engine under ``stock-v3.1.4`` would compute the right numbers and write a
356
+ #: ``.call`` claiming a tree that was not consulted -- a provenance error, which
357
+ #: in this project is the expensive kind.
358
+ _V35_TREE_PROFILES: set[str] = set()
359
+
360
+
361
+ def is_v35_flavoured(candidate: FidelityProfile) -> bool:
362
+ """True when ``candidate`` may be used under ``--engine 3.5``.
363
+
364
+ Two conditions, both required, and the first is the one that carries the
365
+ weight:
366
+
367
+ 1. The profile **declares** that its citations are to the v3.5 tree -- it is
368
+ one of the shipped v3.5 profiles, or a fork registered it with
369
+ ``register_profile(p, cites_tree="v3.5")``. Not inferable from the field
370
+ values; see :data:`_V35_TREE_PROFILES`.
371
+ 2. Every field in :data:`_BEHAVIOUR_FIELDS` equals :data:`STOCK_V35`'s.
372
+ ``reject_thresholds`` is deliberately excluded -- it is the one thing the
373
+ v3.5 engine reads from a profile and the one axis a caller is entitled to
374
+ vary. This second check catches a fork that declares ``v3.5`` while
375
+ describing v3.1.4 behaviour.
376
+
377
+ **Fails closed in both directions.** An undeclared profile is refused however
378
+ its fields read, and a declared one is still refused if its behaviour
379
+ contradicts the declaration. A new field added to :class:`FidelityProfile` and
380
+ not listed in :data:`_BEHAVIOUR_FIELDS` makes this *stricter*, never laxer.
381
+ """
382
+ if candidate.name not in _V35_TREE_PROFILES:
383
+ return False
384
+ stock35 = _LAZY["stock-v3.5"]()
385
+ return all(
386
+ getattr(candidate, f) == getattr(stock35, f) for f in _BEHAVIOUR_FIELDS
387
+ )
388
+
389
+
390
+ #: The shipped variants, plus whatever a caller has registered. Mutable only
391
+ #: through :func:`register_profile`; :data:`PROFILES` is a live read-only view of
392
+ #: it, so a registration is visible to everything that reads the registry.
393
+ #: ``stock-v3.5`` is deliberately absent here until :func:`_build_stock_v35`
394
+ #: runs -- see :data:`SHIPPED` and :class:`_ProfileRegistry` for how lookups,
395
+ #: membership and iteration all stay correct in the meantime.
396
+ _REGISTRY: dict[str, FidelityProfile] = {}
397
+
398
+ #: The names the shipping package declares as its own, fixed once at its import
399
+ #: (:data:`arrayprobe.profiles.SHIPPED` is the frozen public copy). Filled by
400
+ #: the v3.1.4 package when it seeds its variants; read by :func:`register_profile`
401
+ #: so a shipped name can never be reused.
402
+ _SHIPPED: set[str] = set()
403
+
404
+ #: Lazily built shipped profiles, name -> zero-argument builder. The builders
405
+ #: live with the v3.1.4 variants and are injected at
406
+ #: their import, so this module never imports ``arrayprobe``.
407
+ _LAZY: dict[str, Callable[[], FidelityProfile]] = {}
408
+
409
+
410
+ class _ProfileRegistry(Mapping[str, FidelityProfile]):
411
+ """Live view of :data:`_REGISTRY`, materialising ``stock-v3.5`` on demand.
412
+
413
+ The other three shipped profiles, and anything a fork has registered, are
414
+ already in :data:`_REGISTRY` and served directly. ``stock-v3.5`` is the
415
+ one entry whose construction needs ``arrayprobe_uiops``, so asking
416
+ this mapping for it -- by key, by ``in``, or by iterating down to values
417
+ -- builds it once, via :func:`_build_stock_v35`, and never merely by
418
+ importing this module or this class.
419
+ """
420
+
421
+ def __getitem__(self, name: str) -> FidelityProfile:
422
+ if name in _LAZY:
423
+ return _LAZY[name]()
424
+ return _REGISTRY[name]
425
+
426
+ def __iter__(self):
427
+ return iter(_SHIPPED | set(_REGISTRY))
428
+
429
+ def __len__(self) -> int:
430
+ return len(_SHIPPED | set(_REGISTRY))
431
+
432
+
433
+ PROFILES: Mapping[str, FidelityProfile] = _ProfileRegistry()
434
+
435
+
436
+ def register_profile(new: FidelityProfile, *, cites_tree: str = "3.1.4") -> FidelityProfile:
437
+ """Add a fork's own variant to the registry, under its own ``name``.
438
+
439
+ ``cites_tree`` says **which MATLAB tree the variant's file:line citations name**
440
+ -- ``"3.1.4"`` (the default) or ``"3.5"``. It is not inferable from the field
441
+ values, because ``stock-v3.5`` was built by measuring that every field holds
442
+ the same value as ``stock-v3.1.4``: the two are field-identical and only their
443
+ citations differ. A variant registered ``cites_tree="3.5"`` becomes usable
444
+ under ``--engine 3.5`` (see :func:`is_v35_flavoured`, which also re-checks the
445
+ behaviour fields, so declaring ``"3.5"`` over v3.1.4 behaviour is still
446
+ refused). **Defaulting to ``"3.1.4"`` fails closed**: a fork that says nothing
447
+ is refused by the v3.5 gate rather than admitted to it.
448
+
449
+ **Why this exists.** UIOOPS is forked, edited and
450
+ re-forked -- that is how the field-campaign variant behind the archived products came
451
+ to exist -- so a group running their own tree needs to be able to say *my
452
+ fork differs here* without editing this package. Every field of a
453
+ :class:`FidelityProfile` is required by the dataclass, so a registration
454
+ states each divergence explicitly; there is no path here that fills one in.
455
+
456
+ **What this deliberately does not open.** A profile can be registered from
457
+ Python, where the caller constructs the object and names every field, and
458
+ **never from a configuration file**: a ``FidelityProfile`` field *is* a
459
+ threshold, and the configuration rule is that a config file selects
460
+ between documented behaviours and never sets one. ``arrayprobe.config``
461
+ will happily select a registered profile by name once it exists; it still
462
+ refuses to describe one.
463
+
464
+ A registration may not take a name already in use, shipped or registered:
465
+ ``.call`` sidecars, logs and error messages record the *name*, so a name has
466
+ to keep meaning one variant. Raises :class:`ValueError` if it does.
467
+ """
468
+ if not isinstance(new, FidelityProfile):
469
+ raise TypeError(f"register_profile takes a FidelityProfile, got {type(new).__name__}")
470
+ if not new.name or not new.name.strip():
471
+ raise ValueError("a registered profile needs a name; it is what a .call stamp records")
472
+ if not new.description or not new.description.strip():
473
+ raise ValueError(
474
+ f"profile {new.name!r} has no description. Every shipped profile's says which "
475
+ "MATLAB tree it is and where that tree lives, because a variant nobody can "
476
+ "locate cannot be checked against anything")
477
+ # Checked against SHIPPED as well as _REGISTRY: "stock-v3.5" is a shipped
478
+ # name from the moment this module loads (SHIPPED is eager), even before
479
+ # _build_stock_v35 has ever run and actually put it in _REGISTRY -- a
480
+ # registration attempt must not slip through in that window.
481
+ if new.name in _REGISTRY or new.name in _SHIPPED:
482
+ kind = "shipped with this package" if new.name in _SHIPPED else "already registered"
483
+ raise ValueError(
484
+ f"fidelity profile {new.name!r} is {kind}; a name records which MATLAB variant "
485
+ f"produced a file, in .call sidecars and in every error message, so it cannot be "
486
+ f"reused. Known: {sorted(_SHIPPED | set(_REGISTRY))}")
487
+ if cites_tree not in ("3.1.4", "3.5"):
488
+ raise ValueError(
489
+ f"cites_tree must be '3.1.4' or '3.5', got {cites_tree!r}; it names which MATLAB "
490
+ "tree this variant's file:line citations point at, and only those two are vendored")
491
+ _REGISTRY[new.name] = new
492
+ if cites_tree == "3.5":
493
+ _V35_TREE_PROFILES.add(new.name)
494
+ return new
495
+
496
+
497
+ def profile(name: str) -> FidelityProfile:
498
+ """Look a profile up by name, listing the alternatives on a miss."""
499
+ try:
500
+ return PROFILES[name]
501
+ except KeyError:
502
+ known = ", ".join(sorted(PROFILES))
503
+ raise KeyError(f"unknown fidelity profile {name!r}; known profiles: {known}") from None
504
+
505
+
506
+ # The v3.5 builders and register functions, moved from
507
+ # arrayprobe.profiles; arrayprobe.profiles re-exports them.
508
+ _STOCK_V35_NAME = "stock-v3.5"
509
+
510
+ #: Cache for :func:`_build_stock_v35`; ``None`` until the profile is first
511
+ #: actually needed. Deliberately not a plain ``FidelityProfile`` constant --
512
+ #: see the import-time note above.
513
+ _stock_v35_cache: FidelityProfile | None = None
514
+
515
+
516
+ def _build_stock_v35() -> FidelityProfile:
517
+ """Construct :data:`STOCK_V35`, importing ``arrayprobe_uiops`` only here.
518
+
519
+ Called from every access path below (the ``STOCK_V35`` module attribute,
520
+ ``PROFILES["stock-v3.5"]``, ``profile("stock-v3.5")``, iterating
521
+ ``PROFILES`` down to values) so the deferral is invisible to a caller:
522
+ the profile is always complete once returned, just not necessarily built
523
+ yet the first time anything asks. Cached, so the import and the
524
+ construction each happen at most once per process -- the same "once" the
525
+ former eager version paid at ``import arrayprobe`` time, just moved to
526
+ first use.
527
+ """
528
+ global _stock_v35_cache
529
+ if _stock_v35_cache is None:
530
+ from arrayprobe_uiops.measure import STOCK_V35_REJECT_CONFIG
531
+
532
+ _stock_v35_cache = FidelityProfile(
533
+ name=_STOCK_V35_NAME,
534
+ description=(
535
+ "joefinlon/UIOPS v3.5 as shipped (UIOPS-v3.5/joefinlon-UIOPS-039be82/). "
536
+ "Every field holds the same value as UIOOPS v3.1.4 as released -- measured field "
537
+ "by field "
538
+ "against the v3.5 sources, not assumed -- and cites v3.5 lines instead: "
539
+ "buffer guards read_binary_SPEC.m:322-367, shadowed-diode stats "
540
+ "imgProc_sm.m:1208-1211, zero-image recovery :773/:1311, TAS-based "
541
+ "Time_in_seconds :1133-1172, seconds-valued inter_arrival :1176, no "
542
+ "shadow_diode block anywhere, typed output (:1352, :1380), NaN-TAS "
543
+ "substitution sizeDist.m:1959-1971, reject thresholds "
544
+ "calculate_reject_unified.m:60-66. Provenance table and test: "
545
+ "arrayprobe_uiops.profile, tests/test_stock_v35_profile.py. The v3.5 engine "
546
+ "consumes only reject_thresholds (its readers and driver take no profile, "
547
+ "because v3.5 has one source tree); the rest records which source tree a run "
548
+ "translates. v3.5 also writes NETCDF4 with deflate (read_binary_SPEC.m:81, "
549
+ "imgProc_sm.m:289) where v3.1.4 writes classic; that is the engine's own "
550
+ "contract, not a profile axis."
551
+ ),
552
+ spec_buffer_guard=True,
553
+ hvps_reader="spec",
554
+ diode_stats_counts_shadowed=True,
555
+ zero_image_particle_recovery=True,
556
+ time_in_seconds_from_tas=True,
557
+ inter_arrival_in_seconds=True,
558
+ shadow_diode_reillumination=False,
559
+ imgproc_output_typing="typed",
560
+ nan_tas_substitution=True,
561
+ reject_thresholds=STOCK_V35_REJECT_CONFIG,
562
+ )
563
+ _REGISTRY[_STOCK_V35_NAME] = _stock_v35_cache
564
+ _V35_TREE_PROFILES.add(_STOCK_V35_NAME)
565
+ return _stock_v35_cache
566
+
567
+
568
+ _ORACLES_PROD_V35_NAME = "oracles-production-v3.5"
569
+
570
+ #: Cache for :func:`_build_oracles_production_v35`, deferred for the same
571
+ #: reason as :data:`_stock_v35_cache`: it is built from ``STOCK_V35``.
572
+ _oracles_prod_v35_cache: FidelityProfile | None = None
573
+
574
+
575
+ def _build_oracles_production_v35() -> FidelityProfile:
576
+ """Construct :data:`ORACLES_PRODUCTION_V35` -- v3.5 behaviour, ORACLES thresholds.
577
+
578
+ **Why this exists.** CIP results are wanted
579
+ under stock *and* ORACLES-production thresholds "side by side", and the
580
+ batch driver refused: ``--engine 3.5`` accepted only ``stock-v3.5``, whose
581
+ own message said a v3.5-flavoured variant "is not supported here yet". The
582
+ same refusal had already parked CMP-2 on 2026-09-16, where scoring the v3.5
583
+ engine against the author's triage labels would have confounded *engine*
584
+ with *profile* -- on exactly the thresholds worth 38.15 % of used-bin
585
+ particles. Two blockers, one missing object.
586
+
587
+ **Why ``ORACLES_PRODUCTION`` itself could not be passed instead, and why the
588
+ refusal was right.** Measured 2026-09-17: it differs from :data:`STOCK_V35`
589
+ in **all eight** non-threshold fields -- ``spec_buffer_guard``,
590
+ ``hvps_reader``, ``diode_stats_counts_shadowed``,
591
+ ``zero_image_particle_recovery``, ``time_in_seconds_from_tas``,
592
+ ``inter_arrival_in_seconds``, ``shadow_diode_reillumination``,
593
+ ``imgproc_output_typing``. Every one of those describes **v3.1.4 source
594
+ behaviour**, so handing it to the v3.5 engine would assert things about a
595
+ tree that is not running. The gate was not over-strict; the registry was
596
+ short one profile.
597
+
598
+ **What this profile is, stated plainly: a synthetic configuration.** No
599
+ MATLAB tree has ever run the v3.5 engine with the ORACLES thresholds. The
600
+ ORACLES fork froze at v3.1.4 and was never rebased, so the fidelity
601
+ claim is unaffected. So this profile **reproduces no archived
602
+ product and must never be described as doing so**. It exists for exactly one
603
+ purpose: to vary the threshold axis while holding the engine axis fixed, so
604
+ that a difference between two runs can be attributed to one or the other.
605
+ Its ``.call`` stamp records the name, which is how a reader tells such a run
606
+ from a reproduction.
607
+
608
+ The three threshold values and their provenance are the ORACLES fork's own
609
+ dated edits, the ORACLES-variant ``calculate_reject_unified.m`` -- ``:72``
610
+ ``rej_hollow 1 -> 0``, ``:76`` ``max_edge_img_ar 6 -> 4``, ``:77``
611
+ ``max_comp_img_ar 5 -> 4`` -- against the v3.5 tree's stock block at
612
+ ``UIOPS-v3.5/joefinlon-UIOPS-039be82/calculate_reject_unified.m:60-66``
613
+ (``1/1/1/25/6/5``). Both blocks were read, not assumed.
614
+ """
615
+ global _oracles_prod_v35_cache
616
+ if _oracles_prod_v35_cache is None:
617
+ stock35 = _build_stock_v35()
618
+ _oracles_prod_v35_cache = replace(
619
+ stock35,
620
+ name=_ORACLES_PROD_V35_NAME,
621
+ description=(
622
+ "The v3.5 engine run under the reject thresholds a field campaign's "
623
+ "modified UIOOPS v3.1.4 used. "
624
+ "SYNTHETIC: no MATLAB tree ever ran this combination -- that modified "
625
+ "UIOOPS was never moved onto v3.5 -- so this profile "
626
+ "reproduces NO archived product and must not be cited as reproducing one. "
627
+ "It exists to hold the engine fixed while the threshold axis varies, so a "
628
+ "difference between two runs is attributable. Behaviour fields are "
629
+ "stock-v3.5's, unchanged and still cited to "
630
+ "the v3.5 tree. Only reject_thresholds differ, taking that modified "
631
+ "UIOOPS's calculate_reject_unified.m:72 (rej_hollow "
632
+ "1->0), :76 (max_edge_img_ar 6->4) and :77 (max_comp_img_ar 5->4), against "
633
+ "v3.5's stock 1/1/1/25/6/5 at calculate_reject_unified.m:60-66. NOTE for a "
634
+ "64-diode probe: this profile leaves rej_hollow OFF, so unlike stock-v3.5 "
635
+ "it does not exercise the 32-diode hollow packing defect."
636
+ ),
637
+ reject_thresholds=ORACLES_PRODUCTION_REJECT_CONFIG,
638
+ )
639
+ _REGISTRY[_ORACLES_PROD_V35_NAME] = _oracles_prod_v35_cache
640
+ _V35_TREE_PROFILES.add(_ORACLES_PROD_V35_NAME)
641
+ return _oracles_prod_v35_cache
642
+
643
+
644
+ _IMAGE_ASSISTED_V35_NAME = "stock-v3.5-image-assisted"
645
+
646
+ #: Cache for :func:`register_stock_v35_image_assisted`, built from ``STOCK_V35``
647
+ #: the same way :data:`_oracles_prod_v35_cache` is -- ``None`` until first needed.
648
+ _image_assisted_v35_cache: FidelityProfile | None = None
649
+
650
+
651
+ def register_stock_v35_image_assisted() -> FidelityProfile:
652
+ """Build, register and return ``stock-v3.5-image-assisted``.
653
+
654
+ **What it is.** :data:`STOCK_V35` with exactly one field moved:
655
+ ``reject_thresholds`` becomes
656
+ :data:`arrayprobe_uiops.measure.IMAGE_ASSISTED_V35_REJECT_CONFIG` --
657
+ ``rej_hollow`` off, ``max_edge_img_ar`` and ``max_comp_img_ar`` left at
658
+ stock's 6 and 5. See that constant's own docstring for the full
659
+ evidence (200 triage labels) and its honest caveat (this
660
+ configuration is not optimal at 55-105 um, where the hollow test it turns
661
+ off was correct 25/25). Built the same way as
662
+ :func:`_build_oracles_production_v35` -- ``dataclasses.replace`` off
663
+ ``STOCK_V35``, so every non-threshold field is provably identical to it and
664
+ :func:`is_v35_flavoured` admits it without re-deriving anything.
665
+
666
+ **Why registered rather than shipped as a fourth module-level constant
667
+ like ``STOCK_V35``/``ORACLES_PRODUCTION_V35``.** Two existing tests pin the
668
+ module's *shipped, ``dir()``-visible* surface to exactly its current
669
+ members: ``tests/test_profile_registry.py::
670
+ test_the_shipped_set_does_not_grow_with_registrations`` pins :data:`SHIPPED`
671
+ to five names, and ``tests/test_cli_engine_selection.py::
672
+ test_the_second_reason_names_the_v35_profiles_that_exist`` enumerates every
673
+ uppercase ``dir(profiles)`` name whose value is a :class:`FidelityProfile`
674
+ and pins that list to ``["ORACLES_PRODUCTION_V35", "STOCK_V35"]`` --
675
+ the second test's own docstring says outright that "the next one
676
+ registered fails this again and the prose has to catch up" (``cli.py``'s
677
+ refusal message). This profile is deliberately reached the same way a
678
+ fork's own variant is -- ``profiles.PROFILES["stock-v3.5-image-assisted"]``
679
+ or ``profiles.profile(...)``, never ``profiles.STOCK_V35_IMAGE_ASSISTED`` --
680
+ which is also the more accurate description: the project's one-package-per-upstream rule already
681
+ settles this as an opt-in configuration selected per run, not a new shipped
682
+ default, and per that same decision it adds no package.
683
+
684
+ Calls :func:`register_profile` with ``cites_tree="3.5"``, so
685
+ :func:`is_v35_flavoured` -- and therefore the ``--engine 3.5`` gate in
686
+ ``scripts/run_flight.py`` -- admits it exactly as it would a fork's own
687
+ declared variant. Idempotent and cached like :func:`_build_stock_v35`: safe
688
+ to call from every entry point that needs the name resolvable
689
+ (``scripts/run_flight.py``-style CLI lookups, the CIP lane scripts under
690
+ ``_decoded/cip160906/``) without risking ``register_profile``'s
691
+ already-registered ``ValueError`` on a second call.
692
+ """
693
+ global _image_assisted_v35_cache
694
+ if _image_assisted_v35_cache is None:
695
+ from arrayprobe_uiops.measure import IMAGE_ASSISTED_V35_REJECT_CONFIG
696
+
697
+ stock35 = _build_stock_v35()
698
+ new = replace(
699
+ stock35,
700
+ name=_IMAGE_ASSISTED_V35_NAME,
701
+ description=(
702
+ "The v3.5 engine under stock-v3.5's own reject thresholds except "
703
+ "rej_hollow, which is OFF. Behaviour fields are stock-v3.5's, "
704
+ "unchanged (same construction as oracles-production-v3.5: "
705
+ "dataclasses.replace off STOCK_V35). Only reject_thresholds "
706
+ "differs, taking arrayprobe_uiops.measure."
707
+ "IMAGE_ASSISTED_V35_REJECT_CONFIG -- rej_hollow False against "
708
+ "stock-v3.5's True at calculate_reject_unified.m:62 in "
709
+ "UIOPS-v3.5/joefinlon-UIOPS-039be82/, max_edge_img_ar and "
710
+ "max_comp_img_ar left at stock's 6 and 5 (:65, :66), unlike "
711
+ "oracles-production-v3.5 which also moves both of those. NOT a "
712
+ "MATLAB tree's value -- a project decision, "
713
+ "from 200 triage "
714
+ "labels: the hollow test discards 19 of 25 real particles at "
715
+ "205-305um (~5,654 counts, ~76% real) and is ambiguous at "
716
+ "105-205um (11 real/14 artifact), against 25/25 correct at "
717
+ "55-105um. Isolates the axis oracles-production-v3.5's A/B "
718
+ "confounded: stock's looser aspect ratios were partly "
719
+ "cancelling its stricter hollow test (R=1.0396 at 55-105um "
720
+ "vs R=0.2283 at 205-305um). CAVEAT: turning rej_hollow off "
721
+ "flat also admits the 55-105um artifacts that test was "
722
+ "correctly catching -- that bin is 68% artifact even among "
723
+ "particles both configurations accept, so this profile is not "
724
+ "optimal there; a size-dependent rule is future opt-in work "
725
+ "inside the engine, not this profile."
726
+ ),
727
+ reject_thresholds=IMAGE_ASSISTED_V35_REJECT_CONFIG,
728
+ )
729
+ _image_assisted_v35_cache = register_profile(new, cites_tree="3.5")
730
+ return _image_assisted_v35_cache
731
+
732
+
733
+ _LAZY.setdefault(_STOCK_V35_NAME, _build_stock_v35)
734
+ _LAZY.setdefault(_ORACLES_PROD_V35_NAME, _build_oracles_production_v35)
735
+
736
+
737
+ def __getattr__(name: str) -> FidelityProfile:
738
+ """Module-level lazy attribute: ``profiles.STOCK_V35`` triggers the build.
739
+
740
+ Only reached when normal attribute lookup misses -- i.e. before
741
+ :func:`_build_stock_v35` has ever run, since it is only then that this
742
+ module's namespace has no ``STOCK_V35`` of its own. ``from arrayprobe_uiops.
743
+ profiles import STOCK_V35`` goes through this too, the same as any other
744
+ attribute access.
745
+ """
746
+ if name == "STOCK_V35":
747
+ return _build_stock_v35()
748
+ if name == "ORACLES_PRODUCTION_V35":
749
+ return _build_oracles_production_v35()
750
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
751
+
752
+
753
+ def __dir__() -> list[str]:
754
+ """``dir(profiles)`` lists the lazy :data:`STOCK_V35` too (PEP 562), so code that
755
+ enumerates the module's profiles still finds it; listing it builds nothing."""
756
+ return sorted(set(globals()) | {"STOCK_V35", "ORACLES_PRODUCTION_V35"})