box_convolve¶
- sofia_redux.toolkit.fitting.fitpeaks1d.box_convolve(model, box_class, box_width=None, box_x=None, model_x=None, box_var=None, box_params=None, **kwargs)[source]¶
Convolve a model with a box (or another model)
Standard astropy models are easy to convolve (multiply). Unfortunately, during fitting we want the result of this convolution to be treated as a single model, not have the box fitted as well as the original model.
box_convolve
anchors the center of thebox_class
to the center of themodel
. All other box parameters are held constant. As a convenience,box_width
is supplied so that the user can define a fixed width to the box (which can also be defined usingbox_params
). Generally, all astropy models have a fixed amplitude of 1, so in simple cases only the width should be specified. However, if using a more complex model then additional parameters should be specified viabox_params
.In addition, the user may also easily select a single parameter of the
box_class
to be equal to a single parameter of themodel
multiplied by some scaling factor.fitpeaks1d
uses this by default to convolve a Gaussian function with a step function that will always be set to a multiple factor of the FWHM. This is incredibly useful when trying to get a good fit on a peak by only using data in range of the peaks significance; not the entire set of data which may contain artifacts that will interfere with the fit. To do this setbox_width
to (parameter, factor) of the model. For example (‘stddev’, 6) would center a box function with a width of 6 times the FWHM of a Gaussian over the original Gaussian.Note though, that box_width is simply a convenience argument. If you know what you are doing then you can tie or fix multiple parameters between the two models. Look at the code in
box_convolve
for an example or how one should use the ‘tied’, ‘bounds’, and ‘fixed’ keywords in the astropy.modeling documentation. These may be suppled tobox_convolve
via kwargs. kwargs is applied to the model at the very end of the algorithm, so anything here will override any previous logic.- Parameters:
- modelastropy.modeling.Fittable1DModel (class or instance)
model on which to apply box function
- box_classastropy.modeling.Fittable1DModel (class)
The box or model to convolve
model
with.- box_width(float or int) or (2-tuple of (str, float)), optional
If int or float, specifies the fixed width of the box. Using the 2-tuple form scales the width of the box to be equal to box_width[1] * (the parameter box_width[0]) in
model
. If set to None, the default values of the box model or those set in ‘box_params` will define a constant box width.- box_xstr, optional
Determines the
box_class
parameter to always be set equal to themodel
model_x
parameter. If omitted, an attempt will be made to determine what the x-centering parameter is for the box.- model_xstr, optional
Determines which
model
parameter that thebox_x
parameter of thebox_class
will always be set equal to. If omitted, an attempt will be made to determine what the x-centering parameter is for themodel
.- box_varstr, optional
Determines what the “width” parameter of the box is in relation to the
box_width
parameter and its uses. If omitted, an attempt will be made to determine the “width” parameter name of the box model.- box_paramsdict, optional
Used to set initial
box_class
parameters. All parameters set here will be fixed unless overriden by other keyword options. Please seeastropy.modeling.models
for a list of keywords that can be supplied.- kwargsdict, optional
keyword values to be applied that will override everything else. keys should be the name of the output model attributes and values should be the values you wish to set. Dictionaries are applied recursively.
- Returns:
- resultinstance of astropy.modeling.Fittable1DModel
The resulting
model
* box_model