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 the box_class to the center of the model. 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 using box_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 via box_params.

In addition, the user may also easily select a single parameter of the box_class to be equal to a single parameter of the model 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 set box_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 to box_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 the model 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 the box_x parameter of the box_class will always be set equal to. If omitted, an attempt will be made to determine what the x-centering parameter is for the model.

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 see astropy.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