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,134 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """A user-supplied stand-in for ``getPECANparams`` -- opt-in, required for PECAN, no default.
3
+
4
+ Both UIOOPS releases' ``sizeDist.m`` call, in the PECAN ``CIP`` and ``PIP`` cases (v3.5
5
+ ``:164``/``:195``, v3.1.4 ``:132``/``:163``) ``getPECANparams(ddate, probename)``, keeping
6
+ its first, second and fifth outputs (window start times, end times and per-window thresholds).
7
+ The lines that follow (v3.1.4 ``:134-138``) fill the threshold series with
8
+ ``defaultIntArrThresh`` and, for every TAS time inside a window ``[start, end)``, replace it
9
+ with that window's threshold.
10
+
11
+ ``getPECANparams.m`` ships in no release, so MATLAB dies there and both engines refuse the
12
+ project. A run that names a parameter file gets exactly the loop above with the file's values
13
+ in place of the function's three used outputs; the two discarded outputs (``~``) are never
14
+ read, so the file does not carry them. Nothing here supplies a value the file does not.
15
+
16
+ File format (CSV, ``#`` lines are comments, header row required, column order free)::
17
+
18
+ start_s,end_s,intar_threshold_s
19
+ 50400,51000,2.5e-6
20
+ 51600,52200,1.0e-5
21
+
22
+ ``start_s``/``end_s`` are seconds after midnight of the flight date in ``sizeDist.m``'s own
23
+ ``tas_time`` convention (so a flight past midnight carries values above 86400, as the
24
+ ``+240000`` rollover makes ``tas_time``); a second is in a spiral when
25
+ ``start_s <= tas_time < end_s``. ``intar_threshold_s`` is that spiral's inter-arrival
26
+ threshold in seconds. Two optional columns, ``date`` (``YYYYMMDD``) and ``probe``, restrict a
27
+ row to the ``ddate`` and ``probename`` the MATLAB call passes, so one file can hold a
28
+ campaign; a file with neither column applies to the run it is given to. A file (after that
29
+ filter) with no rows is refused rather than read as "no spirals".
30
+ """
31
+
32
+ from __future__ import annotations
33
+
34
+ import csv
35
+ import math
36
+ from dataclasses import dataclass
37
+ from os import PathLike
38
+ from pathlib import Path
39
+ from typing import Any
40
+
41
+ import numpy as np
42
+
43
+ __all__ = ["PecanParams", "load_pecan_params", "pecan_intar_threshold", "resolve_pecan_params"]
44
+
45
+ _REQUIRED = ("start_s", "end_s", "intar_threshold_s")
46
+
47
+
48
+ @dataclass(frozen=True)
49
+ class PecanParams:
50
+ """The three ``getPECANparams`` outputs ``sizeDist.m`` reads, one entry per spiral."""
51
+
52
+ startT: Any # noqa: N815 -- MATLAB names, deliberately
53
+ endT: Any # noqa: N815
54
+ intar_threshold_spirals: Any
55
+ source: str = ""
56
+
57
+ def __post_init__(self) -> None:
58
+ arrays = [np.asarray(a, dtype=np.float64).reshape(-1)
59
+ for a in (self.startT, self.endT, self.intar_threshold_spirals)]
60
+ if not (arrays[0].size == arrays[1].size == arrays[2].size):
61
+ raise ValueError("startT, endT and intar_threshold_spirals must have one entry "
62
+ "per spiral each")
63
+ if arrays[0].size == 0:
64
+ raise ValueError("PECAN parameters with no spirals: refused rather than read as "
65
+ "'no spiral', which would silently apply defaultIntArrThresh "
66
+ "to every second")
67
+ if not all(np.isfinite(a).all() for a in arrays):
68
+ raise ValueError("PECAN parameters must be finite numbers")
69
+ if (arrays[2] < 0).any():
70
+ raise ValueError("intar_threshold_s is a time in seconds and cannot be negative")
71
+ object.__setattr__(self, "startT", arrays[0])
72
+ object.__setattr__(self, "endT", arrays[1])
73
+ object.__setattr__(self, "intar_threshold_spirals", arrays[2])
74
+
75
+
76
+ def _ddate_key(ddate: Any) -> str:
77
+ """``YYYYMMDD`` from ``ddate`` (``'YYYYMMDD'`` or the driver's ``'YYYYMMDD HHMMSS'``)."""
78
+ return str(ddate).strip()[:8]
79
+
80
+
81
+ def load_pecan_params(path: str | PathLike[str], *, ddate: Any = None,
82
+ probename: str | None = None) -> PecanParams:
83
+ """Read the CSV described in the module docstring, filtered to ``ddate``/``probename``
84
+ where the file carries ``date``/``probe`` columns."""
85
+ p = Path(path)
86
+ with p.open(newline="", encoding="utf-8") as fh:
87
+ lines = [ln for ln in fh if ln.strip() and not ln.lstrip().startswith("#")]
88
+ reader = csv.DictReader(lines)
89
+ fields = [f.strip() for f in (reader.fieldnames or [])]
90
+ missing = [c for c in _REQUIRED if c not in fields]
91
+ if missing:
92
+ raise ValueError(f"{p}: PECAN parameter file lacks column(s) {missing}; "
93
+ f"required: {list(_REQUIRED)}")
94
+ rows = []
95
+ for row in reader:
96
+ row = {k.strip(): (v or "").strip() for k, v in row.items() if k is not None}
97
+ if "date" in row and ddate is not None and row["date"] != _ddate_key(ddate):
98
+ continue
99
+ if "probe" in row and probename is not None and row["probe"] != probename:
100
+ continue
101
+ rows.append(row)
102
+ if not rows:
103
+ raise ValueError(f"{p}: no PECAN spiral rows for date={_ddate_key(ddate)!r} "
104
+ f"probe={probename!r}")
105
+ try:
106
+ cols = [[float(r[c]) for r in rows] for c in _REQUIRED]
107
+ except ValueError as exc:
108
+ raise ValueError(f"{p}: a PECAN parameter is not a number ({exc})") from None
109
+ if not all(math.isfinite(v) for col in cols for v in col):
110
+ raise ValueError(f"{p}: PECAN parameters must be finite numbers")
111
+ return PecanParams(cols[0], cols[1], cols[2], source=str(p))
112
+
113
+
114
+ def resolve_pecan_params(value: Any, *, ddate: Any, probename: str | None) -> PecanParams:
115
+ """A :class:`PecanParams` from a path or an existing record."""
116
+ if isinstance(value, PecanParams):
117
+ return value
118
+ if isinstance(value, (str, PathLike)):
119
+ return load_pecan_params(value, ddate=ddate, probename=probename)
120
+ raise TypeError(f"pecan_params is a path to a parameter file or a PecanParams; "
121
+ f"got {type(value).__name__}")
122
+
123
+
124
+ def pecan_intar_threshold(tas_time: Any, params: PecanParams,
125
+ default_int_arr_thresh: float) -> np.ndarray:
126
+ """``intar_threshold`` exactly as ``sizeDist.m``'s PECAN loop builds it: the default every
127
+ second, then each spiral in file order overwriting the seconds in ``[startT, endT)``, so
128
+ where spirals overlap the later one wins, as the inner loop's last assignment does."""
129
+ tas_time = np.asarray(tas_time, dtype=np.float64).reshape(-1)
130
+ out = np.ones(tas_time.shape) * default_int_arr_thresh
131
+ for s, e, t in zip(params.startT, params.endT, params.intar_threshold_spirals,
132
+ strict=True):
133
+ out[(tas_time >= s) & (tas_time < e)] = t
134
+ return out
@@ -0,0 +1,298 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Registered probe cases: a bin ladder v3.5's own ``switch`` does not have.
3
+
4
+ **Why this exists.** ``sizeDist.m``'s ``switch projectname`` / ``switch probename``
5
+ is a closed set of literal cases. A campaign upstream never wrote a case for
6
+ falls to ``otherwise``, and on v3.5 the ``otherwise``/``'2DS'`` case carries the
7
+ **HVPS** ladder (``UIOPS-v3.5/joefinlon-UIOPS-039be82/sizeDist.m:497-505``:
8
+ 28 bins, first edge 0.2 mm, headed by the comment ``% For the HVPS``), with the
9
+ 10 um ladder commented out below it. v3.1.4's same block
10
+ (``UIOPS-v3.1.4/joefinlon-UIOPS-ba5e67c/sizeDist.m:365-376``) has the comment
11
+ markers the other way round. A 2D-S resolves 10-1280 um, so on v3.5 an
12
+ unlisted campaign's 2D-S size distribution is empty: measured on ARM ACE-ENA
13
+ 2017-07-07, summed ``Size Distribution cm-3`` is **11168.6** on v3.1.4 against
14
+ **0.0100** on v3.5, same raw bytes.
15
+
16
+
17
+ **That behaviour is faithful and is not fixed here.** :data:`V35_TABLES` and
18
+ :data:`V314_TABLES` are untouched; ``probe_defaults()`` keeps returning v3.5's
19
+ 28-bin table for ``(unlisted campaign, '2DS')`` for ever. What this module adds
20
+ is the thing upstream's switch has no room for: a **named** case a run may
21
+ select *instead of* the switch, so this package can process a campaign upstream
22
+ never wrote a case for.
23
+
24
+ **Opt-in, default-off.** A run that names no case never touches this registry:
25
+ :func:`arrayprobe_uiops.sizedist.run` resolves through ``probe_defaults()``
26
+ exactly as before, bit for bit
27
+ (``tests/test_v35_probe_cases.py::TestDefaultIsBitIdentical``).
28
+
29
+ **Selection is by name; description is from Python**. A bin
30
+ ladder is a set of constants, exactly like a threshold, so a config file or a
31
+ ``--probe-case`` argument may *select* a registered case and may never describe
32
+ one. Registration is a Python call, the same rule and the same mechanism as
33
+ :func:`arrayprobe.profiles.register_profile`.
34
+
35
+ **Every field must cite a vendored file:line.** :class:`ProbeCase` refuses to
36
+ be built unless :data:`ProbeDefaults`' every field is accounted for in
37
+ ``citations`` -- see :class:`UncitedProbeCaseField`. A constant nobody can cite
38
+ is an invented constant, which this project's fidelity doctrine forbids
39
+ (never invent a fact to fill a gap).
40
+
41
+ **A registered name does not survive a re-exec.** A ``--jobs`` worker
42
+ (``scripts/run_flight.py``) is a *fresh* subprocess that re-imports this module
43
+ and starts with an empty registry, so ``--probe-case NAME`` alone resolves
44
+ nowhere there -- the identical gap
45
+ a profile registered through ``PROFILE_MODULE`` has, and
46
+ it takes the identical answer: a module whose import registers the case
47
+ (:mod:`arrayprobe_uiops.register_arm_ena_2ds`), named by
48
+ ``--probe-case-module`` and forwarded to every worker.
49
+ """
50
+
51
+ from __future__ import annotations
52
+
53
+ import dataclasses
54
+ from collections.abc import Mapping
55
+ from types import MappingProxyType
56
+
57
+ from arrayprobe_uiops.sizedist_tables import OTHERWISE, V35_TABLES, ProbeDefaults
58
+
59
+ __all__ = [
60
+ "ProbeCase",
61
+ "UnknownProbeCase",
62
+ "UncitedProbeCaseField",
63
+ "DuplicateProbeCase",
64
+ "PROBE_CASES",
65
+ "register_probe_case",
66
+ "resolve_probe_case",
67
+ "register_v35_2ds_ladder_fix", "resolve_shipped_probe_case",
68
+ "V35_2DS_LADDER_FIX",
69
+ "REQUIRED_IA_THRESH_TYPE",
70
+ "require_ia_thresh_type",
71
+ "ACCEPTED_IA_THRESH_TYPES",
72
+ "accept_ia_thresh_types",
73
+ ]
74
+
75
+
76
+ class UnknownProbeCase(LookupError):
77
+ """``--probe-case NAME`` named a case nothing has registered in this process."""
78
+
79
+
80
+ class UncitedProbeCaseField(ValueError):
81
+ """A :class:`ProbeCase` left one of :class:`ProbeDefaults`' fields uncited.
82
+
83
+ Not a style rule: the whole warrant for a case that upstream's ``switch``
84
+ does not contain is that every constant in it was **read out of a vendored
85
+ tree**, not chosen. An uncited field is an invented one.
86
+ """
87
+
88
+
89
+ class DuplicateProbeCase(ValueError):
90
+ """Two different cases registered under one name.
91
+
92
+ Re-registering the *same* case is a no-op -- importing a registration
93
+ module twice must not explode -- but a second, different case under a name
94
+ already taken would make ``--probe-case NAME`` mean whichever import ran
95
+ last, which is the silent-wrong-output shape this project treats as serious.
96
+ """
97
+
98
+
99
+ @dataclasses.dataclass(frozen=True)
100
+ class ProbeCase:
101
+ """A named ``(num_bins, kk, and the eleven constants beside them)`` bundle.
102
+
103
+ ``defaults`` is a plain :class:`ProbeDefaults` -- the same record
104
+ ``probe_defaults()`` returns -- so a case reaches ``sizeDist``'s body
105
+ through the identical path a stock case does and changes no code beyond the
106
+ lookup.
107
+ """
108
+
109
+ name: str
110
+ description: str
111
+ defaults: ProbeDefaults
112
+ citations: Mapping[str, str]
113
+
114
+ def __post_init__(self) -> None:
115
+ fields = set(ProbeDefaults.__dataclass_fields__)
116
+ missing = sorted(fields - set(self.citations))
117
+ if missing:
118
+ raise UncitedProbeCaseField(
119
+ f"probe case {self.name!r} cites no vendored file:line for "
120
+ f"{missing}; every field of ProbeDefaults must name the line it "
121
+ "was read from (arrayprobe_uiops/probe_cases.py's module docstring)"
122
+ )
123
+ extra = sorted(set(self.citations) - fields)
124
+ if extra:
125
+ raise UncitedProbeCaseField(
126
+ f"probe case {self.name!r} cites {extra}, which is not a field of "
127
+ "ProbeDefaults"
128
+ )
129
+ object.__setattr__(self, "citations", MappingProxyType(dict(self.citations)))
130
+
131
+
132
+ _REGISTRY: dict[str, ProbeCase] = {}
133
+
134
+ #: Read-only view of what this process has registered. Empty in a fresh
135
+ #: process -- see the module docstring on ``--probe-case-module``.
136
+ PROBE_CASES: Mapping[str, ProbeCase] = MappingProxyType(_REGISTRY)
137
+
138
+
139
+ def register_probe_case(case: ProbeCase) -> ProbeCase:
140
+ """Add ``case`` to this process's registry and return it.
141
+
142
+ Idempotent for an identical case (so a registration module may be imported
143
+ twice); raises :class:`DuplicateProbeCase` for a different one.
144
+ """
145
+ existing = _REGISTRY.get(case.name)
146
+ if existing is not None and (
147
+ existing.defaults != case.defaults or existing.description != case.description
148
+ ):
149
+ raise DuplicateProbeCase(
150
+ f"probe case {case.name!r} is already registered with different "
151
+ "contents; pick another name rather than shadowing it"
152
+ )
153
+ _REGISTRY[case.name] = case
154
+ return case
155
+
156
+
157
+ def resolve_probe_case(name: str) -> ProbeCase:
158
+ """The registered case ``name``, or :class:`UnknownProbeCase`."""
159
+ try:
160
+ return _REGISTRY[name]
161
+ except KeyError:
162
+ raise UnknownProbeCase(
163
+ f"no probe case {name!r} is registered in this process. Registered: "
164
+ f"{sorted(_REGISTRY)}. A case is registered by importing the module "
165
+ "that calls register_probe_case() -- a name alone does not survive a "
166
+ "fresh process (arrayprobe_uiops/probe_cases.py's module docstring)."
167
+ ) from None
168
+
169
+
170
+ # ---------------------------------------------------------------------------
171
+ # The general 2D-S ladder: v3.5's otherwise/'2DS' constants on v3.1.4's ladder.
172
+ # ---------------------------------------------------------------------------
173
+
174
+ _V314_SIZEDIST = "UIOPS-v3.1.4/joefinlon-UIOPS-ba5e67c/sizeDist.m"
175
+ _V35_SIZEDIST = "UIOPS-v3.5/joefinlon-UIOPS-039be82/sizeDist.m"
176
+
177
+ #: Where every field of the 2D-S ladder case's defaults was read from -- shared by
178
+ #: :data:`V35_2DS_LADDER_FIX` and :data:`ARM_ENA_2DS`, whose defaults are identical.
179
+ #:
180
+ #: The case is v3.5's own ``otherwise``/``'2DS'`` record with ``num_bins`` and
181
+ #: ``bins`` taken from v3.1.4's same block -- the only two fields on which the
182
+ #: two releases' ``otherwise``/``'2DS'`` cases differ at all (measured:
183
+ #: ``tests/test_v35_probe_cases.py::TestArmEnaCase``,
184
+ #: ``test_it_differs_from_stock_v35_in_exactly_two_fields``).
185
+ #: So eleven fields cite v3.5, and the two that name the ladder cite v3.1.4.
186
+ _V35_2DS_LADDER_CITATIONS = {
187
+ "num_diodes": f"{_V35_SIZEDIST}:499 -- num_diodes = 128",
188
+ "diodesize": f"{_V35_SIZEDIST}:500 -- diodesize = .010",
189
+ "armdst": f"{_V35_SIZEDIST}:501 -- armdst = 63.",
190
+ "num_bins": f"{_V314_SIZEDIST}:374 -- num_bins = 128 (v3.5's :502 is the HVPS 28)",
191
+ "bins": (
192
+ f"{_V314_SIZEDIST}:376 -- kk = diodesize/2:diodesize:(num_bins+0.6)*diodesize "
193
+ f"(the identical line is commented out at {_V35_SIZEDIST}:507)"
194
+ ),
195
+ "probetype": f"{_V35_SIZEDIST}:508 -- probetype = 2",
196
+ "tasMax": f"{_V35_SIZEDIST}:509 -- tasMax = 170",
197
+ "applyIntArrThresh": f"{_V35_SIZEDIST}:514 -- applyIntArrThresh = 0",
198
+ "defaultIntArrThresh": f"{_V35_SIZEDIST}:515 -- defaultIntArrThresh = 4e-6",
199
+ "reaccptShatrs": f"{_V35_SIZEDIST}:516 -- reaccptShatrs = 0",
200
+ "reaccptD": f"{_V35_SIZEDIST}:517 -- reaccptD = 0.5",
201
+ "reaccptMaxIA": f"{_V35_SIZEDIST}:518 -- reaccptMaxIA = 1e-6",
202
+ "intar_threshold_defaulted": (
203
+ f"{_V35_SIZEDIST}:520 -- intar_threshold = ones(size(tas_time))*defaultIntArrThresh"
204
+ ),
205
+ "calls_getPECANparams": (
206
+ f"{_V35_SIZEDIST}:497-520 -- the otherwise/'2DS' case calls getPECANparams() nowhere"
207
+ ),
208
+ }
209
+
210
+
211
+ def _v35_2ds_ladder_defaults() -> ProbeDefaults:
212
+ """v3.5's own ``otherwise``/``'2DS'`` record with ``num_bins`` and ``bins`` from v3.1.4's.
213
+
214
+ Read from the two vendored tables only (:data:`_V35_2DS_LADDER_CITATIONS`), so the general
215
+ correction depends on no campaign case."""
216
+ from arrayprobe_uiops.sizedist_tables import V314_TABLES
217
+
218
+ stock = V35_TABLES[OTHERWISE]["2DS"]
219
+ v314 = V314_TABLES[OTHERWISE]["2DS"]
220
+ return dataclasses.replace(stock, num_bins=v314.num_bins, bins=v314.bins)
221
+
222
+
223
+ #: ``v35-2ds-ladder-fix``: the swapped-bin-table correction (default on). Built by
224
+ #: :func:`register_v35_2ds_ladder_fix`; ``None`` until then.
225
+ V35_2DS_LADDER_FIX: ProbeCase | None = None
226
+
227
+
228
+ def register_v35_2ds_ladder_fix() -> ProbeCase:
229
+ """Build, register and return ``v35-2ds-ladder-fix`` (swapped-bin-table fix).
230
+
231
+ v3.5's ``otherwise``/``'2DS'`` case with the 2D-S 128-bin ladder that upstream left
232
+ commented out at ``sizeDist.m:506-507`` in place of the HVPS table at ``:502-505``: v3.5's
233
+ own constants and v3.1.4's ``:374``/``:376`` ladder, which is the commented-out line, built
234
+ directly from the two vendored tables (:func:`_v35_2ds_ladder_defaults`). It registers no
235
+ other case. A campaign case built on the same record sizes identically to the batch
236
+ driver's default-on bin-table correction; this is a separate name so a stamp names the
237
+ correction, not a campaign."""
238
+ global V35_2DS_LADDER_FIX
239
+ V35_2DS_LADDER_FIX = register_probe_case(
240
+ ProbeCase(
241
+ name="v35-2ds-ladder-fix",
242
+ description=(
243
+ "Swapped-bin-table correction: a 2D-S on v3.5's otherwise branch is sized "
244
+ "on the 2D-S 128-bin "
245
+ "10 um ladder upstream commented out at sizeDist.m:506-507, not the HVPS 28-bin "
246
+ "0.2-30 mm table at :502-505. Default on in the batch driver on engine 3.5."
247
+ ),
248
+ defaults=_v35_2ds_ladder_defaults(),
249
+ citations=dict(_V35_2DS_LADDER_CITATIONS),
250
+ )
251
+ )
252
+ return V35_2DS_LADDER_FIX
253
+
254
+
255
+ def resolve_shipped_probe_case(name: str) -> ProbeCase:
256
+ """:func:`resolve_probe_case`, registering a case every install carries on first use.
257
+
258
+ ``v35-2ds-ladder-fix`` ships with the package, so a name quoted anywhere (``--probe-case``,
259
+ a run TOML's ``probe_case``, ``tune settings``) resolves in a fresh process without a
260
+ ``--probe-case-module``. The one helper behind the batch driver's preflight and
261
+ :func:`arrayprobe.tune.settings.resolve_probe_defaults`; any other unregistered name is
262
+ refused exactly as :func:`resolve_probe_case` refuses it."""
263
+ if name == "v35-2ds-ladder-fix" and name not in _REGISTRY:
264
+ register_v35_2ds_ladder_fix()
265
+ return resolve_probe_case(name)
266
+
267
+
268
+ #: The ``iaThreshType`` a case needs before its shattering constants act at all. Under
269
+ #: iaThreshType 0 (the driver's plain call with no threshold file) ``sizeDist`` runs no
270
+ #: shattering block, so a gate-on case's gate would silently do nothing and the run would
271
+ #: write the gate-off numbers under the gate-on name. ``scripts/run_flight.py`` refuses such a
272
+ #: run; type 2 is selected by ``[shattering].ia_thresh_type = 2`` in the run's config
273
+ #: (``sizeDist.m:520`` in ``UIOPS-v3.5/joefinlon-UIOPS-039be82/``, the per-second default).
274
+ _REQUIRED_IA_THRESH_TYPE: dict[str, int] = {}
275
+ REQUIRED_IA_THRESH_TYPE: Mapping[str, int] = MappingProxyType(_REQUIRED_IA_THRESH_TYPE)
276
+
277
+
278
+ def require_ia_thresh_type(name: str, ia_thresh_type: int) -> None:
279
+ """Record that registered case ``name`` acts only under ``ia_thresh_type``.
280
+
281
+ Called by the module that registers such a case, beside its
282
+ :func:`register_probe_case` call, so the requirement exists wherever the case does."""
283
+ _REQUIRED_IA_THRESH_TYPE[name] = ia_thresh_type
284
+
285
+
286
+ #: The ``iaThreshType`` values under which a case's shattering constants act, for a case that
287
+ #: accepts more than one (for example 1, a ``--iat-file`` threshold file, ``sizeDist.m:1213``,
288
+ #: and 2, its own ``defaultIntArrThresh``, ``:1308``, never 0). Filled by
289
+ #: :func:`accept_ia_thresh_types` beside the case's :func:`register_probe_case` call;
290
+ #: ``scripts/run_flight.py`` refuses a run outside the set, as it does for
291
+ #: :data:`REQUIRED_IA_THRESH_TYPE`.
292
+ _ACCEPTED_IA_THRESH_TYPES: dict[str, frozenset[int]] = {}
293
+ ACCEPTED_IA_THRESH_TYPES: Mapping[str, frozenset[int]] = MappingProxyType(_ACCEPTED_IA_THRESH_TYPES)
294
+
295
+
296
+ def accept_ia_thresh_types(name: str, ia_thresh_types: frozenset[int]) -> None:
297
+ """Record that registered case ``name`` acts under each of ``ia_thresh_types`` and no other."""
298
+ _ACCEPTED_IA_THRESH_TYPES[name] = frozenset(ia_thresh_types)