microstructure-tpw 0.3.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 (119) hide show
  1. microstructure_tpw-0.3.0.dist-info/METADATA +234 -0
  2. microstructure_tpw-0.3.0.dist-info/RECORD +119 -0
  3. microstructure_tpw-0.3.0.dist-info/WHEEL +5 -0
  4. microstructure_tpw-0.3.0.dist-info/entry_points.txt +7 -0
  5. microstructure_tpw-0.3.0.dist-info/licenses/LICENSE +674 -0
  6. microstructure_tpw-0.3.0.dist-info/top_level.txt +1 -0
  7. odas_tpw/__init__.py +18 -0
  8. odas_tpw/chi/__init__.py +48 -0
  9. odas_tpw/chi/batchelor.py +189 -0
  10. odas_tpw/chi/chi.py +857 -0
  11. odas_tpw/chi/fp07.py +649 -0
  12. odas_tpw/chi/l2_chi.py +153 -0
  13. odas_tpw/chi/l3_chi.py +388 -0
  14. odas_tpw/chi/l4_chi.py +391 -0
  15. odas_tpw/config_base.py +423 -0
  16. odas_tpw/perturb/__init__.py +18 -0
  17. odas_tpw/perturb/adcp.py +274 -0
  18. odas_tpw/perturb/atomic_io.py +47 -0
  19. odas_tpw/perturb/binning.py +761 -0
  20. odas_tpw/perturb/cli.py +591 -0
  21. odas_tpw/perturb/combo.py +346 -0
  22. odas_tpw/perturb/config.py +1046 -0
  23. odas_tpw/perturb/ctd.py +424 -0
  24. odas_tpw/perturb/diag/__init__.py +12 -0
  25. odas_tpw/perturb/diag/_common.py +140 -0
  26. odas_tpw/perturb/diag/chi.py +42 -0
  27. odas_tpw/perturb/diag/cli.py +67 -0
  28. odas_tpw/perturb/diag/data.py +662 -0
  29. odas_tpw/perturb/diag/epsilon.py +45 -0
  30. odas_tpw/perturb/diag/inspector.py +342 -0
  31. odas_tpw/perturb/diag/mixing.py +94 -0
  32. odas_tpw/perturb/diag/render.py +543 -0
  33. odas_tpw/perturb/discover.py +40 -0
  34. odas_tpw/perturb/fp07_cal.py +354 -0
  35. odas_tpw/perturb/gps.py +458 -0
  36. odas_tpw/perturb/hotel.py +572 -0
  37. odas_tpw/perturb/logging_setup.py +181 -0
  38. odas_tpw/perturb/merge.py +320 -0
  39. odas_tpw/perturb/mk_sections.py +310 -0
  40. odas_tpw/perturb/netcdf_schema.py +520 -0
  41. odas_tpw/perturb/pipeline.py +2654 -0
  42. odas_tpw/perturb/plot/__init__.py +15 -0
  43. odas_tpw/perturb/plot/cli.py +107 -0
  44. odas_tpw/perturb/plot/diagnostics.py +195 -0
  45. odas_tpw/perturb/plot/eps_chi.py +524 -0
  46. odas_tpw/perturb/plot/figure.py +679 -0
  47. odas_tpw/perturb/plot/gamma_scaling.py +1097 -0
  48. odas_tpw/perturb/plot/grid.py +112 -0
  49. odas_tpw/perturb/plot/layout.py +361 -0
  50. odas_tpw/perturb/plot/overview.py +547 -0
  51. odas_tpw/perturb/plot/presets/eps-chi.yaml +16 -0
  52. odas_tpw/perturb/plot/presets/profiles.yaml +32 -0
  53. odas_tpw/perturb/plot/presets/scalar.yaml +21 -0
  54. odas_tpw/perturb/plot/profiles.py +652 -0
  55. odas_tpw/perturb/plot/scalar.py +391 -0
  56. odas_tpw/perturb/plot/sections.py +506 -0
  57. odas_tpw/perturb/plot/xaxis.py +396 -0
  58. odas_tpw/perturb/qc_gate.py +177 -0
  59. odas_tpw/perturb/qc_rules.py +373 -0
  60. odas_tpw/perturb/resolve.py +306 -0
  61. odas_tpw/perturb/seawater.py +76 -0
  62. odas_tpw/perturb/speed.py +14 -0
  63. odas_tpw/perturb/trim.py +313 -0
  64. odas_tpw/processing/__init__.py +62 -0
  65. odas_tpw/processing/bottom.py +215 -0
  66. odas_tpw/processing/chi_combine.py +300 -0
  67. odas_tpw/processing/ct_align.py +172 -0
  68. odas_tpw/processing/epsilon_combine.py +210 -0
  69. odas_tpw/processing/mixing.py +630 -0
  70. odas_tpw/processing/thorpe.py +458 -0
  71. odas_tpw/processing/top_trim.py +274 -0
  72. odas_tpw/pyturb/__init__.py +3 -0
  73. odas_tpw/pyturb/__main__.py +5 -0
  74. odas_tpw/pyturb/_compat.py +204 -0
  75. odas_tpw/pyturb/_profind.py +124 -0
  76. odas_tpw/pyturb/bin.py +113 -0
  77. odas_tpw/pyturb/cli.py +175 -0
  78. odas_tpw/pyturb/eps.py +353 -0
  79. odas_tpw/pyturb/merge.py +101 -0
  80. odas_tpw/pyturb/p2nc.py +76 -0
  81. odas_tpw/rsi/__init__.py +31 -0
  82. odas_tpw/rsi/adapter.py +314 -0
  83. odas_tpw/rsi/bench.py +904 -0
  84. odas_tpw/rsi/binning.py +193 -0
  85. odas_tpw/rsi/channels.py +376 -0
  86. odas_tpw/rsi/chi_io.py +980 -0
  87. odas_tpw/rsi/cli.py +1411 -0
  88. odas_tpw/rsi/combine.py +120 -0
  89. odas_tpw/rsi/config.py +126 -0
  90. odas_tpw/rsi/config_patch.py +790 -0
  91. odas_tpw/rsi/convert.py +651 -0
  92. odas_tpw/rsi/deconvolve.py +119 -0
  93. odas_tpw/rsi/diss_look.py +343 -0
  94. odas_tpw/rsi/dissipation.py +669 -0
  95. odas_tpw/rsi/helpers.py +527 -0
  96. odas_tpw/rsi/mixing_look.py +509 -0
  97. odas_tpw/rsi/p_file.py +771 -0
  98. odas_tpw/rsi/pipeline.py +924 -0
  99. odas_tpw/rsi/profile.py +624 -0
  100. odas_tpw/rsi/quick_look.py +758 -0
  101. odas_tpw/rsi/sensor_inventory.py +684 -0
  102. odas_tpw/rsi/shear_noise.py +128 -0
  103. odas_tpw/rsi/speed.py +221 -0
  104. odas_tpw/rsi/vehicle.py +74 -0
  105. odas_tpw/rsi/viewer_base.py +1071 -0
  106. odas_tpw/rsi/window.py +459 -0
  107. odas_tpw/scor160/__init__.py +36 -0
  108. odas_tpw/scor160/cli.py +242 -0
  109. odas_tpw/scor160/compare.py +484 -0
  110. odas_tpw/scor160/despike.py +227 -0
  111. odas_tpw/scor160/goodman.py +288 -0
  112. odas_tpw/scor160/io.py +690 -0
  113. odas_tpw/scor160/l2.py +311 -0
  114. odas_tpw/scor160/l3.py +279 -0
  115. odas_tpw/scor160/l4.py +850 -0
  116. odas_tpw/scor160/nasmyth.py +208 -0
  117. odas_tpw/scor160/ocean.py +287 -0
  118. odas_tpw/scor160/profile.py +231 -0
  119. odas_tpw/scor160/spectral.py +482 -0
