Imaging (+ Modeling)

Hybrid model + image reconstruction: a parametric model handles compact/unresolved components while an image captures the extended emission.

FunctionDescription
reconstruct_hybrid(x0, params, model, data, ft)Alternating image VMLMB + parameter NelderMead
reconstruct_sparco_flat(x0, params, model, data, ft)Joint VMLMB over params + image (legacy)
model_and_image_to_chi2_fg(model, params, image, g_image, ft, data)Hybrid model+image chi² + gradient (mono or poly)
cvis_to_chi2_f(V, data)Chi² from complex visibilities (value only)
cvis_to_chi2_noalloc(V, data)Chi² alone, allocation-free — for inner sampler loops
cvis_to_chi2_fg(V, data)Chi² + complex adjoint source from complex visibilities (building block)
OITOOLS.reconstruct_hybridFunction
reconstruct_hybrid(x_start, params_start, model, data, ft;
                          w_name="W", regularizers=[], weights=[1,1,1],
                          maxiter=200, rounds=5, verb=false, vonmises=false,
                          params_lower=nothing, params_upper=nothing, ...)

SPARCO image reconstruction using a flat-model parametric component.

Alternates between:

  1. Image VMLMB: optimize image pixels with parameters fixed, using model_and_image_to_chi2_fg + regularization.
  2. Parameter NelderMead: optimize model parameters with the image fixed, using optimize_sparco_flat_parameters.

This separation avoids the scale-mismatch problem of jointly optimizing parameters and image pixels in a single VMLMB run.

Returns (params_final, x_final).

source
OITOOLS.model_and_image_to_chi2_fgFunction
model_and_image_to_chi2_fg(model, x_params, image, g_image, ft, data::OIdata;
                            w_name=nothing, weights=[1,1,1], verb=false, vonmises=false)

Hybrid chi2+gradient combining a parametric model with an image (monochromatic).

When w_name is provided, the image weight W(λ) is evaluated from the named model output and V_total = V_model + W(λ) · V_image.

When w_name is nothing, uses the SPARCO flux convention: V_total = (1 - V_model(0,0)) · V_image + V_model.

Mutates g_image in-place. Returns (chi2, g_params).

source
model_and_image_to_chi2_fg(model, x_params, image, g_image, ft, data::Vector{<:OIdata};
                            w_name="W", weights=[1,1,1,0,0,0,0], verb=false, vonmises=false)

Polychromatic hybrid chi2+gradient for a parametric model + power-law grey image.

A single grey image is modulated by W(λ) at each wavelength channel, following the SPARCO convention: V_total(λ) = V_model(λ) + W(λ) · V_image.

Mutates g_image in-place. Returns (chi2, g_params).

source
OITOOLS.cvis_to_chi2_fFunction
cvis_to_chi2_f(V, data; weights=[1,1,1,0,0,0,0], vonmises=false, model_flux=NaN) -> chi2

Chi-squared from complex visibilities V and interferometric data data, without the gradient.

Handles the same per-channel observables as cvis_to_chi2_fg — V², T3amp, T3phi, visamp, visphi — and additionally the flux term: pass the model's zero-baseline flux as model_flux and give weights[6] > 0. (cvis_to_chi2_fg cannot do this, because the flux gradient needs the model Jacobian at zero baseline, which is not derivable from V alone.)

Precision follows the inputs: ComplexF32 visibilities against an OIdata{Float32} return a Float32 chi². Accumulation is via sum, which is pairwise, so Float32 holds ~1e-8 relative accuracy even for millions of residuals.

source
OITOOLS.cvis_to_chi2_fgFunction
cvis_to_chi2_fg(V, data; weights=[1,1,1,0,0,0,0], vonmises=false) -> (chi2, g_cvis)

Compute chi-squared and the complex adjoint source g_cvis from complex visibilities V and interferometric data data.

This is the core building block for all gradient-based chi² code paths (model fitting, image reconstruction, SPARCO, hybrid model+image). It handles per-channel observables: V², T3amp, T3phi, visamp, visphi. It does not handle flux or differential phase (cross-channel observables).

Precision follows the inputs rather than being forced: ComplexF32 visibilities against an OIdata{Float32} return a Float32 chi² and a Vector{ComplexF32} adjoint source, so a Float32 pipeline stays in Float32 end to end. See cvis_to_chi2_f if you do not need the gradient.

The adjoint source g_cvis satisfies:

  • g_params = real(Jᵀ · g_cvis) for any model Jacobian J
  • g_image = real(DFTᵀ · g_cvis) for DFT image reconstruction
  • g_image = real(NFFT^H · conj(g_cvis)) for NFFT image reconstruction
source
OITOOLS.cvis_to_chi2_noallocFunction
cvis_to_chi2_noalloc(V, data; weights=[1,1,1,0,0,0,0], vonmises=false)

Weighted chi2 of model complex visibilities V against data, computed without allocating.

Returns the same value as cvis_to_chi2_f (and as cvis_to_chi2_fg(V, data; weights, vonmises)[1]) to round-off, but fuses every observable into a single pass with no gathered temporaries. Intended for inner sampler loops that evaluate chi2 millions of times — see reconstruct_squeeze. Prefer cvis_to_chi2_f for ordinary use: it is clearer and additionally handles the flux term (weights[6]), which this does not.

source