Inversion functions

Here are listed all the generic inversion functions that act on any type of AbstractSolver. Ideally, users should use these functions to calculate or extract the various quantities of interest from the solver objects. In doing so, it is more likely that users can then more easily switch out solvers without having to adjust other parts of their algorithm.

List of generic inversion functions

RetrievalToolbox.calculate_chi2Method
calculate_chi2(
    s::AbstractSolver
) -> Dict{AbstractSpectralWindow, Float64}

Calculates the reduced $χ^2$ statistic for the spectral fit within solver.

Details

The reduced $χ^2$ statistic is calculated as

\[χ^2 = \frac{1}{N_{\text{spec}} - N_{\text{sv}} - 1} \sum_i^{N_{\text{spec}}} \frac{M_i - O_i}{\varepsilon_i}\]

RetrievalToolbox.calculate_scale_factor_AKMethod
calculate_scale_factor_AK(
    buf::AbstractAtmosphereBuffer,
    s::AbstractSolver,
    gas::GasAbsorber,
    isrf::Dict{<:AbstractSpectralWindow, <:AbstractISRF};
    G
) -> Any

Calculates the averaging kernel profile for a gas absorber gas if that gas was retrieved through a scaling factor (GasLevelScalingFactorSVE) rather than a full profile retrieval. This function assumes that the partial derivatives of optical depths with respect to volume mixing ratios have been calculated - which should be the case if the general set-up through buffer helper functions (e.g. EarthAtmosphereBuffer(...)).

Details

(TODO: add derivation)

RetrievalToolbox.check_solver_validityMethod
check_solver_validity(s::AbstractSolver) -> Bool

Checks if the solver object s is valid, meaning that the mapping indices are not empty, the model radiances do not have any NaNs and the model Jacobians do not have any NaNs. Returns true if all of those checks pass, otherwise returns false.

This function can be used in inversions to prevent later parts of the code from failing due to NaNs being propagated into matrices etc.

RetrievalToolbox.compute_finite_difference_jacobianMethod
compute_finite_difference_jacobian(
    s::AbstractSolver,
    sve::AbstractStateVectorElement,
    Δx
) -> Tuple{Any, Any, Any}

Computes the finite-difference Jacobian for the forward model embedded in solver s. Users must supply a perturbation value Δx (must be unit-compatible with sve), such that (F(x + Δx) - F(x)) / Δx can be computed. Δx must have units. Returns F(x), F(x + Δx), [F(x + Δx) - F(x)]/Δx.

RetrievalToolbox.create_K_from_solverMethod
create_K_from_solver(s::AbstractSolver) -> Any

Turns the Jacobians from the solver object into a freshly allocated matrix, so they can be used in the inversion part of the algorithm.

RetrievalToolbox.create_Se_from_solverMethod
create_Se_from_solver(
    s::AbstractSolver;
    return_inverse
) -> Any

Creates and returns the instrument noise covariance matrix. If the optional keyword return_inverse is set to true, the inverse is returned. For now, this function only supports diagonal noise covariance matrices.

RetrievalToolbox.get_iteration_countMethod
get_iteration_count(s::AbstractSolver) -> Any

Returns the number of iterations performed in an AbstractSolver object s, and also checks if all state vector elements have the same count (as they should).

RetrievalToolbox.get_jacobianMethod
get_jacobian(
    s::AbstractSolver,
    SVE::AbstractStateVectorElement,
    swin::AbstractSpectralWindow;
    view
) -> Any

Returns the partial derivative (Jacobian) with respect to state vector element SVE, as embedded in solver s for a spectral window swin. If the optional keyword view is true, then a view on the Jacobian is returned, otherwise a copy is created and returned.

RetrievalToolbox.get_jacobianMethod
get_jacobian(
    s::AbstractSolver,
    SVE::AbstractStateVectorElement
) -> Any

