astropy / specutils

An Astropy coordinated package for astronomical spectroscopy. Maintainers: @rosteen @keflavich @eteq
http://specutils.readthedocs.io/en/latest/
167 stars 127 forks source link

Continuum normalization #231

Open alexji opened 6 years ago

alexji commented 6 years ago

The project board suggests that a continuum fitting routine is desired. This issue is intended to start a discussion about what functionality and interface would make sense, and I'm happy to implement what we decide on.

@andycasey and I have routine at this link that finds a continuum with iterative sigma clipping. It's meant to be used interactively, but could be ported over.

eteq commented 6 years ago

@alexji - thanks for this - just noticed it now! Can you have a look at the "step 0" in this notebook: https://github.com/spacetelescope/dat_pyinthesky/blob/master/pyinthesky_specutils_fitting.ipynb ?

Do you think that broad "user interface" at least works with the way you're doing to compute continua? The key idea is to separate out the "defining the continuum" step from the subtracting or dividing step, because later analysis tasks sometimes want one or the other (e.g., equivalent width is most naturally done on a continuum-normalized spectrum, signal-to-noise on a raw spectrum, or flux measurements on a continuum-subtracted spectrum). So by storing the continuum model separately and using it on demand the thought is that this will make all that more flexible.

alexji commented 6 years ago

Yeah, that definitely works! Here's what I will implement for fit_continuum_generic:

Let me know if something seems off.

One thing is that looking at astropy.modeling, I don't seem to see 1D splines; did I miss that? If those are not in astropy right now, I will include a temporary option to use scipy fitting.

Regarding tests, I will use spectra of metal-poor stars as a test to start. It might be good to have some other things uploaded to e.g. specutils/specutils/tests/data.

profxj commented 6 years ago

you are encouraged to examine the well tested and used algorithm in linetools:

https://github.com/linetools/linetools/blob/master/linetools/analysis/continuum.py

best to avoid re-inventing the wheel yet again..

profxj commented 6 years ago

And see for the GUI:

http://linetools.readthedocs.io/en/latest/guis.html#continuum-fitting

jessicawerk commented 6 years ago

linetools continuumfit is indispensable in my QSO spectroscopic analyses.

alexji commented 6 years ago

In the above PR, I implemented a bare-bones continuum fitter satisfying the "step 0" interface, and a direct port of @profxj's fitter (i.e. fitting through an Akima spline through iteratively chosen knots).

@eteq I was looking for a spline-like model in astropy, and I couldn't find anything. Does it make sense to define an astropy model that has no parameters and is not fittable, but just calls a pre-computed function on the data?

Or if being fancier, is there a way to implement spline-like models and fitters in the astropy framework?