"""Find where decoded-vs-sidecar diverges for each channel.""" from __future__ import annotations import sys from pathlib import Path REPO = Path(__file__).resolve().parents[1] sys.path.insert(0, str(REPO)) from minimateplus.waveform_codec import decode_waveform_v2 from analysis_idf.recon import TARGET, TXT, load_sidecar_samples def main(): buf = TARGET.read_bytes() sc = load_sidecar_samples(TXT) decoded = decode_waveform_v2(buf[0x0f1f:]) GEO_LSB = 0.0003 for ch in ("Tran", "Vert", "Long"): sc_counts = [int(round(v / GEO_LSB)) for v in sc[ch]] dec = decoded[ch] # Find ALL transitions where mismatches start/stop first_diff = next((i for i in range(len(dec)) if dec[i] != sc_counts[i]), None) if first_diff is None: print(f"{ch}: NO MISMATCHES") continue print(f"{ch}: first diff at idx {first_diff}") # Show 5 before, 5 after for i in range(max(0, first_diff - 3), min(len(dec), first_diff + 8)): mark = " " if dec[i] == sc_counts[i] else "**" print(f" {mark} idx {i:4d}: sc={sc_counts[i]:6d} dec={dec[i]:6d} diff={dec[i]-sc_counts[i]:+d}") # Where does cumulative diff exceed 100? cum_match_run = 0 max_match_run = 0 match_run_start = 0 diff_count = 0 for i in range(len(dec)): if dec[i] == sc_counts[i]: cum_match_run += 1 max_match_run = max(max_match_run, cum_match_run) else: cum_match_run = 0 diff_count += 1 print(f" total mismatches: {diff_count}/{len(dec)}, longest run of matches: {max_match_run}") print() if __name__ == "__main__": main()