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,208 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Per-second agreement against an archived product, stratified by cloud condition.
3
+
4
+ **Why stratify at all.** A single headline percentage can hide a whole regime.
5
+ Written 2026-08-28 for the author's ask that validation be checked *"on multiple
6
+ samples, in and out of cloud, and over different conditions"*, and its first run
7
+ earned that ask immediately: the used-bin deficit was 70 % / 62 % / 62 % across
8
+ sparse / moderate / dense, which one number over the whole flight would have
9
+ averaged into something that looked merely disappointing rather than
10
+ regime-dependent.
11
+
12
+ **Condition is taken from the REFERENCE, never from ours.** The band for each
13
+ second is decided by the *product's* own per-second particle total across all
14
+ bins -- its measure of how much cloud the probe was in. Using our own total
15
+ would make the stratification depend on the thing being tested: a second we
16
+ under-count would be filed as sparser than it was, and the sparse band would
17
+ then flatter us with a second that belongs in the dense one.
18
+
19
+ **In ``src/`` since 2026-09-10.** This was 131 lines inside
20
+ a script and every number it computed went straight
21
+ into a ``print``, so nothing could assert on any of it -- the one part of the
22
+ validation story with no test was the part that answers the author's own
23
+ question. :func:`stratify` returns the numbers; formatting is the caller's.
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ import dataclasses
29
+ import glob
30
+ import os
31
+ import re
32
+
33
+ import netCDF4
34
+ import numpy as np
35
+
36
+ __all__ = ["BANDS", "BandResult", "Stratification", "find_product", "stratify"]
37
+
38
+ #: Lower bound (inclusive), upper bound (exclusive), label. The boundaries are
39
+ #: the author's, from the 2026-08-28 run, and are deliberately round: they are
40
+ #: a way of slicing a flight for inspection, not a published classification, so
41
+ #: nothing downstream should read them as a definition of "dense cloud".
42
+ BANDS = (
43
+ (0, 1, "clear (0/s)"),
44
+ (1, 100, "sparse (1-100/s)"),
45
+ (100, 5000, "moderate(100-5k/s)"),
46
+ (5000, 10 ** 9, "dense (>5k/s)"),
47
+ )
48
+
49
+ #: No built-in products directory, and no assumption about how one is laid out:
50
+ #: pass ``product_dir`` (``--product-dir``) or set ``ARRAYPROBE_PRODUCT_DIR`` to the
51
+ #: directory that holds the products of record.
52
+ DEFAULT_PRODUCTS: str | None = None
53
+
54
+ #: The environment variable naming the directory that holds the products of record.
55
+ PRODUCT_DIR_ENV = "ARRAYPROBE_PRODUCT_DIR"
56
+
57
+
58
+ def resolve_product_dir(product_dir: str | None = None) -> str:
59
+ """``product_dir`` if given, else ``$ARRAYPROBE_PRODUCT_DIR``, used as given.
60
+
61
+ Raises ``ValueError`` when neither is given, rather than guessing a location.
62
+ """
63
+ if product_dir:
64
+ return product_dir
65
+ env = os.environ.get(PRODUCT_DIR_ENV)
66
+ if env:
67
+ return env
68
+ raise ValueError(
69
+ "no products-of-record directory: pass --product-dir (product_dir=) or set "
70
+ f"{PRODUCT_DIR_ENV} to the directory that holds the products of record")
71
+
72
+
73
+ @dataclasses.dataclass(frozen=True)
74
+ class BandResult:
75
+ """One condition band's totals. Ratios are left to the caller.
76
+
77
+ ``all_*`` covers every bin; ``used_*`` drops the first ``drop_bins``, which
78
+ is what the project's headline figures quote -- the low bins are where the
79
+ probe's own response, not the port, dominates the disagreement.
80
+ """
81
+
82
+ label: str
83
+ seconds: int
84
+ all_ours: float
85
+ all_ref: float
86
+ used_ours: float
87
+ used_ref: float
88
+ #: Seconds where every bin matches exactly, in that band.
89
+ exact_seconds: int
90
+
91
+
92
+ @dataclasses.dataclass(frozen=True)
93
+ class Stratification:
94
+ """One comparison: the bands, the whole-window total, and how it was scoped.
95
+
96
+ Carries ``drop_bins`` and both second counts as well as the numbers,
97
+ because a band table read without them is ambiguous -- "used" means
98
+ nothing until you know how many bins the band drops, and a window's totals
99
+ read as a whole flight's unless the two second counts are visible side by
100
+ side.
101
+ """
102
+
103
+ ours_path: str
104
+ ref_path: str
105
+ shared_seconds: int
106
+ #: Seconds inside ``--window``; equal to ``shared_seconds`` without one.
107
+ window_seconds: int
108
+ drop_bins: int
109
+ bands: tuple[BandResult, ...]
110
+ #: Every second in the window, as one band. Not the sum of ``bands``: a
111
+ #: band with no seconds is omitted from that tuple, and this is computed
112
+ #: over the mask directly either way.
113
+ overall: BandResult
114
+
115
+
116
+ def _seconds_of(ds) -> np.ndarray:
117
+ """``Time Vector`` is a MATLAB datenum; the shared key is the whole second."""
118
+ tv = np.asarray(ds.variables["Time Vector"][:], float)
119
+ return np.round((tv - np.floor(tv[0])) * 86400).astype(np.int64)
120
+
121
+
122
+ def _counts_of(ds) -> np.ndarray:
123
+ """``Counts`` as (bins, time), whichever way the file stores it.
124
+
125
+ **The orientation is decided by looking for 128**, the 2D-S/HVPS bin
126
+ count, because a combined product stores the array either way round and
127
+ its dimension names cannot be relied on across the two trees. That makes
128
+ 128 a hard assumption rather than a convention: an array with any other
129
+ bin count is transposed unconditionally, so its seconds and bins swap
130
+ silently. Every real product has 128 bins; a synthetic fixture with fewer
131
+ does not, and one written that way put four seconds spanning four
132
+ condition bands into a single band without error (2026-09-10).
133
+ """
134
+ a = np.nan_to_num(np.asarray(ds.variables["Counts"][:], float))
135
+ return a if a.shape[0] == 128 else a.T
136
+
137
+
138
+ def parse_hhmmss(x: str) -> int:
139
+ """``HHMMSS`` as seconds since midnight.
140
+
141
+ ``int(x)`` first, so ``"070000"`` is 7 h and not an octal-looking string;
142
+ the fields are then split arithmetically rather than by slicing, which
143
+ keeps a malformed length a ``ValueError`` from ``int`` rather than a
144
+ silently wrong time.
145
+ """
146
+ v = int(x)
147
+ return (v // 10000) * 3600 + ((v // 100) % 100) * 60 + v % 100
148
+
149
+
150
+ def find_product(path: str, product_dir: str | None = DEFAULT_PRODUCTS) -> str | None:
151
+ """The archived product whose stem's date matches ``path``'s, if one exists.
152
+
153
+ Matched on the six-digit date in ``base<YYMMDD>``, not on the whole stem: a
154
+ product's stem is the flight's summary-file timestamp and ours is a raw
155
+ file's, so the two agree on the date and generally not on the time.
156
+ ``product_dir`` falls back to :func:`resolve_product_dir`.
157
+ """
158
+ m = re.search(r"base(\d{6})", os.path.basename(path))
159
+ if not m:
160
+ return None
161
+ product_dir = resolve_product_dir(product_dir)
162
+ hits = sorted(glob.glob(os.path.join(
163
+ product_dir, f"base{m.group(1)}*.combined.H.2DS_2.cdf")))
164
+ return hits[0] if hits else None
165
+
166
+
167
+ def stratify(ours_path: str, ref_path: str, window: str | None = None,
168
+ drop_bins: int = 5) -> Stratification:
169
+ """Compare ``ours_path`` against ``ref_path`` second by second, by band.
170
+
171
+ ``window`` is ``HHMMSS-HHMMSS``, inclusive-exclusive, so a partially
172
+ processed flight can be compared only where every contributing raw file is
173
+ present -- otherwise its missing hours land in the clear band and inflate
174
+ the agreement.
175
+ """
176
+ with netCDF4.Dataset(ours_path) as ours, netCDF4.Dataset(ref_path) as ref:
177
+ os_, rs = _seconds_of(ours), _seconds_of(ref)
178
+ shared, oi, ri = np.intersect1d(os_, rs, return_indices=True)
179
+ x, y = _counts_of(ours)[:, oi], _counts_of(ref)[:, ri]
180
+
181
+ win = np.ones(shared.size, bool)
182
+ if window:
183
+ lo, hi = (parse_hhmmss(v) for v in window.split("-"))
184
+ win = (shared >= lo) & (shared < hi)
185
+ density = y.sum(0)
186
+
187
+ def band(label: str, mask: np.ndarray) -> BandResult:
188
+ return BandResult(
189
+ label=label,
190
+ seconds=int(mask.sum()),
191
+ all_ours=float(x[:, mask].sum()),
192
+ all_ref=float(y[:, mask].sum()),
193
+ used_ours=float(x[drop_bins:, mask].sum()),
194
+ used_ref=float(y[drop_bins:, mask].sum()),
195
+ exact_seconds=int(
196
+ (np.abs(x[:, mask] - y[:, mask]).sum(0) == 0).sum()),
197
+ )
198
+
199
+ bands = tuple(
200
+ band(label, mask)
201
+ for lo, hi, label in BANDS
202
+ if (mask := win & (density >= lo) & (density < hi)).any()
203
+ )
204
+ return Stratification(
205
+ ours_path=ours_path, ref_path=ref_path, shared_seconds=int(shared.size),
206
+ window_seconds=int(win.sum()), drop_bins=drop_bins, bands=bands,
207
+ overall=band("ALL", win),
208
+ )
@@ -0,0 +1,166 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Typed results for comparing a port output against a reference product.
3
+
4
+ The acceptance gate (S4c's product against the archived product)
5
+ prints its result; nothing
6
+ returned a value a caller could hold onto, so a notebook wanting to plot
7
+ per-bin agreement or list the seconds that disagree had to re-parse stdout.
8
+ This module computes the same two-denominator, used-bin comparison and
9
+ returns dataclasses instead -- same conventions, same used-bin cut, same
10
+ "always report both denominators" rule (a `both-present` figure and a
11
+ `non-zero` figure have both been quoted under the same headline before, and
12
+ they are not comparable).
13
+
14
+ Deliberately duplicates the gate's small helpers (``_seconds_of``,
15
+ ``_oriented``) rather than importing them: this is the core package, and the
16
+ core package does not depend on the scripts around it -- they may import
17
+ from the core package, not the reverse. The gate itself is untouched by
18
+ this module and keeps
19
+ printing exactly as
20
+ it always has.
21
+ """
22
+ from __future__ import annotations
23
+
24
+ from dataclasses import dataclass
25
+
26
+ import netCDF4
27
+ import numpy as np
28
+
29
+ #: The 2D-S's first five bins sit at the diode-pitch noise floor and are
30
+ #: excluded from every headline this project publishes -- see
31
+ #: ``docs/11-glossary.md``.
32
+ UNUSED_BINS = 5
33
+
34
+ #: The two variables ``validate_combined_product.py`` compares.
35
+ COMPARED_VARIABLES = ("Size Distribution cm-3", "Counts")
36
+
37
+
38
+ def _seconds_of(ds) -> np.ndarray:
39
+ """``Time Vector`` is a MATLAB datenum; the shared key is the whole second."""
40
+ tv = np.asarray(ds.variables["Time Vector"][:], float)
41
+ return np.round((tv - np.floor(tv[0])) * 86400.0).astype(np.int64)
42
+
43
+
44
+ def _oriented(ds, name: str, n_time: int) -> np.ndarray:
45
+ """Return the variable as ``(bins, time)``, whichever way it is stored."""
46
+ a = np.asarray(ds.variables[name][:], float)
47
+ if a.ndim != 2:
48
+ return a
49
+ return a if a.shape[1] == n_time else a.T
50
+
51
+
52
+ @dataclass(frozen=True)
53
+ class CellAgreement:
54
+ """Agreement for one variable, one bin scope ("all bins" or "used bins").
55
+
56
+ Two denominators, always both, for the reason ``validate_combined_product.py``
57
+ exists: ``both_present`` counts every cell neither side left as fill,
58
+ zero-equals-zero included; ``non_zero`` (the headline figure this project
59
+ publishes) excludes cells where both sides agree only because neither saw
60
+ a particle.
61
+ """
62
+ variable: str
63
+ scope: str
64
+ both_present_n: int
65
+ both_present_agree: int
66
+ both_zero_n: int
67
+ non_zero_n: int
68
+ non_zero_agree: int
69
+
70
+ @property
71
+ def both_present_pct(self) -> float:
72
+ """Agreement over every cell neither side left as fill, zero-equals-zero
73
+ included -- the looser of the two denominators."""
74
+ return (100.0 * self.both_present_agree / self.both_present_n
75
+ if self.both_present_n else float("nan"))
76
+
77
+ @property
78
+ def non_zero_pct(self) -> float:
79
+ """Agreement excluding cells where both sides agree only because
80
+ neither recorded a particle -- the headline figure this project
81
+ publishes."""
82
+ return (100.0 * self.non_zero_agree / self.non_zero_n
83
+ if self.non_zero_n else float("nan"))
84
+
85
+
86
+ @dataclass(frozen=True)
87
+ class ProductComparisonReport:
88
+ """The result of :func:`compare_to_product`."""
89
+ ours_path: str
90
+ ref_path: str
91
+ ours_seconds: int
92
+ ref_seconds: int
93
+ shared_seconds: int
94
+ uncovered_ref_seconds: int
95
+ uncovered_ours_seconds: int
96
+ cells: tuple[CellAgreement, ...]
97
+ #: Shared seconds holding at least one differing used-bin non-zero cell,
98
+ #: pooled over every compared variable -- plottable as a residual-over-time
99
+ #: view; empty when every used-bin non-zero cell agrees.
100
+ residual_seconds: tuple[int, ...]
101
+
102
+ def cell(self, variable: str, scope: str) -> CellAgreement:
103
+ """The :class:`CellAgreement` for one compared variable and bin scope
104
+ (``"all bins"`` or ``"used bins N-128"``); raises :class:`KeyError` if
105
+ that combination was not computed (the variable was absent from one
106
+ side)."""
107
+ for c in self.cells:
108
+ if c.variable == variable and c.scope == scope:
109
+ return c
110
+ raise KeyError((variable, scope))
111
+
112
+
113
+ def compare_to_product(our_path: str, ref_path: str,
114
+ drop: int = UNUSED_BINS) -> ProductComparisonReport:
115
+ """The same comparison the acceptance gate prints, as
116
+ typed results a caller can hold onto -- e.g. from a notebook::
117
+
118
+ report = validation_report.compare_to_product(ours, theirs)
119
+ report.cell("Counts", "used bins 6-128").non_zero_pct
120
+ report.residual_seconds
121
+ """
122
+ ours = netCDF4.Dataset(our_path)
123
+ ref = netCDF4.Dataset(ref_path)
124
+ try:
125
+ ours_s, ref_s = _seconds_of(ours), _seconds_of(ref)
126
+ shared, oi, ri = np.intersect1d(ours_s, ref_s, return_indices=True)
127
+
128
+ cells = []
129
+ residual_mask = np.zeros(len(shared), dtype=bool)
130
+ for name in COMPARED_VARIABLES:
131
+ if name not in ours.variables or name not in ref.variables:
132
+ continue
133
+ a = _oriented(ours, name, len(ours_s))[:, oi]
134
+ b = _oriented(ref, name, len(ref_s))[:, ri]
135
+
136
+ for lo, label in ((0, "all bins"), (drop, f"used bins {drop + 1}-128")):
137
+ x, y = a[lo:], b[lo:]
138
+ present = ~np.isnan(x) & ~np.isnan(y)
139
+ both_zero = present & (x == 0) & (y == 0)
140
+ eq = x == y
141
+
142
+ n_p, e_p = int(present.sum()), int((eq & present).sum())
143
+ strict = present & ~both_zero
144
+ n_s, e_s = int(strict.sum()), int((eq & strict).sum())
145
+ cells.append(CellAgreement(
146
+ variable=name, scope=label,
147
+ both_present_n=n_p, both_present_agree=e_p,
148
+ both_zero_n=int(both_zero.sum()),
149
+ non_zero_n=n_s, non_zero_agree=e_s,
150
+ ))
151
+ if lo == drop:
152
+ differing = strict & ~eq
153
+ residual_mask |= differing.any(axis=0)
154
+
155
+ return ProductComparisonReport(
156
+ ours_path=str(our_path), ref_path=str(ref_path),
157
+ ours_seconds=len(ours_s), ref_seconds=len(ref_s),
158
+ shared_seconds=len(shared),
159
+ uncovered_ref_seconds=len(ref_s) - len(shared),
160
+ uncovered_ours_seconds=len(ours_s) - len(shared),
161
+ cells=tuple(cells),
162
+ residual_seconds=tuple(int(s) for s in shared[residual_mask]),
163
+ )
164
+ finally:
165
+ ours.close()
166
+ ref.close()
@@ -0,0 +1,260 @@
1
+ Metadata-Version: 2.4
2
+ Name: arrayprobe
3
+ Version: 0.1.0
4
+ Summary: Python ports of the UIOPS v3.5 and SODA-2 optical array probe processing chains
5
+ Author: Siddhant Gupta
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/sgupta92/arrayprobe
8
+ Project-URL: Documentation, https://sgupta92.github.io/arrayprobe/
9
+ Project-URL: Issues, https://github.com/sgupta92/arrayprobe/issues
10
+ Keywords: optical array probe,OAP,cloud microphysics,2DS,HVPS,UIOPS,SODA-2,particle size distribution,cloud probe
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Natural Language :: English
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
20
+ Requires-Python: >=3.12
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ License-File: LICENSES/BSD-3-Clause.txt
24
+ License-File: NOTICE.md
25
+ Requires-Dist: numpy>=2.0
26
+ Requires-Dist: netCDF4>=1.7.2
27
+ Requires-Dist: scipy>=1.16
28
+ Provides-Extra: extra
29
+ Requires-Dist: scipy>=1.16; extra == "extra"
30
+ Requires-Dist: matplotlib>=3.8.4; extra == "extra"
31
+ Requires-Dist: psutil>=7.2; extra == "extra"
32
+ Provides-Extra: jit
33
+ Requires-Dist: numba>=0.67; extra == "jit"
34
+ Provides-Extra: zarr
35
+ Requires-Dist: zarr>=3.0; extra == "zarr"
36
+ Requires-Dist: xarray>=2025.1.1; extra == "zarr"
37
+ Provides-Extra: parquet
38
+ Requires-Dist: pyarrow>=26.0; extra == "parquet"
39
+ Provides-Extra: enhancements
40
+ Requires-Dist: arrayprobe-uiops-enhancements<0.2,>=0.1.0; extra == "enhancements"
41
+ Requires-Dist: arrayprobe-soda2-enhancements<0.2,>=0.1.0; extra == "enhancements"
42
+ Provides-Extra: dev
43
+ Requires-Dist: pytest>=8; extra == "dev"
44
+ Requires-Dist: ruff>=0.6; extra == "dev"
45
+ Requires-Dist: mypy>=2.3; extra == "dev"
46
+ Requires-Dist: reportlab>=5; extra == "dev"
47
+ Requires-Dist: pypdf>=6; extra == "dev"
48
+ Requires-Dist: build>=1.6; extra == "dev"
49
+ Requires-Dist: coverage>=7.16; extra == "dev"
50
+ Requires-Dist: pre-commit>=4.6; extra == "dev"
51
+ Requires-Dist: twine>=7.0; extra == "dev"
52
+ Provides-Extra: pinned
53
+ Requires-Dist: numpy==2.5.3; extra == "pinned"
54
+ Requires-Dist: netCDF4==1.7.4; extra == "pinned"
55
+ Requires-Dist: pytest==9.1.1; extra == "pinned"
56
+ Requires-Dist: ruff==0.14.4; extra == "pinned"
57
+ Requires-Dist: pre-commit==4.6.2; extra == "pinned"
58
+ Requires-Dist: coverage==7.16.1; extra == "pinned"
59
+ Requires-Dist: mypy==2.3.1; extra == "pinned"
60
+ Requires-Dist: reportlab==5.0.1; extra == "pinned"
61
+ Requires-Dist: pypdf==6.19.0; extra == "pinned"
62
+ Requires-Dist: build==1.6.1; extra == "pinned"
63
+ Requires-Dist: twine==7.0.0; extra == "pinned"
64
+ Requires-Dist: scipy==1.18.1; extra == "pinned"
65
+ Requires-Dist: matplotlib==3.11.2; extra == "pinned"
66
+ Requires-Dist: numba==0.67.0; extra == "pinned"
67
+ Requires-Dist: psutil==7.2.2; extra == "pinned"
68
+ Requires-Dist: zarr==3.4.0; extra == "pinned"
69
+ Requires-Dist: xarray==2026.9.0; extra == "pinned"
70
+ Requires-Dist: pyarrow==26.0.0; extra == "pinned"
71
+ Dynamic: license-file
72
+
73
+ # arrayprobe
74
+
75
+ `arrayprobe` processes the raw data recorded by airborne optical array probes (OAPs), the
76
+ instruments that image cloud and precipitation particles as they pass through a laser beam. It reads
77
+ the probe's raw binary files (SPEC, DMT, PMS and SEA record formats: 2D-S, HVPS, CIP, PIP, 2DC, 2DP
78
+ and Fast2DC), reconstructs each particle's image, measures and accepts or rejects every particle,
79
+ and computes one-second particle size distributions, combined into one product per flight.
80
+
81
+ It is for anyone who works with OAP data: processing a field campaign's flights, re-processing an
82
+ old campaign with documented settings, or checking how a processed product was made. Every run
83
+ writes a `.call` record of exactly how each stage was called, so a result can be traced and
84
+ repeated.
85
+
86
+ Two processing engines ship, each a Python translation of an established processing code and
87
+ checked against that original running unmodified:
88
+
89
+ - **UIOOPS v3.5** (its repository is spelled UIOPS; the default), translated from the MATLAB processing code of the McFarquhar
90
+ group, checked stage by stage and end to end against GNU Octave running v3.5's own sources.
91
+ - **SODA-2**, translated from NCAR's IDL code, checked against GDL running SODA-2's unmodified
92
+ sources.
93
+
94
+ **Start here, with no real data:** [`examples/1_getting_started/01_start_here.ipynb`](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/examples/1_getting_started/01_start_here.ipynb)
95
+ processes a synthetic file and plots what came out, explaining each step.
96
+
97
+ ![What a user runs: a raw probe file goes to the UIOOPS engine (v3.5, default) or the SODA-2 engine, both on their latest releases, with opt-in enhancements beside them, to a combined flight product; set apart below, the earlier v3.1.4 port that reproduced archived products is not part of the package and only gives confidence in the engines](https://raw.githubusercontent.com/sgupta92/arrayprobe/v0.1.0/docs/figures/package_overview.svg)
98
+
99
+ ### Where to read next
100
+
101
+ ![Three reading paths. To process data: the Quickstart below, then the User guide, Choosing an engine and Configuration. To understand the science: Orientation for OAP scientists, then the Scientist's guide, Known gaps and future work, and Enhancements. To maintain or validate the port: Why reproduce the original first, then Validation, Conventions and terms, and For UIOOPS developers](https://raw.githubusercontent.com/sgupta92/arrayprobe/v0.1.0/docs/figures/reading_path.svg)
102
+
103
+ Looking up a command or a function? The [CLI reference](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/13-cli-reference.md) lists every `arrayprobe` command and flag, and the [API reference](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/08-reference.md) links the public Python API, page by page. Each probe has its own page, listed in [The probes](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/33-probes.md); the whole documentation is indexed in [the docs index](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/00-index.md).
104
+
105
+ ## Install
106
+
107
+ Needs Python 3.12 or newer. From PyPI:
108
+
109
+ ```bash
110
+ pip install arrayprobe
111
+ ```
112
+
113
+ Optional additions:
114
+
115
+ - `pip install "arrayprobe[extra]"` adds scipy, matplotlib and psutil (the inter-arrival fitting, plots, and the run's machine-load record).
116
+ - `pip install arrayprobe-uiops-enhancements arrayprobe-soda2-enhancements` adds the opt-in corrections
117
+ for each engine.
118
+ - The example notebooks run from a clone of the repository (`git clone https://github.com/sgupta92/arrayprobe.git`),
119
+ not from a `pip install`, and also need xarray and Jupyter: `pip install "arrayprobe[extra,zarr]" jupyter`.
120
+ [Start here](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/00b-start-here.md) walks through the first one.
121
+
122
+ The install also provides `uiops`, a small module that picks an arrayprobe engine; it is not the
123
+ UIOOPS MATLAB code. To run the test suite or work on the code, install from a clone as described in
124
+ [CONTRIBUTING.md](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/CONTRIBUTING.md).
125
+
126
+ ## Quickstart
127
+
128
+ Run these from any empty folder; the same two lines work on Windows, Linux and macOS:
129
+
130
+ ```bash
131
+ arrayprobe make-demo-flight --dense --with-config demo/base160101000000.2DS
132
+ arrayprobe run demo/run.toml demo/base160101000000.2DS --yes
133
+ ```
134
+
135
+ The first command writes a synthetic raw 2D-S file and a settings file, `demo/run.toml`, beside it.
136
+ The second runs the full pipeline on it in seconds and ends by printing `ALL DONE`. No campaign data
137
+ is needed. The file name carries a flight date because the combine step groups a flight's files by
138
+ it.
139
+
140
+ The run also prints a `LOAD RECORD` line, which says whether other processes were busy during the
141
+ run. It matters only for quoting a run time, never for the results, and reads `UNRECORDED` without
142
+ psutil.
143
+
144
+ ### What a run does
145
+
146
+ ![A raw .2DS or .HVPS file passes through four stages, run by `arrayprobe run` (the `stages` key of its `run` table selects them): read-binary decodes it, imgproc frames and measures particles, sizedist computes one-second size distributions, and combine stitches a flight's files into one product; every output has a .call sidecar recording how the stage was called](https://raw.githubusercontent.com/sgupta92/arrayprobe/v0.1.0/docs/figures/pipeline_stages.svg)
147
+
148
+ ### Look at the particles
149
+
150
+ A run's output folder can be browsed particle by particle, or rendered as image galleries:
151
+
152
+ ```bash
153
+ arrayprobe triage --decoded-dir demo
154
+ arrayprobe gallery --decoded-dir demo --flight base160101000000.H --out demo/galleries
155
+ ```
156
+
157
+ ### Your own data
158
+
159
+ `arrayprobe run <config.toml> <flight>` processes your own flights: the choices live in the
160
+ configuration file ([Configuration](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/06-configuration.md)), and `arrayprobe --help` lists
161
+ every command. If you cloned the source,
162
+ [`examples/start_here/README.md`](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/examples/start_here/README.md) walks through the same run
163
+ with its settings file.
164
+
165
+ ## Running it faster
166
+
167
+ Opt-in parallelism on the default UIOOPS engine and on SODA-2, default serial, part of **this
168
+ package, not the enhancements**, because it moves no written byte. Measured, with its scope, in
169
+ [Processing speed](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/32-processing-speed.md): UIOOPS v3.5's `--chunks 8` runs stage 3 (`imgproc`)
170
+ on a CIP file **2.5–2.6×** faster, all 40 variables byte-equal to the serial run; SODA-2's
171
+ `--jobs 12` runs its buffer loop on a CIP (SEA) file **3.70×** faster, all 35 arrays byte-equal.
172
+ The two figures come from different programs and stages and are not to be ranked against each other.
173
+
174
+ ## Test (from a clone)
175
+
176
+ From a clone of the repository (see [CONTRIBUTING](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/CONTRIBUTING.md) for the development setup):
177
+
178
+ ```bash
179
+ # Linux, macOS
180
+ python3.12 -m venv .venv && .venv/bin/python -m pip install -e ".[pinned]" -e enhancements_uiops -e enhancements_soda2
181
+ .venv/bin/python -m unittest discover -s tests -p "test_*.py"
182
+ .venv/bin/python -m ruff check src tests scripts enhancements_uiops enhancements_soda2
183
+ ```
184
+
185
+ ```powershell
186
+ # Windows, one command per line
187
+ py -3.12 -m venv .venv
188
+ .venv\Scripts\python.exe -m pip install -e ".[pinned]" -e enhancements_uiops -e enhancements_soda2
189
+ .venv\Scripts\python.exe -m unittest discover -s tests -p "test_*.py"
190
+ .venv\Scripts\python.exe -m ruff check src tests scripts enhancements_uiops enhancements_soda2
191
+ ```
192
+
193
+ A full run of the shipped suite: **unittest collects 4,728 tests on this release, and 656 of those skip** (they need an optional dependency, GNU Octave or GDL output, or data files not shipped with the release).
194
+
195
+ With `ARRAYPROBE_SLOW=1` and `ARRAYPROBE_HYGIENE=1` set, which add the slow and documentation
196
+ checks, the first command took 1,403 s (about 23 minutes) on a 10-core laptop (Intel Core
197
+ i7-1365U, 64 GB, Windows 11) with no other load, measured 2026-10-17 with the machine's load
198
+ recorded every 30 s. The same command run from `enhancements_uiops/` and from
199
+ `enhancements_soda2/` took 66 s and 5 s. CI (`.github/workflows/tests.yml`) sets both
200
+ variables and runs all three suites.
201
+
202
+ ## Engines, corrections and validation
203
+
204
+ The package holds two engines: `arrayprobe_uiops`, the default, translated from UIOOPS v3.5, and
205
+ `arrayprobe_soda2`, translated from NCAR's SODA-2 (IDL). Translating them surfaced findings about the
206
+ original code. On engine 3.5 a batch run corrects data-destroying upstream defects by default,
207
+ recorded in each run's `.call` stamp (`--protective off` opts out; stray-pixel removal has its own
208
+ `--stray-pixel off`), and probes with no archived product get further corrections; the full list
209
+ is in [Choosing an engine](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/27-choosing-an-engine.md#corrections-engine-35-applies-by-default).
210
+ Every other correction is opt-in, in the separate packages `arrayprobe-uiops-enhancements` and
211
+ `arrayprobe-soda2-enhancements`; the engines never depend on them.
212
+
213
+ Neither engine has an archived product of its own to be compared with, because none was ever
214
+ written by UIOOPS v3.5 or by this SODA-2 revision, so each is checked against its original running
215
+ unmodified. Before the v3.5 translation, an earlier translation of UIOOPS v3.1.4 was built to test
216
+ the approach against archived products. It is not part of this package. It reproduced archived
217
+ 2D-S products from one field campaign on 15 flights, 10 exactly; on the other five, 49 of 55,008
218
+ non-zero cells differ (0.09 %). [Validation](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/docs/04-validation.md)
219
+ reports that result and how each engine is checked; findings the UIOOPS developers had already
220
+ fixed in v3.5 are marked there. Future UIOOPS and SODA-2 releases will be compared against these
221
+ translations and incorporated where relevant.
222
+
223
+ ## Contributing
224
+
225
+ Questions, bug reports and proposed changes are welcome: email sid.gupta@anl.gov or open a GitHub issue on this repository's Issues page; see [CONTRIBUTING.md](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/CONTRIBUTING.md).
226
+
227
+ ## Credits
228
+
229
+ **Author:** Siddhant Gupta (Argonne National Laboratory).
230
+ **Advisors and collaborators:** Joe O'Brien and Bobby Jackson (ANL), Greg McFarquhar and Yongjie
231
+ Huang (University of Oklahoma), Aaron Bansemer (NCAR MMM).
232
+ **Data providers:** Peter Brechner and Saurabh Patil (University of Oklahoma).
233
+
234
+ This package exists because of UIOOPS and SODA-2 and the work of their developers: the McFarquhar
235
+ group's UIOOPS developers, and Aaron Bansemer (NCAR), who wrote and maintains SODA-2. They wrote and
236
+ still maintain the originals; credit for the processing methods is theirs.
237
+
238
+ ## Generative AI
239
+
240
+ Much of the porting, testing and documentation was written with the help of Anthropic's Claude,
241
+ under the author's direction; the author reviewed and is responsible for the result.
242
+
243
+ ## Licence and citation
244
+
245
+ BSD-3-Clause, with the UIOOPS maintainers' permission; derived from UIOOPS (GPLv3 upstream). [LICENSE](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/LICENSE) and
246
+ [NOTICE.md](https://github.com/sgupta92/arrayprobe/blob/v0.1.0/NOTICE.md) carry the full text and attribution. An independent port; it is not a UIOOPS or SODA-2 release.
247
+
248
+ Cite this package as: Gupta, S. (2026). arrayprobe (Version 0.1.0) [Computer software]. Zenodo.
249
+ [`10.5281/zenodo.23574623`](https://doi.org/10.5281/zenodo.23574623)
250
+
251
+ Please cite UIOOPS alongside it: McFarquhar et al. (2018),
252
+ [`10.5281/zenodo.1285969`](https://doi.org/10.5281/zenodo.1285969) (the methodology), and UIOOPS v3.5,
253
+ [`10.5281/zenodo.18945998`](https://doi.org/10.5281/zenodo.18945998) (the release the default engine
254
+ ports), and say which engine
255
+ produced your numbers.
256
+
257
+ `arrayprobe_soda2` translates NCAR's SODA-2 (3-clause BSD); a result derived from it cites
258
+ SODA-2, as its author asks:
259
+
260
+ > Aaron Bansemer. (2026). abansemer/soda2: v2.26.0 (Version v2.26.0) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.18331418