Returns the partial derivative (Jacobian) with respect to state vector element SVE, as embedded in the solver s. This function does not calculate the Jacobian itself, so in order for this function to return a meaningful quantity, users must call a forward model beforehand, which implements the correct calculations and stores them in s.jacobians. This function returs a newly created vector.

See also create_K_from_solver and get_jacobian(s, SVE, swin).

RetrievalToolbox.get_measured!Method
get_measured!(measured, s)

Returns the measured radiances as of an AbstractSolver s, as seen by the full solver, meaning that all spectral windows are inserted into an existing array measured. This function does not check if measured is big enough.

RetrievalToolbox.get_measuredMethod
get_measured(
    s::AbstractSolver,
    swin::AbstractSpectralWindow;
    view
) -> Any

Returns the measured radiances of an AbstractSolver s, belonging to an AbstractSpectralWindow swin. The optional argument view determines whether to return a view onto the array (true), or a copy (false).

RetrievalToolbox.get_measuredMethod
get_measured(s::AbstractSolver) -> Any

Returns the measured radiances as of an AbstractSolver s, as seen by the full solver, meaning that all spectral windows are concatenated into one newly allocated array. This reads the contents of s.measured but mapped via the solver indices.

RetrievalToolbox.get_modeled!Method
get_modeled!(modeled::AbstractVector, s::AbstractSolver)

Returns the modeled radiance field of an AbstractSolver s for all spectral windows, and stores them into modeled, according to the solver's mapping indices. Does not check whether modeled is large enough to hold all values.

RetrievalToolbox.get_modeledMethod
get_modeled(
    s::AbstractSolver,
    swin::AbstractSpectralWindow;
    view
) -> Any

Returns the modeled radiance currently stored in the radiance field of solver s, corresponding to the spectral window swin. The optional argument view determines whether to return a view onto the array (view=true), or a copy (view=false).

RetrievalToolbox.get_modeledMethod
get_modeled(s::AbstractSolver) -> Any

Returns the modeled radiance currently stored in the radiance field of AbstractSolver s, for all spectral windows, with the ordering given by s.indices. Allocates a new vector.

RetrievalToolbox.get_noise!Method
get_noise!(noise::AbstractVector, s::AbstractSolver)

Returns the noise-equivalent radiances in AbstractSolver s, where the values for all spectral windows inside s are concatenated into the vector noise. Does not check whether noise is large enough to hold all values.

RetrievalToolbox.get_noiseMethod
get_noise(
    s::AbstractSolver,
    swin::AbstractSpectralWindow;
    view
) -> Any

Returns the noise-equivalent radiances in AbstractSolver s, belonging to spectral window swin. If view is true, a view to the vector inside s is returned, otherwise a new vector is allocated and returned.

RetrievalToolbox.get_noiseMethod
get_noise(s::AbstractSolver) -> Any

Returns the noise-equivalent radiances in AbstractSolver s, where the values for all spectral windows inside s are concatenated into a new vector and returned.

RetrievalToolbox.get_wavelengthMethod
get_wavelength(
    s::AbstractSolver,
    swin::AbstractSpectralWindow;
    view
) -> Any

Returns the wavelengths in AbstractSolver s, belonging to spectral window swin, as pointed to by the dispersion object. If view is true, a view to the vector inside s is returned, otherwise a new vector is allocated and returned. See also get_wavenumber.

RetrievalToolbox.get_wavelengthMethod
get_wavelength(s::AbstractSolver) -> Any

Returns the wavelenth vector in AbstractSolver s, where the values for all spectral windows inside s are concatenated into a new vector and returned. See also get_wavenumber.

RetrievalToolbox.print_posteriorMethod
print_posterior(s::AbstractSolver)

Print a convenient summary of the current state vector, including the associated uncertainties. Note that this function does not check for convergence.

RetrievalToolbox.print_posteriorMethod
print_posterior(q::OEQuantities)

Print a convenient summary of the current state vector, including the associated uncertainties. Note that this function does not check for convergence.