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,220 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Reject helpers both UIOOPS engines share: RejectConfig, mask_start_end, _vertical_split."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class RejectConfig:
|
|
13
|
+
"""The six thresholds ``calculate_reject_unified.m:71-77`` assigns itself.
|
|
14
|
+
|
|
15
|
+
Seven *assignments*, six *thresholds*: ``:74`` sets
|
|
16
|
+
``handles.bits_per_slice = n_size(2)``, which is the image width read off
|
|
17
|
+
the data rather than a constant, so it is not a configurable threshold and
|
|
18
|
+
is not a field here.
|
|
19
|
+
|
|
20
|
+
Every one of these is written into ``handles`` at the **top of the
|
|
21
|
+
function**, unconditionally, overwriting whatever the caller had set. So in
|
|
22
|
+
stock UIOOPS they are constants with the values below, and a run script that
|
|
23
|
+
sets ``handles.shadowed_area`` has no effect whatsoever.
|
|
24
|
+
|
|
25
|
+
Exposing them as a frozen dataclass (thresholds-as-data) is a
|
|
26
|
+
possible later step.
|
|
27
|
+
|
|
28
|
+
**It IS carried on the fidelity profile, and the history of that is the
|
|
29
|
+
point.** An earlier reading held that it is "emphatically *not* a
|
|
30
|
+
:class:`~arrayprobe.profiles.FidelityProfile` field -- the two MATLAB trees
|
|
31
|
+
agree on every value here, so there is no divergence to name." That was
|
|
32
|
+
measured wrong 2026-08-28: the tree that actually produced the archived
|
|
33
|
+
ORACLES products carries three different values (``rej_hollow=0``,
|
|
34
|
+
``max_edge_img_ar=4``, ``max_comp_img_ar=4``), and because nothing wired
|
|
35
|
+
them to the profile, every ORACLES file had been running on stock thresholds
|
|
36
|
+
and losing ~40 % of the particles the archive keeps in the used bins. The
|
|
37
|
+
profile carries ``ORACLES_PRODUCTION_REJECT_CONFIG``.
|
|
38
|
+
|
|
39
|
+
The reason the error survived so long is worth keeping with the code: the
|
|
40
|
+
claim was checked against a near-clear-air file on which those thresholds
|
|
41
|
+
can barely fire. An output-pinned claim is only as strong as the file that
|
|
42
|
+
pinned it.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
#: ``:71``. Reject a zero-area particle as ``'z'`` rather than passing it
|
|
46
|
+
#: through as ``'0'``.
|
|
47
|
+
rej_zero_area: bool = True
|
|
48
|
+
|
|
49
|
+
#: ``:72``. Reject a particle that goes dark and lights up again. Also
|
|
50
|
+
#: gates the (dead) vertical-split re-check at :245, which requires this to
|
|
51
|
+
#: be *False* -- so the two split tests are mutually exclusive by
|
|
52
|
+
#: construction and only the first can ever fire.
|
|
53
|
+
rej_split: bool = True
|
|
54
|
+
|
|
55
|
+
#: ``:73``. Run the Korolev hollow analysis at all.
|
|
56
|
+
rej_hollow: bool = True
|
|
57
|
+
|
|
58
|
+
#: ``:75``. Minimum percent of the bounding rectangle that must be
|
|
59
|
+
#: shadowed; below it the particle is rejected ``'p'``.
|
|
60
|
+
shadowed_area: float = 25
|
|
61
|
+
|
|
62
|
+
#: ``:76``. Aspect-ratio ceiling for a particle **touching the array edge**
|
|
63
|
+
#: (reject ``'t'``). The netCDF description at ``imgProc_sm.m:325-329``
|
|
64
|
+
#: swaps this with the next one.
|
|
65
|
+
max_edge_img_ar: float = 6
|
|
66
|
+
|
|
67
|
+
#: ``:77``. Aspect-ratio ceiling for a fully-contained particle, applied in
|
|
68
|
+
#: both directions -- above it, or below its reciprocal, reject ``'a'``.
|
|
69
|
+
#: The reciprocal arm is dated in the source: "Second critirion added on Dec
|
|
70
|
+
#: 2nd, 2013 by Will for small aspect ratio" (:269).
|
|
71
|
+
max_comp_img_ar: float = 5
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
DEFAULT_REJECT_CONFIG = RejectConfig()
|
|
75
|
+
"""The stock v3.1.4 thresholds -- and the named ORACLES variant tree's, whose
|
|
76
|
+
``calculate_reject_unified.m`` is byte-identical to stock. ``arrayprobe.reject`` re-exports
|
|
77
|
+
this object."""
|
|
78
|
+
|
|
79
|
+
ORACLES_PRODUCTION_REJECT_CONFIG = RejectConfig(
|
|
80
|
+
rej_hollow=False,
|
|
81
|
+
max_edge_img_ar=4,
|
|
82
|
+
max_comp_img_ar=4,
|
|
83
|
+
)
|
|
84
|
+
"""The ORACLES fork's dated reject edits, the ORACLES-variant ``calculate_reject_unified.m:73-77``
|
|
85
|
+
(``rej_hollow`` 1->0, ``max_edge_img_ar`` 6->4, ``max_comp_img_ar`` 5->4). Shared by both
|
|
86
|
+
engines (``ORACLES_PRODUCTION`` and ``ORACLES_PRODUCTION_V35``); ``arrayprobe.reject``
|
|
87
|
+
re-exports this object with the full provenance."""
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def mask_start_end(end_mask: int, start_mask: int, shadow_row, bits_per_slice: int) -> np.ndarray:
|
|
91
|
+
"""``:683-702`` -- blank everything outside ``[start_mask, end_mask]``.
|
|
92
|
+
|
|
93
|
+
Source: ``calculate_reject_unified.m`` (UIOOPS v3.1.4), ``mask_start_end`` from ``:683``; bare
|
|
94
|
+
line references here are into that file.
|
|
95
|
+
|
|
96
|
+
Returns the row's **lit** diodes (``True`` = lit = a hole) with everything
|
|
97
|
+
outside the particle's own span forced to False, which is what the caller
|
|
98
|
+
then counts and intersects. MATLAB builds this as a char row of ``'0'``
|
|
99
|
+
with the original characters pasted back into the window.
|
|
100
|
+
|
|
101
|
+
Two MATLAB mechanics folded into that boolean array:
|
|
102
|
+
|
|
103
|
+
* ``result`` starts as the numeric scalar ``0`` and ``result(1:n) = '0'``
|
|
104
|
+
assigns the *code* 48 into a double array, so ``result`` is numeric until
|
|
105
|
+
``char()`` converts it back at :701. Round-trips exactly; no effect.
|
|
106
|
+
* When ``end_mask > bits_per_slice`` -- which happens in
|
|
107
|
+
:func:`is_it_hollow_sidescan`, where ``bits_per_slice`` is capped at 32
|
|
108
|
+
but the scan runs the full slice count -- MATLAB **auto-extends**
|
|
109
|
+
``result`` and pads the gap with numeric ``0``, i.e. NUL characters,
|
|
110
|
+
not ``'0'``. Harmless: NUL is not ``'1'`` so the hole count skips it, and
|
|
111
|
+
the packers only ever read the first ``bits_per_slice`` entries. False
|
|
112
|
+
is the faithful boolean for both.
|
|
113
|
+
|
|
114
|
+
The ``start_mask == 0 & end_mask == 0`` arm at :687 returns the row
|
|
115
|
+
unmasked. Unreachable: every call site guards on ``n_lite > 0``, and a
|
|
116
|
+
non-empty slice has positions of at least 1.
|
|
117
|
+
"""
|
|
118
|
+
shadow_row = np.asarray(shadow_row, dtype=bool)
|
|
119
|
+
if start_mask == 0 and end_mask == 0:
|
|
120
|
+
return ~shadow_row
|
|
121
|
+
result = np.zeros(max(bits_per_slice, end_mask), dtype=bool)
|
|
122
|
+
window = slice(start_mask - 1, end_mask)
|
|
123
|
+
result[window] = ~shadow_row[window]
|
|
124
|
+
return result
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _vertical_split(shadow) -> np.ndarray:
|
|
128
|
+
"""``:138-142`` -- the accumulator behind the (dead) second split test.
|
|
129
|
+
|
|
130
|
+
MATLAB writes ``vertical_split = vertical_split & image_buffer(i,:)``, an
|
|
131
|
+
``&`` between **char** rows. Both ``'0'`` (48) and ``'1'`` (49) are
|
|
132
|
+
non-zero, so the result is ``true`` at every position from the second slice
|
|
133
|
+
onward, and the ``scan_slice(vertical_split)`` at :239 then looks for the
|
|
134
|
+
character ``'0'`` in a logical array -- comparing 1 against 48, which is
|
|
135
|
+
false everywhere. So for any multi-slice particle the scan reports an empty
|
|
136
|
+
slice and the test at :245 can never fire.
|
|
137
|
+
|
|
138
|
+
A single-slice particle escapes: the loop body runs once and takes the
|
|
139
|
+
``else`` arm, leaving ``vertical_split`` as the char row itself, which scans
|
|
140
|
+
normally.
|
|
141
|
+
|
|
142
|
+
Both cases return the row this port must scan for shadow. For the
|
|
143
|
+
multi-slice case that is an all-lit row -- nothing to find -- which is the
|
|
144
|
+
faithful equivalent of "all logical true, compared against ``'0'``".
|
|
145
|
+
"""
|
|
146
|
+
if shadow.shape[0] == 1:
|
|
147
|
+
return shadow[0]
|
|
148
|
+
return np.zeros(shadow.shape[1], dtype=bool)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@dataclass(frozen=True)
|
|
152
|
+
class SliceScan:
|
|
153
|
+
"""The three outputs of ``scan_slice`` (``:379``). Positions are 1-based.
|
|
154
|
+
|
|
155
|
+
Source: ``scan_slice`` in ``calculate_reject_unified.m:379-406`` (UIOOPS v3.1.4)."""
|
|
156
|
+
|
|
157
|
+
min_pos_lite: int
|
|
158
|
+
max_pos_lite: int
|
|
159
|
+
n_lite: int
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
_SCAN_LOADED = False
|
|
163
|
+
_SCAN_HAVE_NUMBA = False
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _ensure_scan_numba_loaded() -> None:
|
|
167
|
+
"""JIT-decorate :func:`_scan_slice_kernel` once, on first use (numba stays lazy and optional).
|
|
168
|
+
|
|
169
|
+
``arrayprobe.reject._ensure_numba_loaded`` calls this and rebinds its own
|
|
170
|
+
``_scan_slice_kernel`` name to the result, so its sidescan kernel sees the dispatcher."""
|
|
171
|
+
global _SCAN_LOADED, _SCAN_HAVE_NUMBA, _scan_slice_kernel
|
|
172
|
+
if _SCAN_LOADED:
|
|
173
|
+
return
|
|
174
|
+
try:
|
|
175
|
+
from numba import njit
|
|
176
|
+
except ImportError: # pragma: no cover - numba is an optional extra
|
|
177
|
+
njit = None # type: ignore[assignment]
|
|
178
|
+
_SCAN_HAVE_NUMBA = njit is not None
|
|
179
|
+
if _SCAN_HAVE_NUMBA:
|
|
180
|
+
_scan_slice_kernel = njit(cache=True, boundscheck=True)(_scan_slice_kernel)
|
|
181
|
+
_SCAN_LOADED = True
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def scan_slice(shadow_row) -> SliceScan:
|
|
185
|
+
"""``calculate_reject_unified.m:379-406`` -- extent of the shadow in one slice.
|
|
186
|
+
|
|
187
|
+
Returns the first and last shadowed diode (1-based) and how many are
|
|
188
|
+
shadowed. All three are 0 when the slice is empty.
|
|
189
|
+
|
|
190
|
+
Note what this does *not* return: the shadowed diodes need not be
|
|
191
|
+
contiguous, and the gap ``max_pos - min_pos + 1 - n_lite`` is precisely what
|
|
192
|
+
the hollow scans call a hole.
|
|
193
|
+
|
|
194
|
+
Dispatches to the numba kernel when available (:data:`HAVE_NUMBA`); numba is imported
|
|
195
|
+
lazily on first call, never at module load.
|
|
196
|
+
"""
|
|
197
|
+
arr = np.asarray(shadow_row, dtype=bool)
|
|
198
|
+
_ensure_scan_numba_loaded()
|
|
199
|
+
if _SCAN_HAVE_NUMBA:
|
|
200
|
+
min_pos, max_pos, n_lite = _scan_slice_kernel(np.ascontiguousarray(arr))
|
|
201
|
+
else:
|
|
202
|
+
min_pos, max_pos, n_lite = _scan_slice_reference(arr)
|
|
203
|
+
return SliceScan(int(min_pos), int(max_pos), int(n_lite))
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _scan_slice_reference(shadow_row):
|
|
207
|
+
"""Pure-Python body of :func:`scan_slice` -- the numba equivalence oracle."""
|
|
208
|
+
lit_positions = np.flatnonzero(shadow_row) + 1
|
|
209
|
+
n_lite = int(lit_positions.size)
|
|
210
|
+
if n_lite == 0:
|
|
211
|
+
return 0, 0, 0
|
|
212
|
+
return int(lit_positions[0]), int(lit_positions[-1]), n_lite
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _scan_slice_kernel(shadow_row):
|
|
216
|
+
lit_positions = np.flatnonzero(shadow_row)
|
|
217
|
+
n_lite = lit_positions.size
|
|
218
|
+
if n_lite == 0:
|
|
219
|
+
return 0, 0, 0
|
|
220
|
+
return lit_positions[0] + 1, lit_positions[-1] + 1, n_lite
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Optical Array Probe sample-area geometry.
|
|
3
|
+
|
|
4
|
+
Ported from: calc_sa_randombins.m (UIOOPS v3.1.4)
|
|
5
|
+
|
|
6
|
+
Reference: Heymsfield & Parrish (1978) sample-area formulation. The
|
|
7
|
+
sa_method=2 correction's 0.72 coefficient is attributed by McFarquhar
|
|
8
|
+
et al. (2017, Meteor. Monogr. 58, ch. 11, Eqs. 11-7/11-8) to a separate
|
|
9
|
+
1979 NCAR technical note by the same two authors (TN-137+IA), not the
|
|
10
|
+
1978 J. Appl. Meteorol. paper -- read directly, not carried from the
|
|
11
|
+
1978 citation by assumption.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
#: Declared so the public surface is explicit rather than whatever happens not to
|
|
15
|
+
#: start with an underscore. The Phase-1 shims at ``<name>.py`` in the original flat layout import
|
|
16
|
+
#: these names directly, CONSTANTS INCLUDED -- omitting a constant here would not
|
|
17
|
+
#: break them, but omitting one from a shim does, which is why they are listed.
|
|
18
|
+
__all__ = [
|
|
19
|
+
"calc_sa_randombins",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def calc_sa_randombins(bins_mid, res, armdst, num_diodes, sa_method, probetype):
|
|
24
|
+
"""OAP sample area (mm^2) per bin, per Heymsfield & Parrish
|
|
25
|
+
(1978, 1979 -- see this module's docstring for which is which).
|
|
26
|
+
|
|
27
|
+
Direct port of calc_sa_randombins.m.
|
|
28
|
+
|
|
29
|
+
bins_mid : sequence of bin midpoints, in MILLIMETRES.
|
|
30
|
+
res : photodiode resolution / bin width, microns.
|
|
31
|
+
armdst : probe arm separation, mm.
|
|
32
|
+
num_diodes: number of active photodiodes.
|
|
33
|
+
sa_method : 0 = center-in, 1 = entire-in, 2 = with correction.
|
|
34
|
+
probetype : 2 selects the alternate depth-of-field formula.
|
|
35
|
+
|
|
36
|
+
Returns a list of sample areas, one per entry in bins_mid.
|
|
37
|
+
|
|
38
|
+
THE UNITS OF ``bins_mid`` are millimetres, not "photodiode-number
|
|
39
|
+
units (not microns -- see original comment)", which is the opposite
|
|
40
|
+
of what the only call site passes. ``sizeDist.m:1562``
|
|
41
|
+
hands it ``cip2_binmid``, built at ``:1541-1543`` from ``kk``, and
|
|
42
|
+
every probe block defines ``kk`` in millimetres -- the 2D-S as
|
|
43
|
+
``diodesize/2 : diodesize : ...`` with ``diodesize = .010`` mm, the
|
|
44
|
+
HVPS as an explicit micron list divided by 1000. The source's comment
|
|
45
|
+
"you can use this one if you provide midpoint in doide number"
|
|
46
|
+
describes the *commented-out* ``radius = bins_mid .* res/2``, not the
|
|
47
|
+
live ``radius = bins_mid/2``.
|
|
48
|
+
|
|
49
|
+
Nothing computed changes either way -- the function does arithmetic on
|
|
50
|
+
whatever it is handed, which is why the wrong reading survived. What
|
|
51
|
+
it would have changed is a caller's. ``tests/test_sample_area_oracle.
|
|
52
|
+
SampleAreaUnitsTest`` pins the reading that is dimensionally coherent:
|
|
53
|
+
``bins_mid/res`` at ``:29`` is a diode count only if ``bins_mid`` is a
|
|
54
|
+
length in mm.
|
|
55
|
+
|
|
56
|
+
Note: the original MATLAB `switch` has no `otherwise` clause, so an
|
|
57
|
+
unsupported sa_method leaves EAWci/EAWri undefined and MATLAB dies at
|
|
58
|
+
`:49` with "'EAWri' undefined" (measured under Octave, and recorded in
|
|
59
|
+
the oracle bank as a status=ERROR case). This port raises ValueError
|
|
60
|
+
explicitly instead -- an intentional, documented deviation, not a
|
|
61
|
+
behavior change for any valid input.
|
|
62
|
+
"""
|
|
63
|
+
if sa_method not in (0, 1, 2):
|
|
64
|
+
raise ValueError(f"Unsupported sa_method {sa_method!r}; expected 0, 1, or 2")
|
|
65
|
+
|
|
66
|
+
res_mm = res * 1e-3 # microns -> mm
|
|
67
|
+
lambda_mm = 680 * 1e-6 # laser wavelength, mm
|
|
68
|
+
|
|
69
|
+
sa = []
|
|
70
|
+
for bin_mid in bins_mid:
|
|
71
|
+
radius = bin_mid / 2
|
|
72
|
+
diameter = 2 * radius
|
|
73
|
+
|
|
74
|
+
if sa_method == 0:
|
|
75
|
+
eaw_ci = num_diodes * res_mm
|
|
76
|
+
eaw_ri = eaw_ci
|
|
77
|
+
elif sa_method == 1:
|
|
78
|
+
eaw_ci = (num_diodes - (bin_mid / res_mm) + 1) * res_mm
|
|
79
|
+
eaw_ci = max(eaw_ci, 0)
|
|
80
|
+
eaw_ri = eaw_ci
|
|
81
|
+
else: # sa_method == 2
|
|
82
|
+
eaw_ci = num_diodes * res_mm
|
|
83
|
+
eaw_ri = eaw_ci + 0.72 * diameter
|
|
84
|
+
|
|
85
|
+
if probetype == 2:
|
|
86
|
+
dof = 20.52 * radius ** 2 * 1000
|
|
87
|
+
else:
|
|
88
|
+
dof = 6 * radius ** 2 / lambda_mm
|
|
89
|
+
dof = min(dof, armdst)
|
|
90
|
+
|
|
91
|
+
sa.append(dof * eaw_ri)
|
|
92
|
+
|
|
93
|
+
return sa
|