astropy / astropy/specutils

Using estimate_line_parameters with Spectrum1D to provide starting estimates of parameters of a Gaussian1D

Open
#700 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
204
Forks
134
Avg merge
12h 55m
Merged PRs (30d)
1

Description

I am running the "simple example" from specutils to do some line-fitting.

The demo code is here:

https://specutils.readthedocs.io/en/stable/fitting.html

This runs and does what it says.

However I want to use parameter estimation to get an approximation to the initial parameters in the Gaussian, because I am interested in looking at a number of long spectra with a lot of lines in and want to attempt initial fits automatically.

So I modify the specutils.fitting import to

from specutils.fitting import fit_lines, estimate_line_parameters

and add in

e1 = estimate_line_parameters(spectrum, models.Gaussian1D())
a = round(e1.amplitude.value,2)
b = round(e1.fwhm.value,2)
c = round(e1.stddev.value,2)

This gives meaningful values and I replace the call to the Gaussian by:

g_init = models.Gaussian1D(amplitude=a*u.Jy, mean=b*u.um, stddev=c*u.um)

then

g_fit = fit_lines(spectrum, g_init)
y_fit = g_fit(x*u.um)

The initial values I get from the estimator are:

initial amplitude= 3.35 initial fwhm = 2.41 initial stddev= 1.02

But on looking at the output parameters using g_fit.amplitude.value etc, I get:

final amplitude= -0.24 Jy final fwhm = 0.0 um final stddev= 0.0 um

for the output values!! If the estimated parameters are correct then the output values should be very close.

Is there an issue in using estimation like this. I can't see that it is forbidden in the documentation or understand why not. If there is an issue what is it - and how to resolve it?

NOTE: If I replace the parameters in g_init with the values given in the example I then get:

initial amplitude= 3.35 initial fwhm = 2.41 initial stddev= 1.02
final amplitude= 3.0471 Jy final fwhm = 1.9157 um final stddev= 0.8135 um

which agrees with what you would expect from the curve plotted in the example.

FWIW I am running Jupyter Notebook, matplotlib 3.2.2, specutils 1.0, numpy 1.19, python 3.6 all over Ubuntu 19.10

Contributor guide

Open the contributing guide

Research direction

Start with the fitting documentation example and reproduce the reported values in a Jupyter Notebook using estimate_line_parameters, Gaussian1D, and fit_lines. Compare the estimator's amplitude, fwhm, and stddev with the parameters passed to the fitted model. Done means identifying why the estimated initialization produces zero or negative fitted values and documenting or correcting the supported usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.