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,127 @@
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
+ """``spec_readint.pro`` -- read ``length`` SPEC integers, skipping buffer
4
+ boundaries transparently.
5
+
6
+ 49 lines of IDL. A SPEC raw file is a sequence of fixed-size buffers
7
+ (default 4114 bytes: an 8-``int16`` header, 4096 bytes of image data, a
8
+ 2-byte footer -- ``headersize=9`` below is this footer-plus-header pair, in
9
+ **words**, not bytes). This routine's whole job is letting a caller ask for
10
+ ``length`` consecutive *data* integers without caring whether that span
11
+ crosses one of those 18-byte dead zones.
12
+
13
+ Provenance: ``SODA2/abansemer-soda2-afcea15/spec_readint.pro`` (whole file),
14
+ Aaron Bansemer, NCAR, 5/2011. Copyright (C) 2016 UCAR, 3-clause BSD.
15
+ Validated against GDL by ``tests/test_soda2_spec_readint.py``; bank at
16
+ ``gdl_oracle/run_soda2_spec_readint_bank.py``. The test also recomputes the
17
+ non-zero cases independently from the tracked fixture's raw bytes with
18
+ ``struct`` -- a third, differently-coded side, never a fixture compared with
19
+ itself.
20
+
21
+ **How many buffer boundaries the requested span crosses decides everything**
22
+ (`:19-23`): ``crossings = (pointer+length*2)//buffsize - pointer//buffsize``.
23
+
24
+ - **0** -- an ordinary contiguous read, no boundary in the way.
25
+ - **1** -- read ``length+9`` words starting at ``pointer`` (spanning straight
26
+ through the dead zone), then splice it out: ``div`` is how many *live*
27
+ words remain before the boundary. `:34`'s two branches are the same
28
+ splice, just written differently when ``div<=0`` (the boundary is at or
29
+ before ``pointer`` itself, so nothing needs keeping from the first side).
30
+ - **2 or more** -- **not implemented upstream.** `:38` prints a message and
31
+ returns ``length + crossings*9`` **zeros** -- not ``length`` zeros, and not
32
+ an error. The file position still advances by the full amount `readu`
33
+ would have consumed (the IDL discards the values with ``x[*]=0`` only
34
+ *after* reading them), so a caller chaining reads stays in sync with the
35
+ file even though this particular read came back meaningless. Finding
36
+ **S4-b**. This port raises no exception either, and reproduces both the
37
+ oversized return and the file-pointer advance; the ``print`` becomes a
38
+ ``warnings.warn`` (a documented divergence -- IDL's original wrote to
39
+ stdout, this cannot, and reproducing a print via a print would be invisible
40
+ to any caller that wanted to know).
41
+
42
+ **The post-read jump** (`:46-47`): after the read, if the pointer lands
43
+ *exactly* on a footer's first byte (``pointer mod buffsize == buffsize-2``),
44
+ the file is advanced a further 18 bytes, over the footer and the next
45
+ buffer's header, so the *next* call starts already inside live data. This
46
+ is why the plan's ``to_footer_exactly`` case (a length chosen so the read
47
+ ends precisely there) reports ``AFTER=4130`` rather than ``4112``.
48
+ """
49
+ from __future__ import annotations
50
+
51
+ import warnings
52
+ from typing import BinaryIO
53
+
54
+ import numpy as np
55
+
56
+ __all__ = ["spec_readint"]
57
+
58
+ #: Words spanning one buffer boundary: a 1-word (2-byte) footer plus an
59
+ #: 8-word (16-byte) header, i.e. 18 bytes -- `:17`, `:47`.
60
+ _HEADERSIZE = 9
61
+
62
+
63
+ def spec_readint(
64
+ f: BinaryIO,
65
+ length: int,
66
+ buffsize: int = 4114,
67
+ signed: bool = False,
68
+ ) -> np.ndarray:
69
+ """``x = spec_readint(lun, length, buffsize=buffsize, signed=signed)``.
70
+
71
+ Source: ``spec_readint.pro`` (SODA-2).
72
+
73
+ ``f`` is an open binary file positioned at the read start (IDL's ``lun``
74
+ plus ``point_lun,-lun,pointer``, here ``f.tell()``/``f.seek()``).
75
+ ``buffsize=0`` bypasses the boundary logic entirely (`:11-16`, the
76
+ 2DSCPIHK-file case, which has no buffer structure to skip).
77
+
78
+ Returns a 1-D array, dtype ``int16`` if ``signed`` else ``uint16``. On a
79
+ 2+-crossing span the array is ``length + crossings*9`` **zeros** --
80
+ longer than ``length`` -- reproducing SODA-2 register entry S4-b rather than raising.
81
+ """
82
+ dtype = np.int16 if signed else np.uint16
83
+ itemsize = 2
84
+
85
+ if buffsize == 0:
86
+ # `:11-16` -- 2DSCPIHK files have no buffer boundaries to skip.
87
+ raw = f.read(length * itemsize)
88
+ return np.frombuffer(raw, dtype=dtype).copy()
89
+
90
+ pointer = f.tell()
91
+ m1 = pointer // buffsize
92
+ m2 = (pointer + length * itemsize) // buffsize
93
+ crossings = m2 - m1
94
+
95
+ if crossings == 0:
96
+ raw = f.read(length * itemsize)
97
+ x = np.frombuffer(raw, dtype=dtype).copy()
98
+ elif crossings == 1:
99
+ total = length + _HEADERSIZE
100
+ raw = f.read(total * itemsize)
101
+ x2 = np.frombuffer(raw, dtype=dtype)
102
+ # `:33` -- live words remaining before the boundary, less one for
103
+ # the footer itself (integer division, matches IDL's `/` on
104
+ # non-negative operands).
105
+ div = (buffsize - (pointer % buffsize)) // 2 - 1
106
+ if div > 0:
107
+ x = np.concatenate([x2[0:div], x2[div + _HEADERSIZE:length + _HEADERSIZE]])
108
+ else:
109
+ x = x2[div + _HEADERSIZE:length + _HEADERSIZE].copy()
110
+ else:
111
+ # `:37-42`, finding S4-b: the file position still advances by the
112
+ # full over-length read; only the returned values are discarded.
113
+ warnings.warn(
114
+ f"spec_readint: frame spans {crossings} buffers, unsupported so far",
115
+ stacklevel=2,
116
+ )
117
+ total = length + crossings * _HEADERSIZE
118
+ f.read(total * itemsize) # advance the file pointer; bytes discarded
119
+ x = np.zeros(total, dtype=dtype)
120
+
121
+ # `:46-47` -- landed exactly on a footer's first byte: skip the footer
122
+ # and the next header so the caller starts already inside live data.
123
+ after = f.tell()
124
+ if (after % buffsize) == (buffsize - 2):
125
+ f.seek(after + _HEADERSIZE * itemsize)
126
+
127
+ return x
@@ -0,0 +1,77 @@
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
+ """The driver's two small time-conversion
4
+ leaves, `hms2sfm.pro` (12 lines) and `soda2_parsedate.pro` (22 lines), ported
5
+ whole -- no round-7 cut in either.
6
+
7
+ Vendored source: `SODA2/abansemer-soda2-afcea15/hms2sfm.pro`,
8
+ `soda2_parsedate.pro`. Bank: `gdl_oracle/run_soda2_preloop_bank.py`, golden
9
+ `tests/data/gdl_soda2_preloop_golden.json`.
10
+ """
11
+ from __future__ import annotations
12
+
13
+ from dataclasses import dataclass
14
+
15
+ import numpy as np
16
+
17
+ from .spec_index import julday
18
+
19
+
20
+ def hms2sfm(hms: float | int | np.floating) -> float:
21
+ """`hms2sfm.pro:6-11`: seconds-from-midnight for an `HHMMSS[.f]`-packed
22
+ time. `long(hms)` truncates toward zero; `fraction = double(hms) -
23
+ long(hms)` widens `hms` to DOUBLE first -- for a FLOAT32 input that
24
+ widening carries float32 rounding error into the DOUBLE result, so a
25
+ `np.float32` argument is widened via `float(np.float32(x))`, never via a
26
+ fresh Python `float(x)` on the original value. The whole expression is
27
+ DOUBLE because `fraction` is DOUBLE (T9: truncation toward zero, so
28
+ `hms2sfm(-1)` truncates to 0, not -1)."""
29
+ if isinstance(hms, np.floating) and hms.dtype == np.float32:
30
+ widened = float(hms) # numpy widens float32 -> python float (== double) faithfully
31
+ else:
32
+ widened = float(hms)
33
+ def _idiv(a: int, b: int) -> int:
34
+ """IDL LONG division truncates toward zero, unlike Python `//`."""
35
+ q = a // b
36
+ if q < 0 and q * b != a:
37
+ q += 1
38
+ return q
39
+
40
+ ihms = int(widened) if widened >= 0 else -int(-widened) # long(): truncate toward zero
41
+ fraction = widened - ihms
42
+ hour = _idiv(ihms, 10000)
43
+ minute = _idiv(ihms - hour * 10000, 100)
44
+ second = ihms - hour * 10000 - minute * 100
45
+ return float(hour * 3600 + minute * 60 + second) + fraction
46
+
47
+
48
+ @dataclass
49
+ class ParsedDate:
50
+ """The structure ``soda2_parsedate.pro:20`` (SODA-2) returns, one field per IDL tag."""
51
+ year: str
52
+ month: str
53
+ day: str
54
+ yearnum: int
55
+ monthnum: int
56
+ daynum: int
57
+ order: str
58
+ julday: int
59
+
60
+
61
+ def soda2_parsedate(date: str) -> ParsedDate:
62
+ """`soda2_parsedate.pro:6-21`. The year-first test is on the first two
63
+ characters of `date` being `'19'` or `'20'`; the other order is assumed
64
+ otherwise (MMDDYYYY). `julday` is called with the three **string**
65
+ fields (`:19`), which the bank's `pd_*` cases pin -- `julday()` here
66
+ takes them straight through `int()` per the golden, not assumed."""
67
+ s = str(date)
68
+ if s[0:2] in ("19", "20"):
69
+ year, month, day = s[0:4], s[4:6], s[6:8]
70
+ order = "ymd"
71
+ else:
72
+ month, day, year = s[0:2], s[2:4], s[4:8]
73
+ order = "mdy"
74
+ yearnum, monthnum, daynum = int(year), int(month), int(day)
75
+ jd = julday(monthnum, daynum, yearnum)
76
+ return ParsedDate(year=year, month=month, day=day, yearnum=yearnum,
77
+ monthnum=monthnum, daynum=daynum, order=order, julday=jd)
@@ -0,0 +1,101 @@
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
+ """`soda2_update_op.pro:1-53` (`:55-84`, the `.txt` model-header
4
+ parse, is refused here by name).
5
+
6
+ Vendored source: `SODA2/abansemer-soda2-afcea15/soda2_update_op.pro`. Bank:
7
+ `gdl_oracle/run_soda2_preloop_bank.py`, golden
8
+ `tests/data/gdl_soda2_preloop_golden.json`.
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import copy
13
+
14
+ import numpy as np
15
+
16
+ #: `:10-42`'s literal defaults, in source order, keyed by lower-case tag name.
17
+ #: Every scalar `0`/`0.0` keeps IDL's own literal dtype (bare `0` is INT16,
18
+ #: `0.0` is FLOAT32) because `soda2_read2dbuffer.pro:116`'s FLOAT-widening
19
+ #: quirk (T7) depends on `timeoffset` staying FLOAT32 here, not Python float.
20
+ _INT16_DEFAULTS: dict[str, int] = {
21
+ "greythresh": 0, "water": 0, "subformat": 0, "particlefile": 0,
22
+ "ncdfparticlefile": 0, "asciipsdfile": 0, "stuckbits": 0, "savfile": 1,
23
+ "rakefix": 0, "keeplargest": 0, "juelichfilter": 0, "ignoredeadtime": 0,
24
+ "apply_psc": 0, "apply_psc_sizelimit": 0, "dofconst": 0, "dofreject": 0,
25
+ "stretchcorrect": 0, "strictcounter": 0, "activetimefrommissed": 0,
26
+ }
27
+ _FLOAT32_DEFAULTS: dict[str, float] = {
28
+ "timeoffset": 0.0, "fixedtas": 0.0, "armwidth": 0.0,
29
+ "clusterthresh": 0.0, "wavelength": 0.658e-6,
30
+ }
31
+ _STR_DEFAULTS: dict[str, str] = {
32
+ "probeid": "A0", "pth": "", "eawmethod": "centerin", "filetag": "",
33
+ }
34
+
35
+
36
+ def update_op(op: dict | None) -> dict:
37
+ """Returns a **new** dict -- IDL's `create_struct` rebuilds the struct
38
+ at each `:10-43` line and the caller's variable is reassigned
39
+ (`soda2_process_2d.pro:27` passes `op` by reference). Keys are
40
+ normalised to lower case on entry (IDL tag-name comparisons are
41
+ case-insensitive, `:10-43`); an already-lower-case caller sees no
42
+ change."""
43
+ if not op:
44
+ # `:5-7`: `res` INT16 0, `endbins` INT16 [0,1000].
45
+ op = {
46
+ "probetype": "", "res": np.int16(0),
47
+ "endbins": np.array([0, 1000], dtype=np.int16),
48
+ "format": "", "fn": "",
49
+ }
50
+ else:
51
+ op = {str(k).lower(): v for k, v in op.items()}
52
+ op = copy.deepcopy(op)
53
+
54
+ for int16_name, int16_value in _INT16_DEFAULTS.items():
55
+ op.setdefault(int16_name, np.int16(int16_value))
56
+ for f32_tag, f32_default in _FLOAT32_DEFAULTS.items():
57
+ op.setdefault(f32_tag, np.float32(f32_default))
58
+ for s_tag, s_default in _STR_DEFAULTS.items():
59
+ op.setdefault(s_tag, s_default)
60
+
61
+ # :25 shortname = probetype (evaluated after probetype's own arrival).
62
+ op.setdefault("shortname", op["probetype"])
63
+ # :32 yres = res.
64
+ op.setdefault("yres", op["res"])
65
+ # :30 seatag = [33000,0,0] -- 33000 exceeds INT16 (32767), IDL promotes
66
+ # the whole literal array to LONG (int32). Measure-not-guess per the
67
+ # plan; recorded here from the bank's `help,op,/structure` read (§3).
68
+ op.setdefault("seatag", np.array([33000, 0, 0], dtype=np.int32))
69
+ # :23 numdiodes = 64 (INT16 literal).
70
+ op.setdefault("numdiodes", np.int16(64))
71
+ # :41 dioderange = [0, numdiodes-1] -- after numdiodes has its final value.
72
+ op.setdefault("dioderange", np.array([0, int(op["numdiodes"]) - 1], dtype=np.int16))
73
+ # :42 customdof = fltarr(n_elements(endbins)-1).
74
+ op.setdefault("customdof", np.zeros(len(op["endbins"]) - 1, dtype=np.float32))
75
+
76
+ # :47-48 print-only diagnostics -- console output, never returned/raised.
77
+
78
+ # :49 probetype 'PIP' -> 'CIP'.
79
+ if op["probetype"] == "PIP":
80
+ op["probetype"] = "CIP"
81
+ # :50 dioderange[1] == 0 -> numdiodes-1 (upper diode range can't be zero).
82
+ dr_dtype = op["dioderange"].dtype if hasattr(op["dioderange"], "dtype") else np.int16
83
+ dr = np.array(op["dioderange"], dtype=dr_dtype)
84
+ if dr[1] == 0:
85
+ dr = dr.copy()
86
+ dr[1] = int(op["numdiodes"]) - 1
87
+ op["dioderange"] = dr
88
+ # :53 probetype '3VCPI' -> subformat=1.
89
+ if op["probetype"] == "3VCPI":
90
+ op["subformat"] = np.int16(1)
91
+
92
+ # :55-84 model .txt header parse -- round 7. Refused by name, not by a
93
+ # blanket `NotImplementedError` on every `.txt` filename: only fires on
94
+ # the exact last-four-characters test `:55` performs.
95
+ fn0 = op["fn"][0] if isinstance(op["fn"], (list, tuple, np.ndarray)) else op["fn"]
96
+ if str(fn0)[-4:] == ".txt":
97
+ raise NotImplementedError(
98
+ "soda2_update_op.pro:55-84 (model .txt header parse) is round-7 "
99
+ "scope; not ported.")
100
+
101
+ return op
@@ -0,0 +1,45 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """arrayprobe_uiops -- a Python port of UIOOPS carrying the developers' own fixes
3
+ for the findings the v3.1.4 port (``arrayprobe``) surfaced. Where a finding
4
+ was fixed upstream in v3.5, this package reproduces that fix; where v3.1.4's
5
+ behaviour was never touched by any later release, this package reproduces it
6
+ bug-for-bug the same way ``arrayprobe`` does.
7
+
8
+ Started 2026-09-10 (author-directed) as new, additional work alongside
9
+ the v3.1.4 port, not a replacement for it. Complete through all ten port stages as
10
+ of 2026-09-12, and the default for new work from that date by the author's
11
+ decision -- but ``arrayprobe`` is **not** deprecated and is not moving: it
12
+ stays live, importable and tested, and it remains what the paper, CI and the
13
+ archived-product validation cite, because no archived campaign product was
14
+ ever produced by v3.5. That v3.5 exists does not weaken the v3.1.4 fidelity claim
15
+ (two independent drifts
16
+ from a shared v3.1.4 base).
17
+
18
+ Zenodo DOI for the v3.5 release: 10.5281/zenodo.18945998.
19
+
20
+
21
+
22
+
23
+ **Reuse of the v3.1.4 port.** 18 of the 25 shared MATLAB/C++ files between
24
+ v3.1.4 and v3.5 are byte-identical (measured directly, not assumed -- see the
25
+ design doc's table). Where a whole module's source MATLAB file is
26
+ byte-identical, this package imports the v3.1.4 port's Python translation of
27
+ it directly rather than duplicating it -- the translation is provably still
28
+ correct, since nothing changed to translate. That reuse is guarded
29
+ mechanically, not merely documented:
30
+ ``tests/test_v35_reuse_byte_identity.py`` hashes each reused
31
+ file's v3.1.4 and v3.5 source against each other and fails the moment they
32
+ diverge, so a future upstream point-release cannot silently invalidate a
33
+ reuse decision made here.
34
+ """
35
+
36
+ import logging
37
+
38
+ __all__: list[str] = []
39
+
40
+ __version__ = "0.1.0" # the distribution's version; tests/test_version.py
41
+
42
+ # Since 2026-09-15: NullHandler by default, matching ``arrayprobe``'s
43
+ # own package logger -- importing this package must never print anything;
44
+ # ``arrayprobe.cli`` attaches the real handler for the console script.
45
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
@@ -0,0 +1,192 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """The production fork's ``combine_sizedist.m``, run over v3.5 ``sd`` output -- BORROWED, OPT-IN.
3
+
4
+ No stock UIOOPS release, v3.5 included, ships a combine step: ``combine_sizedist.m``
5
+ is in neither vendored tree (measured building ``uiops.CATALOGUE`` -- see
6
+ ``uiops/__init__.py``'s ``"combine"`` entry).
7
+ It survives only as the ORACLES
8
+ production fork, held as the ORACLES-variant ``combine_sizedist.m`` (delivered 2026-08-20)
9
+ and ported for v3.1.4 as :mod:`arrayprobe.combine`.
10
+
11
+ The author's decision (2026-09-13): v3.5 does not stop at ``sd``.
12
+ It gets the ORACLES fork's combine too, **labelled as borrowed and opt-in**
13
+ ("an option needs to be there for opt in" -- default OFF). This module adds
14
+ **no arithmetic of its own** (``tests/test_v35_combine.py``'s
15
+ ``ReuseNotCopy`` group asserts that by walking its AST): it guards the input
16
+ schema, then delegates to :func:`arrayprobe.combine.combine_sizedist` --
17
+ reused, never copied -- and records the borrowing beside the product.
18
+
19
+ **Why the v3.1.4 combine can be pointed at v3.5 output at all.** It reads
20
+ exactly 11 variables, all by NAME (``arrayprobe.combine._READ_VARS``), and
21
+ reads no global attribute. Measured against the two Octave-written goldens
22
+ (``tests/data/v35_sizedist/main.nc``, v3.5; ``tests/data/s4_sizedist_octave_golden.nc``,
23
+ v3.1.4): every one of those 11 names resolves to the same on-disk variable
24
+ INDEX in both files (:func:`check_sd_schema` asserts exactly this), and the
25
+ one candidate for a silent mis-read -- whether v3.5's ``mean_area_ratio``
26
+ (the fixed area-ratio double scaling: v3.5 writes it WITH the transpose its
27
+ sibling variables already carry, see ``arrayprobe_uiops/sizedist.py``'s
28
+ ``NOT_TRANSPOSED``-adjacent comment and the earlier translation's
29
+ ``NOT_TRANSPOSED`` set) -- lands on disk with a different dimension order
30
+ than v3.1.4's, measured **false**: both goldens declare ``mean_area_ratio``
31
+ with identical on-disk dims (``Time``, ``CIPcorrlen``), so
32
+ ``ncio.get_var`` returns it in the identical MATLAB shape ``(bin, time)`` for
33
+ both engines, which is exactly what ``arrayprobe.combine``'s own ``.T`` step
34
+ already expects. **No adapter arithmetic is needed**; this module is a guard,
35
+ a label and a delegation, nothing else.
36
+
37
+ **Validation, stated honestly.** Layer 2 at best, and it is *identity*, not
38
+ an oracle: the borrowed combine on v3.5 output can only be shown
39
+ byte-identical to :func:`arrayprobe.combine.combine_sizedist` on the
40
+ identical inputs, because it is the same function. No archived product was
41
+ ever combined from v3.5 ``sd`` files, so no layer-1 claim exists or can
42
+ exist for this module.
43
+ """
44
+
45
+ from __future__ import annotations
46
+
47
+ import os
48
+ from pathlib import Path
49
+ from typing import Any
50
+
51
+ from arrayprobe_uiops import combine_fork as _fork_combine
52
+
53
+ from . import ncio
54
+
55
+ __all__ = [
56
+ "BORROWED_FROM",
57
+ "CALL_STAMP",
58
+ "BorrowedCombineNotEnabled",
59
+ "SdSchemaMismatch",
60
+ "check_sd_schema",
61
+ "combine_sizedist",
62
+ ]
63
+
64
+ #: One line, checkable without reading source: what this delegates to and why.
65
+ BORROWED_FROM = (
66
+ "combine_sizedist.m from a campaign variant of UIOOPS "
67
+ "(in no stock UIOOPS release, v3.5 included); one translation, "
68
+ "reused here, never copied"
69
+ )
70
+
71
+ #: The one-line ``.call`` sidecar stamp -- written beside the product so the
72
+ #: borrowing is recorded even when this is called from Python directly
73
+ #: rather than through ``scripts/run_flight.py`` (which has its own stamping
74
+ #: convention for the v3.1.4 engine; see ``run_flight.py``'s
75
+ #: ``call_path``/``write_stamp``, mirrored, not imported, below).
76
+ CALL_STAMP = (
77
+ "engine=3.5 combine=borrowed-oracles-fork:combine_sizedist.m "
78
+ "opt_in=borrowed_combine=True"
79
+ )
80
+
81
+
82
+ class BorrowedCombineNotEnabled(RuntimeError):
83
+ """Raised when :func:`combine_sizedist` is called without opting in.
84
+
85
+ Default OFF is the point: nothing about v3.5's own output is
86
+ touched unless a caller names ``borrowed_combine=True`` explicitly.
87
+ """
88
+
89
+
90
+ class SdSchemaMismatch(ValueError):
91
+ """An input file does not carry the 11 variables ``combine_sizedist.m``
92
+ reads at the indices it hard-codes -- see :func:`check_sd_schema`."""
93
+
94
+
95
+ def check_sd_schema(path: Any) -> None:
96
+ """Assert ``path`` carries every variable :data:`arrayprobe.combine.MATLAB_VARID`
97
+ names, each at the on-disk index the MATLAB source reads by number.
98
+
99
+ ``arrayprobe.combine`` itself reads by NAME (the combine stage's design rule:
100
+ "read by name, assert by index") and trusts a v3.1.4-shaped ``sd`` file to
101
+ have named things consistently with that hard-coded index table. A v3.5
102
+ file is a different writer; this is that same assertion, run explicitly
103
+ against v3.5 output before delegating, rather than assumed.
104
+ """
105
+ ds = ncio.open(str(path), "nowrite")
106
+ try:
107
+ for name, expected_idx in _fork_combine.MATLAB_VARID.items():
108
+ try:
109
+ got_idx = ncio.inq_var_id(ds, name)
110
+ except KeyError:
111
+ raise SdSchemaMismatch(
112
+ f"{path}: combine_sizedist.m reads a variable named "
113
+ f"{name!r} (its index {expected_idx}), but this file has "
114
+ f"none"
115
+ ) from None
116
+ if got_idx != expected_idx:
117
+ raise SdSchemaMismatch(
118
+ f"{path}: {name!r} is variable {got_idx} here, but "
119
+ f"combine_sizedist.m reads index {expected_idx} for it -- "
120
+ f"the fork combine would silently read the wrong column"
121
+ )
122
+ finally:
123
+ ncio.close(ds)
124
+
125
+
126
+ def _write_call_sidecar(outfile: Path, sd_files: Any) -> None:
127
+ """Mirrors ``scripts/run_flight.py``'s ``call_path``/``write_stamp`` shape
128
+ (partial-write-then-rename) without importing ``tools`` -- this module
129
+ must be usable with no dependency on the CLI driver.
130
+ """
131
+ names = ",".join(Path(p).name for p in sd_files)
132
+ content = f"{CALL_STAMP}\ninputs={names}\n"
133
+ sidecar = outfile.with_name(f"{outfile.name}.call")
134
+ partial = sidecar.with_name(f"{sidecar.name}.partial")
135
+ partial.write_text(content, encoding="utf-8")
136
+ os.replace(partial, sidecar)
137
+
138
+
139
+ def combine_sizedist(
140
+ sd_files: Any,
141
+ outfile: Any,
142
+ *,
143
+ flight_date: Any,
144
+ summary_time: Any,
145
+ borrowed_combine: bool = False,
146
+ current_year: Any = None,
147
+ creation_time: Any = None,
148
+ ) -> Any:
149
+ """The production fork's ``combine_sizedist.m``, over v3.5 ``sd`` files.
150
+
151
+ Same contract as :func:`arrayprobe.combine.combine_sizedist` -- this
152
+ calls that function unmodified, after guarding the input schema -- plus
153
+ one addition:
154
+
155
+ Parameters
156
+ ----------
157
+ borrowed_combine : bool
158
+ Must be ``True`` or this raises :class:`BorrowedCombineNotEnabled`
159
+ and writes nothing. Default OFF: nothing about a v3.5
160
+ run is touched unless a caller opts in explicitly.
161
+
162
+ Raises
163
+ ------
164
+ BorrowedCombineNotEnabled
165
+ ``borrowed_combine`` is not ``True``.
166
+ SdSchemaMismatch
167
+ Some input in ``sd_files`` does not carry the 11 variables the fork
168
+ combine reads at the indices it hard-codes -- see
169
+ :func:`check_sd_schema`.
170
+
171
+ Returns the path written, and stamps a ``<outfile>.call`` sidecar
172
+ recording the borrowing (:data:`CALL_STAMP`) and the input file names.
173
+ """
174
+ if not borrowed_combine:
175
+ raise BorrowedCombineNotEnabled(
176
+ "arrayprobe_uiops.combine.combine_sizedist refuses to run unless "
177
+ "borrowed_combine=True is passed explicitly (the "
178
+ "variant's combine_sizedist.m is opt-in for v3.5, default "
179
+ f"OFF). {BORROWED_FROM}"
180
+ )
181
+ for p in sd_files:
182
+ check_sd_schema(p)
183
+ out = _fork_combine.combine_sizedist(
184
+ sd_files,
185
+ outfile,
186
+ flight_date=flight_date,
187
+ summary_time=summary_time,
188
+ current_year=current_year,
189
+ creation_time=creation_time,
190
+ )
191
+ _write_call_sidecar(Path(outfile), sd_files)
192
+ return out