Concrete IndexFunArrays

Scaling Types

Needed to change the scaling:

IndexFunArrays.ScaType
Sca

Abstract type to indicate a scaling from which several other types subtype.

Possible subtypes

  • ScaUnit: No scaling of the indices
  • ScaNorm: Total length along each dimension is normalized to 1
  • ScaMid: Reaches 1.0 at the borders, if used in combination with CtrMid. Useful for keeping real-space symmetry.
  • ScaFT: Reciprocal Fourier coordinates compared to Nyquist sampling
  • ScaFTEdge: Such that the edge (in FFT sense) of the pixel is 1.0
source

Offset Types

Needed to change the reference offset:

IndexFunArrays.CtrType
Ctr

Abstract type to specify the reference position from which several other types subtype.

Possible subtypes

  • CtrCorner: Set the reference pixel in the corner
  • CtrFFT: Set the reference pixel to the FFT center.
  • CtrFT: Set the reference pixel to the FT center. FT means that the zero frequency is at the FFT convention center (size ÷ 2 + 1).
  • CtrRFFT: Set the reference pixel to the RFFT center. Same as CtrFFT but the first dimension has center at 1.
  • CtrRFT: Set the reference pixel to the RFT center. FT means that the zero frequency is at the FFT convention center (size ÷ 2 + 1). Same as CtrFT but the first dimension has center at 1.
  • CtrMid: Set the reference pixel to real mid. For uneven arrays it is the center pixel, for even arrays it is the centered around a half pixel.
  • CtrEnd Set the reference to the end corner (last pixel)
source

Distance Functions

Some concrete arrays:

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

Calculates the squared radius to a reference pixel. In this case CtrFT is the center defined by the FFT convention. ScaUnit leaves the values unscaled. offset and scale can be either of <:Ctr, <:Sca respectively or simply tuples with the same shape as size. Look at ?Ctr and ?Sca for all options. dims is a keyword argument to specifiy over which dimensions the operation will effectively happen.

The arguments offset, and scale support list-mode, which means that supplying a tuple of tuples or a vector of tuples or a matrix causes the function to automatically generate a superposition of multiple versions of itself. The type of superposition is controlled by the accumulator argument. The relative strength of the individual superposition is controlled via the weight argument, which can be a tuple or vector. Have a look at the Voronoi-example below.

Note that this function is based on a IndexFunArray and therefore does not allocate the full memory needed to represent the array.

Examples

julia> rr2((4, 4))
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 8.0  5.0  4.0  5.0
 5.0  2.0  1.0  2.0
 4.0  1.0  0.0  1.0
 5.0  2.0  1.0  2.0

Change Reference Position

julia> rr2((3,3), offset=CtrCorner)
3×3 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 0.0  1.0  4.0
 1.0  2.0  5.0
 4.0  5.0  8.0

julia> rr2((4,4), offset=CtrFT)
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 8.0  5.0  4.0  5.0
 5.0  2.0  1.0  2.0
 4.0  1.0  0.0  1.0
 5.0  2.0  1.0  2.0

julia> rr2((4,4), offset=CtrMid)
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 4.5  2.5  2.5  4.5
 2.5  0.5  0.5  2.5
 2.5  0.5  0.5  2.5
 4.5  2.5  2.5  4.5

julia> rr2((4,4), offset=CtrEnd)
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 18.0  13.0  10.0  9.0
 13.0   8.0   5.0  4.0
 10.0   5.0   2.0  1.0
  9.0   4.0   1.0  0.0

julia> rr2((3, 3), offset=(1, 1))
3×3 IndexFunArray{Float64, 2, IndexFunArrays.var"#4#5"{Float64, Tuple{Int64, Int64}, Tuple{Int64, Int64}}}:
 0.0  1.0  4.0
 1.0  2.0  5.0
 4.0  5.0  8.0

Change Scaling

julia> rr((4,4), scale=ScaUnit)
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#9#10"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 2.82843  2.23607  2.0  2.23607
 2.23607  1.41421  1.0  1.41421
 2.0      1.0      0.0  1.0
 2.23607  1.41421  1.0  1.41421

julia> rr((4,4), scale=ScaNorm)
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#9#10"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}}}:
 0.942809  0.745356  0.666667  0.745356
 0.745356  0.471405  0.333333  0.471405
 0.666667  0.333333  0.0       0.333333
 0.745356  0.471405  0.333333  0.471405

julia> rr((4,4), scale=ScaFT)
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#9#10"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}}}:
 0.707107  0.559017  0.5   0.559017
 0.559017  0.353553  0.25  0.353553
 0.5       0.25      0.0   0.25
 0.559017  0.353553  0.25  0.353553

julia> rr((4,4), scale=ScaFTEdge)
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#9#10"{Float64, Tuple{Float64, Float64}, Tuple{Float64, Float64}}}:
 1.41421  1.11803   1.0  1.11803
 1.11803  0.707107  0.5  0.707107
 1.0      0.5       0.0  0.5
 1.11803  0.707107  0.5  0.707107

julia> rr2(Int, (3, 3), offset=(1, 1), scale=(10, 10))
3×3 IndexFunArray{Int64, 2, IndexFunArrays.var"#4#5"{Int64, Tuple{Int64, Int64}, Tuple{Int64, Int64}}}:
   0  100  400
 100  200  500
 400  500  800

Application to selected dimensions

