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,103 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Stray-pixel correction for one particle image (library default off,
|
|
3
|
+
batch-driver default on for engine 3.5).
|
|
4
|
+
|
|
5
|
+
An image made of one real particle plus far-off stray pixels is sized by UIOOPS as a whole
|
|
6
|
+
(``image_diam_minR`` encloses every shadowed pixel), so a ~200 um drop plus one stray pixel
|
|
7
|
+
becomes a 500-1000 um particle. :func:`remove_stray_pixels` zeroes the stray pieces and returns
|
|
8
|
+
the main piece, so the engine's unchanged measurement code re-sizes and re-tests it.
|
|
9
|
+
|
|
10
|
+
Wired into ``arrayprobe_uiops.imgproc`` (``stray_pixel_fix=``; library default off, whereas
|
|
11
|
+
``run_flight`` turns it on for every ``--engine 3.5`` run unless ``--stray-pixel off``).
|
|
12
|
+
This module does not import
|
|
13
|
+
``arrayprobe`` (nothing outside the v3.1.4 engine imports it); its constant-gap grouping is
|
|
14
|
+
the same rule as ``arrayprobe.triage_context.piece_groups``.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
#: Default gap, in empty diodes, below which pieces are one particle (the triage page's G = 8).
|
|
23
|
+
STRAY_GAP_DIODES = 8
|
|
24
|
+
#: A group of at most this many pixels, apart from the main piece, is a stray.
|
|
25
|
+
N_STRAY_PIXELS = 2
|
|
26
|
+
#: The main piece must have at least this many pixels (a 3 x 3 drop), or nothing is corrected.
|
|
27
|
+
MIN_MAIN_PIXELS = 9
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _groups(c: np.ndarray, gap: int) -> list[np.ndarray]:
|
|
31
|
+
"""8-connected pieces grouped single-linkage when at most ``gap`` empty diodes apart."""
|
|
32
|
+
from scipy import ndimage
|
|
33
|
+
|
|
34
|
+
eight = np.ones((3, 3), dtype=int)
|
|
35
|
+
if gap <= 0:
|
|
36
|
+
labels, count = ndimage.label(c, structure=eight)
|
|
37
|
+
else:
|
|
38
|
+
pad = gap + 1
|
|
39
|
+
grown = ndimage.binary_dilation(np.pad(c, pad),
|
|
40
|
+
structure=np.ones((gap + 1, gap + 1), dtype=bool))
|
|
41
|
+
labels, count = ndimage.label(grown, structure=eight)
|
|
42
|
+
labels = labels[pad:-pad, pad:-pad] * c
|
|
43
|
+
return [m for m in (labels == lab for lab in range(1, count + 1)) if m.any()]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def remove_stray_pixels(c: Any, gap: int = STRAY_GAP_DIODES, n_stray: int = N_STRAY_PIXELS,
|
|
47
|
+
min_main: int = MIN_MAIN_PIXELS) -> tuple[np.ndarray, dict[str, Any]]:
|
|
48
|
+
"""``(cleaned, record)`` for one particle image ``c`` (nonzero = shadowed).
|
|
49
|
+
|
|
50
|
+
Corrected only when, grouped at ``gap``, there are two or more groups, exactly one has more
|
|
51
|
+
than ``n_stray`` pixels and at least ``min_main``, and every other has at most ``n_stray``.
|
|
52
|
+
The strays are zeroed; ``cleaned`` keeps ``c``'s shape and dtype, and is ``c`` itself
|
|
53
|
+
(unchanged, same object) when nothing is removed. ``record``: ``removed`` (pixels zeroed),
|
|
54
|
+
``pieces`` (stray groups removed), ``positions`` (``(row, col)`` of each zeroed pixel).
|
|
55
|
+
"""
|
|
56
|
+
arr = np.asarray(c)
|
|
57
|
+
none: dict[str, Any] = {"removed": 0, "pieces": 0, "positions": []}
|
|
58
|
+
shadow = arr != 0
|
|
59
|
+
if arr.size == 0 or not shadow.any():
|
|
60
|
+
return c, none
|
|
61
|
+
groups = _groups(shadow, gap)
|
|
62
|
+
if len(groups) < 2:
|
|
63
|
+
return c, none
|
|
64
|
+
sizes = [int(g.sum()) for g in groups]
|
|
65
|
+
big = [i for i, s in enumerate(sizes) if s > n_stray]
|
|
66
|
+
if len(big) != 1 or sizes[big[0]] < min_main:
|
|
67
|
+
return c, none
|
|
68
|
+
stray = np.zeros_like(shadow)
|
|
69
|
+
for i, g in enumerate(groups):
|
|
70
|
+
if i != big[0]:
|
|
71
|
+
stray |= g
|
|
72
|
+
cleaned = arr.copy()
|
|
73
|
+
cleaned[stray] = 0
|
|
74
|
+
rr, cc = np.nonzero(stray)
|
|
75
|
+
return cleaned, {"removed": int(rr.size), "pieces": len(groups) - 1,
|
|
76
|
+
"positions": list(zip(rr.tolist(), cc.tolist(), strict=True))}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
#: The ``.call`` stamp / global-attribute value of the default parameters (design, "Stamp").
|
|
80
|
+
STAMP_ON = f"on:g{STRAY_GAP_DIODES},n{N_STRAY_PIXELS},m{MIN_MAIN_PIXELS}"
|
|
81
|
+
STAMP_OFF = "off"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def correct_engine_image(c: Any) -> tuple[Any, int]:
|
|
85
|
+
"""``(c_out, removed)`` for one engine image -- the ``(nslices, ndiodes)`` ASCII ``c``
|
|
86
|
+
(``'0'`` / 48 / ``True`` shadowed), as ``_process_records`` holds it before
|
|
87
|
+
``measure_record``. Zeroed stray pixels are set to lit (``'1'`` / 49 / ``False``);
|
|
88
|
+
``c_out`` is ``c`` itself when nothing is removed."""
|
|
89
|
+
arr = np.asarray(c)
|
|
90
|
+
lit: Any # bool, numpy str/bytes scalar or int, by the image dtype
|
|
91
|
+
if arr.dtype.kind == "b":
|
|
92
|
+
shadow, lit = arr, False
|
|
93
|
+
elif arr.dtype.kind in "US":
|
|
94
|
+
shadow, lit = arr == arr.dtype.type("0"), arr.dtype.type("1")
|
|
95
|
+
else:
|
|
96
|
+
shadow, lit = arr == 48, 49
|
|
97
|
+
_, rec = remove_stray_pixels(shadow.astype(np.uint8))
|
|
98
|
+
if rec["removed"] == 0:
|
|
99
|
+
return c, 0
|
|
100
|
+
out = arr.copy()
|
|
101
|
+
for r, k in rec["positions"]:
|
|
102
|
+
out[r, k] = lit
|
|
103
|
+
return out, int(rec["removed"])
|
arrayprobe_uiops/tas.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""True-airspeed repair and the probe/aircraft TAS ratio (UIOOPS v3.5).
|
|
3
|
+
|
|
4
|
+
Ported from: ``read_binary_SPEC.m`` (UIOOPS v3.5), the TAS machinery added by
|
|
5
|
+
Joe Finlon 11/3/19 and extended 5/13/22. **None of this exists in v3.1.4** --
|
|
6
|
+
`interp_tas` is absent from that file entirely, and the v3.1.4 reader has no
|
|
7
|
+
`tasRatio`, no aircraft-TAS input and no TAS-update gate. This is new surface,
|
|
8
|
+
not a changed translation, which is why it is its own module rather than a
|
|
9
|
+
delta on ``arrayprobe.readers.spec``.
|
|
10
|
+
|
|
11
|
+
The TAS machinery of the v3.5 port, ported and oracle-validated,
|
|
12
|
+
leaving ``read_binary_SPEC``'s record-walking driver for its own session.
|
|
13
|
+
Every function here is pure -- no file handles, no netCDF, no binary buffers --
|
|
14
|
+
which is exactly why this slice could be separated out and validated on its own.
|
|
15
|
+
|
|
16
|
+
**Fidelity.** Bug-for-bug, as everywhere in this project. Three behaviours below
|
|
17
|
+
are faithful reproductions of measured MATLAB/Octave behaviour that a reader of
|
|
18
|
+
the source would not predict, and each is preserved rather than fixed:
|
|
19
|
+
|
|
20
|
+
1. **A negative TAS is neither good nor bad.** ``interp_tas`` selects nodes with
|
|
21
|
+
``tasValues > 0`` and targets with ``tasValues == 0 | isnan``. A negative
|
|
22
|
+
value satisfies neither, so it is *excluded from the interpolation nodes and
|
|
23
|
+
left in place unrepaired*. This matters because ``-999.`` is the file's own
|
|
24
|
+
sentinel for an uncorrectable probe TAS (``read_binary_SPEC.m:186``), so a
|
|
25
|
+
``-999`` can survive into ``fltTAS_fixed``, pass the ``~isnan`` guard at
|
|
26
|
+
``:185``, and produce a negative ``tasRatio``. Measured, not read.
|
|
27
|
+
2. **Leading and trailing bad values are never repaired.** MATLAB's ``interp1``
|
|
28
|
+
does not extrapolate, so a bad value outside the span of the good nodes
|
|
29
|
+
becomes ``NaN``. Benign in context -- ``:185``'s ``~isnan`` guard then falls
|
|
30
|
+
back to ``tasRatio = 1.0`` -- but it means "fix bad TAS values", the
|
|
31
|
+
function's own comment, is true only in the interior.
|
|
32
|
+
3. **Fewer than two good nodes raises.** ``interp1`` needs two points, so a TAS
|
|
33
|
+
array that is entirely zero/NaN (a dead TAS feed) aborts the decode rather
|
|
34
|
+
than degrading to a fallback. Reproduced as ``InterpTasError``.
|
|
35
|
+
|
|
36
|
+
Interpolation is over *index* coordinates, not over the values, so a
|
|
37
|
+
non-monotonic TAS series interpolates between its neighbours by position.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
from __future__ import annotations
|
|
41
|
+
|
|
42
|
+
from collections.abc import Sequence
|
|
43
|
+
|
|
44
|
+
import numpy as np
|
|
45
|
+
|
|
46
|
+
#: What these functions accept for a TAS or flight-time series. Every one of
|
|
47
|
+
#: them calls ``np.asarray`` on its input, so an ndarray is not merely tolerated
|
|
48
|
+
#: -- it is what :func:`interp_tas` hands to :func:`tas_ratio` in the v3.5
|
|
49
|
+
#: driver (``arrayprobe_uiops.spec.read_binary_spec_v35``). Named so that is a
|
|
50
|
+
#: declared part of the interface rather than something a caller has to
|
|
51
|
+
#: discover.
|
|
52
|
+
Series = Sequence[float] | np.ndarray
|
|
53
|
+
|
|
54
|
+
__all__ = [
|
|
55
|
+
"AmbiguousFlightTimeError",
|
|
56
|
+
"Series",
|
|
57
|
+
"InterpTasError",
|
|
58
|
+
"interp_tas",
|
|
59
|
+
"tas_ratio",
|
|
60
|
+
"update_tas",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
#: ``read_binary_SPEC.m:407-408``. A probe TAS reading of exactly this value is
|
|
64
|
+
#: treated as untrustworthy and the previous record's value is kept instead.
|
|
65
|
+
#: The number is upstream's, unexplained there; it coincides with the 2D-S
|
|
66
|
+
#: ``tasMax`` cap used elsewhere in UIOOPS, which is worth knowing but is not
|
|
67
|
+
#: stated by either site to be the reason.
|
|
68
|
+
SUSPECT_TAS = 170.0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class AmbiguousFlightTimeError(ValueError):
|
|
72
|
+
"""More than one flight-time row matched one record's timestamp.
|
|
73
|
+
|
|
74
|
+
Upstream builds a vector ``tasRatio`` here and writes it with a count of
|
|
75
|
+
one; what MATLAB does with that is unestablished, so this port refuses
|
|
76
|
+
rather than inventing the answer. See :func:`tas_ratio`.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class InterpTasError(ValueError):
|
|
81
|
+
"""``interp1`` could not run: fewer than two usable TAS nodes.
|
|
82
|
+
|
|
83
|
+
MATLAB's message is ``interp1: minimum of 2 points required in each
|
|
84
|
+
dimension``; Octave's is identical, which is how it was measured.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def interp_tas(tas_values: Series) -> np.ndarray:
|
|
89
|
+
"""Repair zero/NaN TAS values by linear interpolation over index position.
|
|
90
|
+
|
|
91
|
+
``read_binary_SPEC.m:453-461``. See this module's docstring for the three
|
|
92
|
+
preserved behaviours -- negatives untouched, ends unrepaired, and a raise
|
|
93
|
+
below two good nodes.
|
|
94
|
+
"""
|
|
95
|
+
values = np.asarray(tas_values, dtype=float)
|
|
96
|
+
out = values.copy()
|
|
97
|
+
good = np.flatnonzero((values > 0) & ~np.isnan(values))
|
|
98
|
+
bad = np.flatnonzero((values == 0) | np.isnan(values))
|
|
99
|
+
if bad.size == 0:
|
|
100
|
+
return out
|
|
101
|
+
if good.size < 2:
|
|
102
|
+
raise InterpTasError("interp1: minimum of 2 points required in each dimension")
|
|
103
|
+
# np.interp clamps outside the node span; MATLAB's interp1 returns NaN there.
|
|
104
|
+
interpolated = np.interp(bad, good, values[good])
|
|
105
|
+
interpolated[(bad < good[0]) | (bad > good[-1])] = np.nan
|
|
106
|
+
out[bad] = interpolated
|
|
107
|
+
return out
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
#: A probe TAS as the reader carries it: a numpy float32 once it came from a
|
|
111
|
+
#: housekeeping packet (MATLAB single), a float for the initial -999 (double).
|
|
112
|
+
TasValue = float | np.float32
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def update_tas(tas_temp: TasValue, tas_prev: TasValue, n_hol: int, n_vol: int) -> TasValue:
|
|
116
|
+
"""The per-record TAS update gate, ``read_binary_SPEC.m:406-414``.
|
|
117
|
+
|
|
118
|
+
A new reading replaces the running value only when it differs from it and is
|
|
119
|
+
not itself suspect: a reading of exactly :data:`SUSPECT_TAS`, or any holdover
|
|
120
|
+
or overload count on either channel, keeps the previous value instead.
|
|
121
|
+
|
|
122
|
+
Returns the TAS to use for this record, which is also the next record's
|
|
123
|
+
``tasPrev``. The MATLAB writes ``tasPrev = tas`` only inside the
|
|
124
|
+
``tasTemp ~= tasPrev`` branch; when the branch is not taken the two are
|
|
125
|
+
already equal, so the single return value here is faithful, not a
|
|
126
|
+
simplification.
|
|
127
|
+
"""
|
|
128
|
+
if tas_temp != tas_prev:
|
|
129
|
+
if tas_temp == SUSPECT_TAS or (n_hol + n_vol) > 0:
|
|
130
|
+
return tas_prev
|
|
131
|
+
return tas_temp
|
|
132
|
+
return tas_prev
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def tas_ratio(
|
|
136
|
+
img_tas: float,
|
|
137
|
+
flt_time: Series,
|
|
138
|
+
flt_tas_fixed: Series,
|
|
139
|
+
hour: int,
|
|
140
|
+
minute: int,
|
|
141
|
+
second: int,
|
|
142
|
+
) -> float:
|
|
143
|
+
"""Probe-to-aircraft TAS ratio for one record, ``read_binary_SPEC.m:176-193``.
|
|
144
|
+
|
|
145
|
+
``flt_tas_fixed`` is the aircraft TAS series already passed through
|
|
146
|
+
:func:`interp_tas`. Returns ``1.0`` -- "assume the probe TAS is correct" --
|
|
147
|
+
whenever the aircraft series has nothing usable at this record's time, and
|
|
148
|
+
likewise when the probe's own TAS is the ``-999.`` uncorrectable sentinel.
|
|
149
|
+
|
|
150
|
+
**The date-crossover dummy** (``:177-181``, Finlon 5/13/22): when the flight
|
|
151
|
+
time series runs past 240000 and this record's hour is before noon, the
|
|
152
|
+
record is looked up at ``hour + 24``. The shifted hour is used for the
|
|
153
|
+
lookup only and is never written.
|
|
154
|
+
"""
|
|
155
|
+
times = np.asarray(flt_time, dtype=float)
|
|
156
|
+
fixed = np.asarray(flt_tas_fixed, dtype=float)
|
|
157
|
+
if times.size == 0:
|
|
158
|
+
# :177 reads `fltTime(end)` before the `&&` can short-circuit, so an
|
|
159
|
+
# empty aircraft series raises in MATLAB (Octave 8.4, measured:
|
|
160
|
+
# tests/data/v35_tas_ratio_octave_golden.json case b11). Pass 6.
|
|
161
|
+
raise IndexError(
|
|
162
|
+
"read_binary_SPEC.m:177: fltTime(0): subscripts must be either "
|
|
163
|
+
"integers 1 to (2^63)-1 or logicals (empty aircraft time series)"
|
|
164
|
+
)
|
|
165
|
+
hour2 = hour + 24 if times.size and times[-1] >= 240000 and hour < 12 else hour
|
|
166
|
+
index = np.flatnonzero(times == hour2 * 10000 + minute * 100 + second)
|
|
167
|
+
if index.size == 0:
|
|
168
|
+
return 1.0
|
|
169
|
+
# MATLAB's `if ~isnan(v)` over a vector is true only when EVERY element is,
|
|
170
|
+
# and `find` can match more than one row. Preserved rather than collapsed to
|
|
171
|
+
# index[0], because the multi-match case is where upstream breaks.
|
|
172
|
+
if np.isnan(fixed[index]).any():
|
|
173
|
+
return 1.0
|
|
174
|
+
if img_tas == -999.0:
|
|
175
|
+
return 1.0
|
|
176
|
+
if index.size > 1:
|
|
177
|
+
# Upstream would build a vector here and hand it to
|
|
178
|
+
# `netcdf.putVar(f, varid10, kk1-1, 1, tasRatio)` -- a count of one. What
|
|
179
|
+
# MATLAB does with that is not established, and guessing a scalar would
|
|
180
|
+
# invent a fidelity claim, so this refuses instead. Reachable only from a
|
|
181
|
+
# flight-time series with duplicate timestamps.
|
|
182
|
+
raise AmbiguousFlightTimeError(
|
|
183
|
+
f"{index.size} flight-time rows match {hour2:02d}:{minute:02d}:{second:02d}; "
|
|
184
|
+
"read_binary_SPEC.m:184-189 would produce a vector tasRatio here"
|
|
185
|
+
)
|
|
186
|
+
# `imgTAS ./ fltTAS_fixed(...)` (:188) is single ./ double, which MATLAB
|
|
187
|
+
# evaluates as single(imgTAS) / single(fltTAS) in single arithmetic
|
|
188
|
+
# (Octave-measured, pass 5 item 4: 4917 of 20000 random pairs differ by one
|
|
189
|
+
# float32 ULP from the double quotient rounded once; applied pass 6).
|
|
190
|
+
# spec.py's outer np.float32() is therefore a no-op, kept as a guard.
|
|
191
|
+
return float(np.float32(img_tas) / np.float32(fixed[index[0]]))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""HHMMSS <-> seconds-since-midnight time conversions.
|
|
3
|
+
|
|
4
|
+
Ported from: hhmmss2insec.m, insec2hhmmss.m (UIOOPS v3.1.4)
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
#: Declared so the public surface is explicit rather than whatever happens not to
|
|
8
|
+
#: start with an underscore. The Phase-1 shims at ``<name>.py`` in the original flat layout import
|
|
9
|
+
#: these names directly, CONSTANTS INCLUDED -- omitting a constant here would not
|
|
10
|
+
#: break them, but omitting one from a shim does, which is why they are listed.
|
|
11
|
+
__all__ = [
|
|
12
|
+
"hhmmss_to_insec",
|
|
13
|
+
"insec_to_hhmmss",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def hhmmss_to_insec(time_hhmmss):
|
|
18
|
+
"""Convert an HHMMSS-formatted time (e.g. 134502) to seconds since midnight.
|
|
19
|
+
|
|
20
|
+
Direct port of hhmmss2insec.m. Values are treated as non-negative,
|
|
21
|
+
matching the original's assumed domain (a time-of-day field). Every term is
|
|
22
|
+
floored, seconds included (Octave: ``hhmmss2insec(120000.5)`` is 43200).
|
|
23
|
+
"""
|
|
24
|
+
t = float(time_hhmmss)
|
|
25
|
+
hh = t // 10000
|
|
26
|
+
mm = (t % 10000) // 100
|
|
27
|
+
ss = (t % 100) // 1
|
|
28
|
+
return hh * 3600 + mm * 60 + ss
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def insec_to_hhmmss(insec):
|
|
32
|
+
"""Convert seconds-since-midnight to HHMMSS format.
|
|
33
|
+
|
|
34
|
+
Direct port of insec2hhmmss.m, every term floored (``insec2hhmmss(43200.5)``
|
|
35
|
+
is 120000).
|
|
36
|
+
"""
|
|
37
|
+
s = float(insec)
|
|
38
|
+
hh = s // 3600
|
|
39
|
+
mm = (s % 3600) // 60
|
|
40
|
+
ss = (s % 60) // 1
|
|
41
|
+
return hh * 10000 + mm * 100 + ss
|