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.
Files changed (189) hide show
  1. arrayprobe/__init__.py +219 -0
  2. arrayprobe/__main__.py +19 -0
  3. arrayprobe/_v314_lazy.py +48 -0
  4. arrayprobe/ai_ready.py +212 -0
  5. arrayprobe/attributed_export.py +1333 -0
  6. arrayprobe/authordefaults.py +267 -0
  7. arrayprobe/cli.py +3510 -0
  8. arrayprobe/combine.py +12 -0
  9. arrayprobe/compare.py +950 -0
  10. arrayprobe/config.py +1239 -0
  11. arrayprobe/constants.py +12 -0
  12. arrayprobe/count_closure.py +204 -0
  13. arrayprobe/diagnostic_views.py +769 -0
  14. arrayprobe/diode_report.py +265 -0
  15. arrayprobe/driver/__init__.py +5 -0
  16. arrayprobe/driver/_load_record.py +331 -0
  17. arrayprobe/driver/preflight_inputs.py +250 -0
  18. arrayprobe/driver/reprocess.py +553 -0
  19. arrayprobe/driver/run_flight.py +8166 -0
  20. arrayprobe/driver/tas_from_probe_housekeeping.py +124 -0
  21. arrayprobe/dropsize.py +519 -0
  22. arrayprobe/friendly.py +206 -0
  23. arrayprobe/geometry/__init__.py +77 -0
  24. arrayprobe/geometry/min_rectangle.py +92 -0
  25. arrayprobe/intarr.py +12 -0
  26. arrayprobe/intarr_analysis.py +16 -0
  27. arrayprobe/intarr_plots.py +12 -0
  28. arrayprobe/inventory.py +129 -0
  29. arrayprobe/jit_kernels.py +344 -0
  30. arrayprobe/lwc.py +44 -0
  31. arrayprobe/masks.py +349 -0
  32. arrayprobe/matio.py +410 -0
  33. arrayprobe/matlab_compat.py +13 -0
  34. arrayprobe/ncio.py +26 -0
  35. arrayprobe/particle.py +55 -0
  36. arrayprobe/particle_perimeter.py +12 -0
  37. arrayprobe/products.py +78 -0
  38. arrayprobe/profiles.py +179 -0
  39. arrayprobe/provenance.py +21 -0
  40. arrayprobe/py.typed +11 -0
  41. arrayprobe/readers/__init__.py +9 -0
  42. arrayprobe/readers/dmt.py +603 -0
  43. arrayprobe/readers/mask_csv.py +12 -0
  44. arrayprobe/readers/pms.py +12 -0
  45. arrayprobe/readers/sea.py +433 -0
  46. arrayprobe/readers/tasinfo.py +12 -0
  47. arrayprobe/regimes.py +507 -0
  48. arrayprobe/render.py +728 -0
  49. arrayprobe/reproduce_report.py +149 -0
  50. arrayprobe/review_agreement.py +135 -0
  51. arrayprobe/review_sampling.py +327 -0
  52. arrayprobe/run_page.py +624 -0
  53. arrayprobe/sample_area.py +12 -0
  54. arrayprobe/selector.py +206 -0
  55. arrayprobe/sizing.py +151 -0
  56. arrayprobe/time_convert.py +12 -0
  57. arrayprobe/timing_closure.py +141 -0
  58. arrayprobe/tools/__init__.py +27 -0
  59. arrayprobe/tools/make_demo_flight.py +1089 -0
  60. arrayprobe/tools/make_tas_file.py +760 -0
  61. arrayprobe/tools/probe_comparison.py +569 -0
  62. arrayprobe/tools/synthetic_truth.py +698 -0
  63. arrayprobe/tools/tas_sources.py +705 -0
  64. arrayprobe/triage_context.py +488 -0
  65. arrayprobe/triage_server.py +5215 -0
  66. arrayprobe/tune/__init__.py +15 -0
  67. arrayprobe/tune/diodes.py +400 -0
  68. arrayprobe/tune/distributions.py +300 -0
  69. arrayprobe/tune/sample.py +243 -0
  70. arrayprobe/tune/score.py +230 -0
  71. arrayprobe/tune/settings.py +354 -0
  72. arrayprobe/validate_by_condition.py +208 -0
  73. arrayprobe/validation_report.py +166 -0
  74. arrayprobe-0.1.0.dist-info/METADATA +260 -0
  75. arrayprobe-0.1.0.dist-info/RECORD +189 -0
  76. arrayprobe-0.1.0.dist-info/WHEEL +5 -0
  77. arrayprobe-0.1.0.dist-info/entry_points.txt +2 -0
  78. arrayprobe-0.1.0.dist-info/licenses/LICENSE +31 -0
  79. arrayprobe-0.1.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +47 -0
  80. arrayprobe-0.1.0.dist-info/licenses/NOTICE.md +369 -0
  81. arrayprobe-0.1.0.dist-info/top_level.txt +4 -0
  82. arrayprobe_soda2/__init__.py +131 -0
  83. arrayprobe_soda2/angles.py +143 -0
  84. arrayprobe_soda2/aspect_ratio.py +541 -0
  85. arrayprobe_soda2/backfill.py +100 -0
  86. arrayprobe_soda2/binary_dof.py +181 -0
  87. arrayprobe_soda2/buildindex.py +113 -0
  88. arrayprobe_soda2/decompress_dmt.py +285 -0
  89. arrayprobe_soda2/enhancement_hooks.py +275 -0
  90. arrayprobe_soda2/export_ascii.py +732 -0
  91. arrayprobe_soda2/export_ncdf.py +683 -0
  92. arrayprobe_soda2/export_ncdf_raf.py +396 -0
  93. arrayprobe_soda2/fillholes.py +161 -0
  94. arrayprobe_soda2/find_radius.py +105 -0
  95. arrayprobe_soda2/findsize.py +407 -0
  96. arrayprobe_soda2/fit_poisson.py +170 -0
  97. arrayprobe_soda2/fix2dimage.py +63 -0
  98. arrayprobe_soda2/fixraking.py +162 -0
  99. arrayprobe_soda2/fixstuckbits.py +146 -0
  100. arrayprobe_soda2/hvps4_read_frame.py +121 -0
  101. arrayprobe_soda2/jit_kernels.py +152 -0
  102. arrayprobe_soda2/label_blobs.py +177 -0
  103. arrayprobe_soda2/min_circle_fast.py +320 -0
  104. arrayprobe_soda2/particlesort.py +703 -0
  105. arrayprobe_soda2/pbp_writer.py +558 -0
  106. arrayprobe_soda2/poisson_spot_correct.py +183 -0
  107. arrayprobe_soda2/princomp.py +107 -0
  108. arrayprobe_soda2/probespecs.py +361 -0
  109. arrayprobe_soda2/process_2d.py +1364 -0
  110. arrayprobe_soda2/process_2d_parallel.py +626 -0
  111. arrayprobe_soda2/process_hk.py +512 -0
  112. arrayprobe_soda2/processbuffer_2dc.py +155 -0
  113. arrayprobe_soda2/processbuffer_cip.py +213 -0
  114. arrayprobe_soda2/processbuffer_f2dc.py +139 -0
  115. arrayprobe_soda2/processbuffer_spec.py +441 -0
  116. arrayprobe_soda2/processbuffer_tail.py +350 -0
  117. arrayprobe_soda2/pth_readers.py +245 -0
  118. arrayprobe_soda2/py.typed +11 -0
  119. arrayprobe_soda2/read2dbuffer.py +371 -0
  120. arrayprobe_soda2/reject.py +246 -0
  121. arrayprobe_soda2/reprocess_pbp.py +156 -0
  122. arrayprobe_soda2/sample_area.py +264 -0
  123. arrayprobe_soda2/save_writer.py +480 -0
  124. arrayprobe_soda2/sea.py +324 -0
  125. arrayprobe_soda2/spec_absolutepointers.py +109 -0
  126. arrayprobe_soda2/spec_decompress.py +203 -0
  127. arrayprobe_soda2/spec_index.py +476 -0
  128. arrayprobe_soda2/spec_read_frame.py +286 -0
  129. arrayprobe_soda2/spec_read_hk.py +301 -0
  130. arrayprobe_soda2/spec_readint.py +127 -0
  131. arrayprobe_soda2/timeconv.py +77 -0
  132. arrayprobe_soda2/update_op.py +101 -0
  133. arrayprobe_uiops/__init__.py +45 -0
  134. arrayprobe_uiops/combine.py +192 -0
  135. arrayprobe_uiops/combine_fork.py +359 -0
  136. arrayprobe_uiops/constants.py +830 -0
  137. arrayprobe_uiops/decode_naming.py +113 -0
  138. arrayprobe_uiops/diode_mask.py +250 -0
  139. arrayprobe_uiops/engine_absence.py +41 -0
  140. arrayprobe_uiops/export_oap.py +325 -0
  141. arrayprobe_uiops/geometry_core.py +366 -0
  142. arrayprobe_uiops/habit.py +749 -0
  143. arrayprobe_uiops/habit_core.py +248 -0
  144. arrayprobe_uiops/hollow_size_rule.py +376 -0
  145. arrayprobe_uiops/imgproc.py +2081 -0
  146. arrayprobe_uiops/imgproc_core.py +275 -0
  147. arrayprobe_uiops/intarr.py +167 -0
  148. arrayprobe_uiops/intarr_analysis.py +569 -0
  149. arrayprobe_uiops/intarr_plots.py +119 -0
  150. arrayprobe_uiops/jit_kernels.py +430 -0
  151. arrayprobe_uiops/lwc.py +70 -0
  152. arrayprobe_uiops/matlab_compat.py +860 -0
  153. arrayprobe_uiops/measure.py +346 -0
  154. arrayprobe_uiops/min_circle.py +204 -0
  155. arrayprobe_uiops/min_ellipse.py +161 -0
  156. arrayprobe_uiops/min_rectangle.py +200 -0
  157. arrayprobe_uiops/ncar_2dc_timing.py +100 -0
  158. arrayprobe_uiops/ncio.py +810 -0
  159. arrayprobe_uiops/oap_read.py +228 -0
  160. arrayprobe_uiops/particle.py +51 -0
  161. arrayprobe_uiops/particle_perimeter.py +94 -0
  162. arrayprobe_uiops/particle_physics.py +199 -0
  163. arrayprobe_uiops/pecan_params.py +134 -0
  164. arrayprobe_uiops/probe_cases.py +298 -0
  165. arrayprobe_uiops/product_sanity.py +337 -0
  166. arrayprobe_uiops/profile.py +71 -0
  167. arrayprobe_uiops/profiles.py +756 -0
  168. arrayprobe_uiops/provenance.py +804 -0
  169. arrayprobe_uiops/py.typed +11 -0
  170. arrayprobe_uiops/qc.py +169 -0
  171. arrayprobe_uiops/readers/__init__.py +8 -0
  172. arrayprobe_uiops/readers/mask_csv.py +74 -0
  173. arrayprobe_uiops/readers/pms.py +239 -0
  174. arrayprobe_uiops/readers/tasinfo.py +57 -0
  175. arrayprobe_uiops/rect_ellipse.py +129 -0
  176. arrayprobe_uiops/register_image_assisted.py +25 -0
  177. arrayprobe_uiops/reject.py +501 -0
  178. arrayprobe_uiops/reject_core.py +220 -0
  179. arrayprobe_uiops/sample_area.py +93 -0
  180. arrayprobe_uiops/sizedist.py +1923 -0
  181. arrayprobe_uiops/sizedist_core.py +814 -0
  182. arrayprobe_uiops/sizedist_tables.py +642 -0
  183. arrayprobe_uiops/spec.py +1094 -0
  184. arrayprobe_uiops/spec_core.py +703 -0
  185. arrayprobe_uiops/stray_pixel.py +103 -0
  186. arrayprobe_uiops/tas.py +191 -0
  187. arrayprobe_uiops/time_convert.py +41 -0
  188. uiops/__init__.py +402 -0
  189. 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"])
@@ -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