-
-
Couldn't load subscription status.
- Fork 132
Fitting of Spectrum1D #210
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
95f40d6
initial fitting structure
brechmos 01e8977
added more documentation
brechmos 83a91bc
fixed for rename
brechmos a215257
added first pass at fitting document
brechmos d975f2c
added documentation, small dir refactor
brechmos 98659a9
fixed *two* typos in the automodapi
brechmos 084dba7
fixed change in directory structure
brechmos 8cc476b
added in region cutouts (excise) of spectra.
brechmos b20ce6a
updated api and tests
brechmos 5a29bd5
changed name to fit_lines to match erick's notebook
brechmos 6e237d5
udpated the continuum fitting and tests
brechmos dcf981f
set the tolerance
brechmos f14f0f9
first pass at cleanup of fitting (model and compoundmodels)
brechmos fa0c5f6
continuum fixes
brechmos 52ef187
fixed for Chebyshev1D model
brechmos a023b4b
remove units, fit, add units back
brechmos 8bf3ecb
works for just adding models
brechmos d9f4d89
works for single models, compound models with units
brechmos 7b3f8d3
all tests confirmed based on plotting
brechmos d616d74
fixed for polynomial based models
brechmos c9b77eb
fix docstring line continuation
brechmos 3b4597f
added fitting into index doctree
brechmos ffa15f4
added text re initial guess code will be added later.
brechmos 6c37563
updates and mods based on PR comments
brechmos b9fe3e4
updated to changed method name
brechmos a8d55a2
added dynamically generated plots
brechmos 906bef9
removed unnecesary static images
brechmos cdc3972
added continuum fitting
brechmos 3273b62
more contextual words about fitting in the docs
eteq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ Using specutils | |
| basic_analysis | ||
| arithmetic | ||
| smoothing | ||
| fitting | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.