Misc

IndexFunArrays.normalFunction
normal([T=Float64], size::NTuple{N, Int};
    offset=CtrFT,
    sigma=1.0,
    scale=ScaUnit,
    weight=1,
    accumulator=sum)

A gaussian peak positioned at offset. Note that this normal distribution (Gaussian) is normalized by its integral. For a version with normalized to the maximum, see gaussian.

Arguments:

  • sigma: the (standard deviation) width of the Gaussian
  • offset: the center position of the Gaussian. You can use a tuple or the indicators CtrCorner, CtrEnd, CtrFT, CtrRFT etc.
  • scale: the scale of the pixel. By default ScaUnit is assumed
  • weight: the strength of the result. Supports list-mode (see rr2 for documentation)
  • accumulator: the method used for superimposing list-mode data. Only applies in list-mode
julia> normal((5,5))
5×5 IndexFunArray{Float64, 2, IndexFunArrays.var"#107#109"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}}}:
 0.00291502  0.0130642  0.0215393  0.0130642  0.00291502
 0.0130642   0.0585498  0.0965324  0.0585498  0.0130642
 0.0215393   0.0965324  0.159155   0.0965324  0.0215393
 0.0130642   0.0585498  0.0965324  0.0585498  0.0130642
 0.00291502  0.0130642  0.0215393  0.0130642  0.00291502

julia> sum(normal((5,5)))
 0.9818147610543744

julia> sum(normal((25,25)))
 1.000000010701151

julia> sum(normal((55,55), sigma=(5.0,2.0)))
0.9999999639340563

normal(arr::AbstractArray; offset=CtrFt, sigma=1.0, scaling=ScaUnit)

This is a wrapper for normal(eltype(arr), size(arr), sigma=sigma, scaling=scaling, offset=offset).

source
IndexFunArrays.gaussianFunction
gaussian([T=Float64], size::NTuple{N, Int};
    offset=CtrFT,
    sigma=1.0,
    dims=ntuple(+, N),
    scale=ScaUnit,
    weight=1,
    accumulator=sum)

A gaussian peak positioned at offset. Note that the gaussian is NOT normalized by its integral, but by its maximum. For a version with a normalized integral, see normal. List-mode is supported also for the argument sigma. See the final example below which generates 60 Gaussians at random positions with random strengths and width along X and Y.

Arguments:

  • sigma: the (standard deviation) width of the Gaussian. If a tuple is supplied, each entry is interpreted as the width along the correspondin dimension.
  • offset: the center position of the Gaussian. You can use a tuple or the indicators CtrCorner, CtrEnd, CtrFT, CtrRFT etc.
  • scale: the scale of the pixel. By default ScaUnit is assumed
  • dims: the dimensions over which to apply this function to.
  • weight: the strength of the result. Supports list-mode (see rr2 for documentation)
  • accumulator: the method used for superimposing list-mode data. Only applies in list-mode
julia> gaussian((5,5))
5×5 IndexFunArray{Float64, 2, IndexFunArrays.var"#100#102"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}}}:
 0.0183156  0.082085  0.135335  0.082085  0.0183156
 0.082085   0.367879  0.606531  0.367879  0.082085
 0.135335   0.606531  1.0       0.606531  0.135335
 0.082085   0.367879  0.606531  0.367879  0.082085
 0.0183156  0.082085  0.135335  0.082085  0.0183156

julia> gaussian((6,6), sigma=5.0)
 6×6 IndexFunArray{Float64, 2, IndexFunArrays.var"#100#102"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}}}:
  0.165299  0.272532  0.367879  0.40657   0.367879  0.272532
  0.272532  0.449329  0.606531  0.67032   0.606531  0.449329
  0.367879  0.606531  0.818731  0.904837  0.818731  0.606531
  0.40657   0.67032   0.904837  1.0       0.904837  0.67032
  0.367879  0.606531  0.818731  0.904837  0.818731  0.606531
  0.272532  0.449329  0.606531  0.67032   0.606531  0.449329

julia> gaussian(Float32,(5,5),offset=CtrCorner)
  5×5 IndexFunArray{Float32, 2, IndexFunArrays.var"#100#102"{Float32, Tuple{Float64, Float64}, Tuple{Float32, Float32}}}:
   1.0          0.606531     0.135335    0.011109    0.000335463
   0.606531     0.367879     0.082085    0.00673795  0.000203468
   0.135335     0.082085     0.0183156   0.00150344  4.53999f-5
   0.011109     0.00673795   0.00150344  0.00012341  3.72665f-6
   0.000335463  0.000203468  4.53999f-5  3.72665f-6  1.12535f-7