@@ -0,0 +1,242 @@
1
+ """CLI for SCOR/ATOMIX benchmark processing.
2
+
3
+ Usage:
4
+ scor160-tpw l1-l2 data/*.nc # L1->L2: section selection, despike, HP filter
5
+ scor160-tpw l2-l3 data/*.nc # L2->L3: wavenumber spectra (uses reference L2)
6
+ scor160-tpw l1-l3 data/*.nc # L1->L3: full pipeline through spectra
7
+ scor160-tpw l3-l4 data/*.nc # L3->L4: dissipation from spectra
8
+ scor160-tpw l2-l4 data/*.nc # L2->L4: spectra + dissipation
9
+ scor160-tpw l1-l4 data/*.nc # L1->L4: full pipeline
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import argparse
15
+ from pathlib import Path
16
+
17
+ import numpy as np
18
+
19
+
20
+ def main(argv: list[str] | None = None) -> None:
21
+ """CLI entry point for scor160-tpw."""
22
+ parser = argparse.ArgumentParser(
23
+ prog="scor160-tpw",
24
+ description="SCOR/ATOMIX benchmark dataset processing",
25
+ )
26
+ sub = parser.add_subparsers(dest="command", required=True)
27
+
28
+ # --- l1-l2 ---
29
+ p = sub.add_parser("l1-l2", help="L1->L2: section selection, despike, HP filter")
30
+ p.add_argument("files", nargs="+", type=Path)
31
+ p.add_argument("--plot", action="store_true")
32
+
33
+ # --- l2-l3 ---
34
+ p = sub.add_parser("l2-l3", help="L2->L3: wavenumber spectra (reference L2 input)")
35
+ p.add_argument("files", nargs="+", type=Path)
36
+
37
+ # --- l1-l3 ---
38
+ p = sub.add_parser("l1-l3", help="L1->L3: full pipeline through spectra")
39
+ p.add_argument("files", nargs="+", type=Path)
40
+
41
+ # --- l3-l4 ---
42
+ p = sub.add_parser("l3-l4", help="L3->L4: dissipation from spectra")
43
+ p.add_argument("files", nargs="+", type=Path)
44
+
45
+ # --- l2-l4 ---
46
+ p = sub.add_parser("l2-l4", help="L2->L4: spectra + dissipation")
47
+ p.add_argument("files", nargs="+", type=Path)
48
+
49
+ # --- l1-l4 ---
50
+ p = sub.add_parser("l1-l4", help="L1->L4: full pipeline")
51
+ p.add_argument("files", nargs="+", type=Path)
52
+
53
+ args = parser.parse_args(argv)
54
+
55
+ dispatch = {
56
+ "l1-l2": _cmd_l1_l2,
57
+ "l2-l3": _cmd_l2_l3,
58
+ "l1-l3": _cmd_l1_l3,
59
+ "l3-l4": _cmd_l3_l4,
60
+ "l2-l4": _cmd_l2_l4,
61
+ "l1-l4": _cmd_l1_l4,
62
+ }
63
+ dispatch[args.command](args)
64
+
65
+
66
+ # ---------------------------------------------------------------------------
67
+ # Shared benchmark runner
68
+ # ---------------------------------------------------------------------------
69
+
70
+ # Level processing specs: (start, end, needs_plot)
71
+ _LEVEL_SPECS = {
72
+ "l1-l2": {"levels": ["l2"]},
73
+ "l2-l3": {"levels": ["l3"]},
74
+ "l1-l3": {"levels": ["l2", "l3"]},
75
+ "l3-l4": {"levels": ["l4"]},
76
+ "l2-l4": {"levels": ["l3", "l4"]},
77
+ "l1-l4": {"levels": ["l2", "l3", "l4"]},
78
+ }
79
+
80
+
81
+ def _run_benchmark(args: argparse.Namespace, levels: list[str]) -> None:
82
+ """Run benchmark processing for the specified levels."""
83
+ from odas_tpw.scor160.compare import (
84
+ compare_l2,
85
+ compare_l3,
86
+ compare_l4,
87
+ format_l2_report,
88
+ format_l3_report,
89
+ format_l4_report,
90
+ )
91
+ from odas_tpw.scor160.io import read_atomix
92
+ from odas_tpw.scor160.l2 import process_l2
93
+ from odas_tpw.scor160.l3 import process_l3
94
+ from odas_tpw.scor160.l4 import process_l4
95
+
96
+ for path in args.files:
97
+ print(f"\nProcessing {path.name} ...")
98
+ l1, l2_params, l2_ref, l3_params, l3_ref, l4_ref = read_atomix(path)
99
+
100
+ if "l2" in levels:
101
+ print(f" L1: {l1.n_time} samples, {l1.n_shear} shear, {l1.n_vib} {l1.vib_type}")
102
+ print(
103
+ f" Params: HP_cut={l2_params.HP_cut} Hz, despike_sh={l2_params.despike_sh}"
104
+ f", speed_tau={l2_params.speed_tau} s"
105
+ f", min_W={l2_params.profile_min_W} m/s"
106
+ )
107
+ l2_comp = process_l2(l1, l2_params)
108
+ print()
109
+ print(format_l2_report(compare_l2(l2_comp, l2_ref), filename=path.name))
110
+ if getattr(args, "plot", False):
111
+ _plot_l2(l1, l2_comp, l2_ref, path.stem)
112
+ else:
113
+ l2_comp = None
114
+
115
+ if "l3" in levels:
116
+ l2_input = l2_comp if l2_comp is not None else l2_ref
117
+ if l2_comp is None:
118
+ print(
119
+ f" L2 ref: {l2_ref.shear.shape[1]} samples, "
120
+ f"{l2_ref.shear.shape[0]} shear, {l2_ref.vib.shape[0]} {l2_ref.vib_type}"
121
+ )
122
+ print(
123
+ f" L3 params: fft={l3_params.fft_length}, diss={l3_params.diss_length}, "
124
+ f"overlap={l3_params.overlap}, goodman={l3_params.goodman}"
125
+ )
126
+ l3_comp = process_l3(l2_input, l1, l3_params)
127
+ print()
128
+ print(format_l3_report(compare_l3(l3_comp, l3_ref), filename=path.name))
129
+ else:
130
+ l3_comp = None
131
+
132
+ if "l4" in levels:
133
+ l3_input = l3_comp if l3_comp is not None else l3_ref
134
+ if l3_comp is None:
135
+ print(
136
+ f" L3 ref: {l3_ref.n_spectra} spectra, "
137
+ f"{l3_ref.n_shear} shear, {l3_ref.n_wavenumber} wavenumbers"
138
+ )
139
+ # Use the dataset's own QC thresholds so the flag comparison
140
+ # against the reference EPSI_FLAGS is like-for-like.
141
+ from odas_tpw.scor160.io import read_l4_qc_limits
142
+
143
+ qc = read_l4_qc_limits(path)
144
+ l4_comp = process_l4(
145
+ l3_input,
146
+ f_AA=l1.f_AA,
147
+ num_ffts=2 * (l3_params.diss_length // l3_params.fft_length) - 1,
148
+ n_v=l1.n_vib if l3_params.goodman else 0,
149
+ fom_limit=qc["FOM_limit"],
150
+ var_resolved_limit=qc["variance_resolved_limit"],
151
+ despike_fraction_limit=qc["despike_shear_fraction_limit"],
152
+ despike_passes_limit=int(qc["despike_shear_iterations_limit"]),
153
+ diss_ratio_limit=qc["diss_ratio_limit"],
154
+ diss_length_s=qc["diss_length_s"],
155
+ )
156
+ print()
157
+ print(format_l4_report(compare_l4(l4_comp, l4_ref), filename=path.name))
158
+
159
+
160
+ def _cmd_l1_l2(args: argparse.Namespace) -> None:
161
+ _run_benchmark(args, ["l2"])
162
+
163
+
164
+ def _cmd_l2_l3(args: argparse.Namespace) -> None:
165
+ _run_benchmark(args, ["l3"])
166
+
167
+
168
+ def _cmd_l1_l3(args: argparse.Namespace) -> None:
169
+ _run_benchmark(args, ["l2", "l3"])
170
+
171
+
172
+ def _cmd_l3_l4(args: argparse.Namespace) -> None:
173
+ _run_benchmark(args, ["l4"])
174
+
175
+
176
+ def _cmd_l2_l4(args: argparse.Namespace) -> None:
177
+ _run_benchmark(args, ["l3", "l4"])
178
+
179
+
180
+ def _cmd_l1_l4(args: argparse.Namespace) -> None:
181
+ _run_benchmark(args, ["l2", "l3", "l4"])
182
+
183
+
184
+ # ---------------------------------------------------------------------------
185
+ # Plotting helpers
186
+ # ---------------------------------------------------------------------------
187
+
188
+
189
+ def _plot_l2(l1, l2_comp, l2_ref, title: str) -> None:
190
+ """Plot L1 vs computed-L2 vs reference-L2 for visual inspection."""
191
+ import matplotlib.pyplot as plt
192
+
193
+ fs = l1.fs_fast
194
+ t = np.arange(l1.n_time) / fs
195
+
196
+ ref_sec = l2_ref.section_number
197
+ sections = np.unique(ref_sec[ref_sec > 0])
198
+ if len(sections) == 0:
199
+ print(" No sections to plot.")
200
+ return
201
+
202
+ sec_mask = ref_sec == sections[0]
203
+ idx = np.where(sec_mask)[0]
204
+ t_sec = t[idx]
205
+
206
+ n_sh = min(l1.n_shear, 2)
207
+ n_vib = min(l1.n_vib, 2)
208
+ n_rows = 1 + n_sh + n_vib
209
+
210
+ _fig, axes = plt.subplots(n_rows, 1, figsize=(14, 3 * n_rows), sharex=True)
211
+ if n_rows == 1:
212
+ axes = [axes]
213
+
214
+ ax = axes[0]
215
+ ax.plot(t_sec, l2_ref.pspd_rel[idx], "b-", alpha=0.7, label="reference")
216
+ ax.plot(t_sec, l2_comp.pspd_rel[idx], "r--", alpha=0.7, label="computed")
217
+ ax.set_ylabel("W [m/s]")
218
+ ax.legend(loc="upper right")
219
+ ax.set_title(f"{title} -- Section {int(sections[0])}")
220
+
221
+ for i in range(n_sh):
222
+ ax = axes[1 + i]
223
+ ax.plot(t_sec, l2_ref.shear[i, idx], "b-", alpha=0.5, lw=0.5, label="reference")
224
+ ax.plot(t_sec, l2_comp.shear[i, idx], "r-", alpha=0.5, lw=0.5, label="computed")
225
+ ax.set_ylabel(f"sh{i + 1} [s-1]")
226
+ ax.legend(loc="upper right")
227
+
228
+ for i in range(n_vib):
229
+ ax = axes[1 + n_sh + i]
230
+ ax.plot(t_sec, l2_ref.vib[i, idx], "b-", alpha=0.5, lw=0.5, label="reference")
231
+ ax.plot(t_sec, l2_comp.vib[i, idx], "r-", alpha=0.5, lw=0.5, label="computed")
232
+ label = "Acc" if l1.vib_type == "ACC" else "Vib"
233
+ ax.set_ylabel(f"{label}{i + 1}")
234
+ ax.legend(loc="upper right")
235
+
236
+ axes[-1].set_xlabel("Time [s]")
237
+ plt.tight_layout()
238
+ plt.show()
239
+
240
+
241
+ if __name__ == "__main__":
242
+ main()