Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuum normalization #231

Open
alexji opened this issue Jun 13, 2018 · 6 comments
Open

Continuum normalization #231

alexji opened this issue Jun 13, 2018 · 6 comments
Labels
analysis Spectral analysis/measurement tools fitting Issues dealing with fitting of lines (or other spectral features) modeling

Comments

@alexji
Copy link

alexji commented Jun 13, 2018

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
Copy link
Member

eteq commented Jul 17, 2018

@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
Copy link
Author

alexji commented Jul 19, 2018

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

  • Default algorithm is iterative sigma clipping to find continuum pixels.
  • Input:
    • a spectrum that needs a continuum model
    • model form/parameters (including sigma clipping parameters), selected from astropy.modeling
    • a fitter, selected from astropy.modeling
    • optional exclusion regions, which is for now a list of dispersion regions.
  • Output: a continuum model (rather than a Spectrum1D)
  • Include documentation about pre-processing e.g. with box smoothing filter, but do not implement in the generic continuum fitter.

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
Copy link

profxj commented Aug 1, 2018

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
Copy link

profxj commented Aug 2, 2018

@jessicawerk
Copy link

linetools continuumfit is indispensable in my QSO spectroscopic analyses.

@alexji
Copy link
Author

alexji commented Aug 27, 2018

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?

@nmearl nmearl added analysis Spectral analysis/measurement tools fitting Issues dealing with fitting of lines (or other spectral features) modeling labels May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Spectral analysis/measurement tools fitting Issues dealing with fitting of lines (or other spectral features) modeling
Projects
None yet
Development

No branches or pull requests

5 participants