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.
- arrayprobe/__init__.py +219 -0
- arrayprobe/__main__.py +19 -0
- arrayprobe/_v314_lazy.py +48 -0
- arrayprobe/ai_ready.py +212 -0
- arrayprobe/attributed_export.py +1333 -0
- arrayprobe/authordefaults.py +267 -0
- arrayprobe/cli.py +3510 -0
- arrayprobe/combine.py +12 -0
- arrayprobe/compare.py +950 -0
- arrayprobe/config.py +1239 -0
- arrayprobe/constants.py +12 -0
- arrayprobe/count_closure.py +204 -0
- arrayprobe/diagnostic_views.py +769 -0
- arrayprobe/diode_report.py +265 -0
- arrayprobe/driver/__init__.py +5 -0
- arrayprobe/driver/_load_record.py +331 -0
- arrayprobe/driver/preflight_inputs.py +250 -0
- arrayprobe/driver/reprocess.py +553 -0
- arrayprobe/driver/run_flight.py +8166 -0
- arrayprobe/driver/tas_from_probe_housekeeping.py +124 -0
- arrayprobe/dropsize.py +519 -0
- arrayprobe/friendly.py +206 -0
- arrayprobe/geometry/__init__.py +77 -0
- arrayprobe/geometry/min_rectangle.py +92 -0
- arrayprobe/intarr.py +12 -0
- arrayprobe/intarr_analysis.py +16 -0
- arrayprobe/intarr_plots.py +12 -0
- arrayprobe/inventory.py +129 -0
- arrayprobe/jit_kernels.py +344 -0
- arrayprobe/lwc.py +44 -0
- arrayprobe/masks.py +349 -0
- arrayprobe/matio.py +410 -0
- arrayprobe/matlab_compat.py +13 -0
- arrayprobe/ncio.py +26 -0
- arrayprobe/particle.py +55 -0
- arrayprobe/particle_perimeter.py +12 -0
- arrayprobe/products.py +78 -0
- arrayprobe/profiles.py +179 -0
- arrayprobe/provenance.py +21 -0
- arrayprobe/py.typed +11 -0
- arrayprobe/readers/__init__.py +9 -0
- arrayprobe/readers/dmt.py +603 -0
- arrayprobe/readers/mask_csv.py +12 -0
- arrayprobe/readers/pms.py +12 -0
- arrayprobe/readers/sea.py +433 -0
- arrayprobe/readers/tasinfo.py +12 -0
- arrayprobe/regimes.py +507 -0
- arrayprobe/render.py +728 -0
- arrayprobe/reproduce_report.py +149 -0
- arrayprobe/review_agreement.py +135 -0
- arrayprobe/review_sampling.py +327 -0
- arrayprobe/run_page.py +624 -0
- arrayprobe/sample_area.py +12 -0
- arrayprobe/selector.py +206 -0
- arrayprobe/sizing.py +151 -0
- arrayprobe/time_convert.py +12 -0
- arrayprobe/timing_closure.py +141 -0
- arrayprobe/tools/__init__.py +27 -0
- arrayprobe/tools/make_demo_flight.py +1089 -0
- arrayprobe/tools/make_tas_file.py +760 -0
- arrayprobe/tools/probe_comparison.py +569 -0
- arrayprobe/tools/synthetic_truth.py +698 -0
- arrayprobe/tools/tas_sources.py +705 -0
- arrayprobe/triage_context.py +488 -0
- arrayprobe/triage_server.py +5215 -0
- arrayprobe/tune/__init__.py +15 -0
- arrayprobe/tune/diodes.py +400 -0
- arrayprobe/tune/distributions.py +300 -0
- arrayprobe/tune/sample.py +243 -0
- arrayprobe/tune/score.py +230 -0
- arrayprobe/tune/settings.py +354 -0
- arrayprobe/validate_by_condition.py +208 -0
- arrayprobe/validation_report.py +166 -0
- arrayprobe-0.1.0.dist-info/METADATA +260 -0
- arrayprobe-0.1.0.dist-info/RECORD +189 -0
- arrayprobe-0.1.0.dist-info/WHEEL +5 -0
- arrayprobe-0.1.0.dist-info/entry_points.txt +2 -0
- arrayprobe-0.1.0.dist-info/licenses/LICENSE +31 -0
- arrayprobe-0.1.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +47 -0
- arrayprobe-0.1.0.dist-info/licenses/NOTICE.md +369 -0
- arrayprobe-0.1.0.dist-info/top_level.txt +4 -0
- arrayprobe_soda2/__init__.py +131 -0
- arrayprobe_soda2/angles.py +143 -0
- arrayprobe_soda2/aspect_ratio.py +541 -0
- arrayprobe_soda2/backfill.py +100 -0
- arrayprobe_soda2/binary_dof.py +181 -0
- arrayprobe_soda2/buildindex.py +113 -0
- arrayprobe_soda2/decompress_dmt.py +285 -0
- arrayprobe_soda2/enhancement_hooks.py +275 -0
- arrayprobe_soda2/export_ascii.py +732 -0
- arrayprobe_soda2/export_ncdf.py +683 -0
- arrayprobe_soda2/export_ncdf_raf.py +396 -0
- arrayprobe_soda2/fillholes.py +161 -0
- arrayprobe_soda2/find_radius.py +105 -0
- arrayprobe_soda2/findsize.py +407 -0
- arrayprobe_soda2/fit_poisson.py +170 -0
- arrayprobe_soda2/fix2dimage.py +63 -0
- arrayprobe_soda2/fixraking.py +162 -0
- arrayprobe_soda2/fixstuckbits.py +146 -0
- arrayprobe_soda2/hvps4_read_frame.py +121 -0
- arrayprobe_soda2/jit_kernels.py +152 -0
- arrayprobe_soda2/label_blobs.py +177 -0
- arrayprobe_soda2/min_circle_fast.py +320 -0
- arrayprobe_soda2/particlesort.py +703 -0
- arrayprobe_soda2/pbp_writer.py +558 -0
- arrayprobe_soda2/poisson_spot_correct.py +183 -0
- arrayprobe_soda2/princomp.py +107 -0
- arrayprobe_soda2/probespecs.py +361 -0
- arrayprobe_soda2/process_2d.py +1364 -0
- arrayprobe_soda2/process_2d_parallel.py +626 -0
- arrayprobe_soda2/process_hk.py +512 -0
- arrayprobe_soda2/processbuffer_2dc.py +155 -0
- arrayprobe_soda2/processbuffer_cip.py +213 -0
- arrayprobe_soda2/processbuffer_f2dc.py +139 -0
- arrayprobe_soda2/processbuffer_spec.py +441 -0
- arrayprobe_soda2/processbuffer_tail.py +350 -0
- arrayprobe_soda2/pth_readers.py +245 -0
- arrayprobe_soda2/py.typed +11 -0
- arrayprobe_soda2/read2dbuffer.py +371 -0
- arrayprobe_soda2/reject.py +246 -0
- arrayprobe_soda2/reprocess_pbp.py +156 -0
- arrayprobe_soda2/sample_area.py +264 -0
- arrayprobe_soda2/save_writer.py +480 -0
- arrayprobe_soda2/sea.py +324 -0
- arrayprobe_soda2/spec_absolutepointers.py +109 -0
- arrayprobe_soda2/spec_decompress.py +203 -0
- arrayprobe_soda2/spec_index.py +476 -0
- arrayprobe_soda2/spec_read_frame.py +286 -0
- arrayprobe_soda2/spec_read_hk.py +301 -0
- arrayprobe_soda2/spec_readint.py +127 -0
- arrayprobe_soda2/timeconv.py +77 -0
- arrayprobe_soda2/update_op.py +101 -0
- arrayprobe_uiops/__init__.py +45 -0
- arrayprobe_uiops/combine.py +192 -0
- arrayprobe_uiops/combine_fork.py +359 -0
- arrayprobe_uiops/constants.py +830 -0
- arrayprobe_uiops/decode_naming.py +113 -0
- arrayprobe_uiops/diode_mask.py +250 -0
- arrayprobe_uiops/engine_absence.py +41 -0
- arrayprobe_uiops/export_oap.py +325 -0
- arrayprobe_uiops/geometry_core.py +366 -0
- arrayprobe_uiops/habit.py +749 -0
- arrayprobe_uiops/habit_core.py +248 -0
- arrayprobe_uiops/hollow_size_rule.py +376 -0
- arrayprobe_uiops/imgproc.py +2081 -0
- arrayprobe_uiops/imgproc_core.py +275 -0
- arrayprobe_uiops/intarr.py +167 -0
- arrayprobe_uiops/intarr_analysis.py +569 -0
- arrayprobe_uiops/intarr_plots.py +119 -0
- arrayprobe_uiops/jit_kernels.py +430 -0
- arrayprobe_uiops/lwc.py +70 -0
- arrayprobe_uiops/matlab_compat.py +860 -0
- arrayprobe_uiops/measure.py +346 -0
- arrayprobe_uiops/min_circle.py +204 -0
- arrayprobe_uiops/min_ellipse.py +161 -0
- arrayprobe_uiops/min_rectangle.py +200 -0
- arrayprobe_uiops/ncar_2dc_timing.py +100 -0
- arrayprobe_uiops/ncio.py +810 -0
- arrayprobe_uiops/oap_read.py +228 -0
- arrayprobe_uiops/particle.py +51 -0
- arrayprobe_uiops/particle_perimeter.py +94 -0
- arrayprobe_uiops/particle_physics.py +199 -0
- arrayprobe_uiops/pecan_params.py +134 -0
- arrayprobe_uiops/probe_cases.py +298 -0
- arrayprobe_uiops/product_sanity.py +337 -0
- arrayprobe_uiops/profile.py +71 -0
- arrayprobe_uiops/profiles.py +756 -0
- arrayprobe_uiops/provenance.py +804 -0
- arrayprobe_uiops/py.typed +11 -0
- arrayprobe_uiops/qc.py +169 -0
- arrayprobe_uiops/readers/__init__.py +8 -0
- arrayprobe_uiops/readers/mask_csv.py +74 -0
- arrayprobe_uiops/readers/pms.py +239 -0
- arrayprobe_uiops/readers/tasinfo.py +57 -0
- arrayprobe_uiops/rect_ellipse.py +129 -0
- arrayprobe_uiops/register_image_assisted.py +25 -0
- arrayprobe_uiops/reject.py +501 -0
- arrayprobe_uiops/reject_core.py +220 -0
- arrayprobe_uiops/sample_area.py +93 -0
- arrayprobe_uiops/sizedist.py +1923 -0
- arrayprobe_uiops/sizedist_core.py +814 -0
- arrayprobe_uiops/sizedist_tables.py +642 -0
- arrayprobe_uiops/spec.py +1094 -0
- arrayprobe_uiops/spec_core.py +703 -0
- arrayprobe_uiops/stray_pixel.py +103 -0
- arrayprobe_uiops/tas.py +191 -0
- arrayprobe_uiops/time_convert.py +41 -0
- uiops/__init__.py +402 -0
- uiops/py.typed +11 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Gross-failure sanity check for size-distribution (sd) and particle (proc) netCDF files.
|
|
3
|
+
|
|
4
|
+
Built after a CIP v3.5 sd came out entirely empty because its proc's
|
|
5
|
+
``particle_time`` was never shifted to UTC: every second of the sd was NaN or
|
|
6
|
+
zero and nothing downstream complained. This tool catches that class of
|
|
7
|
+
failure on any UIOOPS-style product (v3.1.4 or v3.5 sd/proc, combined
|
|
8
|
+
products) without importing any engine: netCDF4 and numpy only.
|
|
9
|
+
|
|
10
|
+
Per file it prints:
|
|
11
|
+
|
|
12
|
+
* sd: fraction of seconds with ``n > 0``, fraction with a nonzero total
|
|
13
|
+
concentration (``conc_minR``, else ``count``), an all-zero/all-NaN verdict,
|
|
14
|
+
fraction of bins empty in every second, time-axis monotonicity and span;
|
|
15
|
+
* proc: fraction of particles whose ``particle_time`` lies within the span of
|
|
16
|
+
the record time axis ``Time``, its monotonicity and span;
|
|
17
|
+
* image (decoded raw, ``data`` + ``hour/minute/second``): time span only;
|
|
18
|
+
* whether a ``.call`` sidecar exists and names ``engine=``.
|
|
19
|
+
|
|
20
|
+
Each file gets OK, ANOMALY (with reasons) or SKIP (variables not
|
|
21
|
+
recognised). Exit status is 1 if any file is ANOMALY, else 0. Read-only.
|
|
22
|
+
|
|
23
|
+
python -m arrayprobe_uiops.product_sanity FILE [FILE ...]
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import argparse
|
|
28
|
+
import os
|
|
29
|
+
import re
|
|
30
|
+
import sys
|
|
31
|
+
from dataclasses import dataclass, field
|
|
32
|
+
from typing import Any
|
|
33
|
+
|
|
34
|
+
import numpy as np
|
|
35
|
+
|
|
36
|
+
# A proc is anomalous when fewer than this fraction of its particles fall in
|
|
37
|
+
# the record-time span; an sd when fewer than this fraction of seconds carry
|
|
38
|
+
# particles is reported but not flagged (sparse cloud is legitimate).
|
|
39
|
+
MIN_PARTICLE_TIME_ON_AXIS = 0.5
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class Report:
|
|
44
|
+
path: str
|
|
45
|
+
kind: str = "unknown"
|
|
46
|
+
facts: dict = field(default_factory=dict)
|
|
47
|
+
reasons: list = field(default_factory=list)
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def verdict(self) -> str:
|
|
51
|
+
if self.kind == "unknown":
|
|
52
|
+
return "SKIP"
|
|
53
|
+
return "ANOMALY" if self.reasons else "OK"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def hhmmss_to_sod(v: np.ndarray) -> np.ndarray:
|
|
57
|
+
"""HHMMSS (possibly fractional, possibly >= 240000 after a rollover) to seconds."""
|
|
58
|
+
v = np.asarray(v, dtype=float)
|
|
59
|
+
whole = np.floor(v)
|
|
60
|
+
h = np.floor(whole / 10000.0)
|
|
61
|
+
m = np.floor(whole / 100.0) % 100
|
|
62
|
+
s = whole % 100 + (v - whole)
|
|
63
|
+
return h * 3600 + m * 60 + s
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _read(ds: Any, name: str) -> Any:
|
|
67
|
+
var = ds.variables[name]
|
|
68
|
+
var.set_auto_mask(False)
|
|
69
|
+
a = np.asarray(var[:], dtype=float)
|
|
70
|
+
fill = getattr(var, "_FillValue", None)
|
|
71
|
+
if fill is not None:
|
|
72
|
+
a = np.where(a == float(fill), np.nan, a)
|
|
73
|
+
return a
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _call_stamp(path: str) -> str:
|
|
77
|
+
call = path + ".call"
|
|
78
|
+
if not os.path.exists(call):
|
|
79
|
+
return "absent"
|
|
80
|
+
try:
|
|
81
|
+
with open(call, encoding="utf-8", errors="replace") as fh:
|
|
82
|
+
text = fh.read()
|
|
83
|
+
except OSError:
|
|
84
|
+
return "unreadable"
|
|
85
|
+
m = re.search(r"engine=(\S+)", text)
|
|
86
|
+
return f"engine={m.group(1)}" if m else "present, no engine="
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _axis_facts(rep: Report, t: np.ndarray, label: str) -> None:
|
|
90
|
+
finite = t[np.isfinite(t)]
|
|
91
|
+
if finite.size == 0:
|
|
92
|
+
rep.reasons.append(f"{label} time axis has no finite values")
|
|
93
|
+
return
|
|
94
|
+
mono = bool(np.all(np.diff(finite) >= 0))
|
|
95
|
+
rep.facts[f"{label}_monotonic"] = mono
|
|
96
|
+
rep.facts[f"{label}_span"] = f"{finite.min():.0f}-{finite.max():.0f}"
|
|
97
|
+
if not mono:
|
|
98
|
+
rep.reasons.append(f"{label} time axis is not monotonic")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def check_sd(ds: Any, rep: Report) -> None:
|
|
102
|
+
rep.kind = "sd"
|
|
103
|
+
tname = "time" if "time" in ds.variables else "Time"
|
|
104
|
+
t = _read(ds, tname)
|
|
105
|
+
nsec = t.size
|
|
106
|
+
rep.facts["seconds"] = nsec
|
|
107
|
+
_axis_facts(rep, t, "time")
|
|
108
|
+
if nsec == 0:
|
|
109
|
+
rep.reasons.append("time axis is empty")
|
|
110
|
+
return
|
|
111
|
+
frac_n = None
|
|
112
|
+
if "n" in ds.variables:
|
|
113
|
+
n = _read(ds, "n").reshape(nsec, -1)
|
|
114
|
+
frac_n = float(np.mean(np.nansum(n, axis=1) > 0))
|
|
115
|
+
rep.facts["frac_n_pos"] = round(frac_n, 4)
|
|
116
|
+
cname = next((c for c in ("conc_minR", "count") if c in ds.variables), None)
|
|
117
|
+
frac_c = None
|
|
118
|
+
if cname is not None:
|
|
119
|
+
c = _read(ds, cname).reshape(nsec, -1)
|
|
120
|
+
allnan = bool(np.all(np.isnan(c)))
|
|
121
|
+
frac_nan_rows = float(np.mean(np.all(np.isnan(c), axis=1)))
|
|
122
|
+
tot = np.nansum(c, axis=1)
|
|
123
|
+
frac_c = float(np.mean(tot > 0))
|
|
124
|
+
rep.facts[f"frac_{cname}_pos"] = round(frac_c, 4)
|
|
125
|
+
rep.facts["frac_rows_all_nan"] = round(frac_nan_rows, 4)
|
|
126
|
+
bins_empty = np.nansum(c, axis=0) <= 0
|
|
127
|
+
rep.facts["frac_bins_always_empty"] = round(float(np.mean(bins_empty)), 4)
|
|
128
|
+
if allnan:
|
|
129
|
+
rep.reasons.append(f"{cname} is NaN everywhere")
|
|
130
|
+
if frac_n is None and frac_c is None:
|
|
131
|
+
rep.kind = "unknown"
|
|
132
|
+
return
|
|
133
|
+
if not (frac_n or frac_c):
|
|
134
|
+
rep.reasons.append("no second has n>0 or a nonzero concentration (all zero/NaN)")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def check_proc(ds: Any, rep: Report) -> None:
|
|
138
|
+
rep.kind = "proc"
|
|
139
|
+
pt = _read(ds, "particle_time")
|
|
140
|
+
rep.facts["particles"] = pt.size
|
|
141
|
+
if pt.size == 0:
|
|
142
|
+
rep.reasons.append("no particles")
|
|
143
|
+
return
|
|
144
|
+
if "Time" in ds.variables:
|
|
145
|
+
rec = hhmmss_to_sod(_read(ds, "Time"))
|
|
146
|
+
rec = rec[np.isfinite(rec)]
|
|
147
|
+
_axis_facts(rep, _read(ds, "Time"), "Time")
|
|
148
|
+
else:
|
|
149
|
+
rec = np.array([])
|
|
150
|
+
ptf = pt[np.isfinite(pt)]
|
|
151
|
+
rep.facts["particle_time_span"] = (
|
|
152
|
+
f"{ptf.min():.0f}-{ptf.max():.0f}" if ptf.size else "none finite")
|
|
153
|
+
if rec.size == 0 or ptf.size == 0:
|
|
154
|
+
rep.reasons.append("no finite record Time or particle_time to compare")
|
|
155
|
+
return
|
|
156
|
+
psod = hhmmss_to_sod(ptf)
|
|
157
|
+
lo, hi = rec.min(), rec.max()
|
|
158
|
+
frac = float(np.mean((psod >= lo - 1) & (psod <= hi + 1)))
|
|
159
|
+
rep.facts["frac_particle_time_on_axis"] = round(frac, 4)
|
|
160
|
+
rep.facts["median_offset_s"] = round(float(np.median(psod) - np.median(rec)), 1)
|
|
161
|
+
if frac < MIN_PARTICLE_TIME_ON_AXIS:
|
|
162
|
+
rep.reasons.append(
|
|
163
|
+
f"only {frac:.2%} of particle_time lies in the record Time span "
|
|
164
|
+
f"(median offset {rep.facts['median_offset_s']:+.0f} s)")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def check_image(ds: Any, rep: Report) -> None:
|
|
168
|
+
rep.kind = "image"
|
|
169
|
+
sod = _read(ds, "hour") * 3600 + _read(ds, "minute") * 60 + _read(ds, "second")
|
|
170
|
+
rep.facts["records"] = sod.size
|
|
171
|
+
if sod.size:
|
|
172
|
+
rep.facts["span_sod"] = f"{np.nanmin(sod):.0f}-{np.nanmax(sod):.0f}"
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def check_file(path: str) -> Report:
|
|
176
|
+
import netCDF4
|
|
177
|
+
|
|
178
|
+
rep = Report(path)
|
|
179
|
+
try:
|
|
180
|
+
ds = netCDF4.Dataset(path)
|
|
181
|
+
except OSError as exc:
|
|
182
|
+
rep.facts["error"] = str(exc)
|
|
183
|
+
return rep
|
|
184
|
+
try:
|
|
185
|
+
names = set(ds.variables)
|
|
186
|
+
if "particle_time" in names:
|
|
187
|
+
check_proc(ds, rep)
|
|
188
|
+
elif names & {"conc_minR", "count", "n"}:
|
|
189
|
+
check_sd(ds, rep)
|
|
190
|
+
elif {"data", "hour", "minute", "second"} <= names:
|
|
191
|
+
check_image(ds, rep)
|
|
192
|
+
finally:
|
|
193
|
+
ds.close()
|
|
194
|
+
if rep.kind != "unknown":
|
|
195
|
+
rep.facts["call"] = _call_stamp(path)
|
|
196
|
+
return rep
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def format_report(rep: Report) -> str:
|
|
200
|
+
facts = " ".join(f"{k}={v}" for k, v in rep.facts.items())
|
|
201
|
+
line = f"{rep.verdict:7s} [{rep.kind}] {rep.path}\n {facts}"
|
|
202
|
+
for r in rep.reasons:
|
|
203
|
+
line += f"\n ! {r}"
|
|
204
|
+
return line
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def main(argv: list[str] | None = None) -> int:
|
|
208
|
+
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
209
|
+
ap.add_argument("files", nargs="+")
|
|
210
|
+
args = ap.parse_args(argv)
|
|
211
|
+
bad = 0
|
|
212
|
+
for f in args.files:
|
|
213
|
+
rep = check_file(f)
|
|
214
|
+
print(format_report(rep))
|
|
215
|
+
bad += rep.verdict == "ANOMALY"
|
|
216
|
+
return 1 if bad else 0
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
if __name__ == "__main__":
|
|
220
|
+
sys.exit(main())
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
# --- The batch driver's post-S4 plausibility gate -----------------------------------
|
|
224
|
+
#: Below this fraction of seconds carrying particles, an sd built from a proc that holds accepted
|
|
225
|
+
#: particles is implausible and the driver refuses it (exit 2). 2026-10-04: an all-zero CIP sd and
|
|
226
|
+
#: near-empty v3.5 2D-S sds were written with exit 0 and caught only by luck.
|
|
227
|
+
MIN_FRAC_SECONDS_WITH_PARTICLES = 0.001
|
|
228
|
+
#: Below this many accepted particles an empty sd is not evidence of a fault: sizeDist's own
|
|
229
|
+
#: rejections (shattering, size range, TAS axis) can legitimately drop a handful. The demo flight
|
|
230
|
+
#: (3 accepted particles, 0 seconds with particles in its sd) is valid; the 2026-10-04 empty CIP sd
|
|
231
|
+
#: had 3,797,537 accepted particles.
|
|
232
|
+
MIN_ACCEPTED_FOR_REFUSAL = 100
|
|
233
|
+
#: A value at or above this is MATLAB's realmax written as a number, not a measurement.
|
|
234
|
+
REALMAX_LIKE = 1e300
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
@dataclass
|
|
238
|
+
class Plausibility:
|
|
239
|
+
seconds: int
|
|
240
|
+
frac_pos: float
|
|
241
|
+
nonfinite_seconds: int
|
|
242
|
+
duplicated_seconds: int
|
|
243
|
+
bins: int
|
|
244
|
+
accepted_particles: int | None
|
|
245
|
+
implausible: bool
|
|
246
|
+
reason: str = ""
|
|
247
|
+
|
|
248
|
+
def token(self) -> str:
|
|
249
|
+
"""One space-free ``.call`` stamp token."""
|
|
250
|
+
acc = "na" if self.accepted_particles is None else str(self.accepted_particles)
|
|
251
|
+
return (f"plausibility=(sec={self.seconds},pos={self.frac_pos:.4f},"
|
|
252
|
+
f"nonfinite={self.nonfinite_seconds},dup={self.duplicated_seconds},"
|
|
253
|
+
f"bins={self.bins},accepted={acc},"
|
|
254
|
+
f"{'IMPLAUSIBLE' if self.implausible else 'ok'})")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def accepted_seconds(proc_path: str | os.PathLike[str]) -> int | None:
|
|
258
|
+
"""Distinct seconds (``floor(particle_time)``) holding an accepted particle, else None. The
|
|
259
|
+
denominator for a short or sparse flight: the sd cannot carry particles in more seconds than
|
|
260
|
+
the proc accepted particles in, whatever the length of its time axis."""
|
|
261
|
+
import netCDF4
|
|
262
|
+
|
|
263
|
+
with netCDF4.Dataset(proc_path) as ds:
|
|
264
|
+
if "particle_time" not in ds.variables:
|
|
265
|
+
return None
|
|
266
|
+
t = np.asarray(_read(ds, "particle_time"), dtype=float).reshape(-1)
|
|
267
|
+
if "image_auto_reject" in ds.variables:
|
|
268
|
+
rej = np.asarray(_read(ds, "image_auto_reject")).reshape(-1)
|
|
269
|
+
if rej.size == t.size:
|
|
270
|
+
t = t[np.isin(rej, [ord(c) for c in "0HhuR"])]
|
|
271
|
+
t = t[np.isfinite(t)]
|
|
272
|
+
return int(np.unique(np.floor(t)).size)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def accepted_particles(proc_path: str | os.PathLike[str]) -> int | None:
|
|
276
|
+
"""Particles a proc accepted (``image_auto_reject`` in ``'0HhuR'``, the codes sizeDist keeps),
|
|
277
|
+
else all particles, else None."""
|
|
278
|
+
import netCDF4
|
|
279
|
+
|
|
280
|
+
with netCDF4.Dataset(proc_path) as ds:
|
|
281
|
+
if "image_auto_reject" in ds.variables:
|
|
282
|
+
rej = _read(ds, "image_auto_reject")
|
|
283
|
+
return int(np.count_nonzero(np.isin(rej, [ord(c) for c in "0HhuR"])))
|
|
284
|
+
if "particle_time" in ds.variables:
|
|
285
|
+
return int(ds.variables["particle_time"].size)
|
|
286
|
+
return None
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _per_second(a: np.ndarray, nsec: int) -> np.ndarray:
|
|
290
|
+
"""``a`` as (seconds, columns) whichever axis the file put the time dimension on: a
|
|
291
|
+
MATLAB-declared (Time, bins) variable is (bins, Time) in the file, so reshaping blindly would
|
|
292
|
+
scramble seconds and bins."""
|
|
293
|
+
if a.ndim == 2 and a.shape[0] != nsec and a.shape[1] == nsec:
|
|
294
|
+
a = a.T
|
|
295
|
+
return a.reshape(nsec, -1)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def sd_plausibility(sd_path: str | os.PathLike[str], accepted: int | None = None,
|
|
299
|
+
min_frac: float = MIN_FRAC_SECONDS_WITH_PARTICLES,
|
|
300
|
+
accepted_secs: int | None = None,
|
|
301
|
+
min_accepted: int = MIN_ACCEPTED_FOR_REFUSAL) -> Plausibility:
|
|
302
|
+
"""Plausibility of one sd: seconds with particles, non-finite/realmax seconds, duplicated
|
|
303
|
+
seconds and bin count. Implausible when no second (or fewer than ``min_frac``) carries
|
|
304
|
+
particles while the proc behind it accepted at least ``min_accepted`` (``None`` = unknown,
|
|
305
|
+
treated as enough). The fraction is of ``min(seconds, accepted_secs)`` when the proc's
|
|
306
|
+
accepted seconds are known, so a short or sparse but valid flight is not refused for the
|
|
307
|
+
length of its axis."""
|
|
308
|
+
import netCDF4
|
|
309
|
+
|
|
310
|
+
with netCDF4.Dataset(sd_path) as ds:
|
|
311
|
+
tname = "time" if "time" in ds.variables else "Time"
|
|
312
|
+
t = _read(ds, tname).reshape(-1) if tname in ds.variables else np.array([])
|
|
313
|
+
nsec = t.size
|
|
314
|
+
cname = next((c for c in ("conc_minR", "count") if c in ds.variables), None)
|
|
315
|
+
c = _per_second(_read(ds, cname), nsec) if cname and nsec else np.zeros((nsec, 0))
|
|
316
|
+
n = _per_second(_read(ds, "n"), nsec) if "n" in ds.variables and nsec else None
|
|
317
|
+
bins = int(c.shape[1]) if c.ndim == 2 else 0
|
|
318
|
+
rows = c if n is None else np.concatenate([c, n], axis=1)
|
|
319
|
+
bad = ~np.isfinite(rows) & ~np.isnan(rows) | (np.abs(np.nan_to_num(rows)) >= REALMAX_LIKE)
|
|
320
|
+
nonfinite = int(np.count_nonzero(bad.any(axis=1))) if rows.size else 0
|
|
321
|
+
clean = np.where(bad, np.nan, rows)
|
|
322
|
+
pos = (np.nansum(np.where(clean > 0, clean, 0), axis=1) > 0
|
|
323
|
+
if rows.size else np.zeros(nsec, bool))
|
|
324
|
+
frac = float(pos.mean()) if nsec else 0.0
|
|
325
|
+
dup = int(nsec - np.unique(np.floor(t[np.isfinite(t)])).size) if nsec else 0
|
|
326
|
+
denom = min(nsec, accepted_secs) if accepted_secs else nsec
|
|
327
|
+
frac_gate = float(pos.sum()) / denom if denom else 0.0
|
|
328
|
+
reason = ""
|
|
329
|
+
if accepted is None or accepted >= min_accepted:
|
|
330
|
+
if nsec == 0:
|
|
331
|
+
reason = "the sd has no seconds"
|
|
332
|
+
elif not pos.any():
|
|
333
|
+
reason = "no second has particles (all zero/NaN)"
|
|
334
|
+
elif frac_gate < min_frac:
|
|
335
|
+
reason = (f"only {int(pos.sum())} of {denom} seconds carry particles "
|
|
336
|
+
f"({frac_gate:.4%}, threshold {min_frac:.1%})")
|
|
337
|
+
return Plausibility(nsec, frac, nonfinite, dup, bins, accepted, bool(reason), reason)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Where every ``STOCK_V35`` field comes from, machine-readable.
|
|
3
|
+
|
|
4
|
+
``arrayprobe.profiles.STOCK_V35`` carries the values; this table carries the
|
|
5
|
+
``file:line`` in ``UIOPS-v3.5/joefinlon-UIOPS-039be82/`` that each value was read
|
|
6
|
+
from and the token the cited line must contain. ``tests/test_stock_v35_profile.py``
|
|
7
|
+
reads the cited lines back and compares the values to an Octave-parsed golden, so
|
|
8
|
+
the profile, this table and the vendored source can only agree by being right.
|
|
9
|
+
|
|
10
|
+
The v3.5 engine takes no ``FidelityProfile`` (``spec.py``, ``sizedist.py``,
|
|
11
|
+
``imgproc.py`` each say why: v3.5 has one source tree). Only ``reject_thresholds``
|
|
12
|
+
is consumed by it; the other fields describe the tree for ``.call`` sidecars and
|
|
13
|
+
readers.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
|
|
19
|
+
__all__ = ["Provenance", "STOCK_V35_PROVENANCE", "V35_TREE"]
|
|
20
|
+
|
|
21
|
+
V35_TREE = ("UIOPS-v3.5", "joefinlon-UIOPS-039be82")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class Provenance:
|
|
26
|
+
"""One cited value of ``STOCK_V35``: the profile ``field``, the ``value`` it carries, and the
|
|
27
|
+
``file`` (relative to :data:`V35_TREE`, e.g. ``calculate_reject_unified.m`` or
|
|
28
|
+
``read_binary_SPEC.m``), ``lines`` and ``token`` it was read from."""
|
|
29
|
+
field: str #: FidelityProfile field, or "reject_thresholds.<name>"
|
|
30
|
+
value: object #: what STOCK_V35 carries
|
|
31
|
+
file: str #: relative to V35_TREE
|
|
32
|
+
lines: tuple[int, ...]
|
|
33
|
+
token: str #: text every cited line must contain
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
_UNIFIED = "calculate_reject_unified.m"
|
|
37
|
+
|
|
38
|
+
STOCK_V35_PROVENANCE: tuple[Provenance, ...] = (
|
|
39
|
+
Provenance("spec_buffer_guard", True, "read_binary_SPEC.m",
|
|
40
|
+
(322, 326, 333, 356, 360, 367), "length(buf)"),
|
|
41
|
+
# hvps_reader: read_binary_hvps.m is absent from the tree -- tested separately.
|
|
42
|
+
Provenance("hvps_reader", "spec", "read_binary_SPEC.m", (1,),
|
|
43
|
+
"function read_binary_SPEC("),
|
|
44
|
+
Provenance("diode_stats_counts_shadowed", True, "imgProc_sm.m",
|
|
45
|
+
(1208, 1210, 1211), "sum(c=='0',1)"),
|
|
46
|
+
Provenance("zero_image_particle_recovery", True, "imgProc_sm.m",
|
|
47
|
+
(773, 1311), "start = j + 2"),
|
|
48
|
+
Provenance("time_in_seconds_from_tas", True, "imgProc_sm.m",
|
|
49
|
+
(1133,), "tas2d = tas(tasTime==tempTime)"),
|
|
50
|
+
Provenance("inter_arrival_in_seconds", True, "imgProc_sm.m", (1176,),
|
|
51
|
+
"images.int_arrival(kk) = time_in_seconds(kk)-time_in_seconds(kk-1)"),
|
|
52
|
+
# shadow_diode_reillumination: () means the token must occur NOWHERE in the file.
|
|
53
|
+
Provenance("shadow_diode_reillumination", False, "imgProc_sm.m", (),
|
|
54
|
+
"shadow_diode"),
|
|
55
|
+
Provenance("imgproc_output_typing", "typed", "imgProc_sm.m",
|
|
56
|
+
(1352,), "int16(images.auto_reject)"),
|
|
57
|
+
Provenance("nan_tas_substitution", True, "sizeDist.m",
|
|
58
|
+
(1962,), "if isnan(tas(i))"),
|
|
59
|
+
Provenance("reject_thresholds.rej_zero_area", True, _UNIFIED,
|
|
60
|
+
(60,), "handles.rej_zero_area = 1;"),
|
|
61
|
+
Provenance("reject_thresholds.rej_split", True, _UNIFIED,
|
|
62
|
+
(61,), "handles.rej_split = 1;"),
|
|
63
|
+
Provenance("reject_thresholds.rej_hollow", True, _UNIFIED,
|
|
64
|
+
(62,), "handles.rej_hollow = 1;"),
|
|
65
|
+
Provenance("reject_thresholds.shadowed_area", 25, _UNIFIED,
|
|
66
|
+
(64,), "handles.shadowed_area = 25;"),
|
|
67
|
+
Provenance("reject_thresholds.max_edge_img_ar", 6, _UNIFIED,
|
|
68
|
+
(65,), "handles.max_edge_img_ar = 6;"),
|
|
69
|
+
Provenance("reject_thresholds.max_comp_img_ar", 5, _UNIFIED,
|
|
70
|
+
(66,), "handles.max_comp_img_ar = 5;"),
|
|
71
|
+
)
|