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/friendly.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""A friendly re-view of four raw contracts, each a finding the port keeps rather than fixes.
|
|
3
|
+
|
|
4
|
+
Four fidelity-forced raw contracts, re-viewed without changing them.
|
|
5
|
+
|
|
6
|
+
The port's public functions stay exactly as they are;
|
|
7
|
+
this module adds documented wrappers for the contracts
|
|
8
|
+
a Python user will trip on.
|
|
9
|
+
This module is that boundary layer, and nothing else -- **rename/re-view
|
|
10
|
+
only**: every function below calls the raw port function unchanged and
|
|
11
|
+
repackages what comes back. None of them computes a number the raw function
|
|
12
|
+
did not already compute; none of them is on the reproduction path
|
|
13
|
+
(``tests/test_friendly.py::TestPipelineStagesDoNotImportFriendly`` sweeps
|
|
14
|
+
every pipeline-stage module and fails if one of them imports this one). This
|
|
15
|
+
is not an opt-in in the ``enhancements_uiops/`` sense -- there is no
|
|
16
|
+
behaviour to turn on, only a friendlier view of behaviour that already
|
|
17
|
+
happened -- so it ships in the port rather than in ``enhancements_uiops/``.
|
|
18
|
+
|
|
19
|
+
**Why a separate module, and not `readers/spec.py`/`reject.py`/
|
|
20
|
+
`readers/mask_csv.py` themselves, and not `uiops`.**
|
|
21
|
+
|
|
22
|
+
1. Keeping the wrappers physically apart from the raw functions they re-view
|
|
23
|
+
makes "the pipeline never imports the friendly module" a real, swept
|
|
24
|
+
property rather than a promise about code sitting next to what it wraps.
|
|
25
|
+
A stray ``from .reject import touching_edge_flag`` inside ``imgproc.py``
|
|
26
|
+
would be one refactor away from pulling a friendly view onto the
|
|
27
|
+
reproduction path if this lived inside ``reject.py`` itself.
|
|
28
|
+
2. ``uiops`` dispatches between the v3.1.4 and v3.5 *engines* and asserts it
|
|
29
|
+
"contains no arithmetic" (``tests/test_uiops_selector.py``). The four
|
|
30
|
+
contracts here are v3.1.4-specific findings about *this* engine's raw
|
|
31
|
+
output shape -- which engine to run is a different question -- so a
|
|
32
|
+
re-view of one engine's internals does not belong there.
|
|
33
|
+
|
|
34
|
+
**The four contracts, each cited to the
|
|
35
|
+
regression test that pins the raw behaviour this module only re-views:**
|
|
36
|
+
|
|
37
|
+
1. :func:`all_record_headers` -- ``readers.spec.iter_record_windows`` yields
|
|
38
|
+
*n-1* windows for a file of *n* records (the last record is never a
|
|
39
|
+
primary). Test pinning the raw contract:
|
|
40
|
+
``test_spec_reader.py::TestTwoRecordWindow::test_final_record_is_never_a_primary``.
|
|
41
|
+
2. :func:`touching_edge_flag` / :class:`TouchingEdge` --
|
|
42
|
+
the earlier translation's reject result carries a ``touching_edge`` field that takes
|
|
43
|
+
the numeric ``0`` or the characters ``"0"``/``"t"``. Test pinning the raw
|
|
44
|
+
contract:
|
|
45
|
+
``test_reject.py::TestTouchingEdgeIsTriState::test_no_slices_returns_the_numeric_initialiser``.
|
|
46
|
+
3. :data:`load_mask_csv` / :data:`MaskRecord` -- re-exported, not
|
|
47
|
+
reimplemented: ``readers.mask_csv.load_mask_csv`` already parses the
|
|
48
|
+
terminator-less ``.MK.csv`` into ordinary records; it is named here only
|
|
49
|
+
so a reader who starts at this module finds it. Test pinning the raw
|
|
50
|
+
contract:
|
|
51
|
+
``test_spec_reader.py::TestHousekeepingPackets::test_mask_records_have_no_line_terminator``.
|
|
52
|
+
4. Every public integer index this port exposes is MATLAB's own 1-based
|
|
53
|
+
convention, stated once rather than at each of the dozens of call sites
|
|
54
|
+
that already say so inline (``docs/09-conventions.md``,
|
|
55
|
+
"Every public index is MATLAB 1-based" -- ``matlab_compat.to0``/``to1``
|
|
56
|
+
are the only place the boundary is crossed). There is no wrapper
|
|
57
|
+
function for this one: the convention already holds, so the deliverable
|
|
58
|
+
is the one central statement plus
|
|
59
|
+
``tests/test_friendly.py::TestOneBasedConventionIsDocumented``'s sweep of
|
|
60
|
+
the source tree, not new code.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
from __future__ import annotations
|
|
64
|
+
|
|
65
|
+
import enum
|
|
66
|
+
import os
|
|
67
|
+
|
|
68
|
+
import numpy as np
|
|
69
|
+
|
|
70
|
+
from arrayprobe_uiops.spec_core import (
|
|
71
|
+
HEADER_WORDS,
|
|
72
|
+
RECORD_BYTES,
|
|
73
|
+
RECORD_WORDS,
|
|
74
|
+
RecordHeader,
|
|
75
|
+
iter_record_windows,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
from .readers.mask_csv import MaskRecord, load_mask_csv
|
|
79
|
+
|
|
80
|
+
__all__ = [
|
|
81
|
+
"all_record_headers",
|
|
82
|
+
"TouchingEdge",
|
|
83
|
+
"touching_edge_flag",
|
|
84
|
+
"load_mask_csv",
|
|
85
|
+
"MaskRecord",
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# --------------------------------------------------------------------------
|
|
90
|
+
# Contract 1: iter_record_windows yields n-1 windows
|
|
91
|
+
# --------------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def all_record_headers(path: str | os.PathLike) -> list[RecordHeader]:
|
|
95
|
+
"""Every record's header, in file order -- *n* headers for *n* records.
|
|
96
|
+
|
|
97
|
+
The earlier translation's record-window iterator (kept in the development
|
|
98
|
+
repository) reproduces
|
|
99
|
+
``read_binary_SPEC.m``'s raw decode loop exactly: the loop reads records
|
|
100
|
+
*N* and *N+1* as a pair, so for a file of two or more records the very
|
|
101
|
+
last record is never fed through it as a primary (preserved bug,
|
|
102
|
+
the v3.1.4 SPEC reader's module docstring, point 2; regression test
|
|
103
|
+
``test_spec_reader.py::TestTwoRecordWindow::test_final_record_is_never_a_primary``).
|
|
104
|
+
A file of *n* >= 2 records therefore yields *n-1* windows from that
|
|
105
|
+
function, and the header of record *n-1* (0-based) never appears in its
|
|
106
|
+
output. (A one-record file is the degenerate case: with no second
|
|
107
|
+
record to pair against, that lone record already comes back as a single
|
|
108
|
+
short window -- see
|
|
109
|
+
``test_spec_reader.py::TestTwoRecordWindow::test_single_record_file_yields_one_short_window``
|
|
110
|
+
-- so there is nothing left for this function to add there.)
|
|
111
|
+
|
|
112
|
+
A caller who wants "every record that exists in this file", rather than
|
|
113
|
+
"every record MATLAB's pairwise scan reached", should not have to
|
|
114
|
+
rediscover that gap. This function re-plays the same *n-1* windows
|
|
115
|
+
unchanged -- one call to the earlier translation's record-window iterator,
|
|
116
|
+
nothing reimplemented -- and appends the one header that function
|
|
117
|
+
structurally cannot produce: the last record's own eight timestamp
|
|
118
|
+
words, read directly with the same :func:`numpy.memmap` shape the raw
|
|
119
|
+
function uses. No window is built for it (matching MATLAB: that record
|
|
120
|
+
was never fed through the two-record decode that produces particles),
|
|
121
|
+
so this adds a header, never a particle.
|
|
122
|
+
|
|
123
|
+
Always ``len(all_record_headers(path)) == n_records`` (whole records), and
|
|
124
|
+
for *n* >= 2 whole records with nothing after them,
|
|
125
|
+
``all_record_headers(path) == [h for h, _ in iter_record_windows(path)]
|
|
126
|
+
+ [<last record's header>]`` -- the identity
|
|
127
|
+
``tests/test_friendly.py::TestAllRecordHeaders`` checks.
|
|
128
|
+
"""
|
|
129
|
+
n_records, tail = divmod(os.path.getsize(path), RECORD_BYTES)
|
|
130
|
+
if n_records == 0:
|
|
131
|
+
# No whole record exists. (The decoder still builds a window from a
|
|
132
|
+
# partial one, and raises where MATLAB dies on it; listing headers
|
|
133
|
+
# has no reason to.)
|
|
134
|
+
return []
|
|
135
|
+
headers = [header for header, _ in iter_record_windows(path)]
|
|
136
|
+
# With a partial record after the last whole one, the scan already made
|
|
137
|
+
# that last record a primary (``iter_record_windows``), so its header is in
|
|
138
|
+
# ``headers``; the partial record itself is not a record.
|
|
139
|
+
if n_records >= 2 and not tail:
|
|
140
|
+
words = np.memmap(path, dtype="<u2", mode="r", shape=(n_records, RECORD_WORDS))
|
|
141
|
+
last = words[n_records - 1, :HEADER_WORDS]
|
|
142
|
+
headers.append(RecordHeader(*(int(v) for v in last)))
|
|
143
|
+
return headers
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# --------------------------------------------------------------------------
|
|
147
|
+
# Contract 2: RejectResult.touching_edge is a tri-state {0, "0", "t"}
|
|
148
|
+
# --------------------------------------------------------------------------
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class TouchingEdge(enum.Enum):
|
|
152
|
+
"""The three values ``imgProc_sm.m:897``'s ``touching_edge - '0'`` writes.
|
|
153
|
+
|
|
154
|
+
Member values are the **written** integers -- what a ``touching_edge``
|
|
155
|
+
variable in a processed netCDF file actually holds, so
|
|
156
|
+
``TouchingEdge(nc_value)`` reads one straight back. See
|
|
157
|
+
:func:`touching_edge_flag` for the raw
|
|
158
|
+
raw ``RejectResult`` field (the earlier translation's reject result, which is not part of
|
|
159
|
+
this package) these come from, which is
|
|
160
|
+
a different, un-subtracted domain.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
#: The zero-slice path (``calculate_reject_unified.m:108``'s numeric
|
|
164
|
+
#: initialiser, never overwritten because the function returns before
|
|
165
|
+
#: :108-216 runs). Raw ``RejectResult.touching_edge`` field: the int ``0``.
|
|
166
|
+
NO_SLICES = -48
|
|
167
|
+
#: The particle's shadow reaches neither diode 1 nor the last diode. Raw field: the str ``"0"``.
|
|
168
|
+
CONTAINED = 0
|
|
169
|
+
#: The particle's shadow reaches diode 1 or the last diode. Raw field: the str ``"t"``.
|
|
170
|
+
TOUCHING = 68
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def touching_edge_flag(raw_field: object) -> TouchingEdge:
|
|
174
|
+
"""The v3.1.4 reject result's raw ``touching_edge`` -> :class:`TouchingEdge`.
|
|
175
|
+
|
|
176
|
+
``calculate_reject_unified.m:108`` initialises ``touching_edge``
|
|
177
|
+
numerically and only ``:213-216`` makes it a character, so
|
|
178
|
+
the reject result's ``touching_edge`` field is a
|
|
179
|
+
genuine three-value union rather than one Python type: the int ``0``
|
|
180
|
+
(no slices at all -- the branch returns before the character
|
|
181
|
+
assignment; regression test
|
|
182
|
+
``test_reject.py::TestTouchingEdgeIsTriState::test_no_slices_returns_the_numeric_initialiser``),
|
|
183
|
+
or the one-character strings ``"0"`` (contained) and ``"t"`` (touching
|
|
184
|
+
diode 1 or the last diode; ``test_contained_and_touching_particles_return_characters``).
|
|
185
|
+
|
|
186
|
+
This maps that raw field onto the same ``{-48, 0, 68}`` domain
|
|
187
|
+
``imgProc_sm.m:897``'s ``touching_edge - '0'`` writes to the product
|
|
188
|
+
file (``test_the_three_values_imgproc_would_write``), losslessly and
|
|
189
|
+
without changing ``RejectResult`` itself -- the raw field is untouched,
|
|
190
|
+
as this module promises.
|
|
191
|
+
|
|
192
|
+
Raises :class:`ValueError` on anything outside the three accepted raw
|
|
193
|
+
values, deliberately: a fourth value would mean the raw contract this
|
|
194
|
+
wraps has changed underneath it, not that the caller should guess what
|
|
195
|
+
it means.
|
|
196
|
+
"""
|
|
197
|
+
if isinstance(raw_field, str):
|
|
198
|
+
if raw_field in ("0", "t"):
|
|
199
|
+
return TouchingEdge(ord(raw_field) - ord("0"))
|
|
200
|
+
raise ValueError(
|
|
201
|
+
f"not a touching_edge character RejectResult ever carries: {raw_field!r}")
|
|
202
|
+
if isinstance(raw_field, int) and not isinstance(raw_field, bool) and raw_field == 0:
|
|
203
|
+
return TouchingEdge.NO_SLICES
|
|
204
|
+
raise ValueError(
|
|
205
|
+
f"not a touching_edge value RejectResult ever carries (expected the int 0, "
|
|
206
|
+
f"or the str '0' or 't'): {raw_field!r}")
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Computational geometry on particle images -- the CGAL MEX replacements.
|
|
3
|
+
|
|
4
|
+
UIOOPS ships three geometry routines (``CGAL_minR``, ``CGAL_RectSize``,
|
|
5
|
+
``CGAL_EllipseSize``) as compiled MEX binaries for Linux and Intel Mac only.
|
|
6
|
+
There is no Windows build and no build script, so on this machine the MATLAB
|
|
7
|
+
pipeline cannot run *at all* -- and the routine on the critical path,
|
|
8
|
+
``CGAL_minR``, produces ``image_diam_minR``, which is the primary particle size
|
|
9
|
+
whenever ``d_choice = 6``. That is the default in every run script UIOOPS ships.
|
|
10
|
+
|
|
11
|
+
Replacing the binaries is therefore not a portability chore; it is the single
|
|
12
|
+
change that makes the pipeline executable here. And the replacement is
|
|
13
|
+
*checkable* in a way the binary never was: `Miniball.hpp` ships as source
|
|
14
|
+
alongside the `.cpp`, so the algorithm has a specification, and the result can
|
|
15
|
+
be cross-validated against brute force on small point sets and against
|
|
16
|
+
``image_diam_minR`` in the ORACLES reference output on real ones.
|
|
17
|
+
|
|
18
|
+
All three CGAL geometry primitives now live here: min-circle,
|
|
19
|
+
min-rectangle and min-ellipse. All three are gated behind
|
|
20
|
+
``iRectEllipse``, which the ORACLES variant sets to ``0``
|
|
21
|
+
(``imgProc_sm.m:51``) and which the reference product confirms -- it
|
|
22
|
+
carries no rectangle or ellipse variables -- so rectangle and ellipse are
|
|
23
|
+
not wired into ``imgproc.py``'s per-particle loop yet; they exist as
|
|
24
|
+
complete, tested, standalone primitives first, matching how the port shipped
|
|
25
|
+
``min_circle.py`` before S3 wired it in.
|
|
26
|
+
|
|
27
|
+
``min_ellipse.py`` is on a different footing from the other two, worth
|
|
28
|
+
knowing before trusting it as far as they're trusted: minimum-enclosing-
|
|
29
|
+
ellipse has no local reference algorithm the way ``Miniball.hpp`` gave
|
|
30
|
+
min-circle one, so it uses an independent numerical method (Khachiyan-
|
|
31
|
+
Todd-Yildirim) rather than reimplementing CGAL's own exact-rational
|
|
32
|
+
incremental algorithm from memory. See its own module docstring for the
|
|
33
|
+
two cross-checks that stand in for a direct oracle.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
from typing import TYPE_CHECKING, Any
|
|
39
|
+
|
|
40
|
+
from arrayprobe_uiops.geometry_core import (
|
|
41
|
+
cgal_ellipse_size,
|
|
42
|
+
cgal_min_r,
|
|
43
|
+
min_area_ellipse,
|
|
44
|
+
min_enclosing_circle,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if TYPE_CHECKING:
|
|
48
|
+
from .min_rectangle import cgal_rect_size as cgal_rect_size
|
|
49
|
+
from .min_rectangle import min_area_rectangle as min_area_rectangle
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"cgal_ellipse_size",
|
|
53
|
+
"cgal_min_r",
|
|
54
|
+
"cgal_rect_size",
|
|
55
|
+
"min_area_ellipse",
|
|
56
|
+
"min_area_rectangle",
|
|
57
|
+
"min_enclosing_circle",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def __getattr__(name: str) -> Any:
|
|
62
|
+
"""Resolve the rectangle names on first access.
|
|
63
|
+
|
|
64
|
+
They live in the v3.5 engine (``CGAL_RectSize.cpp`` is byte-identical between releases), so
|
|
65
|
+
importing ``arrayprobe.geometry`` loads no v3.5 module until one of them is used.
|
|
66
|
+
"""
|
|
67
|
+
if name in ("cgal_rect_size", "min_area_rectangle"):
|
|
68
|
+
from . import min_rectangle as _rect
|
|
69
|
+
|
|
70
|
+
value = getattr(_rect, name)
|
|
71
|
+
globals()[name] = value
|
|
72
|
+
return value
|
|
73
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def __dir__() -> list[str]:
|
|
77
|
+
return sorted(set(globals()) | set(__all__))
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Minimum-area enclosing rectangle -- the replacement for ``CGAL_RectSize.mexa64``.
|
|
3
|
+
|
|
4
|
+
``CGAL_RectSize.cpp`` collects the coordinates of every shadowed pixel as
|
|
5
|
+
``Point_2(i, j)`` -- **column first, row second** (``i`` is the outer/column
|
|
6
|
+
loop, ``j`` the inner/row loop; the opposite convention from
|
|
7
|
+
:mod:`.min_circle`'s ``(row, col)``, kept because the *angle* output depends
|
|
8
|
+
on which axis is which) -- takes their convex hull, and calls
|
|
9
|
+
``CGAL::min_rectangle_2`` (the standard rotating-calipers minimum-area
|
|
10
|
+
bounding rectangle: Toussaint 1983; the minimum-area rectangle enclosing a
|
|
11
|
+
convex polygon always has one side flush with a hull edge, so trying every
|
|
12
|
+
hull edge as a candidate orientation is exhaustive, not heuristic). The two
|
|
13
|
+
resulting edge lengths get ``+1`` each (same "assume round diode, add 1 for
|
|
14
|
+
the boundary" convention :func:`arrayprobe_uiops.geometry_core.cgal_min_r`
|
|
15
|
+
documents) and are returned as ``(length, width, angle)`` with
|
|
16
|
+
``length >= width`` and ``angle`` the direction, in radians, of whichever of
|
|
17
|
+
the two actual computed edges is the *longer* one.
|
|
18
|
+
|
|
19
|
+
**Why this port can be exact where the original is not**, same reasoning as
|
|
20
|
+
:mod:`.min_circle`: the minimum-area bounding rectangle of a finite point set
|
|
21
|
+
is unique (up to the symmetric tie of a square), so there is no "our
|
|
22
|
+
algorithm versus theirs" question -- agreement is a theorem. The comparison
|
|
23
|
+
across candidate hull-edge orientations needs no square root at all: with an
|
|
24
|
+
UNNORMALIZED integer edge vector ``(dx, dy)``, a point's projection along and
|
|
25
|
+
perpendicular to the edge, scaled by ``|edge|``, is a plain integer dot/cross
|
|
26
|
+
product; dividing the resulting box area by ``edge_len_sq`` (exact
|
|
27
|
+
:class:`fractions.Fraction`) gives the true area without ever taking a root.
|
|
28
|
+
Square roots appear exactly once, at the very end, converting the winning
|
|
29
|
+
orientation's two squared extents into the lengths CGAL's polygon output
|
|
30
|
+
would have reported.
|
|
31
|
+
|
|
32
|
+
Provenance: ``CGAL_RectSize.cpp`` (whole file); called at
|
|
33
|
+
``imgProc_sm.m:849``, gated by ``iRectEllipse`` (never ``1`` in any real
|
|
34
|
+
ORACLES call -- see :mod:`arrayprobe.geometry`'s own module docstring).
|
|
35
|
+
|
|
36
|
+
**One place this port cannot claim more than "derived."** No Windows build of
|
|
37
|
+
the CGAL binary exists, and Octave cannot supply an oracle for a MEX-only
|
|
38
|
+
routine, so the degenerate cases below
|
|
39
|
+
were worked out by reading ``CGAL_RectSize.cpp`` and the standard rotating-
|
|
40
|
+
calipers algorithm, not by running the real CGAL library and comparing:
|
|
41
|
+
|
|
42
|
+
* **A single shadowed pixel** (a 1-point hull): no hull edge exists to rotate
|
|
43
|
+
around. Reported as ``length = width = 1.0`` (both extents 0, then the
|
|
44
|
+
``+1``), ``angle = pi/2`` (the perpendicular-direction branch is taken
|
|
45
|
+
because ``L`` is not strictly greater than ``W``, and that direction's own
|
|
46
|
+
``dx`` is 0).
|
|
47
|
+
* **All shadowed pixels collinear** (a 2-point hull after collapsing):
|
|
48
|
+
degenerates to a zero-width rectangle -- ``length = 1 + span``,
|
|
49
|
+
``width = 1``, angle along the line.
|
|
50
|
+
|
|
51
|
+
``CGAL_RectSize.cpp`` is byte-identical between v3.1.4 and v3.5, so one translation serves
|
|
52
|
+
both engines: it lives in :mod:`arrayprobe_uiops.min_rectangle`, and this module re-exports the
|
|
53
|
+
same objects lazily, so importing ``arrayprobe.geometry.min_rectangle`` loads no v3.5 module.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
from __future__ import annotations
|
|
57
|
+
|
|
58
|
+
from typing import TYPE_CHECKING, Any
|
|
59
|
+
|
|
60
|
+
__all__ = ["cgal_rect_size", "min_area_rectangle"]
|
|
61
|
+
|
|
62
|
+
if TYPE_CHECKING:
|
|
63
|
+
from arrayprobe_uiops.min_rectangle import _TRUNCATED_PI as _TRUNCATED_PI
|
|
64
|
+
from arrayprobe_uiops.min_rectangle import _convex_hull as _convex_hull
|
|
65
|
+
from arrayprobe_uiops.min_rectangle import _direction_angle as _direction_angle
|
|
66
|
+
from arrayprobe_uiops.min_rectangle import _shadow_points_xy as _shadow_points_xy
|
|
67
|
+
from arrayprobe_uiops.min_rectangle import cgal_rect_size as cgal_rect_size
|
|
68
|
+
from arrayprobe_uiops.min_rectangle import min_area_rectangle as min_area_rectangle
|
|
69
|
+
|
|
70
|
+
_REEXPORTED = frozenset({
|
|
71
|
+
"_TRUNCATED_PI",
|
|
72
|
+
"_convex_hull",
|
|
73
|
+
"_direction_angle",
|
|
74
|
+
"_shadow_points_xy",
|
|
75
|
+
"cgal_rect_size",
|
|
76
|
+
"min_area_rectangle",
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def __getattr__(name: str) -> Any:
|
|
81
|
+
"""Resolve a re-exported name from ``arrayprobe_uiops.min_rectangle`` on first access."""
|
|
82
|
+
if name in _REEXPORTED:
|
|
83
|
+
from arrayprobe_uiops import min_rectangle as _home
|
|
84
|
+
|
|
85
|
+
value = getattr(_home, name)
|
|
86
|
+
globals()[name] = value
|
|
87
|
+
return value
|
|
88
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def __dir__() -> list[str]:
|
|
92
|
+
return sorted(set(globals()) | set(__all__) | _REEXPORTED)
|
arrayprobe/intarr.py
ADDED
|
@@ -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 intarr 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.intarr import * # noqa: F403
|
|
11
|
+
|
|
12
|
+
_sys.modules[__name__] = _impl
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
import sys as _sys
|
|
3
|
+
import typing as _typing
|
|
4
|
+
|
|
5
|
+
from arrayprobe_uiops import intarr_analysis 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.intarr_analysis import * # noqa: F403
|
|
11
|
+
from arrayprobe_uiops.intarr_analysis import ( # noqa: F401 # not in __all__
|
|
12
|
+
_WIDTH,
|
|
13
|
+
fit_bimodal_intarr,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
_sys.modules[__name__] = _impl
|
|
@@ -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 intarr_plots 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.intarr_plots import * # noqa: F403
|
|
11
|
+
|
|
12
|
+
_sys.modules[__name__] = _impl
|
arrayprobe/inventory.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Raw-file inventory: flag empty and truncated raw probe files before processing.
|
|
3
|
+
|
|
4
|
+
One row per raw file: path, size, SHA-256, ``empty`` (size 0), ``truncated`` (the bytes after
|
|
5
|
+
any header are not a whole number of records) and a probe-format guess. Rows are written to a
|
|
6
|
+
JSON and a CSV inventory file. Nothing here reads a product or changes a computed number; the
|
|
7
|
+
flags live in the inventory file (and in the ``.call`` stamp), never as an
|
|
8
|
+
attribute on a product.
|
|
9
|
+
|
|
10
|
+
Record lengths are the readers' own constants, imported rather than typed:
|
|
11
|
+
SPEC ``spec_core.RECORD_BYTES`` (4114), DMT ``readers.dmt._RECORD_BYTES`` (4112), RAF/PMS ``.2d``
|
|
12
|
+
``readers.pms._RECORD_BYTES`` (4116, after the XML preamble ending ``</OAP>``, skipped with the
|
|
13
|
+
reader's own ``_skip_xml_header``). A format with no fixed record length gets ``truncated=None``.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import csv
|
|
18
|
+
import hashlib
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
from collections.abc import Iterable
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
from arrayprobe_uiops.readers import pms as _pms
|
|
25
|
+
from arrayprobe_uiops.spec_core import RECORD_BYTES as _SPEC_RECORD_BYTES
|
|
26
|
+
|
|
27
|
+
from .readers import dmt as _dmt
|
|
28
|
+
|
|
29
|
+
__all__ = ["RECORD_BYTES", "guess_format", "inventory", "inventory_row", "write_inventory"]
|
|
30
|
+
|
|
31
|
+
#: Record length per format, read from each reader. ``None``: no fixed record length.
|
|
32
|
+
RECORD_BYTES: dict[str, int | None] = {
|
|
33
|
+
"spec": _SPEC_RECORD_BYTES,
|
|
34
|
+
"dmt": _dmt._RECORD_BYTES,
|
|
35
|
+
"pms_2d": _pms._RECORD_BYTES,
|
|
36
|
+
"unknown": None,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_SPEC_SUFFIXES = ("2ds", "hvps", "3v", "3vcpi")
|
|
40
|
+
_DMT_SUFFIXES = ("dmt", "cip", "pip")
|
|
41
|
+
_FIELDS = ("path", "size", "sha256", "format_guess", "record_bytes", "header_bytes",
|
|
42
|
+
"empty", "truncated", "trailing_bytes")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def guess_format(path: str | os.PathLike) -> str:
|
|
46
|
+
"""A guess, not a reader decision: ``pms_2d``, ``spec``, ``dmt`` or ``unknown``."""
|
|
47
|
+
p = Path(path)
|
|
48
|
+
try:
|
|
49
|
+
with open(p, "rb") as fh:
|
|
50
|
+
head = fh.read(65536)
|
|
51
|
+
except OSError:
|
|
52
|
+
head = b""
|
|
53
|
+
if head.lstrip().startswith(b"<") and b"</OAP>" in head:
|
|
54
|
+
return "pms_2d"
|
|
55
|
+
suffix = p.suffix.lower().lstrip(".")
|
|
56
|
+
if suffix == "2d":
|
|
57
|
+
return "pms_2d"
|
|
58
|
+
if suffix in _SPEC_SUFFIXES:
|
|
59
|
+
return "spec"
|
|
60
|
+
if suffix in _DMT_SUFFIXES:
|
|
61
|
+
return "dmt"
|
|
62
|
+
return "unknown"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _header_bytes(path: Path, fmt: str) -> int | None:
|
|
66
|
+
"""Bytes before the first record; ``None`` if the reader's header rule finds no end."""
|
|
67
|
+
if fmt != "pms_2d":
|
|
68
|
+
return 0
|
|
69
|
+
with open(path, "rb") as fh:
|
|
70
|
+
try:
|
|
71
|
+
_pms._skip_xml_header(fh)
|
|
72
|
+
except ValueError:
|
|
73
|
+
return None
|
|
74
|
+
return fh.tell()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _sha256(path: Path) -> str:
|
|
78
|
+
h = hashlib.sha256()
|
|
79
|
+
with open(path, "rb") as fh:
|
|
80
|
+
for block in iter(lambda: fh.read(1 << 20), b""):
|
|
81
|
+
h.update(block)
|
|
82
|
+
return h.hexdigest()
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def inventory_row(path: str | os.PathLike, fmt: str | None = None) -> dict:
|
|
86
|
+
"""One inventory row for ``path``; ``fmt`` overrides the guess."""
|
|
87
|
+
p = Path(path)
|
|
88
|
+
size = p.stat().st_size
|
|
89
|
+
fmt = fmt or guess_format(p)
|
|
90
|
+
rec = RECORD_BYTES.get(fmt)
|
|
91
|
+
row = {"path": str(p), "size": size, "sha256": _sha256(p), "format_guess": fmt,
|
|
92
|
+
"record_bytes": rec, "header_bytes": None, "empty": size == 0,
|
|
93
|
+
"truncated": None, "trailing_bytes": None}
|
|
94
|
+
if rec is None or size == 0:
|
|
95
|
+
return row
|
|
96
|
+
hdr = _header_bytes(p, fmt)
|
|
97
|
+
row["header_bytes"] = hdr
|
|
98
|
+
if hdr is None: # header never ends: nothing after it is a whole record
|
|
99
|
+
row["truncated"] = True
|
|
100
|
+
return row
|
|
101
|
+
trailing = (size - hdr) % rec
|
|
102
|
+
row["trailing_bytes"] = trailing
|
|
103
|
+
row["truncated"] = trailing != 0
|
|
104
|
+
return row
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def inventory(paths: str | os.PathLike | Iterable[str | os.PathLike],
|
|
108
|
+
fmt: str | None = None) -> list[dict]:
|
|
109
|
+
"""Rows for every regular file in a directory (sorted, non-recursive) or for a list."""
|
|
110
|
+
if isinstance(paths, (str, os.PathLike)) and Path(paths).is_dir():
|
|
111
|
+
files = sorted(q for q in Path(paths).iterdir() if q.is_file())
|
|
112
|
+
elif isinstance(paths, (str, os.PathLike)):
|
|
113
|
+
files = [Path(paths)]
|
|
114
|
+
else:
|
|
115
|
+
files = [Path(q) for q in paths]
|
|
116
|
+
return [inventory_row(f, fmt) for f in files]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def write_inventory(rows: list[dict], out_stem: str | os.PathLike) -> tuple[Path, Path]:
|
|
120
|
+
"""Write ``<out_stem>.json`` and ``<out_stem>.csv``; return both paths."""
|
|
121
|
+
# Appended, never with_suffix: a stem like "inv_2026.10.28" keeps every dot.
|
|
122
|
+
jpath, cpath = Path(f"{out_stem}.json"), Path(f"{out_stem}.csv")
|
|
123
|
+
jpath.write_text(json.dumps(rows, indent=1), encoding="utf-8")
|
|
124
|
+
with open(cpath, "w", newline="", encoding="utf-8") as fh:
|
|
125
|
+
w = csv.DictWriter(fh, fieldnames=_FIELDS)
|
|
126
|
+
w.writeheader()
|
|
127
|
+
for r in rows:
|
|
128
|
+
w.writerow({k: r[k] for k in _FIELDS})
|
|
129
|
+
return jpath, cpath
|