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,512 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ # Reproduces SODA-2, Copyright (c) 2016 UCAR; see LICENSES/BSD-3-Clause.txt and NOTICE.md.
3
+ """`spec_process_hk.pro`, versions 1 and 2, and `spec_index_hk.pro`.
4
+ Version 1: (`:1-13`, `:26-102`, `:169-184`). **Version 2** (3VCPI/Hawkeye/HVPS4/
5
+ Fast2DS, `:14-25`, `:104-167`) and the index it needs, `spec_index_hk.pro`
6
+ (whole file), were added on a synthetic 2DSCPIHK file whose
7
+ layout is derived from `spec_index_hk.pro:11,44-52` alone -- no real
8
+ 3VCPI/Hawkeye/HVPS-4 file exists here, so the byte layout is the source's,
9
+ and the channel meanings are the source's own indexing.
10
+
11
+ Vendored sources: `SODA2/abansemer-soda2-afcea15/spec_process_hk.pro`,
12
+ `spec_index_hk.pro`. Banks: version 1, `gdl_oracle/run_soda2_preloop_bank.py`
13
+ (golden `tests/data/gdl_soda2_preloop_golden.json`); version 2,
14
+ `gdl_oracle/run_soda2_spec_read_hk_bank.py --v2` (golden
15
+ `tests/data/gdl_soda2_spec_read_hk_v2_golden.json`).
16
+ """
17
+ from __future__ import annotations
18
+
19
+ import copy
20
+ import os
21
+ from collections.abc import Callable
22
+ from dataclasses import dataclass
23
+ from typing import Any
24
+
25
+ import numpy as np
26
+ from numpy.typing import DTypeLike
27
+
28
+ from .buildindex import GenericIndex, buildindex
29
+ from .spec_index import SpecIndex, julday
30
+ from .spec_read_hk import spec_read_hk
31
+ from .timeconv import soda2_parsedate
32
+ from .update_op import update_op
33
+
34
+
35
+ def f32_via_f64(fn: Callable[..., Any], *args: Any) -> np.ndarray:
36
+ """IDL FLOAT transcendental (``alog``, ``exp``, ``sin`` ...): compute ``fn``
37
+ in float64 and round once to float32. GDL's FLOAT kernels are correctly
38
+ rounded; numpy's float32 ``log``/``exp``/``sin``/``cos``/``log10``/``power``
39
+ are not.
40
+ Use only where the IDL operand is FLOAT."""
41
+ with np.errstate(divide="ignore", invalid="ignore", over="ignore"):
42
+ return np.asarray(fn(*(np.asarray(a, dtype=np.float64) for a in args))).astype(np.float32)
43
+
44
+
45
+ _TEMPID = [
46
+ "horiz arm tx", "horiz arm rx", "vert arm tx", "vert arm rx",
47
+ "horiz tip tx", "horiz tip rx", "rear optical bridge", "DSP board",
48
+ "forward vessel", "horiz laser", "vert laser", "front plate",
49
+ "power supply",
50
+ ]
51
+
52
+
53
+ @dataclass
54
+ class HouseData:
55
+ """The ``data`` structure ``spec_process_hk.pro:183-184`` (SODA-2) builds, one field per
56
+ IDL tag."""
57
+ op: dict
58
+ time: np.ndarray
59
+ nb: np.ndarray
60
+ arrayid: str
61
+ tas: np.ndarray
62
+ diodes: list[int]
63
+ volts: np.ndarray
64
+ canpressure: np.ndarray
65
+ power: np.ndarray
66
+ tempid: list[str]
67
+ temp: np.ndarray
68
+ laservolts: np.ndarray
69
+ overloads: np.ndarray
70
+ counts: np.ndarray
71
+
72
+
73
+ def _idiv(a: float, b: float) -> int:
74
+ """IDL LONG-cast division truncates toward zero (`:32`'s `long(...)`,
75
+ `:62`'s `long(...)` -- trap T2)."""
76
+ q = a / b
77
+ return int(q) if q >= 0 else -int(-q)
78
+
79
+
80
+ def _interpol(v: np.ndarray, x: np.ndarray, xout: float) -> float:
81
+ """IDL `INTERPOL`'s documented linear-case formula, evaluated at one
82
+ `xout` against the bracketing pair of the (sorted) `x`/`v` arrays."""
83
+ i = int(np.searchsorted(x, xout)) - 1
84
+ i = max(0, min(i, len(x) - 2))
85
+ return float(v[i] + (xout - x[i]) * (v[i + 1] - v[i]) / (x[i + 1] - x[i]))
86
+
87
+
88
+ class ProcessHKStop(RuntimeError):
89
+ """An IDL ``stop`` or halt inside ``spec_process_hk``, naming the line."""
90
+
91
+
92
+ @dataclass
93
+ class SpecIndexHK:
94
+ """``spec_index_hk``'s return struct (`spec_index_hk.pro:68`). Dtypes
95
+ are the bank's measured ``size(/tname)``: LONG, DOUBLE, LONG, LONG64,
96
+ LONG64."""
97
+
98
+ date: np.ndarray # int32
99
+ bufftime: np.ndarray # float64
100
+ pointer: np.ndarray # int32 -- a LONG index array (`spec_index_hk.pro:25`)
101
+ hkp: np.ndarray # int64; [0] when the file holds no HK buffer
102
+ maskp: np.ndarray # int64; [0] when it holds no mask buffer
103
+ buffsize: int = 0 # `:67` -- disables `spec_readint`'s framing
104
+ error: int = 0
105
+
106
+
107
+ def spec_index_hk(fn: str) -> SpecIndexHK:
108
+ """``spec_index_hk.pro`` (whole file, 69 lines) -- index a
109
+ 3VCPI/Hawkeye ``2DSCPIHK`` housekeeping file.
110
+
111
+ `:11` the buffer header is eight INTs and a UINT ``buffertype`` (18
112
+ bytes). `:30` **every** 2-byte offset is tried as a header, and `:33-35`
113
+ accept one whose year equals the first header's and whose month and day
114
+ equal it or it plus one -- so a payload word sequence that happens to
115
+ read as a matching date is indexed as a buffer (no framing check).
116
+ `:30`'s bound ``(f.size-headersize)/2 - 1`` leaves the last 2-byte
117
+ position a header could start at unscanned. `:44-52` an HK buffer
118
+ (``buffertype`` 18507) or mask buffer (19787) is recorded AT its
119
+ ``buffertype`` word (``ip*2 + headersize - 2``). `:55-59` each list is
120
+ trimmed to ``[0:(n-1)>0]``: **with no HK buffer at all, ``hkp`` is
121
+ ``[0]``** and ``spec_process_hk`` reads a phantom record from byte 0
122
+ (bank ``phk_nohk``). `:24` ``numbuffs = 100000`` is a hard cap (IDL
123
+ halts on the 100001st match; raised here)."""
124
+ with open(fn, "rb") as fh:
125
+ raw = fh.read()
126
+ size = len(raw)
127
+ headersize = 18
128
+ if size < headersize:
129
+ raise ProcessHKStop("spec_index_hk.pro:16: readu past end of file")
130
+ words = np.frombuffer(raw[: size - (size % 2)], dtype="<i2").astype(np.int64)
131
+ first = words[0:9]
132
+ n_ip = (size - headersize) // 2 # `:30` -- ip = 0 .. n_ip-1
133
+ k = np.arange(max(n_ip, 0))
134
+ year, month, day = words[k], words[k + 1], words[k + 3]
135
+ ok = ((year == first[0])
136
+ & ((month == first[1]) | (month == first[1] + 1))
137
+ & ((day == first[3]) | (day == first[3] + 1)))
138
+ hits = k[ok]
139
+ numbuffs = 100000
140
+ if hits.size > numbuffs:
141
+ raise ProcessHKStop("spec_index_hk.pro:37: more than numbuffs=100000 "
142
+ "header matches -- subscript out of range")
143
+ hour, minute = words[hits + 4], words[hits + 5]
144
+ second, ms = words[hits + 6], words[hits + 7]
145
+ btype = words[hits + 8] & 0xFFFF
146
+ bufftime = (hour * 3600.0 + minute * 60.0) + second + ms / 1000.0 # `:38`
147
+ date = np.array([julday(int(mo), int(d), int(yr)) for mo, d, yr in
148
+ zip(words[hits + 1], words[hits + 3], words[hits], strict=True)],
149
+ dtype=np.int32)
150
+ hkp = (hits[btype == 18507] * 2 + headersize - 2).astype(np.int64)
151
+ maskp = (hits[btype == 19787] * 2 + headersize - 2).astype(np.int64)
152
+
153
+ def _trim(a: np.ndarray, dtype: DTypeLike) -> np.ndarray: # `:55-59`
154
+ return a.astype(dtype) if a.size else np.zeros(1, dtype=dtype)
155
+
156
+ return SpecIndexHK(date=_trim(date, np.int32), bufftime=_trim(bufftime, np.float64),
157
+ pointer=_trim(hits * 2, np.int32), hkp=_trim(hkp, np.int64),
158
+ maskp=_trim(maskp, np.int64))
159
+
160
+
161
+ #: `spec_process_hk.pro:115-151`, version 2: probeid -> (volts columns,
162
+ #: overloads, laservolts, counts), each an `hkraw` column.
163
+ _V2_CASE: dict[str, tuple[list[int], int, int, int]] = {
164
+ "V": (list(range(36, 43)), 67, 30, 58),
165
+ "H": (list(range(44, 51)), 66, 31, 57),
166
+ "V50": (list(range(2, 9)), 67, 30, 60),
167
+ "V150": (list(range(36, 43)), 67, 30, 58),
168
+ "H50": ([24, 25, 26, 27, 30, 31, 32], 66, 30, 59),
169
+ "H150": (list(range(44, 51)), 66, 30, 57),
170
+ }
171
+
172
+ _V2_TEMPID = [
173
+ "fwd sample tube", "central sample tube", "nose cone", "vertical laser",
174
+ "horizontal laser", "vertical optics", "horizontal optics",
175
+ "vertical mirror", "horizontal mirror",
176
+ ]
177
+
178
+
179
+ def _v2_temperature(tempraw: np.ndarray) -> np.ndarray:
180
+ """`:162-163` -- DOUBLE throughout, FLOAT-literal coefficients widened;
181
+ ``^3.`` and ``^(-1.)`` are C ``pow`` calls, evaluated element by element
182
+ with :func:`math.pow` (numpy's ``**`` may take a multiply fast path)."""
183
+ import math
184
+
185
+ a = float(np.float32(1.1117024e-3))
186
+ b = float(np.float32(237.02702e-6))
187
+ c = float(np.float32(75.78814e-9))
188
+ k0 = float(np.float32(6.5536e9))
189
+ t0 = float(np.float32(-273.15))
190
+ out = np.empty(tempraw.shape, dtype=np.float64)
191
+ flat_in = tempraw.astype(np.float64).ravel()
192
+ flat_out = out.ravel()
193
+ for i, v in enumerate(flat_in):
194
+ with np.errstate(divide="ignore", invalid="ignore"):
195
+ rt = float(np.float64(k0) * (1.0 - np.float64(v) / 65536.0) / (5.0 * np.float64(v)))
196
+ lr = math.log(rt) if rt > 0 else (math.inf if rt == math.inf else math.nan)
197
+ if math.isnan(lr):
198
+ flat_out[i] = math.nan
199
+ continue
200
+ inner = a + b * lr + c * (math.pow(lr, 3.0) if math.isfinite(lr) else lr)
201
+ flat_out[i] = t0 + (math.pow(inner, -1.0) if inner != math.inf else 0.0)
202
+ return out
203
+
204
+
205
+ def process_hk(op: dict, y: SpecIndex | None = None) -> HouseData:
206
+ """`spec_process_hk`, both versions. `op` goes through `update_op`
207
+ first (`:9`). ``op.subformat != 0`` is version 2 (3VCPI/Hawkeye/HVPS4/
208
+ Fast2DS): the HK data come from ``op.fn + 'HK'`` indexed by
209
+ :func:`spec_index_hk`, and ``y`` is ignored, as the IDL ignores it.
210
+
211
+ Source: ``spec_process_hk.pro`` (SODA-2); bare line references here are into that file."""
212
+ op = update_op(op)
213
+ version = 2 if int(op.get("subformat", 0)) != 0 else 1
214
+
215
+ fn = op["fn"]
216
+ fn_list = list(fn) if isinstance(fn, (list, tuple)) else [fn]
217
+ hkindex: SpecIndex | SpecIndexHK
218
+ if version == 2:
219
+ # :16-25.
220
+ fn0 = str(fn_list[0]) + "HK"
221
+ if not os.path.exists(fn0):
222
+ raise ProcessHKStop(
223
+ f"spec_process_hk.pro:17-20: stop -- Housekeeping file not "
224
+ f"found: {fn0}")
225
+ hkindex = spec_index_hk(fn0)
226
+ # :25 -- DOUBLE + the caller's own type (FLOAT from update_op).
227
+ hkindex.bufftime = hkindex.bufftime + np.float64(op["timeoffset"])
228
+ if len(fn_list) > 1:
229
+ raise ValueError(
230
+ "spec_process_hk.pro:42 stop,'Multiple SPEC raw files not "
231
+ "supported, concatenate first'")
232
+ if version == 1:
233
+ fn0 = fn_list[0]
234
+ if y is None:
235
+ built = buildindex(fn0, op)
236
+ # buildindex's return type is SpecIndex | GenericIndex in general
237
+ # (it also serves the SEA/CIP generic walk), but this function is
238
+ # only ever reached for op["format"] == "SPEC" -- the same
239
+ # invariant process_2d.py:837 asserts at its own call site -- so
240
+ # buildindex(fn0, op) here always takes its SPEC branch and never
241
+ # returns GenericIndex. Asserted, not just declared, so a caller
242
+ # that broke the invariant would fail loudly here rather than
243
+ # deeper in with an AttributeError.
244
+ assert not isinstance(built, GenericIndex)
245
+ hkindex = built
246
+ else:
247
+ # :29 `hkindex=y` copies the IDL struct; the caller's `y` is not
248
+ # mutated by anything below. Deep-copy so this port cannot mutate
249
+ # it either (hk_y_unmutated).
250
+ hkindex = copy.deepcopy(y)
251
+
252
+ starttime = float(op["starttime"])
253
+ stoptime = float(op["stoptime"])
254
+ rate = float(op["rate"])
255
+ numrecords = _idiv(stoptime - starttime, rate) + 1 # :32
256
+ time = starttime + rate * np.arange(numrecords, dtype=np.float64) # :33
257
+
258
+ numfields = 83 if version == 2 else 49 # :34-35
259
+ hk = np.zeros((numrecords, numfields), dtype=np.float32)
260
+ hkraw = np.zeros((numrecords, numfields), dtype=np.float32)
261
+ tas = np.zeros(numrecords, dtype=np.float32)
262
+ nb = np.zeros(numrecords, dtype=np.float32)
263
+
264
+ startdate = soda2_parsedate(op["date"]).julday # :43
265
+ if abs(int(hkindex.date[0]) - startdate) > 5: # :44
266
+ startdate = int(hkindex.date[0]) # :45
267
+ hkindex.bufftime = hkindex.bufftime + 86400 * (hkindex.date - startdate) # :49
268
+
269
+ with open(fn0, "rb") as f:
270
+ for hkp_i in hkindex.hkp: # :57
271
+ ge = hkindex.pointer < hkp_i
272
+ buffind = int(np.max(np.where(ge)[0])) if np.any(ge) else -1
273
+ buffind = max(buffind, 0) # :59 `> 0`
274
+ bufftime = float(hkindex.bufftime[buffind])
275
+ itime = _idiv(bufftime - starttime, rate) # :62, T2
276
+
277
+ if 0 <= itime < numrecords:
278
+ h = spec_read_hk(f, int(hkp_i), int(hkindex.buffsize), version=version)
279
+ hk[itime, :] = hk[itime, :] + h.x
280
+ # :78 adds `h.raw` into the `hkraw` row for `itime` -- h.raw is the
281
+ # full 53-word record while hkraw's row is 49 wide (`hk`/
282
+ # `hkraw` are both declared `fltarr(numrecords, numfields)`,
283
+ # `numfields=49` for version 1). IDL's binary operators
284
+ # silently truncate the larger array-operand to the
285
+ # smaller's element count rather than erroring; reproduced
286
+ # here by truncating `h.raw` to the first 49 words.
287
+ hkraw[itime, :] = hkraw[itime, :] + h.raw[:numfields]
288
+ tas[itime] = tas[itime] + h.tas
289
+ nb[itime] = nb[itime] + 1
290
+
291
+ probeid = str(op.get("probeid", "A0"))
292
+ if version == 2:
293
+ return _process_hk_v2(op, probeid, time, nb, tas, hk, hkraw, numrecords)
294
+
295
+ # :75-81 -- averages; columns 33-35 and 40-48 stay sums.
296
+ for i in range(numrecords):
297
+ n = max(float(nb[i]), 1.0)
298
+ hk[i, 0:33] = hk[i, 0:33] / n
299
+ hk[i, 36:40] = hk[i, 36:40] / n
300
+ tas[i] = tas[i] / n
301
+
302
+ if probeid == "V":
303
+ volts = hk[:, [4, 29, 30, 5, 31, 32, 6]]
304
+ overloads = hk[:, 44]
305
+ laservolts = hk[:, 37]
306
+ counts = hk[:, 33]
307
+ else:
308
+ volts = hk[:, [1, 25, 26, 2, 27, 28, 3]]
309
+ overloads = hk[:, 43]
310
+ laservolts = hk[:, 36]
311
+ counts = hk[:, 34]
312
+
313
+ canpressure = hk[:, 24] * np.float32(68.9476)
314
+ power = hk[:, [7, 8, 22, 23]]
315
+ temperature = hk[:, 9:22] # IDL 9:21 inclusive -> Python 9:22
316
+ tempid = list(_TEMPID)
317
+
318
+ _fill_tas(tas, time, numrecords)
319
+ diodes = [0, 21, 42, 64, 85, 106, 127]
320
+ return HouseData(op=op, time=time, nb=nb, arrayid=probeid, tas=tas,
321
+ diodes=diodes, volts=volts, canpressure=canpressure,
322
+ power=power, tempid=tempid, temp=temperature,
323
+ laservolts=laservolts, overloads=overloads,
324
+ counts=counts)
325
+
326
+
327
+ def _fill_tas(tas: np.ndarray, time: np.ndarray, numrecords: int) -> None:
328
+ """:170-175 -- TAS gap fill, in place."""
329
+ good = np.where(tas > 0)[0]
330
+ if good.size:
331
+ firstgood, lastgood = int(good.min()), int(good.max())
332
+ idx = np.arange(numrecords)
333
+ bad = np.where((tas == 0) & (idx > firstgood) & (idx < lastgood))[0]
334
+ for b in bad:
335
+ tas[b] = np.float32(_interpol(tas[good], time[good], float(time[b])))
336
+
337
+
338
+ def _process_hk_v2(op: dict, probeid: str, time: np.ndarray, nb: np.ndarray,
339
+ tas: np.ndarray, hk: np.ndarray, hkraw: np.ndarray,
340
+ numrecords: int) -> HouseData:
341
+ """`:104-167`. **Every output is built from ``hkraw``, which is never
342
+ averaged**: `:106-110` divide ``hk[i,2:53]`` by ``nb`` and nothing below
343
+ reads ``hk`` again, so a record holding two HK buffers reports the
344
+ *sum* of their volts, currents, counts, pressure and thermistor words --
345
+ and a temperature computed from a summed raw word (bank ``phk_*``,
346
+ ``NB`` = 2 in record 0). `:115` the CASE has no ELSE: a ``probeid``
347
+ outside V/H/V50/V150/H50/H150 -- including ``update_op``'s own default
348
+ ``'A0'`` -- halts ("CASE statement found no match", bank
349
+ ``phk_A0_3VCPI``)."""
350
+ for i in range(numrecords): # :106-110
351
+ n = max(float(nb[i]), 1.0)
352
+ hk[i, 2:54] = hk[i, 2:54] / n
353
+ tas[i] = tas[i] / n
354
+
355
+ if probeid not in _V2_CASE:
356
+ raise ProcessHKStop(
357
+ f"spec_process_hk.pro:115: CASE statement found no match "
358
+ f"(probeid={probeid!r})")
359
+ vcols, ocol, lcol, ccol = _V2_CASE[probeid]
360
+ f1 = np.float32(0.00244140625) # :113
361
+ volts = hkraw[:, vcols] * f1
362
+ overloads = hkraw[:, ocol].copy()
363
+ laservolts = hkraw[:, lcol].copy()
364
+ counts = hkraw[:, ccol].copy()
365
+
366
+ if str(op.get("probetype", "")) == "HVPS4": # :157-161
367
+ tempraw = hkraw[:, 9:22]
368
+ tempid = list(_TEMPID)
369
+ else: # :154-156
370
+ tempraw = hkraw[:, [2, 5, 7, 13, 14, 17, 19, 20, 21]]
371
+ tempid = list(_V2_TEMPID)
372
+ temperature = _v2_temperature(tempraw)
373
+
374
+ power = hkraw[:, 34:36].copy() # :165
375
+ # :166 -- FLOAT column times FLOAT literals: three float32 roundings.
376
+ canpressure = ((hkraw[:, 29] * np.float32(0.00572205)) - np.float32(3.75)) \
377
+ * np.float32(68.9476)
378
+
379
+ _fill_tas(tas, time, numrecords)
380
+ diodes = [0, 21, 42, 64, 85, 106, 127]
381
+ return HouseData(op=op, time=time, nb=nb, arrayid=probeid, tas=tas,
382
+ diodes=diodes, volts=volts, canpressure=canpressure,
383
+ power=power, tempid=tempid, temp=temperature,
384
+ laservolts=laservolts, overloads=overloads,
385
+ counts=counts)
386
+
387
+
388
+ def _idl_round(x: float) -> int:
389
+ """IDL ``round``: half away from zero, to LONG."""
390
+ return int(np.sign(x) * np.floor(abs(x) + 0.5))
391
+
392
+
393
+ def process_cip1d_sea(op: dict) -> dict:
394
+ """``process_cip1d_sea.pro`` on the ``/nowrite`` path: returns ``data``.
395
+
396
+ Bug-for-bug: the first-line REPEAT switches file on any EOF, the main
397
+ WHILE only on an in-range record; a stamp earlier than ``starttime``
398
+ gains +240000.0 (the midnight fix, which a zero stamp also triggers);
399
+ a negative count zeroes all 62 bins; ``tas`` starts NaN and is
400
+ overwritten for every record. Arrays are returned in IDL index order
401
+ (record first); the arithmetic is FLOAT wherever the IDL is.
402
+ """
403
+ from .sea import SeaEOF, idl_sfm, readseabuffer_caps
404
+
405
+ f32 = np.float32
406
+ starttime = int(op["starttime"])
407
+ stoptime: float = int(op["stoptime"])
408
+ rate = int(op["rate"])
409
+ if stoptime < starttime:
410
+ stoptime = stoptime + 86400.0
411
+ num = int((stoptime - starttime) // rate + 1)
412
+ tag = int(np.atleast_1d(np.asarray(op["seatag"]))[1])
413
+ timeoffset = float(op.get("timeoffset", 0.0))
414
+
415
+ res = f32(op["res"])
416
+ endbins = (res * (np.arange(63, dtype=f32) + f32(1)) + res / f32(2.0)).astype(f32)
417
+ numbins = endbins.size - 1
418
+ midbins = (endbins[0:numbins] + endbins[1:]).astype(np.float64) / 2.0
419
+ binwidth = (endbins[1:] - endbins[0:numbins]).astype(f32)
420
+
421
+ spec = np.zeros((num, numbins), f32)
422
+ hk = np.zeros((num, 16), f32)
423
+ nb = np.zeros(num, np.int32)
424
+ endreject = np.zeros(num, np.int32)
425
+ oversizereject = np.zeros(num, np.int32)
426
+ dofreject = np.zeros(num, np.int32)
427
+ particlecounter = np.zeros(num, np.int32)
428
+ time = starttime + rate * np.arange(num, dtype=np.float64)
429
+
430
+ fns = list(np.atleast_1d(np.asarray(op["fn"])))
431
+ filenum = 0
432
+ fh = open(str(fns[0]), "rb")
433
+
434
+ def _read() -> tuple[object, float]:
435
+ a = readseabuffer_caps(fh, tag=tag, probetype="CIP1D")
436
+ if isinstance(a, SeaEOF):
437
+ return a, float(int(a.starttime + timeoffset))
438
+ return a, float(a.starttime) + timeoffset
439
+
440
+ try:
441
+ while True: # REPEAT
442
+ a, st = _read()
443
+ if isinstance(a, SeaEOF):
444
+ fh.close()
445
+ filenum += 1
446
+ fh = open(str(fns[filenum]), "rb")
447
+ if idl_sfm(st) >= starttime:
448
+ break
449
+ while _idl_round(idl_sfm(st)) <= stoptime:
450
+ i = (_idl_round(idl_sfm(st)) - starttime) // rate
451
+ if 0 <= i < num:
452
+ nb[i] += 1
453
+ img = a.image # type: ignore[attr-defined]
454
+ count = img["count"][0].copy()
455
+ if count.min() < 0:
456
+ count[:] = 0
457
+ spec[i, :] += count.astype(f32)
458
+ hk[i, :] += img["housekeeping"][0].astype(f32)
459
+ endreject[i] += int(img["endreject"][0])
460
+ oversizereject[i] += int(img["oversizereject"][0])
461
+ dofreject[i] += int(img["dofreject"][0])
462
+ particlecounter[i] += int(img["particlecounter"][0])
463
+ if isinstance(a, SeaEOF):
464
+ fh.close()
465
+ filenum += 1
466
+ fh = open(str(fns[filenum]), "rb")
467
+ a, st = _read()
468
+ if idl_sfm(st) < starttime:
469
+ st = st + 240000.0
470
+ if isinstance(a, SeaEOF):
471
+ st = float(int(st))
472
+ finally:
473
+ fh.close()
474
+
475
+ nb = np.maximum(nb, 1)
476
+ tas = np.full(num, np.nan, f32)
477
+ for i in range(num):
478
+ hk[i, :] = (hk[i, :] / f32(nb[i])).astype(f32)
479
+ temp = (hk[i, 13] - f32(1024)) * f32(0.048828125)
480
+ cp, cv, R, rcv = f32(0.24), f32(0.171), f32(0.0668557), f32(1.0)
481
+ difprs = f32(68.9476) * f32(5) * hk[i, 3] / f32(4095)
482
+ totprs = f32(68.9476) * f32(15) * hk[i, 4] / f32(4095)
483
+ Tm = temp + f32(273.16)
484
+ if difprs > 1 and totprs > 10:
485
+ xmach = np.sqrt(f32(2) * (cv / R) * ((difprs / totprs + f32(1)) ** (R / cp) - f32(1)))
486
+ Ta = Tm / (f32(1) + (rcv * (xmach * xmach)) * (cp / cv - f32(1)) / f32(2))
487
+ tas[i] = xmach * f32(20.06) * np.sqrt(Ta)
488
+ else:
489
+ tas[i] = 0
490
+
491
+ with np.errstate(divide="ignore", invalid="ignore"):
492
+ volts = (hk[:, 0:3] * f32(20.0) / f32(4095)).astype(f32)
493
+ dsp_temp = ((hk[:, 7] * f32(10.0) / f32(4095) - f32(1.49)) / f32(5e-3)) + f32(25)
494
+ ambient_temp = (hk[:, 13] - f32(1024)) * f32(0.048828125)
495
+ Rt = ((f32(4095) / hk[:, 10:13]) - f32(1)) * f32(15)
496
+ # IDL's float alog is the C library's correctly rounded logf; numpy's
497
+ # float32 log is a SIMD approximation one ulp off at some inputs
498
+ # (record 10 of the golden window), so take the float64 log and round.
499
+ lr = f32_via_f64(np.log, Rt)
500
+ optional_temps = f32(1.0) / (f32(1.114e-3) + f32(236.43e-6) * lr
501
+ + f32(74.03e-9) * (lr * (lr * lr))) - f32(273.3)
502
+ alltemps = np.column_stack([dsp_temp, ambient_temp, optional_temps]).astype(f32)
503
+
504
+ return {"spec1d": spec, "midbins": midbins, "time": time, "endbins": endbins,
505
+ "binwidth": binwidth, "tas_pitot": tas,
506
+ "pres": (f32(68.9476) * f32(15) * hk[:, 4] / f32(4095)).astype(f32),
507
+ "diodes": np.array([1, 64, 32], np.int16), "volts": volts,
508
+ "tempid": ["DSP", "Ambient", "Option1", "Option2", "Option3"],
509
+ "temp": alltemps, "laser_current": (hk[:, 14] * f32(0.19536)).astype(f32),
510
+ "laser_power": (hk[:, 15] * f32(0.407)).astype(f32), "dofreject": dofreject,
511
+ "endreject": endreject, "oversizereject": oversizereject,
512
+ "particlecounter": particlecounter, "op": op}
@@ -0,0 +1,155 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ # Reproduces SODA-2, Copyright (c) 2016 UCAR; see LICENSES/BSD-3-Clause.txt and NOTICE.md.
3
+ """SODA-2 ``soda2_processbuffer.pro:80-127``, the 2DC branch (probetype ``'2DC'``,
4
+ 32-diode ULONG slices, RAF ``0x55`` timing words; the SEA override at `:123-126`).
5
+
6
+ Line map:
7
+ - `:81-83` ``buffer.stoptime = buffer.time``; fewer than 1024 slices -> ``nullbuffer``.
8
+ - `:84` sync where slice *k* and slice *k-1* both carry top byte ``0x55``
9
+ (over ``image[1:1023]`` / ``image[0:1022]``), plus 1.
10
+ - `:86-91` fewer than three: ``fix2dimage`` and retry, now also requiring
11
+ ``image[k-1] ne '55000000'x``.
12
+ - `:93` still fewer than three: ``nullbuffer``.
13
+ - `:94-97` ``time_ind=sync_ind-1``; ``sync_ind=[0,sync_ind]``; 24-bit timelines.
14
+ - `:99-100` every slice with top byte ``0x55`` blanked to ``0xFFFFFFFF``.
15
+ - `:102-108` ``freq = yres/(1e6*tas)`` (FLOAT: ``yres`` and ``tas`` are FLOAT in
16
+ ``op`` and the buffer), ``parttime=(timelines+2)*freq`` (FLOAT), ``elaptime``
17
+ accumulated in DOUBLE, ``time_sfm`` counted back from ``buffer.time``,
18
+ ``reftime = buffer.time + elaptime[-1]``.
19
+ - `:111` the bit image is the inverted image expanded to bits by ``dec2bin``: 32 columns,
20
+ column 0 = bit 31 (``dec2bin.pro:8``); slice-first here, as the package convention.
21
+ - `:112-113` ``startline = [0,sync_ind] < 1023`` (num_images+1 entries),
22
+ ``stopline = time_ind < 1023``.
23
+ - `:114-118` ``restore_slice=1``, ``missed=0``, counters 0, ``dof`` 1, ``stretch`` 1.
24
+ - `:119-121` ``inttime = time_sfm - [lastclock, time_sfm]`` (IDL truncates to the
25
+ shorter operand), ``lastclock`` saved.
26
+ - `:122` ``clocktas`` the buffer TAS.
27
+ - `:123-126` SEA only: ``stoptime`` widened by the particle span, ``reftime=time_sfm[0]``.
28
+
29
+ The branch's ``restore_slice=1`` sends every ROI through ``soda2_backfill.pro``
30
+ in the shared tail (`:678`), ported as ``arrayprobe_soda2.backfill``;
31
+ :func:`process_2dc_buffer` returns the branch's locals only.
32
+ ``tests/test_soda2_2dc_gdl.py`` compares them with GDL.
33
+
34
+ Source: ``soda2_processbuffer.pro`` (SODA-2); bare line references here are into that file.
35
+ """
36
+ from __future__ import annotations
37
+
38
+ from dataclasses import dataclass
39
+ from typing import Any
40
+
41
+ import numpy as np
42
+
43
+ from .fix2dimage import fix2dimage
44
+ from .processbuffer_cip import CipBufferParticles
45
+ from .processbuffer_spec import NullBuffer
46
+
47
+ __all__ = ["TwoDcOp", "TwoDcMisc", "process_2dc_buffer"]
48
+
49
+ _TOP = np.uint32(0xFF000000)
50
+ _SYNC = np.uint32(0x55000000)
51
+ _BLANK = np.uint32(0xFFFFFFFF)
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ class TwoDcOp:
56
+ """The ``(*pop)`` fields the branch reads."""
57
+
58
+ probetype: str
59
+ format: str
60
+ yres: float
61
+
62
+
63
+ @dataclass
64
+ class TwoDcMisc:
65
+ """``(*pmisc).lastclock`` (``soda2_process_2d.pro:39``), read and written at `:118-120`."""
66
+
67
+ lastclock: float = 0.0
68
+
69
+
70
+ def _sync(img: np.ndarray, retry: bool) -> np.ndarray:
71
+ a = (img[1:1024] & _TOP) == _SYNC # :84 / :88
72
+ b = (img[0:1023] & _TOP) == _SYNC
73
+ m = a & b
74
+ if retry:
75
+ m &= img[0:1023] != _SYNC # :90
76
+ return np.flatnonzero(m).astype(np.int64) + 1
77
+
78
+
79
+ def process_2dc_buffer(image: np.ndarray, buffer_time: float, buffer_tas: float,
80
+ op: TwoDcOp, misc: TwoDcMisc) -> NullBuffer | CipBufferParticles:
81
+ """`:80-127`. Mutates ``misc`` as the IDL writes ``(*pmisc)``. The returned
82
+ ``stoptime`` is ``buffer.stoptime`` after the branch (`:82`, `:124`)."""
83
+ if op.probetype != "2DC":
84
+ raise NotImplementedError(f"soda2_processbuffer.pro:80: probetype {op.probetype!r}")
85
+ img = np.asarray(image, dtype=np.uint32).copy() # :81
86
+ stoptime = float(buffer_time) # :82
87
+ if img.size < 1024: # :83
88
+ return NullBuffer()
89
+ sync_ind = _sync(img, retry=False) # :84
90
+ if sync_ind.size < 3: # :86-91
91
+ img = np.asarray(fix2dimage(img), dtype=np.uint32).copy()
92
+ sync_ind = _sync(img, retry=True)
93
+ num_images = int(sync_ind.size)
94
+ if num_images < 3: # :93
95
+ return NullBuffer()
96
+ time_ind = sync_ind - 1 # :94
97
+ sync_ind = np.concatenate([[0], sync_ind]).astype(np.int64) # :95
98
+
99
+ timelines = img[time_ind] & np.uint32(0x00FFFFFF) # :97
100
+
101
+ extralines = np.flatnonzero((img & _TOP) == _SYNC) # :99
102
+ img[extralines] = _BLANK # :100
103
+
104
+ freq = np.float32(op.yres) / (np.float32(1.0e6) * np.float32(buffer_tas)) # :102
105
+ parttime = ((timelines.astype(np.int64) + 2).astype(np.uint32).astype(np.float32)
106
+ * freq).astype(np.float32) # :103
107
+ elaptime = np.zeros(num_images, dtype=np.float64) # :104
108
+ elaptime[0] = parttime[0] # :105
109
+ for i in range(1, num_images): # :106
110
+ elaptime[i] = elaptime[i - 1] + np.float64(parttime[i])
111
+ time_sfm = np.float64(buffer_time) + elaptime - elaptime[num_images - 1] # :107
112
+ reftime = float(np.float64(buffer_time) + elaptime[num_images - 1]) # :108
113
+ rawtime = timelines.copy() # :109
114
+
115
+ inv = ~img # :111 dec2bin(not(image))
116
+ bitimage = np.unpackbits(inv.astype(">u4").view(np.uint8).reshape(-1, 4),
117
+ axis=1) # column 0 = bit 31
118
+ startline = np.minimum(sync_ind, 1023) # :112
119
+ stopline = np.minimum(time_ind, 1023) # :113
120
+
121
+ previoustime = np.concatenate([[np.float64(misc.lastclock)], time_sfm]) # :119
122
+ inttime = time_sfm - previoustime[:num_images] # :120
123
+ misc.lastclock = float(time_sfm[num_images - 1]) # :121
124
+
125
+ if op.format == "SEA": # :123-126
126
+ stoptime = float(np.float64(buffer_time) + (time_sfm[-1] - time_sfm[0]))
127
+ reftime = float(time_sfm[0])
128
+
129
+ return CipBufferParticles(
130
+ rejectbuffer=0, num_images=num_images, bitimage=bitimage,
131
+ startline=startline, stopline=stopline,
132
+ overload=np.zeros(num_images, dtype=np.uint8), # :648 n_elements guard
133
+ particle_count=np.zeros(num_images, dtype=np.int16), # :116
134
+ rawtime=rawtime,
135
+ clocktas=np.zeros(num_images, dtype=np.float32) + np.float32(buffer_tas), # :122
136
+ stretch=np.zeros(num_images, dtype=np.float32) + np.float32(1.0), # :118
137
+ inttime=inttime,
138
+ dof=np.zeros(num_images, dtype=np.uint8) + np.uint8(1), # :117
139
+ time_sfm=time_sfm, reftime=reftime,
140
+ missed=0, stoptime=stoptime, restore_slice=1) # :114-115
141
+
142
+
143
+ def soda2_processbuffer_2dc(image: np.ndarray, buffer_time: float, buffer_tas: float,
144
+ op: TwoDcOp, tail_op: Any, misc: TwoDcMisc,
145
+ lastdhist: Any) -> Any:
146
+ """``p = soda2_processbuffer(b, pop, pmisc)`` for 2DC: `:80-127` then the
147
+ shared tail `:612-747`, composed the way
148
+ :func:`processbuffer_f2dc.soda2_processbuffer_f2dc` composes `:28-78`.
149
+ Returns a :class:`NullBuffer` or :class:`processbuffer_tail.ProcessedBuffer`."""
150
+ from .processbuffer_tail import process_buffer_tail
151
+
152
+ result = process_2dc_buffer(image, buffer_time, buffer_tas, op, misc)
153
+ if isinstance(result, NullBuffer):
154
+ return result
155
+ return process_buffer_tail(result, tail_op, lastdhist) # type: ignore[arg-type]