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,12 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ import sys as _sys
3
+ import typing as _typing
4
+
5
+ from arrayprobe_uiops import constants as _impl
6
+
7
+ # Static view for type checkers only: the alias below replaces this module at run time,
8
+ # so mypy would otherwise see an empty module. No run-time effect.
9
+ if _typing.TYPE_CHECKING:
10
+ from arrayprobe_uiops.constants import * # noqa: F403
11
+
12
+ _sys.modules[__name__] = _impl
@@ -0,0 +1,204 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Count closure: do a size-distribution product's binned counts sum to the particles S3 holds?
3
+
4
+ Read only. Compares, for one size-distribution product (``sd`` netCDF) and its
5
+ per-particle proc file, **per second, the way sizeDist does**:
6
+
7
+ * ``binned``: the sum of ``count`` over bins (``sizedist.py:1408``,
8
+ ``count = dist_minR * binwidth / 10``) per second;
9
+ * ``accepted``: the particles of the proc file that ``sizeDist`` puts in the
10
+ accepted population of a second on the sd time axis. Every particle that is
11
+ not accepted is listed in ``excluded`` with a named cause and the port line
12
+ that excludes it (``CAUSES``); the closure is exact or the residual is
13
+ attributed particle by particle, never a tolerance.
14
+ * ``probe_reported``: the probe's own particle total. Neither the SPEC reader's
15
+ proc output nor the DMT proc output written by this package carries a
16
+ per-second probe total that is read here, so it is ``None`` ("not available").
17
+
18
+ Causes, each measured on the tracked demo-flight fixtures:
19
+
20
+ ``outside-tas-axis``
21
+ The particle's second (probetype 2: ``Time`` in hhmmss, v3.5
22
+ ``arrayprobe_uiops/sizedist.py:1562-1571``, v3.1.4: the v3.1.4 engine's sizedist
23
+ module, lines 720-734)
24
+ is not on the sd ``time`` axis, which is the TAS axis: sizeDist loops over
25
+ ``n_sec = len(tas)`` seconds only (v3.5 ``:1510``/``:1608``, v3.1.4
26
+ ``:691``/``:786``) and the last edge ``tas_time[-1] + 1`` is exclusive
27
+ (v3.5 ``:1552``/``:1468``). A block past the last TAS second is never read.
28
+ ``shattered-interarrival``
29
+ v3.1.4 with a shattering threshold (``iat_file`` -> ``'NONE'`` ->
30
+ ``default_int_arr_thresh``, ``sizeDist.m:874``; the v3.1.4 engine's sizedist
31
+ module, line 1217, whose line numbers the rest of this entry cites):
32
+ the inter-arrival time, ``0`` for the file's first particle (``:906``) and
33
+ ``diff(Time_in_seconds)`` to the previous particle in file order otherwise
34
+ (``:909-911``), is ``<=`` the threshold, so ``auto_reject`` becomes ``'S'`` in
35
+ memory (``:1221-1227``, ``sizeDist.m:876-888``, the hit and its predecessor).
36
+ The proc file keeps its original code; the sd's ``Reject_ratio`` shows it.
37
+ ``reject-code`` / ``center-out`` / ``diameter-out-of-bins``
38
+ ``image_auto_reject`` not in ``GOOD_REJECT_CODES`` (``"0HhuR"``,
39
+ ``sizedist_core.py:63``, ``sizeDist.m:1080``); ``image_center_in != 1`` under
40
+ ``SAmethod == 0`` (``sizedist.py:1268-1270``); ``image_diam_minR`` outside
41
+ ``[bin_min[0], bin_max[-1])`` (``bin_index``, ``sizedist_core.py:446-464``).
42
+
43
+ The shattering threshold is read from the sd ``.call`` sidecar
44
+ (``default_int_arr_thresh=<value>``) and applied only when the sd's
45
+ ``Shattering Algorithm`` attribute says it was applied; a ``.call`` naming a real
46
+ threshold file is refused rather than guessed. The v3.5 corrupt-time pass
47
+ (``while k < n - 1``) is not re-derived: it runs only on a
48
+ non-monotonic particle-time series (``arrayprobe_uiops/sizedist.py:498``), and
49
+ this module raises ``NotImplementedError`` on one instead of attributing silently.
50
+ """
51
+ from __future__ import annotations
52
+
53
+ import os
54
+ import re
55
+
56
+ import numpy as np
57
+
58
+ from arrayprobe import provenance
59
+
60
+ GOOD_REJECT_CODES = "0HhuR"
61
+ NOT_AVAILABLE = "not available"
62
+ CAUSES = (
63
+ "outside-tas-axis",
64
+ "shattered-interarrival",
65
+ "reject-code",
66
+ "center-out",
67
+ "diameter-out-of-bins",
68
+ )
69
+
70
+
71
+ def _var(ds, name):
72
+ x = ds.variables[name][:]
73
+ if np.ma.isMaskedArray(x) and not np.issubdtype(x.dtype, np.floating):
74
+ # NaN is not a value of an integer dtype; a masked int (a netCDF fill value in an
75
+ # int16/int32 particle variable) is widened to float64 so the fill can be NaN.
76
+ x = x.astype(np.float64)
77
+ return np.ma.filled(x, np.nan)
78
+
79
+
80
+ def _hhmmss_to_insec(t):
81
+ t = np.asarray(t, dtype=np.float64)
82
+ return (np.floor(t / 10000) * 3600 + np.floor((t % 10000) / 100) * 60
83
+ + np.floor(t % 100))
84
+
85
+
86
+ def _shattering_threshold(sd_path, sd_attrs):
87
+ """The per-particle threshold sizeDist applied, or ``None`` when it skipped the block."""
88
+ alg = str(sd_attrs.get("Shattering Algorithm", "Not applied"))
89
+ if alg.startswith("Not applied"):
90
+ return None
91
+ # The driver writes ``<file>.nc.call`` (``run_flight.call_path``); a hand-named
92
+ # ``<stem>.call`` is the fallback, as in ``reproduce_report._call_stamp``.
93
+ call = str(sd_path) + ".call"
94
+ if not os.path.isfile(call):
95
+ call = os.path.splitext(str(sd_path))[0] + ".call"
96
+ if not os.path.isfile(call):
97
+ raise FileNotFoundError(f"{call}: the sd stamp names the shattering threshold")
98
+ with open(call, encoding="utf-8") as fh:
99
+ fields = provenance.parse(fh.read()).fields
100
+ # A field's value runs to the next key ("6e-06 (default)"); its first token is the value.
101
+ iat_file = (fields.get("iat_file") or "").split()
102
+ if iat_file and iat_file[0] not in ("<none>", "NONE") \
103
+ and not iat_file[0].endswith("MISSING.cdf"):
104
+ raise NotImplementedError(
105
+ f"{call} names a real threshold file {iat_file[0]}; "
106
+ "per-particle thresholds from a file are not re-derived here")
107
+ m = re.match(r"[0-9.eE+-]+", fields.get("default_int_arr_thresh") or "")
108
+ if m is None:
109
+ raise ValueError(f"{call}: shattering was applied but no default_int_arr_thresh= stamp")
110
+ return float(m.group(0))
111
+
112
+
113
+ def count_closure(sd_path, proc_path):
114
+ """Return per-second ``binned``/``accepted``, the residual and every excluded particle."""
115
+ import netCDF4
116
+
117
+ with netCDF4.Dataset(str(sd_path)) as sd:
118
+ counts = _var(sd, "count") # (Time, bins)
119
+ bin_min = _var(sd, "bin_min")
120
+ bin_max = _var(sd, "bin_max")
121
+ times = _var(sd, "time")
122
+ attrs = {k: sd.getncattr(k) for k in sd.ncattrs()}
123
+ with netCDF4.Dataset(str(proc_path)) as pr:
124
+ code = _var(pr, "image_auto_reject")
125
+ center = _var(pr, "image_center_in")
126
+ diam = _var(pr, "image_diam_minR")
127
+ ptime = _var(pr, "Time") # hhmmss, probetype 2
128
+ tsec = _var(pr, "Time_in_seconds")
129
+ rec = _var(pr, "parent_rec_num")
130
+ n = int(code.size)
131
+ sa_method = attrs.get("SA Method")
132
+ if sa_method is not None and str(sa_method) != "Center-in":
133
+ # The center-out cause below is sizeDist's SAmethod == 0 rule only.
134
+ raise NotImplementedError(
135
+ f"SA Method {sa_method!r}: only the Center-in acceptance is re-derived")
136
+
137
+ # -- the second each particle belongs to (sizeDist's TAS-axis loop) --------
138
+ tas_time = _hhmmss_to_insec(times)
139
+ if np.any(np.diff(tas_time) <= 0):
140
+ raise NotImplementedError("non-monotonic sd time axis: fix_time_grid path not re-derived")
141
+ image_time = _hhmmss_to_insec(ptime)
142
+ if np.any(np.diff(image_time) < 0):
143
+ raise NotImplementedError(
144
+ "non-monotonic particle times: v3.5's corrupt-time pass is not re-derived")
145
+ if tas_time.size:
146
+ edges = np.concatenate([tas_time, [tas_time[-1] + 1]])
147
+ sec_index = np.searchsorted(edges, image_time, side="right") - 1
148
+ else: # a zero-second sd: no particle lies on its axis
149
+ sec_index = np.full(n, -1)
150
+ on_axis = (sec_index >= 0) & (sec_index < len(tas_time))
151
+
152
+ # -- shattering, v3.1.4 production gate (:866-888) --------------------------
153
+ thresh = _shattering_threshold(sd_path, attrs)
154
+ shattered = np.zeros(n, dtype=bool)
155
+ if thresh is not None and n:
156
+ int_arr = np.concatenate([[0.0], np.diff(tsec)])
157
+ hit = int_arr <= thresh
158
+ shattered = hit.copy()
159
+ shattered[:-1] |= hit[1:] # :884-888 flags ix-1 and ix
160
+
161
+ good_code = np.isin(code, [ord(c) for c in GOOD_REJECT_CODES])
162
+ center_ok = center == 1
163
+ in_range = (diam >= bin_min[0]) & (diam < bin_max[-1])
164
+
165
+ excluded = []
166
+ accepted = np.ones(n, dtype=bool)
167
+ for k in range(n):
168
+ cause = None
169
+ if not on_axis[k]:
170
+ cause = "outside-tas-axis"
171
+ elif shattered[k]:
172
+ cause = "shattered-interarrival"
173
+ elif not good_code[k]:
174
+ cause = "reject-code"
175
+ elif not center_ok[k]:
176
+ cause = "center-out"
177
+ elif not in_range[k]:
178
+ cause = "diameter-out-of-bins"
179
+ if cause is not None:
180
+ accepted[k] = False
181
+ excluded.append({"index": k,
182
+ "parent_rec_num": None if np.isnan(rec[k]) else int(rec[k]),
183
+ "time": float(ptime[k]), "cause": cause})
184
+
185
+ accepted_per_second = np.zeros(len(tas_time))
186
+ for k in np.flatnonzero(accepted):
187
+ accepted_per_second[sec_index[k]] += 1
188
+ binned_per_second = np.nansum(counts, axis=1)
189
+ total_binned = float(np.sum(binned_per_second))
190
+ total_accepted = int(np.count_nonzero(accepted))
191
+ return {
192
+ "time": times,
193
+ "binned_per_second": binned_per_second,
194
+ "accepted_per_second": accepted_per_second,
195
+ "total_binned": total_binned,
196
+ "total_accepted": total_accepted,
197
+ "total_in_proc": n,
198
+ "residual": total_binned - total_accepted,
199
+ "residual_per_second": binned_per_second - accepted_per_second,
200
+ "excluded": excluded,
201
+ "shattering_threshold": thresh,
202
+ "probe_reported": None,
203
+ "probe_reported_note": NOT_AVAILABLE,
204
+ }