Note that the code below yields a 3D array but with a one-sized trailing dimension. This can then be used for broadcasting.

julia> x = ones(5,6,5);

julia> y=rr2(selectsizes(x,(1,2)))
5×6×1 IndexFunArray{Float64, 3, IndexFunArrays.var"#4#5"{Float64, Tuple{Float64, Float64, Float64}, Tuple{Int64, Int64, Int64}}}:
[:, :, 1] =
 13.0  8.0  5.0  4.0  5.0  8.0
 10.0  5.0  2.0  1.0  2.0  5.0
  9.0  4.0  1.0  0.0  1.0  4.0
 10.0  5.0  2.0  1.0  2.0  5.0
 13.0  8.0  5.0  4.0  5.0  8.0

Similarly you can also use dimensions 2 and 3 yielding an array of size(y) == (1,6,5). Note that the necessary modification to the Base.size function is currently provided by this package.

Using List-Mode Arguments

The code below generates 160 Voronoi cells at random positions. The accumulator was set to mimimum yielding in each pixel the square distance to the closest Voronoi center. See gaussian for another example of using list-mode arguments.

julia> y = rr2((1000,1000),offset = (1000.0,1000.0) .* rand(2,160), accumulator=minimum);

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

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

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

See rr2 for a description of all options.

Examples

julia> rr((3, 3))
3×3 IndexFunArray{Float64, 2, IndexFunArrays.var"#9#10"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 1.41421  1.0  1.41421
 1.0      0.0  1.0
 1.41421  1.0  1.41421

julia> rr((3, 3), offset=CtrCorner)
3×3 IndexFunArray{Float64, 2, IndexFunArrays.var"#9#10"{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

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

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

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

A distance ramp along first dimension. See rr2 for a description of all options.

julia> xx((4,4))
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#14#15"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 -2.0  -2.0  -2.0  -2.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

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

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

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

A distance ramp along second dimension. See rr2 for a description of all options.

julia> yy((4,4))
4×4 IndexFunArray{Float64, 2, IndexFunArrays.var"#19#20"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 -2.0  -1.0  0.0  1.0
 -2.0  -1.0  0.0  1.0
 -2.0  -1.0  0.0  1.0
 -2.0  -1.0  0.0  1.0

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

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

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

A distance ramp along third dimension. See rr2 for a description of all options.

julia> zz((1, 1, 4))
1×1×4 IndexFunArray{Float64, 3, IndexFunArrays.var"#24#25"{Float64, Tuple{Float64, Float64, Float64}, Tuple{Int64, Int64, Int64}}}:
[:, :, 1] =
 -2.0

[:, :, 2] =
 -1.0

[:, :, 3] =
 0.0

[:, :, 4] =
 1.0

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

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

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

An azimutal spiral phase ramp using atan(). The azimuthal phase spans dimensions 1 and 2. See rr2 for a description of all options.

julia> phiphi((5, 5))
5×5 IndexFunArray{Float64, 2, IndexFunArrays.var"#29#30"{Float64, Tuple{Float64, Float64}, Tuple{Int64, Int64}}}:
 -2.35619   -2.67795   3.14159  2.67795   2.35619
 -2.03444   -2.35619   3.14159  2.35619   2.03444
 -1.5708    -1.5708    0.0      1.5708    1.5708
 -1.10715   -0.785398  0.0      0.785398  1.10715
 -0.785398  -0.463648  0.0      0.463648  0.785398

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

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

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

A distance ramp along fifth (time) dimension. See rr2 for a description of all options.

julia> tt((1, 1, 1, 1, 4))
1×1×1×1×4 IndexFunArray{Float64, 5, IndexFunArrays.var"#69#72"{Float64, NTuple{5, Float64}}}:
[:, :, 1, 1, 1] =
 -2.0

[:, :, 1, 1, 2] =
 -1.0

[:, :, 1, 1, 3] =
 0.0

[:, :, 1, 1, 4] =
 1.0

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

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

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

A distance ramp along forth (element) dimension. This dimension is often used as a color or wavelength channel. See rr2 for a description of all options.

julia> ee((1, 1, 1, 4))
1×1×1×4 IndexFunArray{Float64, 4, IndexFunArrays.var"#60#63"{Float64, NTuple{4, Float64}}}:
[:, :, 1, 1] =
 -2.0

[:, :, 1, 2] =
 -1.0

[:, :, 1, 3] =
 0.0

[:, :, 1, 4] =
 1.0

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

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

source
IndexFunArrays.rampFunction
ramp(::Type{T}, dim::Int, dim_size::Int;
    offset=CtrFT, scale=ScaUnit,
    weight=1,
    accumulator=sum) where {T}

Generates a dim-dimensional ramp of size dim_size to be used for broadcasting through multidimensional expressions. dim highest dimension of the oriented array to be generated. This is also the ramp direction. dim_size size along this dimension.

For details about offset and scale and dims see rr2.

julia> ramp(Float32, 1, 7; offset=(2,))
7-element IndexFunArray{Float32, 1, IndexFunArrays.var"#434#435"{Tuple{Int64}, Tuple{Int64}, Int64}}:
 -1
  0
  1
  2
  3
  4
  5

ramp(dim::Int, dim_size::Int; offset=CtrFt, scaling=ScaUnit)

This is a wrapper for ramp(Float64, dim::Int, dim_size::Int; offset=CtrFt, scaling=ScaUnit).

source