julia> y = gaussian((100,100),offset = (100,100) .* rand(2,60), weight=rand(60), sigma=2.0 .*(0.3 .+rand(2,60)));

gaussian(arr::AbstractArray; offset=CtrFt, sigma=1.0, scaling=ScaUnit)

This is a wrapper for gaussian(eltype(arr), size(arr), sigma=sigma, scaling=scaling, offset=offset).

source
IndexFunArrays.discFunction
disc([::Type{T}], size::NTuple, disc_radius; offset=CtrFT, scale=ScaFTEdge, dims=ntuple(+, N))

A multidimensional disc (i.e. a disk in 2D and a filled sphere in 3D), being one inside and zero outside. disc_radius defines the radius of the disc. The default result datatype is Float64. An alternative to generating a disc would be the edge-window.

julia> disc((10,10),(3,5))
10×10 IndexFunArray{Float64, 2, IndexFunArrays.var"#g#194"{Float64, Tuple{Int64, Int64}, Tuple{Float64, Float64}, Int64}}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0
 0.0  0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  0.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  0.0
 0.0  0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

 julia> disc((11,8),(0.5,0.5),scale=ScaFT)
11×8 IndexFunArray{Float64, 2, IndexFunArrays.var"#g#194"{Float64, Tuple{Int64, Int64}, Tuple{Float64, Float64}, Int64}}:
 0.0  0.0  0.0  1.0  1.0  1.0  0.0  0.0
 0.0  0.0  1.0  1.0  1.0  1.0  1.0  0.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 0.0  0.0  1.0  1.0  1.0  1.0  1.0  0.0
 0.0  0.0  0.0  1.0  1.0  1.0  0.0  0.0

disc(arr::AbstractArray, disc_radius; offset=CtrFT, scale=ScaUnit, dims=ntuple(+, N))

This is a wrapper for disc(eltype(arr), size(arr), disc_radius; scaling=scaling, offset=offset).

source
IndexFunArrays.idx_maxFunction

idx_max([T=Float64], size::NTuple{N, Int}; offset=CtrFT, dims=ntuple(+, N), scale=ScaUnit, weight=1, accumulator=sum)

returns the maximum of the absolute value of all index dimensions, after offset and scaling was applied. In combination with a comparison operation a box-shaped aperture is easily obtained. See below. See rr2 for a description of all options.

julia> idx_max((5,5)) .< 2
5×5 BitMatrix:
 0  0  0  0  0
 0  1  1  1  0
 0  1  1  1  0
 0  1  1  1  0
 0  0  0  0  0

idx_max(arr::AbstractArray; offset=CtrFt, scaling=ScaUnit)

This is a wrapper for idx_max(eltype(arr), size(arr), scaling=scaling, offset=offset).

source
IndexFunArrays.boxFunction
box([::Type{T}], size::NTuple, boxsize=size./2; offset=CtrFT, scale=ScaFTEdge, dims=ntuple(+, N))

A multidimensional box, being one inside and zero outside. boxsize defines the outer dimensions of the box. To obtain box sizes for integer pixels that correspond to the Fourier-space centers both for the array and the box, an additional offset of 0.25 pixels is automatically applied and box pixels are one if less or equal to half the boxsize along this dimension.

julia> box((10,10),(3,6))
10×10 IndexFunArray{Float64, 2, IndexFunArrays.var"#g#182"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}, Int64}}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  1.0  1.0  1.0  1.0  1.0  1.0  0.0  0.0
 0.0  0.0  1.0  1.0  1.0  1.0  1.0  1.0  0.0  0.0
 0.0  0.0  1.0  1.0  1.0  1.0  1.0  1.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

 julia> box((7,8))
 7×8 IndexFunArray{Float64, 2, IndexFunArrays.var"#g#182"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}, Int64}}:
  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  1.0  1.0  1.0  1.0  0.0  0.0
  0.0  0.0  1.0  1.0  1.0  1.0  0.0  0.0
  0.0  0.0  1.0  1.0  1.0  1.0  0.0  0.0
  0.0  0.0  1.0  1.0  1.0  1.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

box(arr::AbstractArray, boxsize; offset=CtrFT, scale=ScaUnit, dims=ntuple(+, N))

