Modeling with non-analytic Fourier transforms

using VLBISkyModels


using CairoMakie
  Activating project at `~/work/VLBISkyModels.jl/VLBISkyModels.jl/examples`

While most of the models implemented in VLBISkyModels have an analytic Fourier transform this is not required. In this notebook we will describe how a user can do Bayesian model fitting with a non-analytic model.

The ExtendedRing model is an example of a non-analytic model. The image structure is given by

\[I(r) = \frac{\beta^\alpha}{2\pi \Gamma(\alpha)} r^{-\alpha-2}e^{-\beta/r}\]

This can be created as follows

m = ExtendedRing(8.0)
ExtendedRing{Float64}(8.0)

The argument is \alpha in the above equation. beta is given by $(1+\alpha)$.

This model does not have a simple analytic Fourier transform, e.g.

VLBISkyModels.visanalytic(ExtendedRing)
ComradeBase.NotAnalytic()

Therefore, to find the Fourier transform of the image we need to revert to numerical methods. For this notebook we will use the fast Fourier transform or FFT. Specifically we will use FFTW. To compute a numerical Fourier transform we first need to specify the image domain

gim = imagepixels(10.0, 10.0, 256, 256)
RectiGrid(
executor: Serial()
Dimensions: 
(↓ X Sampled{Float64} LinRange{Float64}(-4.98046875, 4.98046875, 256) ForwardOrdered Regular Points,
→ Y Sampled{Float64} LinRange{Float64}(-4.98046875, 4.98046875, 256) ForwardOrdered Regular Points)
)

Second we need to specify the list of points in the uv domain we are interested in. Since VLBI tends sparsely sample the UV plan we provide a specific type for this type called UnstructuredDomain that can be used to specify the UV points,

u = randn(1000) / 2
v = randn(1000) / 2
guv = UnstructuredDomain((U=u, V=v))
UnstructredDomain(
executor: Serial()
Dimensions: 
1000-element StructArray(::Vector{Float64}, ::Vector{Float64}) with eltype @NamedTuple{U::Float64, V::Float64}:
 (U = 0.8431157056577325, V = 0.14283598674570494)
 (U = 0.19847076493875845, V = -0.5929319219686562)
 (U = -0.44301378256594254, V = 0.09295968598299885)
 (U = -0.06941120681187396, V = -0.24550261191791847)
 (U = 0.13445524947933213, V = 0.6709571595112053)
 (U = 0.834875473067222, V = 0.36022473541440425)
 (U = 1.0893755365050977, V = 0.6500202690828596)
 (U = 0.06745794965694152, V = -0.008336624453304424)
 (U = -0.15851141818272063, V = 0.4277448283617935)
 (U = -0.3712202622561482, V = -0.33631690031778405)
 ⋮
 (U = -0.051968712273406055, V = -0.15197665904816582)
 (U = -0.7018296205875453, V = -0.1884314443506616)
 (U = 0.314121735172335, V = 0.2835944164874998)
 (U = -0.029667776743551318, V = 1.2669302771362236)
 (U = -0.9961526728835518, V = 1.0585141297600114)
 (U = 0.5354043061509292, V = -0.5836540646074047)
 (U = -0.2520739815361669, V = 0.03244413673463663)
 (U = -0.06454032693136638, V = 0.810917215793429)
 (U = 0.3755711629045757, V = 0.03942431783260867)
)

We can now create a dual domain that contains both the image and the UV points and the specific Fourier transform algorithm we want to use. The options for algorithms are:

  1. NFFTAlg: Uses the Non-Uniform Fast Fourier Transform. Fast and accurate, this is the recommended algorithm for most cases.
  2. DFTAlg: Uses the Discrete Time Non-Uniform Fourier transform. Slow but exact, so only use for small image grids.
  3. FFTAlg: Moderately fast and moderately accurate. Typically only used internally for testing.

For this example we will use NFFTAlg since it is the recommended algorithm for most cases.

