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,220 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Reject helpers both UIOOPS engines share: RejectConfig, mask_start_end, _vertical_split."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import dataclass
7
+
8
+ import numpy as np
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class RejectConfig:
13
+ """The six thresholds ``calculate_reject_unified.m:71-77`` assigns itself.
14
+
15
+ Seven *assignments*, six *thresholds*: ``:74`` sets
16
+ ``handles.bits_per_slice = n_size(2)``, which is the image width read off
17
+ the data rather than a constant, so it is not a configurable threshold and
18
+ is not a field here.
19
+
20
+ Every one of these is written into ``handles`` at the **top of the
21
+ function**, unconditionally, overwriting whatever the caller had set. So in
22
+ stock UIOOPS they are constants with the values below, and a run script that
23
+ sets ``handles.shadowed_area`` has no effect whatsoever.
24
+
25
+ Exposing them as a frozen dataclass (thresholds-as-data) is a
26
+ possible later step.
27
+
28
+ **It IS carried on the fidelity profile, and the history of that is the
29
+ point.** An earlier reading held that it is "emphatically *not* a
30
+ :class:`~arrayprobe.profiles.FidelityProfile` field -- the two MATLAB trees
31
+ agree on every value here, so there is no divergence to name." That was
32
+ measured wrong 2026-08-28: the tree that actually produced the archived
33
+ ORACLES products carries three different values (``rej_hollow=0``,
34
+ ``max_edge_img_ar=4``, ``max_comp_img_ar=4``), and because nothing wired
35
+ them to the profile, every ORACLES file had been running on stock thresholds
36
+ and losing ~40 % of the particles the archive keeps in the used bins. The
37
+ profile carries ``ORACLES_PRODUCTION_REJECT_CONFIG``.
38
+
39
+ The reason the error survived so long is worth keeping with the code: the
40
+ claim was checked against a near-clear-air file on which those thresholds
41
+ can barely fire. An output-pinned claim is only as strong as the file that
42
+ pinned it.
43
+ """
44
+
45
+ #: ``:71``. Reject a zero-area particle as ``'z'`` rather than passing it
46
+ #: through as ``'0'``.
47
+ rej_zero_area: bool = True
48
+
49
+ #: ``:72``. Reject a particle that goes dark and lights up again. Also
50
+ #: gates the (dead) vertical-split re-check at :245, which requires this to
51
+ #: be *False* -- so the two split tests are mutually exclusive by
52
+ #: construction and only the first can ever fire.
53
+ rej_split: bool = True
54
+
55
+ #: ``:73``. Run the Korolev hollow analysis at all.
56
+ rej_hollow: bool = True
57
+
58
+ #: ``:75``. Minimum percent of the bounding rectangle that must be
59
+ #: shadowed; below it the particle is rejected ``'p'``.
60
+ shadowed_area: float = 25
61
+
62
+ #: ``:76``. Aspect-ratio ceiling for a particle **touching the array edge**
63
+ #: (reject ``'t'``). The netCDF description at ``imgProc_sm.m:325-329``
64
+ #: swaps this with the next one.
65
+ max_edge_img_ar: float = 6
66
+
67
+ #: ``:77``. Aspect-ratio ceiling for a fully-contained particle, applied in
68
+ #: both directions -- above it, or below its reciprocal, reject ``'a'``.
69
+ #: The reciprocal arm is dated in the source: "Second critirion added on Dec
70
+ #: 2nd, 2013 by Will for small aspect ratio" (:269).
71
+ max_comp_img_ar: float = 5
72
+
73
+
74
+ DEFAULT_REJECT_CONFIG = RejectConfig()
75
+ """The stock v3.1.4 thresholds -- and the named ORACLES variant tree's, whose
76
+ ``calculate_reject_unified.m`` is byte-identical to stock. ``arrayprobe.reject`` re-exports
77
+ this object."""
78
+
79
+ ORACLES_PRODUCTION_REJECT_CONFIG = RejectConfig(
80
+ rej_hollow=False,
81
+ max_edge_img_ar=4,
82
+ max_comp_img_ar=4,
83
+ )
84
+ """The ORACLES fork's dated reject edits, the ORACLES-variant ``calculate_reject_unified.m:73-77``
85
+ (``rej_hollow`` 1->0, ``max_edge_img_ar`` 6->4, ``max_comp_img_ar`` 5->4). Shared by both
86
+ engines (``ORACLES_PRODUCTION`` and ``ORACLES_PRODUCTION_V35``); ``arrayprobe.reject``
87
+ re-exports this object with the full provenance."""
88
+
89
+
90
+ def mask_start_end(end_mask: int, start_mask: int, shadow_row, bits_per_slice: int) -> np.ndarray:
91
+ """``:683-702`` -- blank everything outside ``[start_mask, end_mask]``.
92
+
93
+ Source: ``calculate_reject_unified.m`` (UIOOPS v3.1.4), ``mask_start_end`` from ``:683``; bare
94
+ line references here are into that file.
95
+
96
+ Returns the row's **lit** diodes (``True`` = lit = a hole) with everything
97
+ outside the particle's own span forced to False, which is what the caller
98
+ then counts and intersects. MATLAB builds this as a char row of ``'0'``
99
+ with the original characters pasted back into the window.
100
+
101
+ Two MATLAB mechanics folded into that boolean array:
102
+
103
+ * ``result`` starts as the numeric scalar ``0`` and ``result(1:n) = '0'``
104
+ assigns the *code* 48 into a double array, so ``result`` is numeric until
105
+ ``char()`` converts it back at :701. Round-trips exactly; no effect.
106
+ * When ``end_mask > bits_per_slice`` -- which happens in
107
+ :func:`is_it_hollow_sidescan`, where ``bits_per_slice`` is capped at 32
108
+ but the scan runs the full slice count -- MATLAB **auto-extends**
109
+ ``result`` and pads the gap with numeric ``0``, i.e. NUL characters,
110
+ not ``'0'``. Harmless: NUL is not ``'1'`` so the hole count skips it, and
111
+ the packers only ever read the first ``bits_per_slice`` entries. False
112
+ is the faithful boolean for both.
113
+
114
+ The ``start_mask == 0 & end_mask == 0`` arm at :687 returns the row
115
+ unmasked. Unreachable: every call site guards on ``n_lite > 0``, and a
116
+ non-empty slice has positions of at least 1.
117
+ """
118
+ shadow_row = np.asarray(shadow_row, dtype=bool)
119
+ if start_mask == 0 and end_mask == 0:
120
+ return ~shadow_row
121
+ result = np.zeros(max(bits_per_slice, end_mask), dtype=bool)
122
+ window = slice(start_mask - 1, end_mask)
123
+ result[window] = ~shadow_row[window]
124
+ return result
125
+
126
+
127
+ def _vertical_split(shadow) -> np.ndarray:
128
+ """``:138-142`` -- the accumulator behind the (dead) second split test.
129
+
130
+ MATLAB writes ``vertical_split = vertical_split & image_buffer(i,:)``, an
131
+ ``&`` between **char** rows. Both ``'0'`` (48) and ``'1'`` (49) are
132
+ non-zero, so the result is ``true`` at every position from the second slice
133
+ onward, and the ``scan_slice(vertical_split)`` at :239 then looks for the
134
+ character ``'0'`` in a logical array -- comparing 1 against 48, which is
135
+ false everywhere. So for any multi-slice particle the scan reports an empty
136
+ slice and the test at :245 can never fire.
137
+
138
+ A single-slice particle escapes: the loop body runs once and takes the
139
+ ``else`` arm, leaving ``vertical_split`` as the char row itself, which scans
140
+ normally.
141
+
142
+ Both cases return the row this port must scan for shadow. For the
143
+ multi-slice case that is an all-lit row -- nothing to find -- which is the
144
+ faithful equivalent of "all logical true, compared against ``'0'``".
145
+ """
146
+ if shadow.shape[0] == 1:
147
+ return shadow[0]
148
+ return np.zeros(shadow.shape[1], dtype=bool)
149
+
150
+
151
+ @dataclass(frozen=True)
152
+ class SliceScan:
153
+ """The three outputs of ``scan_slice`` (``:379``). Positions are 1-based.
154
+
155
+ Source: ``scan_slice`` in ``calculate_reject_unified.m:379-406`` (UIOOPS v3.1.4)."""
156
+
157
+ min_pos_lite: int
158
+ max_pos_lite: int
159
+ n_lite: int
160
+
161
+
162
+ _SCAN_LOADED = False
163
+ _SCAN_HAVE_NUMBA = False
164
+
165
+
166
+ def _ensure_scan_numba_loaded() -> None:
167
+ """JIT-decorate :func:`_scan_slice_kernel` once, on first use (numba stays lazy and optional).
168
+
169
+ ``arrayprobe.reject._ensure_numba_loaded`` calls this and rebinds its own
170
+ ``_scan_slice_kernel`` name to the result, so its sidescan kernel sees the dispatcher."""
171
+ global _SCAN_LOADED, _SCAN_HAVE_NUMBA, _scan_slice_kernel
172
+ if _SCAN_LOADED:
173
+ return
174
+ try:
175
+ from numba import njit
176
+ except ImportError: # pragma: no cover - numba is an optional extra
177
+ njit = None # type: ignore[assignment]
178
+ _SCAN_HAVE_NUMBA = njit is not None
179
+ if _SCAN_HAVE_NUMBA:
180
+ _scan_slice_kernel = njit(cache=True, boundscheck=True)(_scan_slice_kernel)
181
+ _SCAN_LOADED = True
182
+
183
+
184
+ def scan_slice(shadow_row) -> SliceScan:
185
+ """``calculate_reject_unified.m:379-406`` -- extent of the shadow in one slice.
186
+
187
+ Returns the first and last shadowed diode (1-based) and how many are
188
+ shadowed. All three are 0 when the slice is empty.
189
+
190
+ Note what this does *not* return: the shadowed diodes need not be
191
+ contiguous, and the gap ``max_pos - min_pos + 1 - n_lite`` is precisely what
192
+ the hollow scans call a hole.
193
+
194
+ Dispatches to the numba kernel when available (:data:`HAVE_NUMBA`); numba is imported
195
+ lazily on first call, never at module load.
196
+ """
197
+ arr = np.asarray(shadow_row, dtype=bool)
198
+ _ensure_scan_numba_loaded()
199
+ if _SCAN_HAVE_NUMBA:
200
+ min_pos, max_pos, n_lite = _scan_slice_kernel(np.ascontiguousarray(arr))
201
+ else:
202
+ min_pos, max_pos, n_lite = _scan_slice_reference(arr)
203
+ return SliceScan(int(min_pos), int(max_pos), int(n_lite))
204
+
205
+
206
+ def _scan_slice_reference(shadow_row):
207
+ """Pure-Python body of :func:`scan_slice` -- the numba equivalence oracle."""
208
+ lit_positions = np.flatnonzero(shadow_row) + 1
209
+ n_lite = int(lit_positions.size)
210
+ if n_lite == 0:
211
+ return 0, 0, 0
212
+ return int(lit_positions[0]), int(lit_positions[-1]), n_lite
213
+
214
+
215
+ def _scan_slice_kernel(shadow_row):
216
+ lit_positions = np.flatnonzero(shadow_row)
217
+ n_lite = lit_positions.size
218
+ if n_lite == 0:
219
+ return 0, 0, 0
220
+ return lit_positions[0] + 1, lit_positions[-1] + 1, n_lite
@@ -0,0 +1,93 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Optical Array Probe sample-area geometry.
3
+
4
+ Ported from: calc_sa_randombins.m (UIOOPS v3.1.4)
5
+
6
+ Reference: Heymsfield & Parrish (1978) sample-area formulation. The
7
+ sa_method=2 correction's 0.72 coefficient is attributed by McFarquhar
8
+ et al. (2017, Meteor. Monogr. 58, ch. 11, Eqs. 11-7/11-8) to a separate
9
+ 1979 NCAR technical note by the same two authors (TN-137+IA), not the
10
+ 1978 J. Appl. Meteorol. paper -- read directly, not carried from the
11
+ 1978 citation by assumption.
12
+ """
13
+
14
+ #: Declared so the public surface is explicit rather than whatever happens not to
15
+ #: start with an underscore. The Phase-1 shims at ``<name>.py`` in the original flat layout import
16
+ #: these names directly, CONSTANTS INCLUDED -- omitting a constant here would not
17
+ #: break them, but omitting one from a shim does, which is why they are listed.
18
+ __all__ = [
19
+ "calc_sa_randombins",
20
+ ]
21
+
22
+
23
+ def calc_sa_randombins(bins_mid, res, armdst, num_diodes, sa_method, probetype):
24
+ """OAP sample area (mm^2) per bin, per Heymsfield & Parrish
25
+ (1978, 1979 -- see this module's docstring for which is which).
26
+
27
+ Direct port of calc_sa_randombins.m.
28
+
29
+ bins_mid : sequence of bin midpoints, in MILLIMETRES.
30
+ res : photodiode resolution / bin width, microns.
31
+ armdst : probe arm separation, mm.
32
+ num_diodes: number of active photodiodes.
33
+ sa_method : 0 = center-in, 1 = entire-in, 2 = with correction.
34
+ probetype : 2 selects the alternate depth-of-field formula.
35
+
36
+ Returns a list of sample areas, one per entry in bins_mid.
37
+
38
+ THE UNITS OF ``bins_mid`` are millimetres, not "photodiode-number
39
+ units (not microns -- see original comment)", which is the opposite
40
+ of what the only call site passes. ``sizeDist.m:1562``
41
+ hands it ``cip2_binmid``, built at ``:1541-1543`` from ``kk``, and
42
+ every probe block defines ``kk`` in millimetres -- the 2D-S as
43
+ ``diodesize/2 : diodesize : ...`` with ``diodesize = .010`` mm, the
44
+ HVPS as an explicit micron list divided by 1000. The source's comment
45
+ "you can use this one if you provide midpoint in doide number"
46
+ describes the *commented-out* ``radius = bins_mid .* res/2``, not the
47
+ live ``radius = bins_mid/2``.
48
+
49
+ Nothing computed changes either way -- the function does arithmetic on
50
+ whatever it is handed, which is why the wrong reading survived. What
51
+ it would have changed is a caller's. ``tests/test_sample_area_oracle.
52
+ SampleAreaUnitsTest`` pins the reading that is dimensionally coherent:
53
+ ``bins_mid/res`` at ``:29`` is a diode count only if ``bins_mid`` is a
54
+ length in mm.
55
+
56
+ Note: the original MATLAB `switch` has no `otherwise` clause, so an
57
+ unsupported sa_method leaves EAWci/EAWri undefined and MATLAB dies at
58
+ `:49` with "'EAWri' undefined" (measured under Octave, and recorded in
59
+ the oracle bank as a status=ERROR case). This port raises ValueError
60
+ explicitly instead -- an intentional, documented deviation, not a
61
+ behavior change for any valid input.
62
+ """
63
+ if sa_method not in (0, 1, 2):
64
+ raise ValueError(f"Unsupported sa_method {sa_method!r}; expected 0, 1, or 2")
65
+
66
+ res_mm = res * 1e-3 # microns -> mm
67
+ lambda_mm = 680 * 1e-6 # laser wavelength, mm
68
+
69
+ sa = []
70
+ for bin_mid in bins_mid:
71
+ radius = bin_mid / 2
72
+ diameter = 2 * radius
73
+
74
+ if sa_method == 0:
75
+ eaw_ci = num_diodes * res_mm
76
+ eaw_ri = eaw_ci
77
+ elif sa_method == 1:
78
+ eaw_ci = (num_diodes - (bin_mid / res_mm) + 1) * res_mm
79
+ eaw_ci = max(eaw_ci, 0)
80
+ eaw_ri = eaw_ci
81
+ else: # sa_method == 2
82
+ eaw_ci = num_diodes * res_mm
83
+ eaw_ri = eaw_ci + 0.72 * diameter
84
+
85
+ if probetype == 2:
86
+ dof = 20.52 * radius ** 2 * 1000
87
+ else:
88
+ dof = 6 * radius ** 2 / lambda_mm
89
+ dof = min(dof, armdst)
90
+
91
+ sa.append(dof * eaw_ri)
92
+
93
+ return sa