Skip to content

Commit b8b3ca9

Browse files
ivhclaude
andcommitted
Fix continuum trace count mismatch when norm_flat drops edge traces
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 999e50c commit b8b3ca9

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

pyreduce/reduce.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,11 +2481,23 @@ def run(self, science, norm_flat, trace: list):
24812481
trace_list = valid
24822482
wave = wavelengths_from_traces(trace_list)
24832483

2484-
# Trim to match spectra count (extraction may have skipped edge traces)
2485-
if len(wave) > nspec:
2486-
wave = wave[len(wave) - nspec :]
2487-
if len(blaze) > nspec:
2488-
blaze = blaze[len(blaze) - nspec :]
2484+
if wave is None:
2485+
raise ValueError(
2486+
"Continuum normalization requires wavelength data. "
2487+
"Run wavecal or freq_comb steps first."
2488+
)
2489+
2490+
# Align all arrays to the smallest count (norm_flat may skip edge traces)
2491+
nmin = min(nspec, len(blaze), len(wave) if wave is not None else nspec)
2492+
if nspec > nmin:
2493+
specs = [s[nspec - nmin :] for s in specs]
2494+
sigmas = [s[nspec - nmin :] for s in sigmas]
2495+
columns = [c[nspec - nmin :] for c in columns]
2496+
nspec = nmin
2497+
if wave is not None and len(wave) > nmin:
2498+
wave = wave[len(wave) - nmin :]
2499+
if len(blaze) > nmin:
2500+
blaze = blaze[len(blaze) - nmin :]
24892501

24902502
logger.info("Continuum normalization")
24912503
conts = [None for _ in specs]

0 commit comments

Comments
 (0)