desihub / fastspecfit

Fast spectral synthesis and emission-line fitting of DESI spectra.
https://fastspecfit.readthedocs.org
BSD 3-Clause "New" or "Revised" License
13 stars 2 forks source link

RuntimeError: Problem in scipy.optimize.least_squares for targetid XX #103

Closed moustakas closed 1 year ago

moustakas commented 1 year ago

There are just 5 crashes in Iron all with a scipy.optimize.least_squares runtime error. Investigate and fix.

fastspec /global/cfs/cdirs/desi/spectro/redux/iron/healpix/main/dark/66/6642/redrock-main-dark-6642.fits --targetids 39633239580608311
fastspec /global/cfs/cdirs/desi/spectro/redux/iron/healpix/main/dark/267/26731/redrock-main-dark-26731.fits --targetids 39627576666226836
fastspec /global/cfs/cdirs/desi/spectro/redux/iron/healpix/main/dark/63/6383/redrock-main-dark-6383.fits --targetids 39633043085855316
fastspec /global/cfs/cdirs/desi/spectro/redux/iron/healpix/main/dark/218/21848/redrock-main-dark-21848.fits --targetids 39627774838704776
fastspec /global/cfs/cdirs/desi/spectro/redux/iron/healpix/main/dark/270/27054/redrock-main-dark-27054.fits --targetids 39627811564029314
moustakas commented 1 year ago

The first four crashes were the same underlying issue: high-redshift targets with a masked z-band camera, so that not even Lyman-alpha was in the wavelength range. #104 fixes this problem of not having any emission lines to optimize, during fitting and also when generating the QA plot.

The last crash (39627811564029314) was a run-of-the-mill target but because of a somewhat odd spectrum, the lower bound on two of the Balmer emission lines ended up being zero and equal to the initial value, which least_squares does not like / allow. The fix was straightforward and implemented in #104.