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
arrayprobe/__init__.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""arrayprobe -- a Python port of UIOOPS. Porting v3.1.4 line by line surfaced a
|
|
3
|
+
set of findings about the MATLAB; those findings are fixed in the v3.5 engine
|
|
4
|
+
(``arrayprobe_uiops``, the default) where the developers addressed them, and in
|
|
5
|
+
the opt-in ``arrayprobe-enhancements`` package otherwise.
|
|
6
|
+
|
|
7
|
+
UIOOPS (University of Illinois / Oklahoma OAP Processing Software, McFarquhar
|
|
8
|
+
group, GPLv3) turns raw optical-array-probe buffers into particle-by-particle
|
|
9
|
+
records and then into size distributions. This package -- the v3.1.4 engine
|
|
10
|
+
-- reproduces that original's behaviour first, bugs included: a "fix" that
|
|
11
|
+
changes a computed value is a defect here, because the archived campaign
|
|
12
|
+
products were written by the MATLAB as it actually behaves, and reproducing
|
|
13
|
+
that behaviour exactly is what let every fix above be checked against the
|
|
14
|
+
archived record before it was trusted. See the repository ``README.md`` for
|
|
15
|
+
the validation evidence, the known gaps, and the fidelity doctrine, and
|
|
16
|
+
``docs/developer/`` for the per-stage design documents.
|
|
17
|
+
|
|
18
|
+
The names re-exported below are the package's public front door -- the four
|
|
19
|
+
pipeline stages, the fidelity profiles that select between the MATLAB source
|
|
20
|
+
trees, and the run-configuration and comparison entry points. Everything else
|
|
21
|
+
remains reachable by its submodule (``arrayprobe.reject``,
|
|
22
|
+
``arrayprobe.habit``, ``arrayprobe.geometry`` and the rest); this list is the
|
|
23
|
+
subset a caller running or checking a flight actually needs.
|
|
24
|
+
|
|
25
|
+
To process data, use the default engine, UIOOPS v3.5, which :func:`engine`
|
|
26
|
+
returns. The shortest route is a run configuration and ``arrayprobe run
|
|
27
|
+
<config.toml>`` (``examples/configs/`` has configs). The same chain from
|
|
28
|
+
Python, for a CIP recorded in a SEA file::
|
|
29
|
+
|
|
30
|
+
import importlib
|
|
31
|
+
|
|
32
|
+
import netCDF4
|
|
33
|
+
import numpy as np
|
|
34
|
+
|
|
35
|
+
import arrayprobe as ap
|
|
36
|
+
|
|
37
|
+
eng = ap.engine() # "3.5", the default engine
|
|
38
|
+
imgproc = importlib.import_module(f"{eng.package}.imgproc")
|
|
39
|
+
sizedist = importlib.import_module(f"{eng.package}.sizedist")
|
|
40
|
+
|
|
41
|
+
# Decode: one file per probe in the SEA container (decoded.CIP.cdf,
|
|
42
|
+
# decoded.2DC.cdf). The SEA reader is the same code under both engines.
|
|
43
|
+
ap.read_binary_SEA("flight.sea", "decoded")
|
|
44
|
+
with netCDF4.Dataset("decoded.CIP.cdf") as nc:
|
|
45
|
+
n_records = len(nc.dimensions["time"])
|
|
46
|
+
|
|
47
|
+
# Frame particles. A CIP takes no airspeed here (tas_time/tas are None).
|
|
48
|
+
imgproc.imgproc_sm_v35(
|
|
49
|
+
"decoded.CIP.cdf", "proc.nc", "CIP", 1, n_records, "UND2016",
|
|
50
|
+
iNewHabit=0, reject_config=ap.profile("stock-v3.5").reject_thresholds,
|
|
51
|
+
tas_time=None, tas=None, software="UIOOPS_v3.5")
|
|
52
|
+
|
|
53
|
+
# One-second size distributions. The airspeed series must be in the CIP's
|
|
54
|
+
# own clock (see examples/configs/cip_uiops/README.md).
|
|
55
|
+
timehhmmss, tas = ap.load_tas_info("airspeed.tas.csv")
|
|
56
|
+
sizedist.run(
|
|
57
|
+
"proc.nc", "sd.nc", tas, np.floor(timehhmmss), "CIP", 6, 0,
|
|
58
|
+
np.full_like(tas, 9e5), np.full_like(tas, 15.0), 0, 0, 0, 0,
|
|
59
|
+
"UND2016", "20160906 064017", software="UIOOPS_v3.5")
|
|
60
|
+
|
|
61
|
+
``tests/test_package_docstring_example.py`` runs that block as written.
|
|
62
|
+
|
|
63
|
+
**The validation path.** The names re-exported below are the v3.1.4 engine,
|
|
64
|
+
used to reproduce archived UIOOPS products such as the ORACLES 2016 2D-S
|
|
65
|
+
record, not to process new data. Its chain, exactly as the reproduction was
|
|
66
|
+
checked, including the twelfth ``sizeDist`` argument that names a file which
|
|
67
|
+
must not exist (``sizedist.run``'s docstring says why)::
|
|
68
|
+
|
|
69
|
+
import arrayprobe as ap
|
|
70
|
+
|
|
71
|
+
ap.read_binary_SPEC("base160906064403.2DS", "decoded",
|
|
72
|
+
profile=ap.ORACLES_PRODUCTION)
|
|
73
|
+
ap.imgproc_sm("decoded.H.cdf", "proc.nc", "2DS", 1, 1, "ORACLES",
|
|
74
|
+
profile=ap.ORACLES_PRODUCTION)
|
|
75
|
+
ap.size_dist("proc.nc", "sd.nc", tas, timehhmmss, "2DS", 6, 2,
|
|
76
|
+
pres, temp, "ORACLES", "20160906",
|
|
77
|
+
"2DS_intArrThreshold_MISSING.cdf",
|
|
78
|
+
tree="production")
|
|
79
|
+
ap.combine_sizedist([...], "flight.nc", flight_date=..., summary_time=...)
|
|
80
|
+
|
|
81
|
+
``read_binary_SPEC`` keeps the MATLAB's own capitalisation, as the porting
|
|
82
|
+
convention requires; ``size_dist`` is ``sizeDist.m`` under the package's
|
|
83
|
+
snake-case rule and is the same object as :func:`arrayprobe.sizedist.run`.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
from __future__ import annotations
|
|
87
|
+
|
|
88
|
+
import logging
|
|
89
|
+
|
|
90
|
+
from .combine import combine_sizedist
|
|
91
|
+
from .compare import ComparisonReport, compare_files, format_report
|
|
92
|
+
from .config import ConfigError, RunConfig, load_config
|
|
93
|
+
from .products import open_product
|
|
94
|
+
from .profiles import (
|
|
95
|
+
ORACLES_2016,
|
|
96
|
+
ORACLES_PRODUCTION,
|
|
97
|
+
PROFILES,
|
|
98
|
+
STOCK_V314,
|
|
99
|
+
FidelityProfile,
|
|
100
|
+
profile,
|
|
101
|
+
register_profile,
|
|
102
|
+
)
|
|
103
|
+
from .readers.dmt import read_binary_DMT
|
|
104
|
+
from .readers.pms import read_binary_PMS
|
|
105
|
+
from .readers.sea import read_binary_SEA
|
|
106
|
+
from .readers.tasinfo import load_tas_info
|
|
107
|
+
from .selector import DEFAULT_ENGINE, ENGINES, Engine, UnknownEngine, engine
|
|
108
|
+
from .timing_closure import ClosureResult, check_closure
|
|
109
|
+
from .validation_report import CellAgreement, ProductComparisonReport, compare_to_product
|
|
110
|
+
|
|
111
|
+
# The v3.1.4 validation engine is not part of the public distribution
|
|
112
|
+
#: its top-level names load on first access (PEP 562).
|
|
113
|
+
_V314_NAMES = {
|
|
114
|
+
"imgproc_sm": (".imgproc", "imgproc_sm"),
|
|
115
|
+
"read_binary_SPEC": (".readers.spec", "read_binary_SPEC"),
|
|
116
|
+
"read_binary_hvps": (".readers.spec", "read_binary_hvps"),
|
|
117
|
+
"size_dist": (".sizedist", "run"),
|
|
118
|
+
}
|
|
119
|
+
from arrayprobe_uiops.engine_absence import ABSENT_MESSAGE as _V314_ABSENT # noqa: E402
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def __getattr__(name: str):
|
|
123
|
+
spec = _V314_NAMES.get(name)
|
|
124
|
+
if spec is None:
|
|
125
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
126
|
+
import importlib
|
|
127
|
+
|
|
128
|
+
modname, attr = spec
|
|
129
|
+
try:
|
|
130
|
+
module = importlib.import_module(modname, __name__)
|
|
131
|
+
except ModuleNotFoundError as exc:
|
|
132
|
+
if exc.name in (f"{__name__}{modname}", f"{__name__}.{modname.lstrip('.')}"):
|
|
133
|
+
raise ImportError(_V314_ABSENT) from exc
|
|
134
|
+
raise
|
|
135
|
+
value = getattr(module, attr)
|
|
136
|
+
globals()[name] = value
|
|
137
|
+
return value
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def __dir__() -> list[str]:
|
|
141
|
+
return sorted(set(globals()) | set(_V314_NAMES))
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
#: The first release, ``0.1.0``: usable, open and still in development.
|
|
145
|
+
#:
|
|
146
|
+
#: What the number claims: the ORACLES 2D-S lineage is feature-complete and
|
|
147
|
+
#: validated against the archived MATLAB products cell by cell on whole
|
|
148
|
+
#: flights. What ``0.x`` withholds: the interface may still change before
|
|
149
|
+
#: 1.0, the stock-tree ``sizeDist`` control flow
|
|
150
|
+
#: is not implemented, and the probes no UIOOPS product exists for
|
|
151
|
+
#: here are validated against Octave oracles and synthetic fixtures only.
|
|
152
|
+
#: ``pyproject.toml``'s ``version`` carries the same string, and
|
|
153
|
+
#: ``tests/test_version.py`` reads the two from different places so they
|
|
154
|
+
#: cannot drift.
|
|
155
|
+
__version__ = "0.1.0"
|
|
156
|
+
|
|
157
|
+
# 2026-09-15: the library never configures its own handler --
|
|
158
|
+
# a bare ``import arrayprobe`` must stay silent for a notebook, a pipeline
|
|
159
|
+
# caller, or a future ``xarray`` user, matching the same "no default silently
|
|
160
|
+
# picks a side" discipline :mod:`arrayprobe.profiles` applies to fidelity
|
|
161
|
+
# choices. ``arrayprobe.cli`` attaches a real handler for the console script;
|
|
162
|
+
# nothing here does. ``print()`` remains the output channel for the CLI
|
|
163
|
+
# modules themselves (``cli.py``, ``triage_server.py``,
|
|
164
|
+
# ``scripts/make_demo_flight.py``) -- those are user-facing console text, not
|
|
165
|
+
# library progress, and stay untouched.
|
|
166
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
167
|
+
|
|
168
|
+
__all__ = [
|
|
169
|
+
"__version__",
|
|
170
|
+
# -- Stage 2: raw probe buffer -> uncompressed image netCDF -------------
|
|
171
|
+
"read_binary_SPEC",
|
|
172
|
+
"read_binary_hvps",
|
|
173
|
+
"read_binary_DMT",
|
|
174
|
+
"read_binary_PMS",
|
|
175
|
+
"read_binary_SEA",
|
|
176
|
+
"load_tas_info",
|
|
177
|
+
# -- Stage 3: images -> per-particle records ----------------------------
|
|
178
|
+
"imgproc_sm",
|
|
179
|
+
# -- Stage 4: per-particle records -> size distributions ----------------
|
|
180
|
+
"size_dist",
|
|
181
|
+
# -- Stage 8: several sd files -> one flight product --------------------
|
|
182
|
+
"combine_sizedist",
|
|
183
|
+
# -- Which MATLAB is being reproduced ----------------------------------
|
|
184
|
+
"FidelityProfile",
|
|
185
|
+
"STOCK_V314",
|
|
186
|
+
"ORACLES_2016",
|
|
187
|
+
"ORACLES_PRODUCTION",
|
|
188
|
+
"PROFILES",
|
|
189
|
+
"profile",
|
|
190
|
+
"register_profile",
|
|
191
|
+
# -- Run configuration (selection only; never sets a threshold) --------
|
|
192
|
+
"RunConfig",
|
|
193
|
+
"ConfigError",
|
|
194
|
+
"load_config",
|
|
195
|
+
# -- Checking a run against a reference product ------------------------
|
|
196
|
+
"compare_files",
|
|
197
|
+
"format_report",
|
|
198
|
+
"ComparisonReport",
|
|
199
|
+
# -- Checking a run against the archived product, typed -----------------
|
|
200
|
+
"compare_to_product",
|
|
201
|
+
"ProductComparisonReport",
|
|
202
|
+
"CellAgreement",
|
|
203
|
+
# -- Diagnostic: particle clock vs. housekeeping clock ------------------
|
|
204
|
+
"check_closure",
|
|
205
|
+
"ClosureResult",
|
|
206
|
+
# -- The project-level engine selector -----------------------------------
|
|
207
|
+
# Dispatches across all three engines, SODA-2 included, and computes
|
|
208
|
+
# nothing. `uiops.engine()` still answers the narrower question of which
|
|
209
|
+
# UIOOPS release. See selector.py's docstring for why this name and not
|
|
210
|
+
# that one.
|
|
211
|
+
"engine",
|
|
212
|
+
"Engine",
|
|
213
|
+
"ENGINES",
|
|
214
|
+
"DEFAULT_ENGINE",
|
|
215
|
+
"UnknownEngine",
|
|
216
|
+
# -- Reading a product for analysis -------------------------------------
|
|
217
|
+
# Engine-neutral: opens a file written by any engine, exactly as written.
|
|
218
|
+
"open_product",
|
|
219
|
+
]
|
arrayprobe/__main__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""``python -m arrayprobe`` -- the same front door as the ``arrayprobe`` console script.
|
|
3
|
+
|
|
4
|
+
Before 2026-09-15 this file did not exist, so the first command a Python user
|
|
5
|
+
types, ``python -m arrayprobe --help``, failed with ``No module named
|
|
6
|
+
arrayprobe.__main__`` (the R1 independent review, row 2). It delegates to
|
|
7
|
+
:func:`arrayprobe.cli.main` and adds nothing: no argument of its own, no
|
|
8
|
+
default, no engine choice. ``tests/test_python_dash_m.py`` asserts that its
|
|
9
|
+
``--help`` output equals the console script's.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from arrayprobe.cli import main
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
sys.exit(main())
|
arrayprobe/_v314_lazy.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Lazy access to the v3.1.4 validation engine, which the public distribution omits.
|
|
3
|
+
|
|
4
|
+
``lazy_module("arrayprobe.imgproc")`` returns a stand-in that imports the real module on first
|
|
5
|
+
attribute access and raises :class:`V314EngineAbsent` (an ``ImportError``) when it is not
|
|
6
|
+
installed. Attribute writes go to the real module so ``mock.patch.object`` behaves as on it.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import importlib
|
|
12
|
+
|
|
13
|
+
# ``engine_present`` lives in the v3.5 engine so the ``uiops`` selector can ask the same
|
|
14
|
+
# question without importing this package (engines sit below the selector); re-exported here so
|
|
15
|
+
# ``mock.patch("arrayprobe._v314_lazy.engine_present")`` keeps reaching this package's callers.
|
|
16
|
+
from arrayprobe_uiops.engine_absence import ABSENT_MESSAGE, V314EngineAbsent, engine_present
|
|
17
|
+
|
|
18
|
+
__all__ = ["ABSENT_MESSAGE", "V314EngineAbsent", "engine_present", "lazy_module"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _Lazy:
|
|
22
|
+
def __init__(self, name: str, message: str = ABSENT_MESSAGE) -> None:
|
|
23
|
+
object.__setattr__(self, "_name", name)
|
|
24
|
+
object.__setattr__(self, "_message", message)
|
|
25
|
+
|
|
26
|
+
def _load(self):
|
|
27
|
+
name = object.__getattribute__(self, "_name")
|
|
28
|
+
try:
|
|
29
|
+
return importlib.import_module(name)
|
|
30
|
+
except ModuleNotFoundError as exc:
|
|
31
|
+
if exc.name == name:
|
|
32
|
+
raise V314EngineAbsent(object.__getattribute__(self, "_message")) from exc
|
|
33
|
+
raise
|
|
34
|
+
|
|
35
|
+
def __getattr__(self, attr: str):
|
|
36
|
+
return getattr(self._load(), attr)
|
|
37
|
+
|
|
38
|
+
def __setattr__(self, attr: str, value) -> None:
|
|
39
|
+
setattr(self._load(), attr, value)
|
|
40
|
+
|
|
41
|
+
def __delattr__(self, attr: str) -> None:
|
|
42
|
+
delattr(self._load(), attr)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def lazy_module(name: str, message: str = ABSENT_MESSAGE) -> _Lazy:
|
|
46
|
+
"""A stand-in for module ``name`` that imports it on first use, or raises V314EngineAbsent
|
|
47
|
+
carrying ``message``."""
|
|
48
|
+
return _Lazy(name, message)
|
arrayprobe/ai_ready.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""A machine check that a file is "AI-ready" in exactly the sense this package claims.
|
|
3
|
+
|
|
4
|
+
:mod:`arrayprobe.attributed_export` writes OUTPUT 2, the attributed analysis-ready netCDF4 export
|
|
5
|
+
(and the opt-in Zarr copy, :func:`~arrayprobe.attributed_export.export_zarr`). Its docstring makes
|
|
6
|
+
specific claims; this module turns each into a named check, so the claim is a test and not a
|
|
7
|
+
sentence. :func:`check` returns human-readable failures, empty when the file passes.
|
|
8
|
+
|
|
9
|
+
The criteria, each one function below, each claimed by the exporter and nothing more:
|
|
10
|
+
|
|
11
|
+
- ``units_and_long_name`` -- every variable carries a non-empty ``units`` and ``long_name``, because
|
|
12
|
+
the exporter states a sourced unit and name on every variable it copies.
|
|
13
|
+
- ``acdd_discovery`` -- every name in :data:`~arrayprobe.attributed_export.ACDD_KEYS` is a non-empty
|
|
14
|
+
global attribute, because the exporter writes the ACDD-1.3 discovery block.
|
|
15
|
+
- ``conventions_names_acdd`` -- ``Conventions`` contains ``ACDD``, because that is the convention
|
|
16
|
+
the file claims (and the only one: CF is deliberately not claimed, so no CF ``standard_name`` is
|
|
17
|
+
required here).
|
|
18
|
+
- ``run_record`` -- ``arrayprobe_call_stamp`` is present and non-empty (a stamp, or the exporter's
|
|
19
|
+
explicit ``ABSENT`` statement), because the file must say how it was made or say that it cannot.
|
|
20
|
+
- ``source_hash`` -- ``arrayprobe_source_sha256`` is a 64-hex-digit digest, because it ties the
|
|
21
|
+
export to the exact faithful bytes it was copied from.
|
|
22
|
+
- ``encoding_statement`` -- ``arrayprobe_encoding`` is present and non-empty, because the file says
|
|
23
|
+
how it is stored.
|
|
24
|
+
- ``chunked_and_compressed`` (netCDF4 only) -- every numeric variable with at least one non-empty
|
|
25
|
+
dimension is chunked (not contiguous) and zlib-compressed, because the default export is the
|
|
26
|
+
analysis-ready encoding (:func:`~arrayprobe.attributed_export.storage_options`). A Zarr store is
|
|
27
|
+
chunked by construction and is not checked here.
|
|
28
|
+
- ``no_fill_value`` -- no variable carries ``_FillValue``: the faithful combined writer defines none
|
|
29
|
+
(``combine_sizedist.m:202-231``; missing seconds are NaN) and the exporter adds none. If a future
|
|
30
|
+
faithful source writes one, this check is to be relaxed to compare against that source.
|
|
31
|
+
|
|
32
|
+
**Further work.** These criteria are the package's own claims. Whether the file also meets a
|
|
33
|
+
published AI-readiness checklist is to be checked against a published checklist; none is named
|
|
34
|
+
here, because none has been verified against this file.
|
|
35
|
+
|
|
36
|
+
``python -m arrayprobe.ai_ready FILE [FILE...]`` prints PASS or FAIL per file with its failures and
|
|
37
|
+
exits 0 only when every file passes. Zarr support needs the ``[zarr]`` extra (xarray), imported
|
|
38
|
+
only when a directory is checked.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
from __future__ import annotations
|
|
42
|
+
|
|
43
|
+
import re
|
|
44
|
+
import sys
|
|
45
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
46
|
+
from dataclasses import dataclass, field
|
|
47
|
+
from pathlib import Path
|
|
48
|
+
|
|
49
|
+
import numpy as np
|
|
50
|
+
from netCDF4 import Dataset
|
|
51
|
+
|
|
52
|
+
from .attributed_export import ACDD_KEYS, ATTR_PREFIX
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class _Var:
|
|
57
|
+
name: str
|
|
58
|
+
attrs: Mapping[str, object]
|
|
59
|
+
dtype: np.dtype
|
|
60
|
+
sizes: tuple[int, ...]
|
|
61
|
+
chunking: object = None # netCDF4: "contiguous" or a list; None when not known
|
|
62
|
+
zlib: bool | None = None # netCDF4 filters()["zlib"]; None when not known
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass
|
|
66
|
+
class _File:
|
|
67
|
+
kind: str # "netcdf4" or "zarr"
|
|
68
|
+
attrs: Mapping[str, object]
|
|
69
|
+
variables: list[_Var] = field(default_factory=list)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _blank(value: object) -> bool:
|
|
73
|
+
return value is None or (isinstance(value, str) and not value.strip())
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _read_netcdf(path: Path) -> _File:
|
|
77
|
+
ds = Dataset(str(path), "r")
|
|
78
|
+
try:
|
|
79
|
+
ds.set_auto_maskandscale(False)
|
|
80
|
+
out = _File("netcdf4", {k: ds.getncattr(k) for k in ds.ncattrs()})
|
|
81
|
+
for name, var in ds.variables.items():
|
|
82
|
+
filters = var.filters() or {}
|
|
83
|
+
out.variables.append(_Var(
|
|
84
|
+
name, {k: var.getncattr(k) for k in var.ncattrs()}, np.dtype(var.dtype),
|
|
85
|
+
tuple(len(ds.dimensions[d]) for d in var.dimensions),
|
|
86
|
+
chunking=var.chunking(), zlib=bool(filters.get("zlib"))))
|
|
87
|
+
return out
|
|
88
|
+
finally:
|
|
89
|
+
ds.close()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _read_zarr(path: Path) -> _File:
|
|
93
|
+
import xarray as xr # lazy: the [zarr] extra, needed only for a store
|
|
94
|
+
with xr.open_zarr(path, decode_cf=False, mask_and_scale=False, decode_times=False,
|
|
95
|
+
decode_coords=False, consolidated=False) as ds:
|
|
96
|
+
out = _File("zarr", dict(ds.attrs))
|
|
97
|
+
for name, var in ds.variables.items():
|
|
98
|
+
out.variables.append(_Var(str(name), dict(var.attrs), np.dtype(var.dtype),
|
|
99
|
+
tuple(int(n) for n in var.shape)))
|
|
100
|
+
return out
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def check_units_and_long_name(f: _File) -> list[str]:
|
|
104
|
+
"""Every variable has a non-empty ``units`` and ``long_name`` (the exporter sources both)."""
|
|
105
|
+
return [f"variable {v.name!r} has no non-empty {key!r}"
|
|
106
|
+
for v in f.variables for key in ("units", "long_name") if _blank(v.attrs.get(key))]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def check_acdd_discovery(f: _File) -> list[str]:
|
|
110
|
+
"""Every ACDD discovery attribute the exporter writes is present and non-empty."""
|
|
111
|
+
return [f"global attribute {key!r} (ACDD discovery) is missing or empty"
|
|
112
|
+
for key in ACDD_KEYS if _blank(f.attrs.get(key))]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def check_conventions_names_acdd(f: _File) -> list[str]:
|
|
116
|
+
"""``Conventions`` names ACDD, the convention the file claims."""
|
|
117
|
+
value = f.attrs.get("Conventions")
|
|
118
|
+
if isinstance(value, str) and "ACDD" in value:
|
|
119
|
+
return []
|
|
120
|
+
return [f"global attribute 'Conventions' does not name ACDD (got {value!r})"]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def check_run_record(f: _File) -> list[str]:
|
|
124
|
+
"""``arrayprobe_call_stamp`` is present: the run record, or the explicit ABSENT statement."""
|
|
125
|
+
if _blank(f.attrs.get(f"{ATTR_PREFIX}call_stamp")):
|
|
126
|
+
return [f"global attribute '{ATTR_PREFIX}call_stamp' (the run record, or its ABSENT "
|
|
127
|
+
f"statement) is missing or empty"]
|
|
128
|
+
return []
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def check_source_hash(f: _File) -> list[str]:
|
|
132
|
+
"""``arrayprobe_source_sha256`` is a sha256 digest tying the export to the faithful bytes."""
|
|
133
|
+
value = f.attrs.get(f"{ATTR_PREFIX}source_sha256")
|
|
134
|
+
if isinstance(value, str) and re.fullmatch(r"[0-9a-f]{64}", value):
|
|
135
|
+
return []
|
|
136
|
+
return [f"global attribute '{ATTR_PREFIX}source_sha256' is missing or not a sha256 digest "
|
|
137
|
+
f"(got {value!r})"]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def check_encoding_statement(f: _File) -> list[str]:
|
|
141
|
+
"""``arrayprobe_encoding`` states how the file is stored."""
|
|
142
|
+
if _blank(f.attrs.get(f"{ATTR_PREFIX}encoding")):
|
|
143
|
+
return [f"global attribute '{ATTR_PREFIX}encoding' is missing or empty"]
|
|
144
|
+
return []
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def check_chunked_and_compressed(f: _File) -> list[str]:
|
|
148
|
+
"""netCDF4: every numeric variable with a non-empty dimension is chunked and zlib-compressed."""
|
|
149
|
+
if f.kind != "netcdf4":
|
|
150
|
+
return []
|
|
151
|
+
failures = []
|
|
152
|
+
for v in f.variables:
|
|
153
|
+
if v.dtype.kind not in "biuf" or not v.sizes or any(n == 0 for n in v.sizes):
|
|
154
|
+
continue
|
|
155
|
+
if v.chunking == "contiguous":
|
|
156
|
+
failures.append(f"variable {v.name!r} is stored contiguous, not chunked")
|
|
157
|
+
if not v.zlib:
|
|
158
|
+
failures.append(f"variable {v.name!r} is not zlib-compressed")
|
|
159
|
+
return failures
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def check_no_fill_value(f: _File) -> list[str]:
|
|
163
|
+
"""No variable carries ``_FillValue``: the faithful writer defines none, the export none."""
|
|
164
|
+
return [f"variable {v.name!r} carries a _FillValue the faithful source never wrote"
|
|
165
|
+
for v in f.variables if "_FillValue" in v.attrs]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
#: Every named check, in report order.
|
|
169
|
+
CHECKS: tuple[tuple[str, Callable[[_File], list[str]]], ...] = (
|
|
170
|
+
("units_and_long_name", check_units_and_long_name),
|
|
171
|
+
("acdd_discovery", check_acdd_discovery),
|
|
172
|
+
("conventions_names_acdd", check_conventions_names_acdd),
|
|
173
|
+
("run_record", check_run_record),
|
|
174
|
+
("source_hash", check_source_hash),
|
|
175
|
+
("encoding_statement", check_encoding_statement),
|
|
176
|
+
("chunked_and_compressed", check_chunked_and_compressed),
|
|
177
|
+
("no_fill_value", check_no_fill_value),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def check(path: Path | str) -> list[str]:
|
|
182
|
+
"""Failures for the netCDF4 file or Zarr store (a directory) at ``path``; empty = passes.
|
|
183
|
+
|
|
184
|
+
Each failure is prefixed with the name of the check that produced it."""
|
|
185
|
+
path = Path(path)
|
|
186
|
+
try:
|
|
187
|
+
f = _read_zarr(path) if path.is_dir() else _read_netcdf(path)
|
|
188
|
+
except Exception as exc: # an unreadable file fails the check; it does not crash the CLI
|
|
189
|
+
return [f"unreadable: {type(exc).__name__}: {exc}"]
|
|
190
|
+
return [f"{name}: {msg}" for name, fn in CHECKS for msg in fn(f)]
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
194
|
+
"""``python -m arrayprobe.ai_ready FILE [FILE...]``; exit 0 only when every file passes."""
|
|
195
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
196
|
+
if not args or any(a in ("-h", "--help") for a in args):
|
|
197
|
+
print("usage: python -m arrayprobe.ai_ready FILE [FILE...]\n"
|
|
198
|
+
"Check netCDF4 files or Zarr stores against the AI-ready claims of "
|
|
199
|
+
"arrayprobe.attributed_export.")
|
|
200
|
+
return 0 if args else 2
|
|
201
|
+
ok = True
|
|
202
|
+
for arg in args:
|
|
203
|
+
failures = check(arg)
|
|
204
|
+
print(f"{'PASS' if not failures else 'FAIL'} {arg}")
|
|
205
|
+
for msg in failures:
|
|
206
|
+
print(f" - {msg}")
|
|
207
|
+
ok = ok and not failures
|
|
208
|
+
return 0 if ok else 1
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
if __name__ == "__main__":
|
|
212
|
+
sys.exit(main())
|