Skip to content

Commit

Permalink
docs: remove old defining new models section
Browse files Browse the repository at this point in the history
  • Loading branch information
fjebaker committed May 21, 2024
1 parent 90d3505 commit 9686072
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
39 changes: 0 additions & 39 deletions docs/src/models/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,6 @@ PowerLaw
BlackBody
```

### Defining new models

To define a new Julia model, we need only implement the [`AbstractSpectralModel`](@ref) interface. As a pedagogical example, consider an implementation of [`PowerLaw`](@ref):

```julia
# define the model and parameters
@with_kw struct PowerLaw{F1,F2} <: AbstractSpectralModel
"Normalisation."
K::F1 = FitParam(1.0)
"Photon index."
a::F2 = FitParam(0.5)
end

# tell the package what kind of model this is
modelkind(::Type{<:PowerLaw}) = Additive()

# define how the model acts:
# all of the parameters are passed, in order, as arguments
function SpectralFitting.invoke!(flux, energy, ::Type{<:PowerLaw}, a)
α = 1 - a
α⁻¹ = inv(α)
SpectralFitting.finite_diff_kernel!(flux, energy) do E
α⁻¹ * E^α
end
end
```

Note that each parameter has its own parametric type, here `::F1` and `::F2`. This is so that the type of fit parameters can be changed, or alternative number types inserted (see [Why & how](@ref)). The standard parameter type is [`FitParam`](@ref), which is what we have used here.

The model is defined to be additive by overloading [`modelkind`](@ref).

!!! danger
Additive models _must have_ a normalisation parameter with the symbol `K`, which is, however, _not passed_ to [`SpectralFitting.invoke!`](@ref). Multiplicative and convolutional models have no such requirements.

We have also used the [`SpectralFitting.finite_diff_kernel!`](@ref) utility function, which is designed to help us efficiently compute finite-difference integrations of flux, just as XSPEC does.

!!! note
To add additional XSPEC models, see [Wrapping new XSPEC models](@ref).

## XSPEC models

XSPEC models frequently have tabular data dependencies, without which the models fail to invoke (see [Model data availability](@ref)). If the data files are known but not present, the XSPEC models will throw an error with instructions for downloading the missing data. If the data files are unknown, Julia may crash catastrophically. If this is the case, often a single line will be printed with the LibXSPEC error, specifying the name of the missing source file. This can be registered as a data dependency of a model using [`SpectralFitting.register_model_data`](@ref).
Expand Down
3 changes: 3 additions & 0 deletions docs/src/models/using-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ domain = collect(range(0.1, 10.0, 100))
invokemodel(domain, model)
```

!!! note
To add new XSPEC or foreign function models, see [Wrapping new XSPEC models](@ref).

## Model abstraction

All spectral models are a sub-type of [`AbstractSpectralModel`](@ref).
Expand Down

0 comments on commit 9686072

Please sign in to comment.