Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
95f40d6
initial fitting structure
brechmos May 29, 2018
01e8977
added more documentation
brechmos May 29, 2018
83a91bc
fixed for rename
brechmos May 30, 2018
a215257
added first pass at fitting document
brechmos May 30, 2018
d975f2c
added documentation, small dir refactor
brechmos May 30, 2018
98659a9
fixed *two* typos in the automodapi
brechmos May 30, 2018
084dba7
fixed change in directory structure
brechmos May 30, 2018
8cc476b
added in region cutouts (excise) of spectra.
brechmos Jun 25, 2018
b20ce6a
updated api and tests
brechmos Jul 16, 2018
5a29bd5
changed name to fit_lines to match erick's notebook
brechmos Jul 16, 2018
6e237d5
udpated the continuum fitting and tests
brechmos Jul 16, 2018
dcf981f
set the tolerance
brechmos Jul 16, 2018
f14f0f9
first pass at cleanup of fitting (model and compoundmodels)
brechmos Aug 8, 2018
fa0c5f6
continuum fixes
brechmos Aug 9, 2018
52ef187
fixed for Chebyshev1D model
brechmos Aug 14, 2018
a023b4b
remove units, fit, add units back
brechmos Aug 14, 2018
8bf3ecb
works for just adding models
brechmos Aug 15, 2018
d9f4d89
works for single models, compound models with units
brechmos Aug 15, 2018
7b3f8d3
all tests confirmed based on plotting
brechmos Aug 15, 2018
d616d74
fixed for polynomial based models
brechmos Aug 17, 2018
c9b77eb
fix docstring line continuation
brechmos Aug 17, 2018
3b4597f
added fitting into index doctree
brechmos Aug 17, 2018
ffa15f4
added text re initial guess code will be added later.
brechmos Sep 4, 2018
6c37563
updates and mods based on PR comments
brechmos Sep 4, 2018
b9fe3e4
updated to changed method name
brechmos Sep 4, 2018
a8d55a2
added dynamically generated plots
brechmos Sep 4, 2018
906bef9
removed unnecesary static images
brechmos Sep 4, 2018
cdc3972
added continuum fitting
brechmos Sep 4, 2018
3273b62
more contextual words about fitting in the docs
eteq Sep 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
481 changes: 481 additions & 0 deletions docs/fitting.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Using specutils
basic_analysis
arithmetic
smoothing
fitting

.. toctree::
:maxdepth: 1
Expand Down
4 changes: 4 additions & 0 deletions specutils/fitting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import absolute_import

from .fitmodels import *
from .continuum import *
101 changes: 101 additions & 0 deletions specutils/fitting/continuum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from __future__ import division

from astropy.modeling.polynomial import Chebyshev1D
from astropy.modeling.fitting import SLSQPLSQFitter

from ..fitting import fit_lines
from ..manipulation.smoothing import median_smooth


__all__ = ['fit_continuum', 'fit_generic_continuum']


def fit_generic_continuum(spectrum, median_window=3, model=Chebyshev1D(3),
fitter=SLSQPLSQFitter(),
exclude_regions=None, weights=None):
"""
Basic fitting of the continuum of an input spectrum. The input
spectrum is smoothed using a median filter to remove the spikes.

Parameters
----------
spectrum : Spectrum1D
The spectrum object overwhich the equivalent width will be calculated.

model : list of `~astropy.modeling.Model`
The list of models that contain the initial guess.

exclude_regions : list of 2-tuples
List of regions to exclude in the fitting. Passed through
to the fitmodels routine.

weights : list (NOT IMPLEMENTED YET)
List of weights to define importance of fitting regions.

Returns
-------
continuum_spectrum : Spectrum `~specutils.Spectrum1D`
Underlying continuum based on a Chebyshev1D fit (default).

Notes
-----
* Could add functionality to set the bounds in
``model`` if they are not set.
* The models in the list of ``model`` are added together and passed as a
compound model to the `~astropy.modeling.fitting.Fitter` class instance.

"""

#
# Simple median smooth to remove spikes and peaks
#

spectrum_smoothed = median_smooth(spectrum, median_window)

#
# Return the fitted continuum
#

return fit_continuum(spectrum_smoothed, model, fitter, exclude_regions, weights)


def fit_continuum(spectrum, model=Chebyshev1D(3), fitter=SLSQPLSQFitter(),
exclude_regions=None, window=None, weights=None):
"""
Entry point for fitting using the `~astropy.modeling.fitting`
machinery.

Parameters
----------
spectrum : Spectrum1D
The spectrum object overwhich the equivalent width will be calculated.

model: list of `~astropy.modeling.Model`
The list of models that contain the initial guess.

fitmodels_type: str
String representation of fit method to use as defined by the dict fitmodels_types.

window : tuple of wavelengths (NOT IMPLEMENTED YET)
Start and end wavelengths used for fitting.

weights : list (NOT IMPLEMENTED YET)
List of weights to define importance of fitting regions.

Returns
-------
models : list of `~astropy.modeling.Model`
The list of models that contain the fitted model parmeters.

"""

if window is not None or weights is not None:
raise NotImplementedError('window and weights are not yet implemented')

#
# Fit the flux to the model.
#

continuum_spectrum = fit_lines(spectrum, model, fitter, exclude_regions, weights)

return continuum_spectrum
Loading