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,213 @@
|
|
|
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
|
+
"""``soda2_processbuffer.pro``, the CIP branch (`:129-203`).
|
|
4
|
+
|
|
5
|
+
The DMT CIP's buffer processing, composed with the shared tail
|
|
6
|
+
(:mod:`processbuffer_tail`, `:612-747`) into the whole
|
|
7
|
+
``soda2_processbuffer`` for ``probetype eq 'CIP'``. The CIPG (grey) branch
|
|
8
|
+
(`:205-262`, ``decompress_dmt_grey``) is not ported and is refused by name.
|
|
9
|
+
|
|
10
|
+
Vendored source (never edited): ``SODA2/abansemer-soda2-afcea15/
|
|
11
|
+
soda2_processbuffer.pro``. GDL bank: ``gdl_oracle/run_soda2_cip_bank.py``,
|
|
12
|
+
which runs the real ``soda2_processbuffer`` (all 748 lines) on synthetic
|
|
13
|
+
buffers and, when the UND data is present, on real ones.
|
|
14
|
+
|
|
15
|
+
**Line-by-line** (IDL 0-based):
|
|
16
|
+
|
|
17
|
+
- `:130` -- ``x = decompress_dmt3(buffer.image)``.
|
|
18
|
+
- `:134-135` -- ``good1``: particles whose computed slice count is within 1
|
|
19
|
+
of the header's and is positive; fewer than 3 -> ``nullbuffer``.
|
|
20
|
+
- `:138-140` -- ``good2``: within 100 s of the ``median`` (IDL ``MEDIAN``
|
|
21
|
+
without ``/EVEN``: the upper-middle element for an even count) of the
|
|
22
|
+
``good1`` times; fewer than 3 -> ``nullbuffer``.
|
|
23
|
+
- `:146-160` -- ``good4``: counter differences (UINT, wrapping at 65536)
|
|
24
|
+
and interarrival times, against ``(*pmisc).lastparticlecount`` and
|
|
25
|
+
``lastclock``; the neighbour tests read ``[x[1:*], 0]``, so the **last**
|
|
26
|
+
particle is always compared with 0. ``strictcounter`` (default 0) adds the
|
|
27
|
+
counter tests.
|
|
28
|
+
- `:166-167` -- ``startline = sync_ind + 2``, ``stopline = startline +
|
|
29
|
+
slice_count - 1``: ends on the next particle's sync slice (see
|
|
30
|
+
:mod:`decompress_dmt`).
|
|
31
|
+
- `:180-181` -- every sync and header slice of the buffer is blanked, not
|
|
32
|
+
only the kept particles'.
|
|
33
|
+
- `:184-187` -- ``missed = uint(pc) - uint(prev) - 1``: UINT minus INT is
|
|
34
|
+
UINT in IDL (measured under GDL: ``0us - 1`` is 65535), so a repeated
|
|
35
|
+
counter gives ``missed = 65535``, not -1. ``overload = byte(missed < 1)``:
|
|
36
|
+
1 unless ``missed`` is 0.
|
|
37
|
+
- `:189-191` -- ``inttime = rawtime - [lastclock, time_sfm]`` (IDL takes
|
|
38
|
+
the shorter operand's length); ``lastclock`` and ``lastparticlecount``
|
|
39
|
+
are written only when the buffer is kept.
|
|
40
|
+
- `:199-202` -- for ``format eq 'SEA'``, the caller's buffer ``stoptime``
|
|
41
|
+
is **overwritten** (IDL passes ``b`` by reference) and ``reftime`` becomes
|
|
42
|
+
the first kept particle's time.
|
|
43
|
+
|
|
44
|
+
The ``nullbuffer`` returns at `:135`, `:140`, `:160` leave ``pmisc``
|
|
45
|
+
untouched.
|
|
46
|
+
"""
|
|
47
|
+
from __future__ import annotations
|
|
48
|
+
|
|
49
|
+
from dataclasses import dataclass
|
|
50
|
+
from typing import Any
|
|
51
|
+
|
|
52
|
+
import numpy as np
|
|
53
|
+
|
|
54
|
+
from .decompress_dmt import decompress_dmt3
|
|
55
|
+
from .particlesort import idl_median
|
|
56
|
+
from .processbuffer_spec import NullBuffer
|
|
57
|
+
|
|
58
|
+
__all__ = ["CipOp", "CipMisc", "CipBufferParticles", "process_cip_buffer",
|
|
59
|
+
"soda2_processbuffer_cip"]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class CipOp:
|
|
64
|
+
"""The ``(*pop)`` fields the CIP branch reads."""
|
|
65
|
+
|
|
66
|
+
probetype: str
|
|
67
|
+
format: str
|
|
68
|
+
strictcounter: int
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class CipMisc:
|
|
73
|
+
"""The ``(*pmisc)`` fields the CIP branch reads and writes
|
|
74
|
+
(``soda2_process_2d.pro:39-41``: ``lastclock:0d``, ``lastparticlecount:0L``)."""
|
|
75
|
+
|
|
76
|
+
lastclock: float = 0.0
|
|
77
|
+
lastparticlecount: int = 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass
|
|
81
|
+
class CipBufferParticles:
|
|
82
|
+
"""The branch's locals at `:203`, what the shared tail consumes (the
|
|
83
|
+
attribute names :func:`processbuffer_tail.process_buffer_tail` reads).
|
|
84
|
+
``bitimage`` is ``(slices, 64)``, slice first (the package convention).
|
|
85
|
+
|
|
86
|
+
Source: ``soda2_processbuffer.pro`` (SODA-2); bare line references here are into that file."""
|
|
87
|
+
|
|
88
|
+
rejectbuffer: int
|
|
89
|
+
num_images: int
|
|
90
|
+
bitimage: np.ndarray # BYTE (slices, 64)
|
|
91
|
+
startline: np.ndarray # INT
|
|
92
|
+
stopline: np.ndarray # INT
|
|
93
|
+
overload: np.ndarray # BYTE
|
|
94
|
+
particle_count: np.ndarray # LONG
|
|
95
|
+
rawtime: np.ndarray # DOUBLE
|
|
96
|
+
clocktas: np.ndarray # FLOAT
|
|
97
|
+
stretch: np.ndarray # FLOAT
|
|
98
|
+
inttime: np.ndarray # DOUBLE
|
|
99
|
+
dof: np.ndarray # BYTE
|
|
100
|
+
time_sfm: np.ndarray # DOUBLE
|
|
101
|
+
reftime: float # DOUBLE
|
|
102
|
+
missed: np.ndarray | int # UINT (an array here; scalar 0 for SPEC and Fast-2DC)
|
|
103
|
+
stoptime: float # the caller's `buffer.stoptime` after `:200`
|
|
104
|
+
restore_slice: int = 0
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _uint(a: np.ndarray) -> np.ndarray:
|
|
108
|
+
"""IDL ``uint()`` of a LONG: the low 16 bits."""
|
|
109
|
+
return (np.asarray(a).astype(np.int64) & 0xFFFF).astype(np.uint16)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def process_cip_buffer(image: np.ndarray, buffer_time: float, buffer_stoptime: float,
|
|
113
|
+
buffer_tas: float, op: CipOp, misc: CipMisc,
|
|
114
|
+
) -> CipBufferParticles | NullBuffer:
|
|
115
|
+
"""``soda2_processbuffer.pro:129-203``. ``misc`` is mutated in place where
|
|
116
|
+
the IDL writes ``(*pmisc)``; the returned ``stoptime`` is the value the
|
|
117
|
+
IDL leaves in the caller's ``buffer.stoptime``."""
|
|
118
|
+
x = decompress_dmt3(image) # :130
|
|
119
|
+
|
|
120
|
+
# :134-135. The nullbuffer's scalars (slice_count 0, header 999) give none.
|
|
121
|
+
sc = x.slice_count.astype(np.int64)
|
|
122
|
+
hsc = x.header_slice_count.astype(np.int64)
|
|
123
|
+
good1 = np.flatnonzero((np.abs(sc - hsc) <= 1) & (sc > 0))
|
|
124
|
+
if good1.size < 3:
|
|
125
|
+
return NullBuffer()
|
|
126
|
+
|
|
127
|
+
t = x.time_sfm
|
|
128
|
+
mediantime = idl_median(t[good1]) # :138
|
|
129
|
+
good2 = np.flatnonzero(np.abs(t[good1] - mediantime) < 100) # :139
|
|
130
|
+
if good2.size < 3:
|
|
131
|
+
return NullBuffer()
|
|
132
|
+
good3 = good1[good2] # :143
|
|
133
|
+
|
|
134
|
+
pc = x.particle_count
|
|
135
|
+
previouscount = np.concatenate([[misc.lastparticlecount], pc[good3]]) # :146
|
|
136
|
+
diffcount = (_uint(pc[good3]).astype(np.int64)
|
|
137
|
+
- _uint(previouscount[: good3.size]).astype(np.int64)) & 0xFFFF # :147
|
|
138
|
+
previoustime = np.concatenate([[misc.lastclock], t[good3]]) # :148
|
|
139
|
+
inttime4 = t[good3] - previoustime[: good3.size] # :149
|
|
140
|
+
nxt_it = np.concatenate([inttime4[1:], [0.0]])
|
|
141
|
+
if int(op.strictcounter) == 1: # :153-155
|
|
142
|
+
nxt_dc = np.concatenate([diffcount[1:], [0]])
|
|
143
|
+
good4 = np.flatnonzero((diffcount < 10000) & (nxt_dc < 10000)
|
|
144
|
+
& (inttime4 >= 0) & (nxt_it >= 0))
|
|
145
|
+
else: # :156-158
|
|
146
|
+
good4 = np.flatnonzero((inttime4 >= 0) & (nxt_it >= 0))
|
|
147
|
+
if good4.size < 3: # :160
|
|
148
|
+
return NullBuffer()
|
|
149
|
+
|
|
150
|
+
good = good3[good4] # :163
|
|
151
|
+
num_images = int(good.size)
|
|
152
|
+
|
|
153
|
+
si = x.sync_ind.astype(np.int16)
|
|
154
|
+
startline = (si[good] + np.int16(2)).astype(np.int16) # :166
|
|
155
|
+
stopline = (startline + x.slice_count[good] - np.int16(1)).astype(np.int16) # :167
|
|
156
|
+
|
|
157
|
+
time_sfm = t[good].copy() # :174
|
|
158
|
+
reftime = float(time_sfm[num_images - 1]) # :175
|
|
159
|
+
rawtime = time_sfm.copy() # :176
|
|
160
|
+
dof = x.dof[good].copy() # :177
|
|
161
|
+
particle_count = pc[good].copy() # :178
|
|
162
|
+
bitimage = x.bitimage.copy() # :179
|
|
163
|
+
bitimage[si.astype(np.int64), :] = 0 # :180
|
|
164
|
+
bitimage[si.astype(np.int64) + 1, :] = 0 # :181
|
|
165
|
+
|
|
166
|
+
prev2 = np.concatenate([[misc.lastparticlecount], particle_count]) # :184
|
|
167
|
+
diff2 = ((_uint(particle_count).astype(np.int64)
|
|
168
|
+
- _uint(prev2[:num_images]).astype(np.int64)) & 0xFFFF) # :185 UINT
|
|
169
|
+
missed = ((diff2 - 1) & 0xFFFF).astype(np.uint16) # :186 UINT - INT
|
|
170
|
+
misc.lastparticlecount = int(particle_count[num_images - 1]) # :187
|
|
171
|
+
|
|
172
|
+
previoustime2 = np.concatenate([[misc.lastclock], time_sfm]) # :189
|
|
173
|
+
inttime = rawtime - previoustime2[:num_images] # :190
|
|
174
|
+
misc.lastclock = float(time_sfm[num_images - 1]) # :191
|
|
175
|
+
|
|
176
|
+
overload = np.minimum(missed, 1).astype(np.uint8) # :193
|
|
177
|
+
stretch = np.ones(num_images, dtype=np.float32) # :194
|
|
178
|
+
clocktas = np.zeros(num_images, dtype=np.float32) + np.float32(buffer_tas) # :195
|
|
179
|
+
|
|
180
|
+
stoptime = buffer_stoptime
|
|
181
|
+
if op.format == "SEA": # :199-202
|
|
182
|
+
stoptime = buffer_time + (float(time_sfm[-1]) - float(time_sfm[0]))
|
|
183
|
+
reftime = float(time_sfm[0])
|
|
184
|
+
|
|
185
|
+
return CipBufferParticles(
|
|
186
|
+
rejectbuffer=0, num_images=num_images, bitimage=bitimage,
|
|
187
|
+
startline=startline, stopline=stopline, overload=overload,
|
|
188
|
+
particle_count=particle_count, rawtime=rawtime, clocktas=clocktas,
|
|
189
|
+
stretch=stretch, inttime=inttime, dof=dof, time_sfm=time_sfm,
|
|
190
|
+
reftime=reftime, missed=missed, stoptime=stoptime, restore_slice=0)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def soda2_processbuffer_cip(image: np.ndarray, buffer_time: float, buffer_stoptime: float,
|
|
194
|
+
buffer_tas: float, op: CipOp, tail_op: Any, misc: CipMisc,
|
|
195
|
+
lastdhist: Any) -> tuple[Any, float]:
|
|
196
|
+
"""``p = soda2_processbuffer(b, pop, pmisc)`` for ``probetype 'CIP'``, the
|
|
197
|
+
whole function (`:129-203` then `:612-747`). Returns ``(p, stoptime)``:
|
|
198
|
+
``p`` a :class:`NullBuffer` or :class:`processbuffer_tail.ProcessedBuffer`,
|
|
199
|
+
``stoptime`` the caller's ``buffer.stoptime`` afterwards (unchanged on a
|
|
200
|
+
null return).
|
|
201
|
+
|
|
202
|
+
Source: ``soda2_processbuffer.pro`` (SODA-2); bare line references here are into that file."""
|
|
203
|
+
from .processbuffer_tail import process_buffer_tail
|
|
204
|
+
|
|
205
|
+
if op.probetype != "CIP":
|
|
206
|
+
raise NotImplementedError(
|
|
207
|
+
f"soda2_processbuffer.pro: probetype {op.probetype!r} -- only the CIP "
|
|
208
|
+
"branch (:129-203) is ported here (CIPG, :205-262, needs "
|
|
209
|
+
"decompress_dmt_grey.pro)")
|
|
210
|
+
result = process_cip_buffer(image, buffer_time, buffer_stoptime, buffer_tas, op, misc)
|
|
211
|
+
if isinstance(result, NullBuffer):
|
|
212
|
+
return result, buffer_stoptime
|
|
213
|
+
return process_buffer_tail(result, tail_op, lastdhist), result.stoptime # type: ignore[arg-type]
|
|
@@ -0,0 +1,139 @@
|
|
|
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:28-78``, the Fast-2DC branch
|
|
4
|
+
(probetype ``'F2DC'`` and ``'F2DC_v2'``), ahead of the shared tail.
|
|
5
|
+
|
|
6
|
+
Line map:
|
|
7
|
+
- `:31-35` the previous buffer's remainder is prepended; ``bufflength``.
|
|
8
|
+
- `:38` sync where the top two bytes are ``0xAAAA``, over every slice.
|
|
9
|
+
- `:39-43` fewer than three syncs: ``f2d_remainder_slices`` cleared, ``nullbuffer``.
|
|
10
|
+
- `:45-52` v2: 44-bit timeline, dof bit 44; v1: 40-bit timeline, dof bit 40; ``dof=1-dof``.
|
|
11
|
+
- `:54-58` sync slices blanked, the inverted image expanded to bits by ``dec2bin64``
|
|
12
|
+
(column 0 = bit 63), ``startline=[0,sync_ind+1]``, ``stopline=((sync_ind-1)>0)>startline`` (IDL's
|
|
13
|
+
``>`` on unequal lengths truncates to the shorter operand).
|
|
14
|
+
- `:60-64` ``clockHz`` 12e6, v2 ``1e8/3d``; ``time_sfm``, ``reftime``, ``rawtime``.
|
|
15
|
+
- `:70-73` remainder from the last sync slice (already blanked) to the end, written
|
|
16
|
+
into the fixed 512-slice ``f2d_remainder`` (``soda2_process_2d.pro:39``); a
|
|
17
|
+
remainder longer than 512 is an IDL subscript error at `:73`, raised here.
|
|
18
|
+
- `:74-77` ``stretch`` 1, ``inttime`` 0, ``clocktas`` the buffer TAS.
|
|
19
|
+
|
|
20
|
+
The F2DC branch sets no ``overload``; the CIP shape's ``overload`` field is
|
|
21
|
+
filled with zeros here so the shared tail can run. This matches IDL:
|
|
22
|
+
`:648` guards the read with ``n_elements(overload)``, so for the F2DC branch
|
|
23
|
+
the tail sees ``bytarr(num_images)``, all zeros, as here
|
|
24
|
+
(``tests/test_soda2_f2dc_gdl_golden.py``).
|
|
25
|
+
|
|
26
|
+
Source: ``soda2_processbuffer.pro`` (SODA-2); bare line references here are into that file.
|
|
27
|
+
"""
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
from dataclasses import dataclass, field
|
|
31
|
+
from typing import Any
|
|
32
|
+
|
|
33
|
+
import numpy as np
|
|
34
|
+
|
|
35
|
+
from .processbuffer_cip import CipBufferParticles
|
|
36
|
+
from .processbuffer_spec import NullBuffer
|
|
37
|
+
|
|
38
|
+
__all__ = ["F2dcOp", "F2dcMisc", "process_f2dc_buffer", "soda2_processbuffer_f2dc",
|
|
39
|
+
"F2DC_REMAINDER_CAPACITY"]
|
|
40
|
+
|
|
41
|
+
F2DC_REMAINDER_CAPACITY = 512 # soda2_process_2d.pro:39, f2d_remainder:ulon64arr(512)
|
|
42
|
+
_SYNC_MASK = np.uint64(0xFFFF000000000000)
|
|
43
|
+
_SYNC = np.uint64(0xAAAA000000000000)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class F2dcOp:
|
|
48
|
+
"""The ``(*pop)`` field the branch reads."""
|
|
49
|
+
|
|
50
|
+
probetype: str
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass
|
|
54
|
+
class F2dcMisc:
|
|
55
|
+
"""``(*pmisc)`` fields the branch reads and writes (``soda2_process_2d.pro:39``)."""
|
|
56
|
+
|
|
57
|
+
f2d_remainder: np.ndarray = field(
|
|
58
|
+
default_factory=lambda: np.zeros(F2DC_REMAINDER_CAPACITY, dtype=np.uint64))
|
|
59
|
+
f2d_remainder_slices: int = 0
|
|
60
|
+
lastbufftime: float = 0.0
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def process_f2dc_buffer(image: np.ndarray, buffer_time: float, buffer_tas: float,
|
|
64
|
+
op: F2dcOp, misc: F2dcMisc) -> NullBuffer | CipBufferParticles:
|
|
65
|
+
"""`:28-78`. Mutates ``misc`` as the IDL writes ``(*pmisc)``."""
|
|
66
|
+
if op.probetype not in ("F2DC", "F2DC_v2"):
|
|
67
|
+
raise NotImplementedError(f"soda2_processbuffer.pro:28: probetype {op.probetype!r}")
|
|
68
|
+
buf = np.asarray(image, dtype=np.uint64)
|
|
69
|
+
if misc.f2d_remainder_slices > 0: # :31-34
|
|
70
|
+
img = np.concatenate([misc.f2d_remainder[:misc.f2d_remainder_slices], buf])
|
|
71
|
+
else:
|
|
72
|
+
img = buf.copy()
|
|
73
|
+
bufflength = img.size # :35
|
|
74
|
+
sync_ind = np.flatnonzero((img & _SYNC_MASK) == _SYNC) # :38
|
|
75
|
+
num_images = max(sync_ind.size, 1) # where() -> -1 gives n_elements 1
|
|
76
|
+
if sync_ind.size == 0 or num_images < 3: # :39-43
|
|
77
|
+
misc.f2d_remainder_slices = 0
|
|
78
|
+
return NullBuffer()
|
|
79
|
+
|
|
80
|
+
words = img[sync_ind]
|
|
81
|
+
if op.probetype == "F2DC_v2": # :45-48
|
|
82
|
+
timelines = words & np.uint64(0x00000FFFFFFFFFFF)
|
|
83
|
+
dof = np.minimum(words & np.uint64(0x0000100000000000), np.uint64(1))
|
|
84
|
+
else: # :49-51
|
|
85
|
+
timelines = words & np.uint64(0x000000FFFFFFFFFF)
|
|
86
|
+
dof = np.minimum(words & np.uint64(0x0000010000000000), np.uint64(1))
|
|
87
|
+
dof = (1 - dof.astype(np.int64)).astype(np.uint8) # :52
|
|
88
|
+
|
|
89
|
+
img[sync_ind] = np.uint64(0xFFFFFFFFFFFFFFFF) # :54
|
|
90
|
+
inv = ~img # :55 dec2bin64(not(image))
|
|
91
|
+
bitimage = np.unpackbits(inv.astype(">u8").view(np.uint8).reshape(-1, 8),
|
|
92
|
+
axis=1) # column 0 = bit 63
|
|
93
|
+
startline = np.concatenate([[0], sync_ind + 1]).astype(np.int64) # :56
|
|
94
|
+
stopline = np.maximum(sync_ind - 1, 0) # :57
|
|
95
|
+
stopline = np.maximum(stopline, startline[:stopline.size]) # :58
|
|
96
|
+
|
|
97
|
+
clock_hz = 12.0e6 # :60
|
|
98
|
+
if op.probetype == "F2DC_v2":
|
|
99
|
+
clock_hz = 1e8 / 3.0 # :61
|
|
100
|
+
time_sfm = timelines.astype(np.float64) / clock_hz # :62
|
|
101
|
+
reftime = float(timelines[num_images - 1]) / clock_hz # :63
|
|
102
|
+
rawtime = timelines.copy() # :64
|
|
103
|
+
|
|
104
|
+
particle_count = np.zeros(num_images, dtype=np.int16) # :68
|
|
105
|
+
|
|
106
|
+
last = int(sync_ind.max()) # :71-73
|
|
107
|
+
nremainder = bufflength - last
|
|
108
|
+
if nremainder > F2DC_REMAINDER_CAPACITY:
|
|
109
|
+
raise IndexError(
|
|
110
|
+
f"soda2_processbuffer.pro:73: remainder of {nremainder} slices exceeds "
|
|
111
|
+
f"f2d_remainder's {F2DC_REMAINDER_CAPACITY} (IDL subscript out of range)")
|
|
112
|
+
misc.f2d_remainder_slices = nremainder
|
|
113
|
+
misc.f2d_remainder[:nremainder] = img[last:bufflength]
|
|
114
|
+
misc.lastbufftime = buffer_time # :74
|
|
115
|
+
|
|
116
|
+
return CipBufferParticles(
|
|
117
|
+
rejectbuffer=0, num_images=num_images, bitimage=bitimage,
|
|
118
|
+
startline=startline, stopline=stopline,
|
|
119
|
+
overload=np.zeros(num_images, dtype=np.uint8),
|
|
120
|
+
particle_count=particle_count, rawtime=rawtime,
|
|
121
|
+
clocktas=np.zeros(num_images, dtype=np.float32) + np.float32(buffer_tas), # :77
|
|
122
|
+
stretch=np.zeros(num_images, dtype=np.float32) + np.float32(1.0), # :75
|
|
123
|
+
inttime=np.zeros(num_images, dtype=np.float64), # :76
|
|
124
|
+
dof=dof, time_sfm=time_sfm, reftime=reftime,
|
|
125
|
+
missed=0, stoptime=0.0, restore_slice=0) # :66-67 (`missed=0`, an IDL scalar, :67)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def soda2_processbuffer_f2dc(image: np.ndarray, buffer_time: float, buffer_tas: float,
|
|
129
|
+
op: F2dcOp, tail_op: Any, misc: F2dcMisc,
|
|
130
|
+
lastdhist: Any) -> Any:
|
|
131
|
+
"""``p = soda2_processbuffer(b, pop, pmisc)`` for Fast-2DC: `:28-78` then
|
|
132
|
+
the shared tail `:612-747`. Returns a :class:`NullBuffer` or
|
|
133
|
+
:class:`processbuffer_tail.ProcessedBuffer`."""
|
|
134
|
+
from .processbuffer_tail import process_buffer_tail
|
|
135
|
+
|
|
136
|
+
result = process_f2dc_buffer(image, buffer_time, buffer_tas, op, misc)
|
|
137
|
+
if isinstance(result, NullBuffer):
|
|
138
|
+
return result
|
|
139
|
+
return process_buffer_tail(result, tail_op, lastdhist) # type: ignore[arg-type]
|