Skip to content

Commit 5640b7b

Browse files
committed
Documentation and variable name fixes
1 parent 17ab4c3 commit 5640b7b

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

specutils/manipulation/continuum.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,53 +28,62 @@ def fit_continuum_generic(spectrum,
2828
spectrum : `~specutils.Spectrum1D`
2929
The `~specutils.Spectrum1D` object to which a continuum model is fit
3030
31-
model : `XXXX`
31+
model : `astropy.modeling.FittableModel`
3232
The type of model to use for the continuum.
33-
astropy.modeling.models
34-
Must either be astropy.modeling.Fittable1DModel
35-
or the string "spline" (since this is not currently implemented)
33+
Must be astropy.modeling.FittableModel
34+
See astropy.modeling.models
3635
Default: models.Chebyshev1D(3)
36+
TODO add a spline option (since this is not currently implemented)
3737
38-
fitter : `XXXX`
38+
fitter : `astropy.modeling.fitting.Fitter`
3939
The type of fitter to use for the continuum.
40-
astropy.modeling.fitting
40+
See astropy.modeling.fitting for valid choices
41+
TODO currently does not typecheck because fitters do not subclass fitting.Fitter
4142
Default: fitting.LevMarLSQFitter()
4243
4344
sigma : float, optional
4445
The number of standard deviations to use for both lower and upper clipping limit.
4546
Defaults to 3.0
46-
47+
4748
sigma_lower : float or None, optional
4849
Number of standard deviations for lower bound clipping limit.
4950
If None (default), then `sigma` is used.
50-
51+
5152
sigma_upper : float or None, optional
5253
Number of standard deviations for upper bound clipping limit.
5354
If None (default), then `sigma` is used.
54-
55+
5556
iters : int or None, optional
5657
Number of iterations to perform sigma clipping.
5758
If None, clips until convergence achieved.
5859
Defaults to 5
59-
60+
6061
exclude_regions : list of tuples, optional
6162
A list of dispersion regions to exclude.
6263
Each tuple must be sorted.
6364
e.g. [(6555,6575)]
64-
65+
6566
full_output : bool, optional
6667
If True, return more information.
6768
Currently, just the model and the pixels-used boolean array
68-
69+
6970
Returns
7071
-------
71-
continuum_model : `XXXX`
72-
Output `XXXX` which is a model for the continuum
73-
72+
continuum_model : `astropy.modeling.FittableModel`
73+
Output a model for the continuum
74+
7475
Raises
7576
------
7677
ValueError
77-
In the case that ``spectrum`` .... is not the correct type
78+
If: spectrum is not the correct type,
79+
the exclude regions do not satisfy a list of sorted tuples,
80+
the model and/or fitter are of the wrong type,
81+
82+
Examples
83+
--------
84+
TODO add more and unit tests
85+
86+
See https://github.com/spacetelescope/dat_pyinthesky/blob/master/pyinthesky_specutils_fitting.ipynb
7887
7988
"""
8089

@@ -95,10 +104,10 @@ def fit_continuum_generic(spectrum,
95104
fitter = fitting.LevMarLSQFitter()
96105
if not isinstance(model, modeling.FittableModel):
97106
raise ValueError('The model parameter must be a astropy.modeling.FittableModel object')
98-
## TODO this is waiting on a refactor in fitting to work
107+
## TODO this is waiting on a refactor in modeling.fitting to work
99108
#if not isinstance(fitter, fitting.Fitter):
100109
# raise ValueError('The model parameter must be a astropy.modeling.fitting.Fitter object')
101-
110+
102111
## Get input spectrum data
103112
x = spectrum.spectral_axis.value
104113
y = spectrum.flux.value
@@ -118,19 +127,18 @@ def fit_continuum_generic(spectrum,
118127
logging.info("Iter {}: Fitting {}/{} pixels".format(i_iter, good.sum(), len(good)))
119128
## Fit model
120129
## TODO include data uncertainties
121-
new_model = fitter(model, x[good], y[good])
130+
continuum_model = fitter(model, x[good], y[good])
122131

123132
## Sigma clip
124-
difference = new_model(x) - y
133+
difference = continuum_model(x) - y
125134
finite = np.isfinite(difference)
126135
sigma_difference = difference / np.std(difference[np.logical_and(good, finite)])
127136
good[sigma_difference > sigma_upper] = False
128137
good[sigma_difference < -sigma_lower] = False
129138

130-
model = new_model
131139
if full_output:
132-
return model, good
133-
return model
140+
return continuum_model, good
141+
return continuum_model
134142

135143
def fit_continuum_linetools(spec, edges=None, ax=None, debug=False, kind="QSO", **kwargs):
136144
"""

0 commit comments

Comments
 (0)