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

smooth continuum is drastically changing flux in some cases #128

Closed ashodkh closed 1 year ago

ashodkh commented 1 year ago

I noticed that for some spectra the smooth continuum is drastically changing the flux (incorrectly) in some cases. This seems to be around H alpha but I haven't checked. As an example, https://fastspecfit.desi.lbl.gov/target/sv3-bright-26272-39627751547735909?index=1

This is the same spectrum without the smooth continuum: Screen Shot 2023-05-01 at 5 51 10 PM

another example: https://fastspecfit.desi.lbl.gov/target/sv3-bright-26965-39627781696392988?index=1

moustakas commented 1 year ago

Thanks for the ticket @ashodkh. The smooth continuum is critical for getting good line-flux measurements, especially in the presence of broad-line emission. However, in the two examples you've highlighted, it's clear that the code isn't behaving as expected.

I'll play around with the algorithm. One idea is to switch to this new "smooth spline" implementation in scipy, but please let me know if you have any other thoughts: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.make_smoothing_spline.html

moustakas commented 1 year ago

@ashodkh I took a look at this ticket to see if there was a quick fix that wouldn't break other parts of the line-fitting (particularly the broad-line modeling).

I still think this is an important area of improvement, but in the meantime I (in a branch):

In general, these changes reduce the high-frequency smooth-continuum corrections while still being able to adapt to (low-frequency) calibration errors and spectra which are not well-fit by SPS models (i.e.g, most QSO spectra).

With these changes, here's the fit to 39627751547735909 with main and with my branch, respectively (note especially the region around Halpha). There's still lots of (statistically insignificant) funny business in the blue part of the spectrum, but the interpolation across the Ha+[NII] complex is much better behaved.

Screenshot 2023-08-16 at 3 56 12 PM Screenshot 2023-08-16 at 3 56 46 PM

Here's 39627781696392988 (before and after---note the very noisy NIR camera; it's not perfect but arguably not wrong due to a low-level mis-calibration of the camera edges, especially around [SII]).

Screenshot 2023-08-16 at 3 58 58 PM Screenshot 2023-08-16 at 4 28 29 PM

And here's one of @Ragadeepika-Pucha's low-mass AGN, as a null test to make sure that things are still reasonably well-behaved:

Screenshot 2023-08-16 at 4 33 17 PM

And finally one of @VFawcett's totally crazy red quasars. This fit was never good, but at least the code doesn't crash!

Screenshot 2023-08-16 at 4 35 19 PM

If you're happy with these changes I'll get them merged in.

ashodkh commented 1 year ago

@moustakas These look great! Thank you!

moustakas commented 1 year ago

Done in https://github.com/desihub/fastspecfit/pull/148/commits/a3093c2e51085fc6456d185aae483d7ced762ec5.