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,698 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Known-truth synthetic 2D-S flights: raw ``.2DS`` bytes plus a manifest of every particle.
3
+
4
+ **What this is for** (author: *"we will eventually use synthetic data also"* and
5
+ *"we are seeking the truth ... need evidence"*). Every other validation in this project is
6
+ *fidelity*: does the port reproduce what MATLAB (or IDL) wrote. Fidelity cannot say whether the
7
+ answer is right. A synthetic flight whose particle population is known exactly can: run it
8
+ through a chain and compare the size distribution the chain recovers with the one that was
9
+ drawn. This module writes such flights; ``scripts/truth_harness.py`` runs the chains
10
+ and does the comparison.
11
+
12
+ **What a truth test here can and cannot establish.** It establishes how a chain responds to
13
+ *this optical model's* images of round droplets: which gates remove which true droplets, how
14
+ the chain's assumed depth of field compares with where images actually form, how sizing moves
15
+ out-of-focus droplets between bins. It cannot establish that the chain is right on real data:
16
+ the optical model is ours (a binary-annulus rendering of Korolev's 50 %-threshold dimensions,
17
+ below), real probes add noise, stuck and dirty diodes, non-spherical ice, electronics dead time
18
+ and timing jitter that none of this reproduces, and a chain can be right on synthetic data and
19
+ wrong on real data. A chain that is *wrong* here, on round droplets under a documented model,
20
+ has a finding that does not depend on any archive.
21
+
22
+ The optical model -- every piece named, and marked where it is ours
23
+ ------------------------------------------------------------------
24
+ * **Image dimensions** are Korolev (2007, JTECH 24:376-389, doi:10.1175/JTECH1980.1), Appendix
25
+ B, p. 388: "Lookup Table for Retrieval of Sizes of Spherical Particles from their Binary
26
+ Images Formed at 50 % Intensity Threshold Level" -- ``Z_d`` from 0 to 8.15 in steps of 0.05,
27
+ ``D_edge/D0`` (the paper's eta for the external diameter, p. 377: "the normalized size of the
28
+ image eta = D_m/D0 is solely a function of Z_d") and ``D_spot/D_edge``. Transcribed in full as
29
+ :data:`KOROLEV_2007_APPENDIX_B` (164 rows) from the page image of
30
+ ``developer/literature/atot-jtech1980_1.pdf``. ``Z_d = 4 lambda Z / D0**2`` (p. 377); beyond
31
+ ``Z_dmax = 8.18`` no area of the image is below the 50 % level (p. 378), so the droplet
32
+ produces no image at all (:data:`KOROLEV_2007_ZDMAX_50`). Lookup is **nearest row**, never
33
+ interpolated: the table jumps where a second ring appears (e.g. ``D_edge/D0`` 1.407 at 1.90,
34
+ 1.074 at 1.95), and a linear interpolation would invent images across the jump.
35
+ * **The image is rendered as a binary annulus** -- outer diameter ``D_edge``, hole ``D_spot`` --
36
+ **ours, an approximation**: Korolev's Eqs. (1)-(2), p. 378, treat the 50 % image as one ring
37
+ and state the second rings are insignificant for retrieval; the continuous intensity inside
38
+ the ring is not uniform, which this ignores.
39
+ * **Diodes**: Korolev p. 379's model for "conventional 2D probes" -- active area 0.8 of the pitch
40
+ across the array by 1 slice along it, triggered when the light integrated over the area is
41
+ decreased by 50 %; with a binary annulus that is "at least half of the active area is inside
42
+ the ring" (:attr:`OpticalModel.active_x`, :attr:`OpticalModel.n_sub`).
43
+ * **2D-S geometry**: 128 diodes at 10 um, arm separation 63 mm -- ``sizeDist.m:365-390``'s 2DS
44
+ case, as :func:`arrayprobe.constants.sizedist_config` carries it; wavelength 785 nm, SODA-2's
45
+ 2D-S probe specification (``arrayprobe_soda2.probespecs``, ``soda2_probespecs.pro:955``).
46
+ Note that UIOOPS' own depth of field uses a hard-coded 680 nm for every probe
47
+ (``calc_sa_randombins.m``, ``arrayprobe.sample_area``) -- a chain property the harness
48
+ measures, not something this module adopts.
49
+ * **Clock**: the particle time word counts one tick per slice, ``pixel / TAS`` seconds -- the
50
+ convention ``imgproc.py:955`` and SODA-2's ``freq`` both decode with. Records never straddle a
51
+ second, and each record's header time is its last particle's time (SODA-2 counts particle
52
+ times backwards from the buffer time, ``processbuffer_spec.py`` ``:352-357``).
53
+ * **Arrival**: droplets arrive as a Poisson process in time; the centre is uniform across the
54
+ sampled width and (``depth="uniform"``) uniform in ``Z`` between the arms. Two particles
55
+ closer than the first one's image length plus two slices cannot both be imaged by a real
56
+ array, so a later particle is pushed back to that separation (ours; recorded in the manifest).
57
+ * **Shattering bursts** (optional): a burst is a cluster of small in-focus fragments, each
58
+ separated from the previous by a gap drawn uniformly from ``burst_gap_us``. Fragments are
59
+ ``kind="fragment"`` in the manifest and are **not** part of the true droplet population.
60
+
61
+ The truth
62
+ ---------
63
+ The manifest records every drawn particle, imaged or not: its true diameter, time, position
64
+ across the array, distance from the object plane, ``Z_d``, whether it produced an image, whether
65
+ that image was clipped by an array end, and the clock value written. The true number
66
+ concentration of droplets in a size bin is the count drawn in that bin divided by the volume the
67
+ draw covered, ``TAS * T * width * depth`` (:meth:`TruthManifest.sampled_volume_m3`).
68
+ """
69
+
70
+ from __future__ import annotations
71
+
72
+ import dataclasses
73
+ import json
74
+ import math
75
+ from pathlib import Path
76
+
77
+ import numpy as np
78
+
79
+ from arrayprobe.tools.make_demo_flight import _hk_words, image_packet, raw_file, run_word
80
+ from arrayprobe_uiops import spec_core as spec
81
+
82
+ __all__ = [
83
+ "KOROLEV_2007_APPENDIX_B", "KOROLEV_2007_ZDMAX_50", "korolev_dimensions",
84
+ "OpticalModel", "render_droplet", "image_runs", "PSD", "FlightSpec",
85
+ "TruthManifest", "build_truth_flight", "MANIFEST_SUFFIX", "write_aircraft_tas",
86
+ ]
87
+
88
+ # ---------------------------------------------------------------------------
89
+ # Korolev (2007) Appendix B, p. 388 -- transcribed from the page, all 164 rows.
90
+ # Three column blocks on the page; each string below is one block, one row per
91
+ # line: Z_d, D_edge/D0, D_spot/D_edge.
92
+ # ---------------------------------------------------------------------------
93
+ _APPENDIX_B_TEXT = """
94
+ 0.00 1.000 0.003
95
+ 0.05 1.054 0.008
96
+ 0.10 1.083 0.017
97
+ 0.15 1.101 0.024
98
+ 0.20 1.095 0.033
99
+ 0.25 1.110 0.040
100
+ 0.30 1.148 0.047
101
+ 0.35 1.162 0.054
102
+ 0.40 1.155 0.062
103
+ 0.45 1.123 0.072
104
+ 0.50 1.182 0.076
105
+ 0.55 1.121 0.088
106
+ 0.60 1.162 0.093
107
+ 0.65 1.210 0.096
108
+ 0.70 1.242 0.101
109
+ 0.75 1.134 0.119
110
+ 0.80 1.166 0.123
111
+ 0.85 1.202 0.127
112
+ 0.90 1.238 0.130
113
+ 0.95 1.270 0.134
114
+ 1.00 1.294 0.139
115
+ 1.05 1.278 0.148
116
+ 1.10 1.130 0.175
117
+ 1.15 1.148 0.180
118
+ 1.20 1.170 0.184
119
+ 1.25 1.194 0.188
120
+ 1.30 1.218 0.192
121
+ 1.35 1.242 0.195
122
+ 1.40 1.265 0.199
123
+ 1.45 1.288 0.202
124
+ 1.50 1.310 0.206
125
+ 1.55 1.331 0.209
126
+ 1.60 1.351 0.213
127
+ 1.65 1.369 0.217
128
+ 1.70 1.386 0.221
129
+ 1.75 1.400 0.225
130
+ 1.80 1.411 0.230
131
+ 1.85 1.416 0.235
132
+ 1.90 1.407 0.243
133
+ 1.95 1.074 0.327
134
+ 2.00 1.080 0.334
135
+ 2.05 1.087 0.340
136
+ 2.10 1.096 0.345
137
+ 2.15 1.106 0.351
138
+ 2.20 1.117 0.355
139
+ 2.25 1.127 0.360
140
+ 2.30 1.139 0.365
141
+ 2.35 1.150 0.369
142
+ 2.40 1.162 0.373
143
+ 2.45 1.173 0.377
144
+ 2.50 1.185 0.381
145
+ 2.55 1.197 0.385
146
+ 2.60 1.208 0.389
147
+ 2.65 1.220 0.393
148
+ 2.70 1.232 0.397
149
+ 2.75 1.243 0.400
150
+ 2.80 1.255 0.404
151
+ 2.85 1.266 0.408
152
+ 2.90 1.277 0.411
153
+ 2.95 1.289 0.415
154
+ 3.00 1.300 0.419
155
+ 3.05 1.311 0.422
156
+ 3.10 1.322 0.426
157
+ 3.15 1.333 0.429
158
+ 3.20 1.344 0.433
159
+ 3.25 1.355 0.436
160
+ 3.30 1.366 0.439
161
+ 3.35 1.376 0.443
162
+ 3.40 1.387 0.446
163
+ 3.45 1.397 0.450
164
+ 3.50 1.407 0.453
165
+ 3.55 1.418 0.457
166
+ 3.60 1.428 0.460
167
+ 3.65 1.438 0.463
168
+ 3.70 1.448 0.467
169
+ 3.75 1.458 0.470
170
+ 3.80 1.467 0.473
171
+ 3.85 1.477 0.477
172
+ 3.90 1.486 0.480
173
+ 3.95 1.496 0.484
174
+ 4.00 1.505 0.487
175
+ 4.05 1.515 0.490
176
+ 4.10 1.524 0.494
177
+ 4.15 1.533 0.497
178
+ 4.20 1.542 0.501
179
+ 4.25 1.551 0.504
180
+ 4.30 1.559 0.507
181
+ 4.35 1.568 0.511
182
+ 4.40 1.577 0.514
183
+ 4.45 1.585 0.518
184
+ 4.50 1.594 0.521
185
+ 4.55 1.602 0.525
186
+ 4.60 1.610 0.528
187
+ 4.65 1.618 0.532
188
+ 4.70 1.626 0.535
189
+ 4.75 1.634 0.539
190
+ 4.80 1.642 0.543
191
+ 4.85 1.650 0.547
192
+ 4.90 1.657 0.550
193
+ 4.95 1.665 0.554
194
+ 5.00 1.673 0.558
195
+ 5.05 1.680 0.562
196
+ 5.10 1.687 0.566
197
+ 5.15 1.694 0.569
198
+ 5.20 1.702 0.572
199
+ 5.25 1.709 0.575
200
+ 5.30 1.716 0.578
201
+ 5.35 1.722 0.581
202
+ 5.40 1.729 0.584
203
+ 5.45 1.736 0.587
204
+ 5.50 1.742 0.590
205
+ 5.55 1.749 0.593
206
+ 5.60 1.755 0.596
207
+ 5.65 1.761 0.598
208
+ 5.70 1.768 0.601
209
+ 5.75 1.774 0.605
210
+ 5.80 1.780 0.610
211
+ 5.85 1.786 0.614
212
+ 5.90 1.791 0.618
213
+ 5.95 1.797 0.623
214
+ 6.00 1.803 0.627
215
+ 6.05 1.808 0.631
216
+ 6.10 1.813 0.635
217
+ 6.15 1.819 0.640
218
+ 6.20 1.824 0.644
219
+ 6.25 1.829 0.648
220
+ 6.30 1.834 0.653
221
+ 6.35 1.839 0.657
222
+ 6.40 1.843 0.662
223
+ 6.45 1.848 0.666
224
+ 6.50 1.852 0.671
225
+ 6.55 1.857 0.676
226
+ 6.60 1.861 0.680
227
+ 6.65 1.865 0.685
228
+ 6.70 1.869 0.690
229
+ 6.75 1.872 0.695
230
+ 6.80 1.876 0.700
231
+ 6.85 1.880 0.705
232
+ 6.90 1.883 0.711
233
+ 6.95 1.886 0.716
234
+ 7.00 1.889 0.721
235
+ 7.05 1.892 0.727
236
+ 7.10 1.895 0.733
237
+ 7.15 1.897 0.738
238
+ 7.20 1.899 0.744
239
+ 7.25 1.901 0.751
240
+ 7.30 1.903 0.757
241
+ 7.35 1.905 0.763
242
+ 7.40 1.906 0.770
243
+ 7.45 1.907 0.777
244
+ 7.50 1.908 0.784
245
+ 7.55 1.908 0.792
246
+ 7.60 1.908 0.800
247
+ 7.65 1.907 0.808
248
+ 7.70 1.907 0.817
249
+ 7.75 1.905 0.826
250
+ 7.80 1.903 0.836
251
+ 7.85 1.900 0.846
252
+ 7.90 1.897 0.858
253
+ 7.95 1.892 0.870
254
+ 8.00 1.885 0.884
255
+ 8.05 1.877 0.901
256
+ 8.10 1.865 0.921
257
+ 8.15 1.845 0.950
258
+ """
259
+
260
+ def _parse_appendix_b_row(line: str) -> tuple[float, float, float]:
261
+ """Each row is exactly ``(Z_d, D_edge/D0, D_spot/D_edge)``; unpacking (rather than a
262
+ variable-length ``tuple(float(v) for v in ...)``) is what lets mypy see the fixed width
263
+ the type below declares -- a malformed row now fails loudly here instead of silently
264
+ producing a tuple of the wrong length."""
265
+ a, b, c = line.split()
266
+ return float(a), float(b), float(c)
267
+
268
+
269
+ #: Korolev (2007) Appendix B (p. 388): ``(Z_d, D_edge/D0, D_spot/D_edge)``, 50 % threshold.
270
+ KOROLEV_2007_APPENDIX_B: tuple[tuple[float, float, float], ...] = tuple(
271
+ _parse_appendix_b_row(line) for line in _APPENDIX_B_TEXT.strip().splitlines()
272
+ )
273
+
274
+ #: Korolev (2007) p. 378: the largest ``Z_d`` at which any area of the image is below the 50 %
275
+ #: intensity level (citing KEA98). Beyond it a droplet produces no image.
276
+ KOROLEV_2007_ZDMAX_50: float = 8.18
277
+
278
+ _ZD = np.array([r[0] for r in KOROLEV_2007_APPENDIX_B])
279
+ _EDGE = np.array([r[1] for r in KOROLEV_2007_APPENDIX_B])
280
+ _SPOT = np.array([r[2] for r in KOROLEV_2007_APPENDIX_B])
281
+
282
+
283
+ def korolev_dimensions(zd: float) -> tuple[float, float] | None:
284
+ """``(D_edge/D0, D_spot/D_edge)`` at ``zd`` -- the nearest Appendix B row; ``None`` beyond
285
+ ``Z_dmax`` (no image). Never interpolated (see the module docstring)."""
286
+ zd = abs(float(zd))
287
+ if zd > KOROLEV_2007_ZDMAX_50:
288
+ return None
289
+ i = int(np.argmin(np.abs(_ZD - zd)))
290
+ return float(_EDGE[i]), float(_SPOT[i])
291
+
292
+
293
+ # ---------------------------------------------------------------------------
294
+ # Rendering onto the diode array
295
+ # ---------------------------------------------------------------------------
296
+
297
+ @dataclasses.dataclass(frozen=True)
298
+ class OpticalModel:
299
+ """How a droplet becomes a binary image on a 2D-S-like array. Defaults: the 2D-S."""
300
+
301
+ pixel_um: float = 10.0 #: diode pitch = slice length (TAS-clocked); sizeDist.m 2DS case
302
+ num_diodes: int = 128 #: sizeDist.m 2DS case
303
+ armdst_mm: float = 63.0 #: arm separation; sizeDist.m 2DS case
304
+ wavelength_um: float = 0.785 #: soda2_probespecs.pro 2D-S rows
305
+ active_x: float = 0.8 #: diode active width / pitch (Korolev 2007 p. 379)
306
+ active_y: float = 1.0 #: diode active length / slice (Korolev 2007 p. 379)
307
+ n_sub: int = 5 #: sub-samples per axis over the active area
308
+ coverage: float = 0.5 #: shadowed when >= this fraction of the active area is dark
309
+
310
+ def zd(self, d0_um: float, z_mm: float) -> float:
311
+ """Korolev's ``Z_d = 4 lambda Z / D0**2`` (p. 377), dimensionless."""
312
+ return 4.0 * self.wavelength_um * abs(z_mm) * 1000.0 / (d0_um * d0_um)
313
+
314
+ def z_max_mm(self, d0_um: float) -> float:
315
+ """Distance from the object plane at which ``Z_d`` reaches ``Z_dmax`` (8.18)."""
316
+ return KOROLEV_2007_ZDMAX_50 * d0_um * d0_um / (4.0 * self.wavelength_um) / 1000.0
317
+
318
+
319
+ def render_droplet(d0_um: float, zd: float, x_um: float, y_phase: float,
320
+ model: OpticalModel) -> tuple[np.ndarray, bool] | None:
321
+ """The binary image of one droplet, ``(rows=slices, cols=num_diodes)`` bool, and whether it
322
+ touches an array end; ``None`` if nothing on the array is shadowed.
323
+
324
+ ``x_um`` is the centre across the array, measured from the outer edge of diode 1 (so the
325
+ array spans ``[0, num_diodes * pixel_um)``); ``y_phase`` in ``[0, 1)`` places the centre
326
+ within a slice. Diodes outside the array are simply absent -- that is the edge clipping.
327
+ """
328
+ dims = korolev_dimensions(zd)
329
+ if dims is None:
330
+ return None
331
+ edge, spot = dims
332
+ r_out = 0.5 * d0_um * edge
333
+ r_in = r_out * spot
334
+ p = model.pixel_um
335
+ k = (np.arange(model.n_sub) + 0.5) / model.n_sub - 0.5
336
+ sx = k * model.active_x * p
337
+ sy = k * model.active_y * p
338
+ n_rows = int(math.ceil(2.0 * r_out / p)) + 2
339
+ yc = r_out + p + y_phase * p # centre, from the start of row 0
340
+ rows_c = (np.arange(n_rows) + 0.5) * p # slice centres
341
+ lo = max(0, int(math.floor((x_um - r_out) / p)) - 1)
342
+ hi = min(model.num_diodes, int(math.ceil((x_um + r_out) / p)) + 1)
343
+ if hi <= lo:
344
+ return None
345
+ cols_c = (np.arange(lo, hi) + 0.5) * p
346
+ dy = rows_c[:, None, None, None] + sy[None, None, :, None] - yc
347
+ dx = cols_c[None, :, None, None] + sx[None, None, None, :] - x_um
348
+ r = np.sqrt(dx * dx + dy * dy)
349
+ dark = ((r <= r_out) & (r >= r_in)).mean(axis=(2, 3)) >= model.coverage
350
+ img = np.zeros((n_rows, model.num_diodes), dtype=bool)
351
+ img[:, lo:hi] = dark
352
+ rows = np.flatnonzero(img.any(axis=1))
353
+ if rows.size == 0:
354
+ return None
355
+ img = img[rows[0]:rows[-1] + 1]
356
+ touches = bool(img[:, 0].any() or img[:, -1].any())
357
+ return img, touches
358
+
359
+
360
+ def image_runs(img: np.ndarray) -> list[int]:
361
+ """Run-length words for a binary image, one slice per row, in the encoding
362
+ the earlier translation's SPEC decoder reads (``read_binary_SPEC.m:223-241``): a
363
+ slice's first word carries the absolute clear count, later words the clear gap from the
364
+ previous run's end (the same rule :func:`arrayprobe.tools.make_demo_flight.ring_runs`
365
+ documents). An empty interior slice is ``run_word(0, 0)``, which the decoder writes as
366
+ nothing; a run longer than 127 diodes is split, since a run field is seven bits."""
367
+ words: list[int] = []
368
+ for j, row in enumerate(img):
369
+ idx = np.flatnonzero(row)
370
+ first = True
371
+ if idx.size == 0:
372
+ words.append(run_word(0, 0, new_slice=(j > 0)))
373
+ continue
374
+ breaks = np.flatnonzero(np.diff(idx) > 1)
375
+ starts = np.concatenate([[idx[0]], idx[breaks + 1]])
376
+ ends = np.concatenate([idx[breaks], [idx[-1]]]) + 1 # exclusive
377
+ prev_end = 0
378
+ for s, e in zip(starts.tolist(), ends.tolist(), strict=True):
379
+ gap = s - prev_end
380
+ length = e - s
381
+ while length > 0:
382
+ aa = min(length, 127)
383
+ words.append(run_word(aa, gap, new_slice=(first and j > 0)))
384
+ first = False
385
+ gap = 0
386
+ length -= aa
387
+ prev_end = e
388
+ return words
389
+
390
+
391
+ # ---------------------------------------------------------------------------
392
+ # The population and the flight
393
+ # ---------------------------------------------------------------------------
394
+
395
+ @dataclasses.dataclass(frozen=True)
396
+ class PSD:
397
+ """The true droplet size distribution the flight draws from.
398
+
399
+ ``kind="lognormal"``: ``median_um`` and geometric standard deviation ``gsd``, truncated to
400
+ ``[d_min_um, d_max_um]``. ``kind="discrete"``: ``diameters_um`` drawn uniformly (e.g. one
401
+ diameter per bin centre, for a flat-in-count test).
402
+ """
403
+
404
+ kind: str = "lognormal"
405
+ median_um: float = 60.0
406
+ gsd: float = 1.8
407
+ d_min_um: float = 15.0
408
+ d_max_um: float = 500.0
409
+ diameters_um: tuple[float, ...] = ()
410
+
411
+ def draw(self, rng: np.random.Generator, n: int) -> np.ndarray:
412
+ """Draw ``n`` true diameters (um) from this distribution using ``rng``."""
413
+ if self.kind == "discrete":
414
+ return rng.choice(np.asarray(self.diameters_um, dtype=float), size=n)
415
+ if self.kind != "lognormal":
416
+ raise ValueError(f"unknown PSD kind {self.kind!r}")
417
+ out = np.empty(0)
418
+ while out.size < n:
419
+ d = np.exp(rng.normal(math.log(self.median_um), math.log(self.gsd), 2 * n + 16))
420
+ out = np.concatenate([out, d[(d >= self.d_min_um) & (d <= self.d_max_um)]])
421
+ return out[:n]
422
+
423
+
424
+ @dataclasses.dataclass(frozen=True)
425
+ class FlightSpec:
426
+ """Everything that determines a synthetic flight. Same spec + same seed = same bytes."""
427
+
428
+ n_seconds: int = 20
429
+ rate_per_s: float = 400.0 #: mean droplets per second drawn in the sampled volume
430
+ psd: PSD = PSD()
431
+ seed: int = 20260915
432
+ tas_mps: float = 130.0
433
+ depth: str = "uniform" #: "uniform" in Z between the arms, or "in_focus" (Z = 0)
434
+ across: str = "margin" #: "margin": centre uniform over the array +- margin_um;
435
+ #: "mid": centre uniform where the in-focus disk cannot touch an array end
436
+ margin_um: float = 600.0
437
+ burst_rate_per_s: float = 0.0 #: shattering bursts per second (0 = none)
438
+ fragments_per_burst: tuple[int, int] = (4, 12)
439
+ fragment_d_um: tuple[float, float] = (20.0, 80.0)
440
+ burst_gap_us: tuple[float, float] = (0.3, 3.0)
441
+ start: tuple[int, int, int] = (6, 6, 40) #: HH, MM, SS of the first second
442
+ date: tuple[int, int, int, int] = (2016, 9, 2, 6) #: year, month, day-of-week, day
443
+
444
+ def to_dict(self) -> dict:
445
+ """A plain-dict form of this spec, JSON-round-trippable via :meth:`from_dict`."""
446
+ d = dataclasses.asdict(self)
447
+ return d
448
+
449
+ @classmethod
450
+ def from_dict(cls, d: dict) -> FlightSpec:
451
+ """Rebuild a spec from :meth:`to_dict`'s output (tuples restored from lists)."""
452
+ d = dict(d)
453
+ d["psd"] = PSD(**{**d["psd"], "diameters_um": tuple(d["psd"]["diameters_um"])})
454
+ for k in ("fragments_per_burst", "fragment_d_um", "burst_gap_us", "start", "date"):
455
+ d[k] = tuple(d[k])
456
+ return cls(**d)
457
+
458
+
459
+ MANIFEST_SUFFIX = ".truth.json"
460
+
461
+ #: Manifest columns, in order, with their dtype.
462
+ _COLUMNS = {
463
+ "kind": str, "d0_um": float, "t_s": float, "second": int, "x_um": float, "z_mm": float,
464
+ "zd": float, "imaged": bool, "clipped": bool, "n_slices": int, "clock": int,
465
+ "record": int, "pushed_us": float,
466
+ }
467
+
468
+
469
+ @dataclasses.dataclass
470
+ class TruthManifest:
471
+ """The truth: the spec, the optical model, and one entry per drawn particle (columnar)."""
472
+
473
+ spec: FlightSpec
474
+ model: OpticalModel
475
+ columns: dict[str, list]
476
+ raw_name: str = ""
477
+
478
+ def __len__(self) -> int:
479
+ return len(self.columns["kind"])
480
+
481
+ def array(self, name: str) -> np.ndarray:
482
+ """The named manifest column (see :data:`_COLUMNS`) as a NumPy array."""
483
+ return np.asarray(self.columns[name])
484
+
485
+ @property
486
+ def sampled_width_um(self) -> float:
487
+ """Across-array width the centres were drawn over."""
488
+ w = self.model.num_diodes * self.model.pixel_um
489
+ if self.spec.across == "margin":
490
+ return w + 2.0 * self.spec.margin_um
491
+ return w # "mid": reported as the array width; mid mode is a count-level anchor only
492
+
493
+ def sampled_volume_m3(self) -> float:
494
+ """``TAS * T * width * depth`` -- the volume the droplets were drawn in. Meaningful for
495
+ ``depth="uniform"``; an in-focus flight has no depth, so its truth is counts only."""
496
+ if self.spec.depth != "uniform":
497
+ raise ValueError("an in-focus flight has no sampled depth; compare counts")
498
+ return (self.spec.tas_mps * self.spec.n_seconds * self.sampled_width_um * 1e-6
499
+ * self.model.armdst_mm * 1e-3)
500
+
501
+ def to_json(self, path) -> Path:
502
+ """Write this manifest (spec, optical model and per-particle columns) as JSON."""
503
+ path = Path(path)
504
+ doc = {"format": "arrayprobe synthetic truth manifest v1", "raw": self.raw_name,
505
+ "spec": self.spec.to_dict(), "model": dataclasses.asdict(self.model),
506
+ "columns": self.columns}
507
+ path.write_text(json.dumps(doc, separators=(",", ":")), encoding="utf-8")
508
+ return path
509
+
510
+ @classmethod
511
+ def from_json(cls, path) -> TruthManifest:
512
+ """Read a manifest written by :meth:`to_json` back into a :class:`TruthManifest`."""
513
+ doc = json.loads(Path(path).read_text(encoding="utf-8"))
514
+ cols = {k: [_COLUMNS[k](v) for v in doc["columns"][k]] for k in _COLUMNS}
515
+ return cls(spec=FlightSpec.from_dict(doc["spec"]), model=OpticalModel(**doc["model"]),
516
+ columns=cols, raw_name=doc.get("raw", ""))
517
+
518
+
519
+ def _draw_population(spec: FlightSpec, model: OpticalModel, rng: np.random.Generator):
520
+ """Droplets and fragments, time-ordered: (kind, d0, t, x, z) arrays."""
521
+ width = model.num_diodes * model.pixel_um
522
+ kinds, d0s, ts, xs, zs = [], [], [], [], []
523
+ for sec in range(spec.n_seconds):
524
+ n = int(rng.poisson(spec.rate_per_s))
525
+ d = spec.psd.draw(rng, n)
526
+ t = sec + rng.uniform(0.0, 1.0, n)
527
+ if spec.across == "margin":
528
+ x = rng.uniform(-spec.margin_um, width + spec.margin_um, n)
529
+ elif spec.across == "mid":
530
+ # The in-focus disk of diameter d stays two diodes clear of both ends.
531
+ half = 0.5 * d + 2 * model.pixel_um
532
+ x = half + rng.uniform(0.0, 1.0, n) * (width - 2 * half)
533
+ else:
534
+ raise ValueError(f"unknown across mode {spec.across!r}")
535
+ if spec.depth == "uniform":
536
+ z = rng.uniform(-0.5 * model.armdst_mm, 0.5 * model.armdst_mm, n)
537
+ elif spec.depth == "in_focus":
538
+ z = np.zeros(n)
539
+ else:
540
+ raise ValueError(f"unknown depth mode {spec.depth!r}")
541
+ kinds += ["droplet"] * n
542
+ d0s.append(d)
543
+ ts.append(t)
544
+ xs.append(x)
545
+ zs.append(z)
546
+ if spec.burst_rate_per_s > 0:
547
+ for _ in range(int(rng.poisson(spec.burst_rate_per_s))):
548
+ k = int(rng.integers(spec.fragments_per_burst[0], spec.fragments_per_burst[1] + 1))
549
+ t0 = sec + rng.uniform(0.0, 0.99)
550
+ gaps = rng.uniform(*spec.burst_gap_us, k) * 1e-6
551
+ fd = rng.uniform(*spec.fragment_d_um, k)
552
+ fx = rng.uniform(0.25 * width, 0.75 * width, k)
553
+ kinds += ["fragment"] * k
554
+ d0s.append(fd)
555
+ ts.append(t0 + np.cumsum(gaps))
556
+ xs.append(fx)
557
+ zs.append(np.zeros(k))
558
+ kind = np.array(kinds, dtype=object)
559
+ d0 = np.concatenate(d0s) if d0s else np.zeros(0)
560
+ t = np.concatenate(ts) if ts else np.zeros(0)
561
+ x = np.concatenate(xs) if xs else np.zeros(0)
562
+ z = np.concatenate(zs) if zs else np.zeros(0)
563
+ order = np.argsort(t, kind="stable")
564
+ return kind[order], d0[order], t[order], x[order], z[order]
565
+
566
+
567
+ #: Particle clock at the start of the flight (ticks). Low enough that a flight of a few hundred
568
+ #: seconds at 170 m/s never wraps the 32-bit counter.
569
+ CLOCK0 = 0x0100_0000
570
+
571
+ #: Image-record payload budget (words): ``DATA_WORDS`` less a margin, so no packet reaches the
572
+ #: end of the record.
573
+ _RECORD_BUDGET = spec.DATA_WORDS - 8
574
+
575
+
576
+ #: Sub-second stamp of each housekeeping record; see the comment where it is used.
577
+ HK_STAMP = 0.990
578
+
579
+
580
+ def build_truth_flight(path, flight: FlightSpec | None = None,
581
+ model: OpticalModel | None = None) -> TruthManifest:
582
+ """Write the raw ``.2DS`` file at ``path`` and its manifest at ``path + MANIFEST_SUFFIX``.
583
+
584
+ ``path``'s stem should follow SPEC's ``base<YYMMDDhhmmss>`` convention if the combine stage
585
+ is to run on it (see :mod:`arrayprobe.tools.make_demo_flight`). Returns the manifest.
586
+ """
587
+ flight = FlightSpec() if flight is None else flight
588
+ model = OpticalModel() if model is None else model
589
+ rng = np.random.default_rng(flight.seed)
590
+ kind, d0, t, x, z = _draw_population(flight, model, rng)
591
+ n = len(t)
592
+ zd = np.array([model.zd(a, b) for a, b in zip(d0, z, strict=True)])
593
+ phase = rng.uniform(0.0, 1.0, n)
594
+ tick_s = model.pixel_um * 1e-6 / flight.tas_mps
595
+
596
+ imaged = np.zeros(n, bool)
597
+ clipped = np.zeros(n, bool)
598
+ n_slices = np.zeros(n, np.int64)
599
+ clock = np.full(n, -1, np.int64)
600
+ record = np.full(n, -1, np.int64)
601
+ pushed = np.zeros(n)
602
+ t_eff = t.copy()
603
+
604
+ hh, mm, ss = flight.start
605
+ year, month, dow, day = flight.date
606
+ records: list[tuple[tuple, list[int]]] = []
607
+ last_tick = -(10 ** 9)
608
+ last_len = 0
609
+ counter = 0
610
+
611
+ def header(sec: int, t_last: float) -> tuple:
612
+ tod = hh * 3600 + mm * 60 + ss + sec
613
+ ms = int(min(999, math.floor((t_last - sec) * 1000.0)))
614
+ return (year, month, dow, day, tod // 3600, (tod // 60) % 60, tod % 60, ms)
615
+
616
+ i = 0
617
+ for sec in range(flight.n_seconds):
618
+ payload: list[int] = []
619
+ t_last = float(sec)
620
+ while i < n and t[i] < sec + 1:
621
+ out = render_droplet(d0[i], zd[i], x[i], phase[i], model)
622
+ if out is None:
623
+ i += 1
624
+ continue
625
+ img, touches = out
626
+ tick = int(round(t_eff[i] / tick_s))
627
+ min_tick = last_tick + last_len + 2
628
+ if tick < min_tick:
629
+ pushed[i] = (min_tick - tick) * tick_s * 1e6
630
+ tick = min_tick
631
+ t_eff[i] = tick * tick_s
632
+ if t_eff[i] >= sec + 1: # pushed out of its second: not imaged in this one
633
+ i += 1
634
+ continue
635
+ runs = image_runs(img)
636
+ counter = (counter + 1) % 65536
637
+ pkt = image_packet(runs, img.shape[0], channel="H", pc=counter,
638
+ t_particle=CLOCK0 + tick)
639
+ if len(payload) + len(pkt) > _RECORD_BUDGET:
640
+ records.append((header(sec, t_last), payload))
641
+ payload = []
642
+ payload.extend(pkt)
643
+ t_last = t_eff[i]
644
+ imaged[i], clipped[i], n_slices[i] = True, touches, img.shape[0]
645
+ clock[i] = CLOCK0 + tick
646
+ record[i] = len(records)
647
+ last_tick, last_len = tick, img.shape[0]
648
+ i += 1
649
+ if payload:
650
+ records.append((header(sec, t_last), payload))
651
+ tod = hh * 3600 + mm * 60 + ss + sec
652
+ # Stamped at .990, not .999: `read_binary_SPEC.m:302` writes the .tas.csv row as a
653
+ # MATLAB single, and hhmmss.999 rounds up to the next whole second (single spacing is
654
+ # 1/256 s near 06:06:40), which moves every TAS row a second late and leaves the first
655
+ # second's particles uncounted -- measured under Octave, NIGHT_FINDINGS 2026-09-28 #2.
656
+ # .990 stays inside its second at every hhmmss below 240000 (spacing <= 1/64 s).
657
+ records.append((header(sec, sec + HK_STAMP), _hk_words(flight.tas_mps, tod)))
658
+ # One spare housekeeping record after the last second: the last record of a raw file is
659
+ # never a primary (preserved `read_binary_SPEC.m` behaviour), so without it the
660
+ # final second's TAS row -- and with it that second's particles -- would never be counted.
661
+ tod = hh * 3600 + mm * 60 + ss + flight.n_seconds
662
+ records.append((header(flight.n_seconds, flight.n_seconds + HK_STAMP),
663
+ _hk_words(flight.tas_mps, tod)))
664
+ raw = raw_file(str(path), records)
665
+ # Rounded so the manifest stays small; the rounding is far below any quantity the chains
666
+ # resolve (0.001 um in size, 1 ns in time, 0.01 um across the array, 1 um in depth), and
667
+ # the values written ARE the truth -- the raw bytes were rendered from the same numbers
668
+ # before rounding, which is below one sub-sample of the rendering in every case.
669
+ cols = {
670
+ "kind": kind.tolist(), "d0_um": np.round(d0, 3).tolist(),
671
+ "t_s": np.round(t_eff, 9).tolist(),
672
+ "second": np.floor(t_eff).astype(int).tolist(), "x_um": np.round(x, 2).tolist(),
673
+ "z_mm": np.round(z, 3).tolist(), "zd": np.round(zd, 4).tolist(),
674
+ "imaged": imaged.tolist(), "clipped": clipped.tolist(),
675
+ "n_slices": n_slices.tolist(), "clock": clock.tolist(), "record": record.tolist(),
676
+ "pushed_us": np.round(pushed, 4).tolist(),
677
+ }
678
+ manifest = TruthManifest(spec=flight, model=model, columns=cols, raw_name=raw.name)
679
+ manifest.to_json(str(raw) + MANIFEST_SUFFIX)
680
+ return manifest
681
+
682
+
683
+ def write_aircraft_tas(path, flight: FlightSpec) -> Path:
684
+ """The aircraft file a TAS-reading ``imgProc_sm`` takes as ``varargin{1}``
685
+ (``imgProc_sm.m:183-185``; the v3.1.4 image processing reads ``Time`` as HHMMSS and
686
+ ``TAS`` in m/s): one
687
+ sample per second of the flight, at the flight's constant TAS."""
688
+ import netCDF4
689
+
690
+ hh, mm, ss = flight.start
691
+ tod = hh * 3600 + mm * 60 + ss + np.arange(flight.n_seconds)
692
+ hhmmss = (tod // 3600) * 10000 + ((tod // 60) % 60) * 100 + tod % 60
693
+ path = Path(path)
694
+ with netCDF4.Dataset(str(path), "w", format="NETCDF3_CLASSIC") as d:
695
+ d.createDimension("time", len(tod))
696
+ d.createVariable("Time", "f8", ("time",))[:] = hhmmss.astype(float)
697
+ d.createVariable("TAS", "f8", ("time",))[:] = np.full(len(tod), flight.tas_mps)
698
+ return path