This is a wrapper for box(eltype(arr), size(arr), boxsize; scaling=scaling, offset=offset).

source
IndexFunArrays.exp_ikxFunction
exp_ikx([T=Float64], size::NTuple{N, Int};
    offset=CtrFT,
    shift_by=size.÷2
    dims=ntuple(+, N),
    scale=ScaFT,
    weight=1,
    accumulator=sum)

A complex-valued phase ramp according to exp(-2pi i <k,x>). If applied as a multiplicative factor in Fourier space, it will lead to a shift of x pixels in real space. Note that this effect is actually realized by a change to the scaling parameter. The default shift is size.÷2 which corresponds to CtrFT, however, the Ctr... arguments cannot be used for shift_by.

The argument shift_by supports list-mode, which can be used to conveniently perform multiple shifts simulatneously. See the final example below, which generates delta peaks at randomized subpixel positions.

Arguments:

  • offset: the center position of the Gaussian. You can use a tuple or the indicators CtrCorner, CtrEnd, CtrFT, CtrRFT etc.
  • shift_by: the amount to shift by in real space.
  • scale: the scale of the pixel. By default ScaUnit is assumed
  • dims: the dimensions over which to apply this function to.
  • weight: the strength of the result. Supports list-mode (see rr2 for documentation)
  • accumulator: the method used for superimposing list-mode data. Only applies in list-mode
julia> a = rr((4,3),offset=CtrCorner)
4×3 IndexFunArray{Float64, 2, IndexFunArrays.var"#37#39"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 0.0  1.0      2.0
 1.0  1.41421  2.23607
 2.0  2.23607  2.82843
 3.0  3.16228  3.60555

julia> using FourierTools; real(iffts(ffts(a).*exp_ikx(a, shift_by=(2.0,1.0))))
4×3 Matrix{Float64}:
 2.82843   2.0          2.23607
 3.60555   3.0          3.16228
 2.0      -2.22045e-16  1.0
 2.23607   1.0          1.41421

 julia> using FourierTools; y = real(ift(exp_ikx((101,101),weight=rand(60), shift_by=101.0 .*rand(2,60))));

exp_ikx(arr::AbstractArray; offset=CtrFt, shift_by==size(arr).÷2, scaling=ScaUnit)

This is a wrapper for exp_ikx(eltype(arr), size(arr), shift_by=shift_by, scaling=scaling, offset=offset).

source
IndexFunArrays.idx_minFunction

idx_min([T=Float64], size::NTuple{N, Int}; offset=CtrFT, dims=ntuple(+, N), scale=ScaUnit, weight=1, accumulator=sum)

returns the minimum of the absolute value of all index dimensions, after offset and scaling was applied. In combination with a comparison operation a cross-shaped aperture is easily obtained. See below. See rr2 for a description of all options.

julia> idx_min((5,5)) .< 1
5×5 BitMatrix:
 0  0  1  0  0
 0  0  1  0  0
 1  1  1  1  1
 0  0  1  0  0
 0  0  1  0  0

idx_min(arr::AbstractArray; offset=CtrFt, scaling=ScaUnit)

This is a wrapper for idx_min(eltype(arr), size(arr), scaling=scaling, offset=offset).

source
IndexFunArrays.deltaFunction
delta([T=Float64], size::NTuple{N, Int};
    offset=CtrFT,
    dims=ntuple(+, N),
    scale=ScaUnit,
    weight=1,
    accumulator=sum)

A delta peak positioned at offset. See rr2() for a description of all options. Note that scale does not influence the result. Also note that this function operates on a comparison for equality, which means a sub-pixel offset of the delta results into zero.

julia> delta((5,5))
5×5 IndexFunArray{Float64, 2, IndexFunArrays.var"#79#81"{Float64, Tuple{Float64, Float64}}}:
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  1.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0

julia> delta((6,6))
6×6 IndexFunArray{Float64, 2, IndexFunArrays.var"#79#81"{Float64, Tuple{Float64, Float64}}}:
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  1.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0

 julia> delta((5,5),offset=CtrCorner)
 5×5 IndexFunArray{Float64, 2, IndexFunArrays.var"#79#81"{Float64, Tuple{Float64, Float64}}}:
  1.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0
  0.0  0.0  0.0  0.0  0.0
  

delta(arr::AbstractArray; offset=CtrFt, scaling=ScaUnit)

This is a wrapper for delta(eltype(arr), size(arr), scaling=scaling, offset=offset).

source