<p>I'm fitting Gaussians to optical lines spanning from H-beta to Sulfur using Astropy's Gaussian (<a href="https://docs.astropy.org/en/latest/api/astropy.modeling.functional_models.Gaussian1D.html" rel="nofollow noreferrer">https://docs.astropy.org/en/latest/api/astropy.modeling.functional_models.Gaussian1D.html</a>) model with a LevMarLSQFitter (<a href="https://docs.astropy.org/en/stable/api/astropy.modeling.fitting.LinearLSQFitter.html" rel="nofollow noreferrer">https://docs.astropy.org/en/stable/api/astropy.modeling.fitting.LinearLSQFitter.html</a>). My goal is to perform strong line diagnostics on my target of interest.</p>
<p>I plot the fits on top of the data and am returned the nominal values and standard deviations of the fit. Everything looks reasonable (I know the data quality is less than ideal); however, the standard deviations for the sulfur lines are consistently several times larger than the nominal value. This issue occurs for the two sulfur lines in every fiber (IFU data).</p>
<p>I’ve tried limiting the spectral region given to the fitter, not limiting it, and fitting a double line simultaneously (as opposed to fitting the two S lines individually), but I still have the same issue. ie. I either get inf, none, or a huge value for the STD. I don’t think this data is high quality enough to completely reinvent what I’m doing, but I still want to report something reasonable until better data is accessible.</p>
<p>Attached is sample of the data and the fit on top. As you can see, the fit to the sulfur lines are reasonable. I'm looking for suggestions on how to compute an error on these fits and am open to suggestions.</p>
<p>The S lines can be seen on the right hand side. They are the last two on the right (around 6766-6785 Angstroms).</p>
<p><a href="https://i.sstatic.net/3IpOQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3IpOQ.png" alt="Optical spectra data (black) with gaussian fits (colored)" /></a></p>

CC BY-SA 4.0
2023-08-14T18:40:07.020Z
I can't see what the problem is. The lines appear to be barely significant, if at all in the case of the 6785A line. You should expect enormous error bars in such cases. Can you clarify what you are trying to find the uncertainty in?
ProfRob
CC BY-SA 4.0
2023-08-14T18:43:02.090Z
@ProfRob I'm getting better quality data in a few months. I'm wondering if I should just wave the white flag with this data set. You're suggesting the S lines are too poor SN to be useful? This is my first reduction of optical IFU data.

I'm trying to get an uncertainty on the fitted lines. I am able to with H-Beta, Oxygen, H-alpha, and Nitrogen, but the fitter blows up for the S lines. Ie. it fits the lines, but I cannot get a STD from the fitter.
Astroturf
CC BY-SA 4.0
2023-08-14T18:57:34.713Z
Uncertainty in all parameters. The amplitude, mean, and standard deviation of the gaussian. For example, this is how it's supposed to be reported:  g_fit_208_Ha
Out[114]: <Gaussian1D(amplitude=4.16793993 Jy2, mean=6612.21805333 Angstrom, stddev=2.09704864 Angstrom)>

g_fit_208_Ha.stds
Out[115]: 
standard deviations
amplitude| 0.21
mean     | 0.122
stddev   | 0.122

The issue is STDs for the S lines are either none, inf, or above 100%.
Astroturf
CC BY-SA 4.0
2023-08-14T19:17:38.243Z
You are not going to be able to get uncertainty on three parameters with that quality of data. The fits are telling you that the lines could be any width. I think even if you fix the line centre you will still get garbage (but you could try).
ProfRob
CC BY-SA 4.0
2023-08-14T22:37:57.990Z
Bootstrap resampling? (I agree that the quality of the S lines is terrible.)
Peter Erwin
CC BY-SA 4.0
2023-08-15T13:34:06.487Z
If your goal is testing your software, create reasonable synthetic data, with a S/N ratio similar to what you actually expect to get, and use that.
Jon Custer
CC BY-SA 4.0
2023-08-15T21:52:51.033Z
JonCuster's suggestion is spot-on. It's an extremely instructive and absolutely standard thing to do. Generate say 10,000 or more artificial spectra with the same peak parameters but different (but equivalent S/N) random noise contributions and run your fitting routine on all of them. Then histogram the returned values for each parameter, and make correlating scatter plots for each possible pair. The results will surprise you and you may likely raise that white flag for now. Repeat again for the expected S/N of the "better quality data" you plan to get "in a few months" to manage expectations
uhoh
<observational-astronomy><data-analysis><spectroscopy><python><astropy>
How can I compute reasonable errors on my Gaussian fits to the observed strong optical lines of interest?
Astroturf
# How can I compute reasonable errors on my Gaussian fits to the observed strong optical lines of interest?

(Asked by: username_0 on 2023-08-14)

I'm fitting Gaussians to optical lines spanning from H-beta to Sulfur using Astropy's Gaussian (<https://docs.astropy.org/en/latest/api/astropy.modeling.functional_models.Gaussian1D.html>) model with a LevMarLSQFitter (<https://docs.astropy.org/en/stable/api/astropy.modeling.fitting.LinearLSQFitter.html>). My goal is to perform strong line diagnostics on my target of interest.

I plot the fits on top of the data and am returned the nominal values and standard deviations of the fit. Everything looks reasonable (I know the data quality is less than ideal); however, the standard deviations for the sulfur lines are consistently several times larger than the nominal value. This issue occurs for the two sulfur lines in every fiber (IFU data).

I’ve tried limiting the spectral region given to the fitter, not limiting it, and fitting a double line simultaneously (as opposed to fitting the two S lines individually), but I still have the same issue. ie. I either get inf, none, or a huge value for the STD. I don’t think this data is high quality enough to completely reinvent what I’m doing, but I still want to report something reasonable until better data is accessible.

Attached is sample of the data and the fit on top. As you can see, the fit to the sulfur lines are reasonable. I'm looking for suggestions on how to compute an error on these fits and am open to suggestions.

The S lines can be seen on the right hand side. They are the last two on the right (around 6766-6785 Angstroms).

[![Optical spectra data (black) with gaussian fits (colored)](https://i.sstatic.net/3IpOQ.png)](https://i.sstatic.net/3IpOQ.png)

**Tags:** observational-astronomy, data-analysis, spectroscopy, python, astropy
> **Comments:**
> **username_1**: I can't see what the problem is. The lines appear to be barely significant, if at all in the case of the 6785A line. You should expect enormous error bars in such cases. Can you clarify what you are trying to find the uncertainty in?  
> **username_0**: @ProfRob I'm getting better quality data in a few months. I'm wondering if I should just wave the white flag with this data set. You're suggesting the S lines are too poor SN to be useful? This is my first reduction of optical IFU data.  I'm trying to get an uncertainty on the fitted lines. I am able to with H-Beta, Oxygen, H-alpha, and Nitrogen, but the fitter blows up for the S lines. Ie. it fits the lines, but I cannot get a STD from the fitter.  
> **username_0**: Uncertainty in all parameters. The amplitude, mean, and standard deviation of the gaussian. For example, this is how it's supposed to be reported:  g_fit_208_Ha Out[114]: <Gaussian1D(amplitude=4.16793993 Jy2, mean=6612.21805333 Angstrom, stddev=2.09704864 Angstrom)>  g_fit_208_Ha.stds Out[115]:  standard deviations amplitude| 0.21 mean     | 0.122 stddev   | 0.122  The issue is STDs for the S lines are either none, inf, or above 100%.  
> **username_1**: You are not going to be able to get uncertainty on three parameters with that quality of data. The fits are telling you that the lines could be any width. I think even if you fix the line centre you will still get garbage (but you could try).  
> **username_2**: Bootstrap resampling? (I agree that the quality of the S lines is terrible.)  
> **username_3**: If your goal is testing your software, create reasonable synthetic data, with a S/N ratio similar to what you actually expect to get, and use that.  
> **username_4**: JonCuster's suggestion is spot-on. It's an extremely instructive and absolutely standard thing to do. Generate say 10,000 or more artificial spectra with the same peak parameters but different (but equivalent S/N) random noise contributions and run your fitting routine on all of them. Then histogram the returned values for each parameter, and make correlating scatter plots for each possible pair. The results will surprise you and you may likely raise that white flag for now. Repeat again for the expected S/N of the "better quality data" you plan to get "in a few months" to manage expectations  

---

## 0 answers

