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,359 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""``combine_sizedist.m`` -- stitch a flight's several ``sd`` files into one product.
|
|
3
|
+
|
|
4
|
+
Ported from: the ORACLES-variant ``combine_sizedist.m`` (the 2026-08-20 delivery)
|
|
5
|
+
Several things here look wrong
|
|
6
|
+
and are not.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This is the ONLY comparison in the project whose two sides are built from the same
|
|
10
|
+
inputs -- a raw flight's several files, combined -- as opposed to a per-file
|
|
11
|
+
comparison against a product that was itself built from all of a flight's files
|
|
12
|
+
(which is why per-file checks are indicative, never the acceptance gate).
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import datetime as _dt
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from . import ncio
|
|
23
|
+
from .matlab_compat import datenum, mint16
|
|
24
|
+
|
|
25
|
+
__all__ = ["combine_sizedist"]
|
|
26
|
+
|
|
27
|
+
#: :5-13's ``netcdf.getVar(ncid_k, N)`` calls, by variable NAME rather than the
|
|
28
|
+
#: bare index the MATLAB uses -- the combine stage's design rule: "read by name, assert
|
|
29
|
+
#: by index". ``test_combine.py`` pins that these names still resolve to the
|
|
30
|
+
#: indices the MATLAB hard-codes, so a future S4 write-order change fails there
|
|
31
|
+
#: instead of silently combining the wrong columns.
|
|
32
|
+
_READ_VARS = (
|
|
33
|
+
"time", "bin_min", "bin_max", "bin_mid", "bin_dD",
|
|
34
|
+
"conc_minR", "conc_AreaR", "n", "Reject_ratio", "count", "mean_area_ratio",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
#: :5-13 -> the MATLAB's own hard-coded ``netcdf.getVar(ncid, N)`` indices, for
|
|
38
|
+
#: the pinning test above. Not used by :func:`combine_sizedist` itself.
|
|
39
|
+
MATLAB_VARID = {
|
|
40
|
+
"time": 0, "bin_min": 1, "bin_max": 2, "bin_mid": 3, "bin_dD": 4,
|
|
41
|
+
"conc_minR": 5, "conc_AreaR": 7, "n": 8, "Reject_ratio": 15,
|
|
42
|
+
"count": 20, "mean_area_ratio": 21,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#: :101-107. A SPEC clock can emit a seconds field of 60 (``HHMM60``); the
|
|
46
|
+
#: MATLAB rewrites the string's seconds field to '00' and adds a minute to the
|
|
47
|
+
#: datenum. Implemented here directly on the integer HHMMSS field instead of
|
|
48
|
+
#: through MATLAB's num2str/datenum('HHMMSS') string round trip -- the design
|
|
49
|
+
#: doc S2 table measured that round trip as numerically clean (space- vs
|
|
50
|
+
#: zero-padding parses to the identical instant, diff 0.000000 s), so the
|
|
51
|
+
#: string detour has no effect the integer arithmetic below doesn't already
|
|
52
|
+
#: reproduce.
|
|
53
|
+
_ONE_MINUTE = 1.0 / 1440.0
|
|
54
|
+
_ONE_SECOND = 1.0 / 86400.0
|
|
55
|
+
#: :135. ``abs(timevec_new - timevec(k)) < datenum(0,0,0,0,0,0.3)`` -- 0.3 s.
|
|
56
|
+
_SYNC_TOL_DAYS = 0.3 / 86400.0
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _read_one(path) -> dict:
|
|
60
|
+
ds = ncio.open(str(path), "nowrite")
|
|
61
|
+
try:
|
|
62
|
+
return {name: ncio.get_var(ds, ncio.inq_var_id(ds, name)) for name in _READ_VARS}
|
|
63
|
+
finally:
|
|
64
|
+
ncio.close(ds)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _time_of_day(hhmmss: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
|
|
68
|
+
"""HHMMSS integers -> (time-of-day in days, was-a-:60-second-field mask).
|
|
69
|
+
|
|
70
|
+
The mask drives the :101-107 fixup: those rows get one more minute added
|
|
71
|
+
to their datenum by the caller, after the date component is added in.
|
|
72
|
+
"""
|
|
73
|
+
hh = np.floor_divide(hhmmss, 10000)
|
|
74
|
+
mm = np.mod(np.floor_divide(hhmmss, 100), 100)
|
|
75
|
+
ss = np.mod(hhmmss, 100)
|
|
76
|
+
is_60 = ss == 60
|
|
77
|
+
ss = np.where(is_60, 0, ss)
|
|
78
|
+
tod = hh / 24.0 + mm / 1440.0 + ss / 86400.0
|
|
79
|
+
return tod, is_60
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _timevec_matlab_replica(hhmmss: np.ndarray, year2: int, month: int, day: int,
|
|
83
|
+
current_year: int) -> np.ndarray:
|
|
84
|
+
""":109-110's two-datenum-cancellation arithmetic, literally.
|
|
85
|
+
|
|
86
|
+
``datenum(time_1, 'HHMMSS')`` on a string with no date component is
|
|
87
|
+
documented MATLAB/Octave behaviour that resolves to "January 1 of the
|
|
88
|
+
year the code is RUN in, plus the time of day" (design doc S4, measured
|
|
89
|
+
under Octave). ``current_year`` exists to cancel that run-year term, and
|
|
90
|
+
the design doc's own finding is that nothing checks it -- a wrong value
|
|
91
|
+
silently shifts every timestamp by whole years. That
|
|
92
|
+
dependency on the real-world calendar date at execution time is not a
|
|
93
|
+
shortcut taken here: it is the bug being reproduced. Use this only to
|
|
94
|
+
reproduce a *specific* historical mis-set run for comparison;
|
|
95
|
+
:func:`combine_sizedist`'s default (``current_year=None``) computes the
|
|
96
|
+
intended axis directly and does not call this at all.
|
|
97
|
+
"""
|
|
98
|
+
run_year = _dt.date.today().year
|
|
99
|
+
tod, is_60 = _time_of_day(hhmmss)
|
|
100
|
+
# :110's `datenum(current_year,0,1,0,0,0)` -- month 0, day 1. Empirically
|
|
101
|
+
# verified under Octave (the project's only available interpreter -- no
|
|
102
|
+
# MATLAB licence, ever) that this call clamps to January 1 of
|
|
103
|
+
# `current_year` itself: `datenum(Y,0,1,...) == datenum(Y,1,1,...)`
|
|
104
|
+
# exactly, numerically confirmed. The port's datenum() reproduces Octave's
|
|
105
|
+
# month<1 -> 1 rule bit for bit (the Octave bank run_datenum_bank.py, dev repository only), so
|
|
106
|
+
# passing month 0 would give the same value; it is written as the latter
|
|
107
|
+
# so the clamp is explicit at the call site. The S4c design doc S2 table
|
|
108
|
+
# flags MATLAB/Octave as diverging on month<1; matching the measured
|
|
109
|
+
# behaviour of the computation that made the actual product outranks a
|
|
110
|
+
# documentation reading for this environment-dependent secondary path --
|
|
111
|
+
# see Z_D/SPOT_EDGE in reject.py for the same principle applied elsewhere.
|
|
112
|
+
tv = (datenum(year2, month, day) + datenum(run_year, 1, 1) + tod
|
|
113
|
+
- datenum(current_year, 1, 1, 0, 0, 0))
|
|
114
|
+
return tv + np.where(is_60, _ONE_MINUTE, 0.0)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def combine_sizedist(sd_files, outfile, *, flight_date, summary_time,
|
|
118
|
+
current_year=None, creation_time=None):
|
|
119
|
+
"""``combine_sizedist.m`` -- stitch several ``sd`` files into one flight product.
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
sd_files : sequence of paths, IN ORDER
|
|
124
|
+
``:31,:37`` glob a directory and process files in ``dir`` order, which
|
|
125
|
+
is alphabetical for these basenames. Passing an explicit ordered list
|
|
126
|
+
turns that coincidence into a contract (the combine design record, section 8, decision 1); a
|
|
127
|
+
test pins that the product-of-record's own file order is what
|
|
128
|
+
alphabetical globbing of the five 09/06 raw-derived basenames gives.
|
|
129
|
+
outfile : path to write.
|
|
130
|
+
flight_date : str, ``'YYYYMMDD'``
|
|
131
|
+
Full year. ``:9`` slices ``flightdate(3:8)`` (MATLAB 1-based) for the
|
|
132
|
+
output stem and ``(3:4)`` for the *wrong* two-digit year used in the
|
|
133
|
+
MATLAB's own cancellation trick (see ``current_year`` below) -- this
|
|
134
|
+
function's default path uses the full year correctly instead.
|
|
135
|
+
summary_time : str, ``'YY_MM_DD_HH_MM_SS'``
|
|
136
|
+
The campaign summary file's own basename, without the campaign
|
|
137
|
+
extension -- e.g. ``'16_09_06_06_40_17'`` for
|
|
138
|
+
``16_09_06_06_40_17.oracles``. ``:150-154`` needs its full date and
|
|
139
|
+
time for the sync step below; ``:199-200`` needs only its HH/MM/SS
|
|
140
|
+
for the output filename, which this module's caller builds separately
|
|
141
|
+
(the combine design record, section 3: the script uses the summary file's NAME only, never
|
|
142
|
+
its contents, so there is no filesystem dependency to satisfy here).
|
|
143
|
+
current_year : int or None
|
|
144
|
+
``None`` (default) computes the intended time axis directly: the
|
|
145
|
+
flight date plus time of day, with no dependency on when this code
|
|
146
|
+
happens to run. A given int replicates ``:109-110``'s own arithmetic
|
|
147
|
+
via :func:`_timevec_matlab_replica`, for reproducing a specific
|
|
148
|
+
historical mis-set run -- see that function's docstring.
|
|
149
|
+
creation_time : unused
|
|
150
|
+
``combine_sizedist.m`` writes no global attributes at all (measured;
|
|
151
|
+
``:202-231`` defines only variables). Accepted for interface symmetry
|
|
152
|
+
with the earlier translation's ``imgproc_sm`` and ``sizedist.run``, and ignored.
|
|
153
|
+
|
|
154
|
+
Returns the path written.
|
|
155
|
+
"""
|
|
156
|
+
per_file = [_read_one(p) for p in sd_files]
|
|
157
|
+
|
|
158
|
+
# :62-65. Reassigned every loop iteration to file 1's values regardless of
|
|
159
|
+
# `i` -- a MATLAB quirk with no effect (the bin ladder does not vary
|
|
160
|
+
# file to file), reproduced by simply reading it once, from file 1.
|
|
161
|
+
bin_min = np.asarray(per_file[0]["bin_min"], dtype=np.float64).reshape(-1)
|
|
162
|
+
bin_max = np.asarray(per_file[0]["bin_max"], dtype=np.float64).reshape(-1)
|
|
163
|
+
bin_mid = np.asarray(per_file[0]["bin_mid"], dtype=np.float64).reshape(-1)
|
|
164
|
+
bin_dD = np.asarray(per_file[0]["bin_dD"], dtype=np.float64).reshape(-1)
|
|
165
|
+
|
|
166
|
+
time_parts, nd_parts, darea_parts = [], [], []
|
|
167
|
+
nt_parts, count_parts, mar_parts, rr_parts = [], [], [], []
|
|
168
|
+
for vals in per_file:
|
|
169
|
+
t_k = np.asarray(vals["time"], dtype=np.float64).reshape(-1)
|
|
170
|
+
# :47-50. get_var returns MATLAB shape (bin, time); '.T' is the ' in
|
|
171
|
+
# the MATLAB source, giving (time, bin) to match the concat target.
|
|
172
|
+
nd_k = (np.asarray(vals["conc_minR"], dtype=np.float64).T / 10.0) * bin_dD
|
|
173
|
+
darea_k = (np.asarray(vals["conc_AreaR"], dtype=np.float64).T / 10.0 ** 4) * bin_dD
|
|
174
|
+
# :70-71. MATLAB reads count/mean_area_ratio untransposed and
|
|
175
|
+
# transposes at the concat step instead; same result, done here.
|
|
176
|
+
count_k = np.asarray(vals["count"], dtype=np.float64).T
|
|
177
|
+
mar_k = np.asarray(vals["mean_area_ratio"], dtype=np.float64).T
|
|
178
|
+
nt_k = np.asarray(vals["n"], dtype=np.float64).reshape(-1)
|
|
179
|
+
rr_k = np.asarray(vals["Reject_ratio"], dtype=np.float64).reshape(-1)
|
|
180
|
+
|
|
181
|
+
time_parts.append(t_k)
|
|
182
|
+
nd_parts.append(nd_k)
|
|
183
|
+
darea_parts.append(darea_k)
|
|
184
|
+
nt_parts.append(nt_k)
|
|
185
|
+
count_parts.append(count_k)
|
|
186
|
+
mar_parts.append(mar_k)
|
|
187
|
+
rr_parts.append(rr_k)
|
|
188
|
+
|
|
189
|
+
time = np.concatenate(time_parts)
|
|
190
|
+
twods_Nd = np.concatenate(nd_parts, axis=0)
|
|
191
|
+
conc_darea = np.concatenate(darea_parts, axis=0)
|
|
192
|
+
twods_Nt = np.concatenate(nt_parts)
|
|
193
|
+
count = np.concatenate(count_parts, axis=0)
|
|
194
|
+
mean_area_ratio = np.concatenate(mar_parts, axis=0)
|
|
195
|
+
reject_ratio = np.concatenate(rr_parts)
|
|
196
|
+
|
|
197
|
+
# :84-91. Drop the SECOND of each *consecutive* duplicate stamp -- MATLAB's
|
|
198
|
+
# diff(time)==0 only ever fires on adjacent equal pairs, so a repeat that
|
|
199
|
+
# is not adjacent (e.g. after other stamps in between) is kept. This is
|
|
200
|
+
# the same rule combine's own use as an oracle target already pins.
|
|
201
|
+
#
|
|
202
|
+
dup = np.flatnonzero(np.diff(time) == 0) + 1
|
|
203
|
+
keep = np.ones(len(time), dtype=bool)
|
|
204
|
+
keep[dup] = False
|
|
205
|
+
time = time[keep]
|
|
206
|
+
twods_Nd = twods_Nd[keep]
|
|
207
|
+
conc_darea = conc_darea[keep]
|
|
208
|
+
twods_Nt = twods_Nt[keep]
|
|
209
|
+
count = count[keep]
|
|
210
|
+
mean_area_ratio = mean_area_ratio[keep]
|
|
211
|
+
reject_ratio = reject_ratio[keep]
|
|
212
|
+
|
|
213
|
+
# :95-120. Time axis.
|
|
214
|
+
hhmmss = time.astype(np.int64)
|
|
215
|
+
if current_year is None:
|
|
216
|
+
year, month, day = int(flight_date[0:4]), int(flight_date[4:6]), int(flight_date[6:8])
|
|
217
|
+
tod, is_60 = _time_of_day(hhmmss)
|
|
218
|
+
timevec = datenum(year, month, day) + tod + np.where(is_60, _ONE_MINUTE, 0.0)
|
|
219
|
+
else:
|
|
220
|
+
year2 = int(flight_date[2:4])
|
|
221
|
+
month, day = int(flight_date[4:6]), int(flight_date[6:8])
|
|
222
|
+
timevec = _timevec_matlab_replica(hhmmss, year2, month, day, current_year)
|
|
223
|
+
|
|
224
|
+
# :124-148. Append missing 1 Hz steps. Built by multiplication from an
|
|
225
|
+
# integer step count rather than MATLAB's colon-operator accumulation, for
|
|
226
|
+
# the same reason Z_D is in reject.py: many thousands of 1/86400 additions
|
|
227
|
+
# would drift off an exact-second grid.
|
|
228
|
+
n_steps = int(round((timevec[-1] - timevec[0]) * 86400.0)) + 1
|
|
229
|
+
if n_steps > 5_000_000 or n_steps < 1:
|
|
230
|
+
# A real flight file is a few hours (<20,000 s). Something this far
|
|
231
|
+
# off the rail is a garbage time axis -- almost certainly a bad
|
|
232
|
+
# current_year for _timevec_matlab_replica -- not a real gap to fill.
|
|
233
|
+
# Fail loudly rather than allocate tens of gigabytes silently.
|
|
234
|
+
raise ValueError(
|
|
235
|
+
f"combine_sizedist: computed a {n_steps}-second time axis "
|
|
236
|
+
f"({timevec[0]!r} to {timevec[-1]!r}); this is almost certainly a "
|
|
237
|
+
f"bad current_year, not a real flight gap. Refusing to allocate."
|
|
238
|
+
)
|
|
239
|
+
timevec_new = timevec[0] + np.arange(n_steps) * _ONE_SECOND
|
|
240
|
+
B = len(bin_mid)
|
|
241
|
+
# :125,:161 build a NaN-padded `time` (the HHMMSS stamps) here too, but it
|
|
242
|
+
# is never passed to a `putVar` call (the combine design doc: "time... is never
|
|
243
|
+
# written") -- dead in the MATLAB, so not reproduced here either.
|
|
244
|
+
nt_new = np.full(n_steps, np.nan)
|
|
245
|
+
nd_new = np.full((n_steps, B), np.nan)
|
|
246
|
+
count_new = np.full((n_steps, B), np.nan)
|
|
247
|
+
mar_new = np.full((n_steps, B), np.nan)
|
|
248
|
+
rr_new = np.full(n_steps, np.nan)
|
|
249
|
+
darea_new = np.full((n_steps, B), np.nan)
|
|
250
|
+
|
|
251
|
+
# :135. MATLAB searches for the nearest new-grid index within 0.3 s; every
|
|
252
|
+
# timevec value here is an exact whole second (built from integer HHMMSS
|
|
253
|
+
# plus, at most, one exact extra minute), so the nearest index is just the
|
|
254
|
+
# rounded integer offset -- no search needed, and no risk of the 0.3 s
|
|
255
|
+
# tolerance ever mattering for this data.
|
|
256
|
+
idx = np.round((timevec - timevec[0]) * 86400.0).astype(np.int64)
|
|
257
|
+
nt_new[idx] = twods_Nt
|
|
258
|
+
nd_new[idx] = twods_Nd
|
|
259
|
+
count_new[idx] = count
|
|
260
|
+
mar_new[idx] = mean_area_ratio
|
|
261
|
+
rr_new[idx] = reject_ratio
|
|
262
|
+
darea_new[idx] = conc_darea
|
|
263
|
+
|
|
264
|
+
# :150-182. Sync with the summary file's own timestamp.
|
|
265
|
+
yy2, mm_, dd_ = int(summary_time[0:2]), int(summary_time[3:5]), int(summary_time[6:8])
|
|
266
|
+
hh_, mi_, ss_ = int(summary_time[9:11]), int(summary_time[12:14]), int(summary_time[15:17])
|
|
267
|
+
# :152-154 computes this as `datenum(2000,0,0,0,0,0) + datenum(YY,MM,DD,...)`
|
|
268
|
+
# with a 2-digit YY -- the same shape of two-small-numbers-cancel trick as
|
|
269
|
+
# the flight-date arithmetic in :109-110, and just as run-environment
|
|
270
|
+
# dependent: verified under Octave that the trick DOES recover the correct
|
|
271
|
+
# instant (736579.277974537 for this file, matching the design doc's own
|
|
272
|
+
# measured product value) -- because Octave sets a month below 1 to 1,
|
|
273
|
+
# which the port's datenum() reproduces, so the two-term form evaluated
|
|
274
|
+
# here gives the same 736579.277974537. MATLAB's documentation is read as
|
|
275
|
+
# treating month<1 differently (S4c design doc S2), so the two-term form
|
|
276
|
+
# is an environment-specific coincidence, not the intended computation.
|
|
277
|
+
# Same port decision as the flight-date axis (S4c design doc S4): compute
|
|
278
|
+
# the intended value directly.
|
|
279
|
+
timevec_summary = float(datenum(2000 + yy2, mm_, dd_, hh_, mi_, ss_))
|
|
280
|
+
|
|
281
|
+
if timevec_new[0] > timevec_summary:
|
|
282
|
+
# :157-167. Prepend NaN rows from the summary time up to (not
|
|
283
|
+
# including) the first real row.
|
|
284
|
+
n_pad = int(round((timevec_new[0] - timevec_summary) * 86400.0))
|
|
285
|
+
if n_pad > 5_000_000:
|
|
286
|
+
# Same guard as n_steps above, same reason: a real summary-to-data
|
|
287
|
+
# gap is minutes, not years. This path is reachable with a bad
|
|
288
|
+
# current_year (the flight-date and summary-time axes then use
|
|
289
|
+
# different year conventions and appear days or years apart).
|
|
290
|
+
raise ValueError(
|
|
291
|
+
f"combine_sizedist: computed {n_pad} s of summary-sync padding "
|
|
292
|
+
f"(summary {timevec_summary!r}, data starts {timevec_new[0]!r}); "
|
|
293
|
+
f"almost certainly a bad current_year. Refusing to allocate."
|
|
294
|
+
)
|
|
295
|
+
pad = timevec_summary + np.arange(n_pad) * _ONE_SECOND
|
|
296
|
+
timevec_final = np.concatenate([pad, timevec_new])
|
|
297
|
+
nt_final = np.concatenate([np.full(n_pad, np.nan), nt_new])
|
|
298
|
+
nd_final = np.concatenate([np.full((n_pad, B), np.nan), nd_new], axis=0)
|
|
299
|
+
count_final = np.concatenate([np.full((n_pad, B), np.nan), count_new], axis=0)
|
|
300
|
+
mar_final = np.concatenate([np.full((n_pad, B), np.nan), mar_new], axis=0)
|
|
301
|
+
rr_final = np.concatenate([np.full(n_pad, np.nan), rr_new])
|
|
302
|
+
else:
|
|
303
|
+
# :169-181. Trim leading rows before the summary time. Dead for every
|
|
304
|
+
# real ORACLES flight measured so far (the summary file always
|
|
305
|
+
# predates the first raw file by design doc S3), reproduced anyway:
|
|
306
|
+
# MATLAB's `arr(1:y,:)=[]` with y<=0 removes nothing (`1:0` is empty
|
|
307
|
+
# in MATLAB), which int16's saturating round-half-away-from-zero cast
|
|
308
|
+
# can only produce when the two datenums are equal or `timevec_new`
|
|
309
|
+
# is (impossibly) earlier than a summary time already excluded by the
|
|
310
|
+
# branch condition -- so y>0 whenever this branch is reached at all.
|
|
311
|
+
y = int(mint16((timevec_new[0] - timevec_summary) * 86400.0))
|
|
312
|
+
y = max(y, 0)
|
|
313
|
+
timevec_final = timevec_new[y:]
|
|
314
|
+
nt_final = nt_new[y:]
|
|
315
|
+
nd_final = nd_new[y:]
|
|
316
|
+
count_final = count_new[y:]
|
|
317
|
+
mar_final = mar_new[y:]
|
|
318
|
+
rr_final = rr_new[y:]
|
|
319
|
+
|
|
320
|
+
_write(outfile, len(sd_files), bin_min, bin_max, bin_mid, bin_dD,
|
|
321
|
+
timevec_final, mar_final, count_final, nd_final, nt_final, rr_final)
|
|
322
|
+
return outfile
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def _write(outfile, n_files, bin_min, bin_max, bin_mid, bin_dD,
|
|
326
|
+
timevec, mean_area_ratio, count, twods_Nd, twods_Nt, reject_ratio):
|
|
327
|
+
""":202-231. Ten variables, no global attributes -- measured, not assumed."""
|
|
328
|
+
f = ncio.create(str(outfile), "clobber")
|
|
329
|
+
time_dim = ncio.def_dim(f, "time", len(timevec))
|
|
330
|
+
bin_dim = ncio.def_dim(f, "bin_count", len(bin_min))
|
|
331
|
+
# :207. Declared, used by no variable -- the only record of how many
|
|
332
|
+
# files went into the product. Preserved rather than dropped.
|
|
333
|
+
ncio.def_dim(f, "files_stitched", n_files)
|
|
334
|
+
|
|
335
|
+
v_time = ncio.def_var(f, "Time Vector", "double", [time_dim])
|
|
336
|
+
v_bmin = ncio.def_var(f, "Bin Minimum", "double", [bin_dim])
|
|
337
|
+
v_bmax = ncio.def_var(f, "Bin Maximum", "double", [bin_dim])
|
|
338
|
+
v_bmid = ncio.def_var(f, "Bin Midpoints", "double", [bin_dim])
|
|
339
|
+
v_bdD = ncio.def_var(f, "Bin Width", "double", [bin_dim])
|
|
340
|
+
# :213 etc. -- MATLAB's own dims list is [dimid0 dimid1] = [time, bin],
|
|
341
|
+
# in that order; ncio.def_var takes dimids in that same MATLAB order.
|
|
342
|
+
v_mar = ncio.def_var(f, "Mean Area Ratio", "double", [time_dim, bin_dim])
|
|
343
|
+
v_count = ncio.def_var(f, "Counts", "double", [time_dim, bin_dim])
|
|
344
|
+
v_nd = ncio.def_var(f, "Size Distribution cm-3", "double", [time_dim, bin_dim])
|
|
345
|
+
v_nt = ncio.def_var(f, "Number Concentration cm-3", "double", [time_dim])
|
|
346
|
+
v_rr = ncio.def_var(f, "Reject Ratio", "double", [time_dim])
|
|
347
|
+
ncio.end_def(f)
|
|
348
|
+
|
|
349
|
+
ncio.put_var(f, v_time, timevec)
|
|
350
|
+
ncio.put_var(f, v_bmin, bin_min)
|
|
351
|
+
ncio.put_var(f, v_bmax, bin_max)
|
|
352
|
+
ncio.put_var(f, v_bmid, bin_mid)
|
|
353
|
+
ncio.put_var(f, v_bdD, bin_dD)
|
|
354
|
+
ncio.put_var(f, v_mar, mean_area_ratio)
|
|
355
|
+
ncio.put_var(f, v_count, count)
|
|
356
|
+
ncio.put_var(f, v_nd, twods_Nd)
|
|
357
|
+
ncio.put_var(f, v_nt, twods_Nt)
|
|
358
|
+
ncio.put_var(f, v_rr, reject_ratio)
|
|
359
|
+
ncio.close(f)
|