gfour = FourierDualDomain(gim, guv, NFFTAlg())
FourierDualDomain(
Algorithm: NFFTAlg{Float64, AbstractNFFTs.PrecomputeFlags, UInt32}(1, 1.0e-9, AbstractNFFTs.TENSOR, 0x00000000)
Image Domain: RectiGrid(
executor: Serial()
Dimensions: 
(↓ X Sampled{Float64} LinRange{Float64}(-4.98046875, 4.98046875, 256) ForwardOrdered Regular Points,
→ Y Sampled{Float64} LinRange{Float64}(-4.98046875, 4.98046875, 256) ForwardOrdered Regular Points)
)
Visibility Domain: UnstructredDomain(
executor: Serial()
Dimensions: 
1000-element StructArray(::Vector{Float64}, ::Vector{Float64}) with eltype @NamedTuple{U::Float64, V::Float64}:
 (U = 0.8431157056577325, V = 0.14283598674570494)
 (U = 0.19847076493875845, V = -0.5929319219686562)
 (U = -0.44301378256594254, V = 0.09295968598299885)
 (U = -0.06941120681187396, V = -0.24550261191791847)
 (U = 0.13445524947933213, V = 0.6709571595112053)
 (U = 0.834875473067222, V = 0.36022473541440425)
 (U = 1.0893755365050977, V = 0.6500202690828596)
 (U = 0.06745794965694152, V = -0.008336624453304424)
 (U = -0.15851141818272063, V = 0.4277448283617935)
 (U = -0.3712202622561482, V = -0.33631690031778405)
 ⋮
 (U = -0.051968712273406055, V = -0.15197665904816582)
 (U = -0.7018296205875453, V = -0.1884314443506616)
 (U = 0.314121735172335, V = 0.2835944164874998)
 (U = -0.029667776743551318, V = 1.2669302771362236)
 (U = -0.9961526728835518, V = 1.0585141297600114)
 (U = 0.5354043061509292, V = -0.5836540646074047)
 (U = -0.2520739815361669, V = 0.03244413673463663)
 (U = -0.06454032693136638, V = 0.810917215793429)
 (U = 0.3755711629045757, V = 0.03942431783260867)
)

Given this FourierDualDomain everything now works as before with analytic models. For example we can compute the intensitymap of the model as

img = intensitymap(m, gfour)
imageviz(img)
Example block output

and the visibility map using

vis = visibilitymap(m, gfour)
fig, ax = scatter(hypot.(vis.U, vis.V), real.(vis); label="Real")
scatter!(ax, hypot.(vis.U, vis.V), imag.(vis); label="Imag")
axislegend(ax)
ax.xlabel = "uv-dist"
ax.ylabel = "Flux"
fig
Example block output

Additionally, you can also modify the models and add them in complete generality. For example

mmod = modify(m, Shift(2.0, 2.0)) + Gaussian()
mimg = intensitymap(mmod, gfour)
mvis = visibilitymap(mmod, gfour)
1000-element UnstructuredMap{ComplexF64, Vector{ComplexF64}, UnstructuredDomain{StructArrays.StructVector{@NamedTuple{U::Float64, V::Float64}, @NamedTuple{U::Vector{Float64}, V::Vector{Float64}}, Int64}, Serial, ComradeBase.NoHeader}}:
 -0.020767821001988908 + 0.004019684811927233im
 -0.034195957951444235 - 0.13924755476270084im
   0.06397708670360676 - 0.14358384640069788im
   0.10751788290212441 + 0.18087636738796461im
   0.08525616378526238 + 0.07168643546135955im
 0.0011640586724056255 - 0.0009833394335203069im
  -0.02477580519538743 + 0.0033235250057027325im
    1.5872122700522548 + 0.6173914913210382im
   0.16541388050922345 + 0.03695087627544057im
    0.1544675229655087 + 0.08701154475772811im
                       ⋮
   0.09170820453855999 - 0.3331987021649405im
   -0.0166763015021037 - 0.08485976915808581im
 -0.013660842349588045 - 0.11989597066855237im
 -0.024352904185317603 + 0.003963840372746247im
  0.007891024450368433 + 0.007866242745839715im
  -0.04153634119162859 + 0.028799979866472595im
  0.046442183909729595 - 0.09234648882724159im
   0.03942004891445555 - 0.0021806740468891172im
  0.026822611206553007 + 0.05796201868850386im

Plotting everything gives

fig = Figure(; size=(800, 400))
ax1 = Axis(fig[1, 1]; xreversed=true, xlabel="RA (radians)", ylabel="Dec (radians)",
           aspect=1)
ax2 = Axis(fig[1, 2]; xlabel="uv-dist", ylabel="Amplitude")
image!(ax1, mimg; colormap=:afmhot)
scatter!(ax2, hypot.(mvis.U, mvis.V), abs.(mvis); label="Real")
fig
Example block output

This page was generated using Literate.jl.