Wrapper models

Wrapper models are a type of "meta-model" that can be used to change the behaviour of other models. Their constructors commonly take a model as an argument, and change the way this model is called.

The following wrapper models are available

SpectralFitting.ParameterPatchType
ParameterPatch(model; patch::Function)

An AbstractModelWrapper that can be used to manipulate the parameters of the model it wraps. For example

model = PowerLaw() + PowerLaw()

function patcher!(p)
    # any arbitrary function may be defined here
    p.a1.K = 3 * p.a2.K + sqrt(p.a2.a)
end

patched_model = ParameterPatch(model; patch = patcher!)

# set the patched parameter as frozen so it is not fitted
# failing to do so may ruin a fit
patched_model.a1.K.frozen = true

When the model is invoked, it will call the patch function to manipulate the parameters as desired.

Warning

This wrapper is relatively new and not extensively tested. It should be noted nothing is done to validate if a parameter that you are modifying is actually a frozen parameter. This will change in the future, and parameters patched this way will be labelled as bound.

source
SpectralFitting.apply_patch!Function
apply_patch!(model::ParameterPatch)

Apply a patch to the model (i.e. use the patch! function to update the model parameters).

source
SpectralFitting.AsConvolutionType
AsConvolution(model; domain = collect(range(0, 2, 100)))

Turn an additive model into a convolutional model.

Example

convolution_model = AsConvolution(GaussianLine())

The above model will now convolve the GaussianLine model onto whatever it is applied to.

The domain keyword can be used to pass the domain on which to evaluate the wrapped model before convolution. The domain is such that x = 1 corresponds to no domain shift in the convolution (e.g., if the domain is energy, this would be the rest energy of a line).

source
SpectralFitting.AutoCacheType
AutoCache

Used to automatically create a cache of another model, to avoid re-evaluating the model if the next parameters are close to the previous parameters. The intended use is for fitting expensive models which.

Example

model = PhotoelectricAbsorption() * AutoCache(PowerLaw())

In the above model, the PowerLaw component will be augmented with the caching behaviour.

source
SpectralFitting.AbstractModelWrapperType
abstract type AbstractModelWrapper{M,T,K} <: AbstractSpectralModel{T,K} end

Used to implement wrapper models that take existing models as their argument and modify their behaviour.

source