From 13d83ca21b359149fc40584b14d9d30f3d8c168e Mon Sep 17 00:00:00 2001 From: Tom Hehir <148493038+tom-hehir@users.noreply.github.com> Date: Wed, 27 May 2026 14:29:15 +0100 Subject: [PATCH] fix(spectrum): use 'wavelength' key in pad_spectrum sentinels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `pad_spectrum` looks up sentinel values in `padding_values` while iterating over the attribute names of `Spectrum` (`flux`, `ivar`, `mask`, `wavelength`), but the dict key is `"lambda"`, so the `wavelength` lookup misses and the wavelength tensor is padded with the default `0` instead of the intended `99999`. That makes the wavelength array non-monotonic (`[real_min, …, real_max, 0, 0, …, 0]`). `LatentSpectralGrid.to_latent` feeds it to `interp1d`, whose out-of-range mask is `(xnew < x[..., 0]) | (xnew > x[..., -1])`. With `x[..., -1] == 0`, every latent grid position satisfies `xnew > 0` and the whole latent representation is replaced with `mask_value = 0.0`. Every spectrum then encodes to (essentially) the same null embedding. This shows up in downstream consumers that call the spectrum codec on inputs whose length is less than `pad_length` (so `F.pad` actually appends elements). Switching the dict key to `"wavelength"` so it matches the attribute name fixes the sentinel. Co-Authored-By: Claude Opus 4.7 (1M context) --- aion/codecs/preprocessing/spectrum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aion/codecs/preprocessing/spectrum.py b/aion/codecs/preprocessing/spectrum.py index 78429f2..8ee00b2 100644 --- a/aion/codecs/preprocessing/spectrum.py +++ b/aion/codecs/preprocessing/spectrum.py @@ -9,7 +9,7 @@ def pad_spectrum(x: Spectrum) -> Spectrum: Note: Each of the sequence attributes (flux, ivar, mask, wavelength) should be 2D tensors. """ - padding_values = {"lambda": 99999, "mask": True, "ivar": 0} + padding_values = {"wavelength": 99999, "mask": True, "ivar": 0} for k in ["flux", "ivar", "mask", "wavelength"]: setattr(