"""Labels per warp sample (plan §4.3): y^(s)(t_i) = (𝒜φ)(τ^(s)(t_i)). Logs live on the uniform fine τ grid (sonic time). 𝒜 is a zero-phase low-pass filter applied before 4 ms sampling (as in resample.log_to_time); τ^(s) is the inverse map of t(·; u^(s)), which exists because t is monotone. """ from __future__ import annotations import numpy as np from scipy import signal def antialias(y: np.ndarray, d_fine_ms: float, out_dt_ms: float = 4.0, cutoff_frac: float = 0.8, order: int = 6) -> np.ndarray: """Low-pass filter at cutoff_frac·Nyquist of the out_dt_ms grid (default 100 Hz for 4 ms).""" fc = cutoff_frac * 500.0 / out_dt_ms sos = signal.butter(order, fc, fs=1000.0 / d_fine_ms, output="sos") return signal.sosfiltfilt(sos, y, padtype="even") def invert_warps(t_of_tau: np.ndarray, tau: np.ndarray, t_out: np.ndarray) -> np.ndarray: """τ(t_out) for each warp sample; t_of_tau (S, n) strictly increasing on the tau grid. NaN outside the domain.""" t_of_tau = np.atleast_2d(t_of_tau) out = np.empty((len(t_of_tau), len(t_out))) for s, ts in enumerate(t_of_tau): out[s] = np.interp(t_out, ts, tau, left=np.nan, right=np.nan) return out def labels_for_warps(tau_fine: np.ndarray, y_filtered: np.ndarray, t_of_tau_fine: np.ndarray, t_out: np.ndarray) -> np.ndarray: """(S, L): labels at t_out for each warp. y_filtered is the log after `antialias` on tau_fine.""" tau_at = invert_warps(t_of_tau_fine, tau_fine, t_out) return np.where(np.isfinite(tau_at), np.interp(np.nan_to_num(tau_at), tau_fine, y_filtered), np.nan)