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,4 @@
1
+ arrayprobe
2
+ arrayprobe_soda2
3
+ arrayprobe_uiops
4
+ uiops
@@ -0,0 +1,131 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ # Reproduces SODA-2, Copyright (c) 2016 UCAR; see LICENSES/BSD-3-Clause.txt and NOTICE.md.
3
+ """arrayprobe_soda2 -- a from-source Python port of SODA-2's OAP processing.
4
+
5
+ Scaffolded 2026-09-10 (author-directed) as V0 of a third, separate
6
+ package alongside the v3.1.4 port (``arrayprobe``) and the v3.5 port
7
+ (``arrayprobe_uiops``), touching neither. SODA-2 (NCAR/MMM, Aaron Bansemer,
8
+ ``github.com/abansemer/soda2``) is a from-scratch IDL implementation of a
9
+ different OAP processing method, not a UIOOPS derivative -- so this is a
10
+ faithful *reimplementation* of SODA-2's own algorithm, the same discipline
11
+ the v3.1.4/v3.5 ports apply to UIOOPS, not an adaptation of anything already
12
+ in this repository.
13
+
14
+ **Citation.** Cite SODA-2, as its author asks, for anything computed here:
15
+ Aaron Bansemer. (2026). abansemer/soda2: v2.26.0 (Version v2.26.0) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.18331418
16
+
17
+ **Licence, read directly rather than inferred from GitHub's badge** (which
18
+ shows ``NOASSERTION``): ``LICENSE.txt`` in the vendored source is a
19
+ 3-clause BSD licence (UCAR, 2016). This reproduction is distributed under
20
+ the same licence (LICENSES/BSD-3-Clause.txt), with the UCAR notice and
21
+ conditions kept. Nothing about the licence blocks porting
22
+ or incorporating SODA-2's logic.
23
+
24
+
25
+
26
+
27
+ Modules shipping here: ``sample_area`` (doctrine layer 3 -- no GDL bank),
28
+ the GDL-validated ``angles``, ``find_radius``, ``princomp``, ``reject`` and
29
+ ``findsize`` (the sizing and rejection core), the SPEC
30
+ buffer-decode leaves, ``spec_decompress`` and ``spec_readint``, the
31
+ `spec_read_frame`, which composes them, `spec_read_hk`, the 53-word
32
+ housekeeping record, P-b's `spec_index` and `spec_absolutepointers`,
33
+ the buffer walk that produces the pointers all of them consume, and
34
+ P-c/P-d's `processbuffer_spec`, the SPEC branch of
35
+ `soda2_processbuffer.pro` (`:264-376`), and `poisson_spot_correct`, the
36
+ first leaf of its shared tail; the rest of the tail (`:612-747`) and the
37
+ driver remain unported. The stage table in the design record is
38
+ authoritative; this list is a map.
39
+
40
+ `binary_dof` and `fillholes`, two more leaves of the
41
+ shared tail (`:612-747`); `processbuffer_spec` now honours `dofreject == 3`.
42
+
43
+ `fixstuckbits` and `label_blobs`, two more tail leaves
44
+ (`:615`/`:687-689`). `soda2_backfill` (2DC only, `:678`) is ported in
45
+ `backfill`, GDL-matched (`tests/test_soda2_backfill_gdl.py`).
46
+
47
+ Round 5 (lane 6-B): `particlesort` (`soda2_particlesort.pro:1-171`, the
48
+ per-second accumulation) and `fit_poisson` (its
49
+ shattering-correction fit; no GDL oracle, since GDL 1.1.2 has no `LMFIT`
50
+ -- a documented substitute, see the module docstring).
51
+ Round 6, lane B (R6B) added the driver's SPEC pre-loop --
52
+ `timeconv` (`hms2sfm`, `soda2_parsedate`), `read2dbuffer`
53
+ (`read2dbuffer_spec`), `buildindex`, `update_op`, and `process_hk`
54
+ (`spec_process_hk`, both versions, and `spec_index_hk`). `buildindex`
55
+ covers the generic walk (`buildindex_generic`) and `read2dbuffer` the SPEC,
56
+ SEA (CIP) and DMT formats. Still refused by name: the model `.txt` header
57
+ parse (`soda2_update_op.pro:55-84`, `update_op.py`), the legacy SEA probes
58
+ (`soda2_read2dbuffer.pro:77-82`) and the remaining formats (T28, HVPS1995).
59
+
60
+ Round 6-A: `processbuffer_tail`, the shared per-particle tail of
61
+ `soda2_processbuffer.pro` (`:612-747`), SPEC path -- `soda2_processbuffer`
62
+ (in `processbuffer_spec.py`) now runs the whole function end to end for
63
+ SPEC, composing `process_spec_buffer` with `process_buffer_tail`.
64
+
65
+ Round 7-A (lane A): `process_2d` -- `soda2_process_2d.pro`, SPEC path,
66
+ raw bytes to the in-memory `data` struct end to end (`soda2_process_2d`).
67
+ Composes every module above with `sample_area` and `particlesort`.
68
+ Findings S6-a..S6-d.
69
+
70
+ Since then (rounds 7-B to 11 and Y1/Y1s, 2026-09-14): `pbp_writer`, the
71
+ `.pbp.csv` and `.pbp.nc` per-particle writers, GDL-checked and wired into
72
+ `process_2d` (`particlefile`, `ncdfparticlefile` 1); `export_ascii`, the
73
+ ASCII size-distribution export (`soda2_export_ascii.pro`, `asciipsdfile`);
74
+ the `dat`/`sav` PTH readers; and the CLI, `arrayprobe soda2 run <config>`,
75
+ which writes a `.pbp.call` sidecar.
76
+
77
+ Port lanes (2026-09-15): `save_writer`, the IDL SAVE file (`:729-731`,
78
+ `savfile`) written as `<outdir>/<date>_<hhmmss>_<shortname>[_<probeid>].dat`;
79
+ `pth_readers`, the ASCII/CSV and netCDF PTH formats (`:147-172`), wired
80
+ into `process_2d`; `probespecs`; `enhancement_hooks`, the named hook
81
+ points the SODA-2 enhancements adapter substitutes; `reprocess_pbp`,
82
+ the reprocess-from-PBP path (`:30-35,584-617`, `spec_newtime.pro`,
83
+ `soda2_restore_pbp.pro`), reached through `soda2_process_2d(op, fn_pbp=...)`.
84
+ Particle-image output (`ncdfparticlefile` 2, `:286-306`, `:546-553`) is
85
+ written on the serial driver (`pbp_writer`); it is refused by name only on
86
+ the parallel driver (`soda2_process_2d` with `jobs > 1`) and for a flush
87
+ chunk under two slices (`write_pbp_ncdf_images`), whose IDL behaviour is
88
+ unmeasured.
89
+ """
90
+
91
+ import logging
92
+
93
+ # NullHandler by default, matching ``arrayprobe``'s
94
+ # own package logger -- importing this package must never print anything;
95
+ # ``arrayprobe.cli`` attaches the real handler for the console script.
96
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
97
+
98
+ __all__: list[str] = [
99
+ "angles",
100
+ "aspect_ratio",
101
+ "binary_dof",
102
+ "buildindex",
103
+ "find_radius",
104
+ "findsize",
105
+ "fillholes",
106
+ "fixraking",
107
+ "fixstuckbits",
108
+ "label_blobs",
109
+ "min_circle_fast",
110
+ "poisson_spot_correct",
111
+ "fit_poisson",
112
+ "particlesort",
113
+ "princomp",
114
+ "process_2d",
115
+ "process_hk",
116
+ "processbuffer_spec",
117
+ "read2dbuffer",
118
+ "processbuffer_tail",
119
+ "reject",
120
+ "sample_area",
121
+ "spec_absolutepointers",
122
+ "spec_decompress",
123
+ "spec_index",
124
+ "spec_read_frame",
125
+ "spec_read_hk",
126
+ "spec_readint",
127
+ "timeconv",
128
+ "update_op",
129
+ ]
130
+
131
+ __version__ = "0.1.0" # the distribution's version; tests/test_version.py
@@ -0,0 +1,143 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ # Reproduces SODA-2, Copyright (c) 2016 UCAR; see LICENSES/BSD-3-Clause.txt and NOTICE.md.
3
+ """``find_angle.pro`` and ``find_angle_array.pro`` -- SODA-2's two angle routines.
4
+
5
+ Both return the angle at vertex ``p1``. They are the leaves of the
6
+ geometry chain: ``min_circle_fast`` calls both, on every iteration of its search.
7
+
8
+ **They use different formulas, and that is not cosmetic.**
9
+
10
+ =================== ==========================================================
11
+ ``find_angle`` ``acos( B.C / sqrt(|B|^2 |C|^2) )`` dot product
12
+ ``find_angle_array`` ``acos( (b2+c2-a2) / (2 sqrt(b2 c2)) )`` law of cosines
13
+ =================== ==========================================================
14
+
15
+ Algebraically the same; numerically not. Measured over 200,000 random triangles
16
+ they disagree in **56 % of cases**, by up to **8.3e-10 rad** — and the GDL golden
17
+ carries a triangle where the real IDL shows it (``3.14159185086`` against
18
+ ``3.14159185003``).
19
+
20
+ **This matters because `min_circle_fast` mixes them.** It takes ``angR`` from
21
+ ``find_angle_array`` and ``angQ`` from ``find_angle``, then computes the third
22
+ angle as ``angP = !pi - angR - angQ`` — never directly. So the two formulas'
23
+ disagreement lands in ``angP``, which is then compared against ``!pi/2`` to
24
+ decide whether to keep iterating. On a near-right vertex that comparison can go
25
+ either way, and the port must inherit the same arithmetic to inherit the same
26
+ decision. Reproducing this pair with one shared helper would be a "tidy-up" that
27
+ silently changes which circle SODA-2 returns.
28
+
29
+ **Two degeneracies, both reproduced rather than guarded.**
30
+
31
+ * Coincident points make the denominator zero, so the argument is ``0/0`` and
32
+ ``acos`` yields NaN. Measured under GDL for ``p2 == p1``, ``p3 == p1``, and all
33
+ three equal.
34
+ * **A thin angle is lost entirely.** For ``p1=(0,0)``, ``p2=(1,0)``,
35
+ ``p3=(1,1e-9)`` the true angle is about ``1e-9`` rad, and both routines return
36
+ **exactly 0** — the cosine rounds to 1.0 and ``acos(1.0)`` is 0. This is
37
+ inherent to an ``acos`` formulation: it cannot resolve angles below roughly
38
+ ``1.5e-8`` rad. It is not a defect introduced by either formula, and it is
39
+ reproduced because SODA-2's answers depend on it.
40
+
41
+ **`find_angle_array` halts on a non-double input.**
42
+ ``IF typename(x1) ne 'DOUBLE' THEN stop, 'find_angle_array.pro needs double
43
+ floating point values.'`` — ``stop`` drops IDL to its prompt, which ends a batch
44
+ run. Reproduced as a raise, for the same reason ``princomp``'s length check is:
45
+ the original produces no value on that path.
46
+
47
+ Provenance: ``SODA2/abansemer-soda2-afcea15/find_angle.pro`` (8 lines) and
48
+ ``find_angle_array.pro`` (24 lines), both whole-file. Validated against GDL by
49
+ ``tests/test_soda2_angles.py``.
50
+ """
51
+ from __future__ import annotations
52
+
53
+ import numpy as np
54
+ from numpy.typing import ArrayLike
55
+
56
+ __all__ = ["NotDoublePrecision", "find_angle", "find_angle_array"]
57
+
58
+
59
+ class NotDoublePrecision(RuntimeError):
60
+ """``find_angle_array.pro``'s own type guard reached. It ``stop``s rather
61
+ than returning, so there is no value for the port to produce."""
62
+
63
+
64
+ def find_angle(p1: ArrayLike, p2: ArrayLike, p3: ArrayLike) -> float:
65
+ """``find_angle(p1, p2, p3)`` -- the angle at ``p1``, by the dot product.
66
+
67
+ Source: ``find_angle.pro`` (SODA-2).
68
+
69
+ ``p1``/``p2``/``p3`` are 2-element ``[x, y]``. NaN for coincident points;
70
+ exactly 0 for an angle too thin for ``acos`` to resolve. See the module
71
+ docstring — do not substitute :func:`find_angle_array` here.
72
+ """
73
+ a = np.asarray(p1, dtype=np.float64).ravel()
74
+ b = np.asarray(p2, dtype=np.float64).ravel() - a
75
+ c = np.asarray(p3, dtype=np.float64).ravel() - a
76
+ with np.errstate(invalid="ignore", divide="ignore"):
77
+ arg = (b * c).sum() / np.sqrt((b ** 2).sum() * (c ** 2).sum())
78
+ return float(np.arccos(arg))
79
+
80
+
81
+ def find_angle_f32(p1: ArrayLike, p2: ArrayLike, p3: ArrayLike) -> np.float32:
82
+ """``find_angle.pro`` evaluated in IDL FLOAT, as ``aspect_ratio.pro:35-37``
83
+ calls it: the points are ``[x_ind, y_ind*tas_adjust]`` literals (LONG with
84
+ FLOAT promotes to FLOAT), so every intermediate -- the differences, the
85
+ two-element ``total``s, the ``sqrt`` -- is float32 and ``acos`` is the
86
+ correctly rounded FLOAT kernel (computed in float64, rounded once).
87
+ Measured under GDL (a GDL probe script, 2026-10-04): on
88
+ x=[109,101,105], y=[10,99,54] this gives angP = angQ = 0.0009765625 and
89
+ angR = 3.139579534531, where :func:`find_angle` (float64) gives a strict
90
+ minimum at Q. ``min_circle_fast`` keeps :func:`find_angle` (DOUBLE)."""
91
+ from arrayprobe_soda2.process_hk import f32_via_f64
92
+
93
+ a = np.asarray(p1, dtype=np.float32).ravel()
94
+ b = np.asarray(p2, dtype=np.float32).ravel() - a
95
+ c = np.asarray(p3, dtype=np.float32).ravel() - a
96
+ with np.errstate(invalid="ignore", divide="ignore"):
97
+ dot = np.float32(0)
98
+ bb = np.float32(0)
99
+ cc = np.float32(0)
100
+ for i in range(b.size): # IDL total: sequential FLOAT accumulation
101
+ dot = np.float32(dot + b[i] * c[i])
102
+ bb = np.float32(bb + b[i] * b[i])
103
+ cc = np.float32(cc + c[i] * c[i])
104
+ arg = np.float32(dot / np.sqrt(np.float32(bb * cc)))
105
+ return np.float32(f32_via_f64(np.arccos, arg))
106
+
107
+
108
+ def find_angle_array(
109
+ x1: ArrayLike, y1: ArrayLike, x2: ArrayLike, y2: ArrayLike,
110
+ x3: ArrayLike, y3: ArrayLike,
111
+ ) -> float | np.ndarray:
112
+ """``find_angle_array(x1, y1, x2, y2, x3, y3)`` -- the angle at
113
+ ``(x1, y1)``, by the law of cosines. ``x1``/``y1`` may be arrays.
114
+
115
+ Source: ``find_angle_array.pro`` (SODA-2).
116
+
117
+ Raises :class:`NotDoublePrecision` for a non-floating input, reproducing the
118
+ source's own ``typename(x1) ne 'DOUBLE'`` guard. Integer input is refused
119
+ rather than silently promoted: IDL would have halted, and promoting it here
120
+ would answer a question the original refuses to answer.
121
+ """
122
+ x1a = np.asarray(x1)
123
+ if x1a.dtype.kind != "f":
124
+ raise NotDoublePrecision(
125
+ "find_angle_array.pro needs double floating point values; it calls "
126
+ f"stop for anything else, and x1 is {x1a.dtype!s}")
127
+ x1a = x1a.astype(np.float64)
128
+ y1a = np.asarray(y1, dtype=np.float64)
129
+ x2a = np.asarray(x2, dtype=np.float64)
130
+ y2a = np.asarray(y2, dtype=np.float64)
131
+ x3a = np.asarray(x3, dtype=np.float64)
132
+ y3a = np.asarray(y3, dtype=np.float64)
133
+
134
+ dx1, dy1 = x2a - x3a, y2a - y3a # side opposite the vertex
135
+ dx2, dy2 = x1a - x2a, y1a - y2a
136
+ dx3, dy3 = x1a - x3a, y1a - y3a
137
+ b2 = dx2 ** 2 + dy2 ** 2
138
+ c2 = dx3 ** 2 + dy3 ** 2
139
+ a2 = dx1 ** 2 + dy1 ** 2
140
+
141
+ with np.errstate(invalid="ignore", divide="ignore"):
142
+ out = np.arccos((b2 + c2 - a2) / (2 * np.sqrt(b2 * c2)))
143
+ return float(out) if out.ndim == 0 else out