@@ -28,53 +28,62 @@ def fit_continuum_generic(spectrum,
28
28
spectrum : `~specutils.Spectrum1D`
29
29
The `~specutils.Spectrum1D` object to which a continuum model is fit
30
30
31
- model : `XXXX `
31
+ model : `astropy.modeling.FittableModel `
32
32
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
36
35
Default: models.Chebyshev1D(3)
36
+ TODO add a spline option (since this is not currently implemented)
37
37
38
- fitter : `XXXX `
38
+ fitter : `astropy.modeling.fitting.Fitter `
39
39
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
41
42
Default: fitting.LevMarLSQFitter()
42
43
43
44
sigma : float, optional
44
45
The number of standard deviations to use for both lower and upper clipping limit.
45
46
Defaults to 3.0
46
-
47
+
47
48
sigma_lower : float or None, optional
48
49
Number of standard deviations for lower bound clipping limit.
49
50
If None (default), then `sigma` is used.
50
-
51
+
51
52
sigma_upper : float or None, optional
52
53
Number of standard deviations for upper bound clipping limit.
53
54
If None (default), then `sigma` is used.
54
-
55
+
55
56
iters : int or None, optional
56
57
Number of iterations to perform sigma clipping.
57
58
If None, clips until convergence achieved.
58
59
Defaults to 5
59
-
60
+
60
61
exclude_regions : list of tuples, optional
61
62
A list of dispersion regions to exclude.
62
63
Each tuple must be sorted.
63
64
e.g. [(6555,6575)]
64
-
65
+
65
66
full_output : bool, optional
66
67
If True, return more information.
67
68
Currently, just the model and the pixels-used boolean array
68
-
69
+
69
70
Returns
70
71
-------
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
+
74
75
Raises
75
76
------
76
77
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
78
87
79
88
"""
80
89
@@ -95,10 +104,10 @@ def fit_continuum_generic(spectrum,
95
104
fitter = fitting .LevMarLSQFitter ()
96
105
if not isinstance (model , modeling .FittableModel ):
97
106
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
99
108
#if not isinstance(fitter, fitting.Fitter):
100
109
# raise ValueError('The model parameter must be a astropy.modeling.fitting.Fitter object')
101
-
110
+
102
111
## Get input spectrum data
103
112
x = spectrum .spectral_axis .value
104
113
y = spectrum .flux .value
@@ -118,19 +127,18 @@ def fit_continuum_generic(spectrum,
118
127
logging .info ("Iter {}: Fitting {}/{} pixels" .format (i_iter , good .sum (), len (good )))
119
128
## Fit model
120
129
## TODO include data uncertainties
121
- new_model = fitter (model , x [good ], y [good ])
130
+ continuum_model = fitter (model , x [good ], y [good ])
122
131
123
132
## Sigma clip
124
- difference = new_model (x ) - y
133
+ difference = continuum_model (x ) - y
125
134
finite = np .isfinite (difference )
126
135
sigma_difference = difference / np .std (difference [np .logical_and (good , finite )])
127
136
good [sigma_difference > sigma_upper ] = False
128
137
good [sigma_difference < - sigma_lower ] = False
129
138
130
- model = new_model
131
139
if full_output :
132
- return model , good
133
- return model
140
+ return continuum_model , good
141
+ return continuum_model
134
142
135
143
def fit_continuum_linetools (spec , edges = None , ax = None , debug = False , kind = "QSO" , ** kwargs ):
136
144
"""
0 commit comments