SphericalHarmonicArrays.jl
SphericalHarmonicArrays.SHArray
— Types = SHArray(arr::AbstractArray{T,N}, modes::NTuple{N, Union{AbstractUnitRange, SphericalHarmonicModes.ModeRange}}) where {T,N}
s = SHArray(arr::AbstractArray{T,N}, modes::Vararg{Union{AbstractUnitRange, SphericalHarmonicModes.ModeRange}, N}) where {T,N}
Create a wrapper around an array such that certain dimensions may be indexed using Tuple
of spherical harmonic modes. Often the indices would be spherical harmonic degrees (l,m)
. The argument modes
dictates the map between spherical harmonic modes and the indices of the parent array. The indices of modes
that are of a ModeRange
type correspond to the dimensions of s
that enable indexing with a Tuple
of spherical harmonic degrees.
Use the iterators provided by SphericalHarmonicModes
in modes
to generate the map between the indices of the array and Tuple
s of spherical harmonic degrees. The resulting map would be of the form s[collect(modes[1])[i], collect(modes[2])[j], ...] == s[i,j, ...]
.
Examples
julia> using SphericalHarmonicModes: LM
julia> s = SHArray(reshape(1:4, 2, 2), (LM(0:1, 0:0), 1:2))
2×2 SHArray(reshape(::UnitRange{Int64}, 2, 2), (LM(0:1, 0:0), 1:2)):
1 3
2 4
julia> s.modes[1] |> collect
2-element Vector{Tuple{Int64, Int64}}:
(0, 0)
(1, 0)
julia> s[(1,0), 1]
2
SphericalHarmonicArrays.SHArray
— Methods = SHArray(arr::AbstractArray{T,N}, dimsmodes::Pairs{Int, <:SphericalHarmonicModes.ModeRange}) where {T,N}
Return an SHArray
where the dimensions specified as the keys
of dimsmodes
may be indexed using Tuple
s of spherical harmonic degrees. This constructor is not type-stable in general, therefore this should be avoided within a loop if performance is a concern.
Examples
julia> using SphericalHarmonicModes: LM
julia> s2 = SHArray(reshape(1:4, 2, 2), 1 => LM(0:1, 0:0))
2×2 SHArray(reshape(::UnitRange{Int64}, 2, 2), (LM(0:1, 0:0), Base.OneTo(2))):
1 3
2 4
SphericalHarmonicArrays.SHArray
— MethodSHArray{T}(init, modes::NTuple{N,Union{Integer, AbstractUnitRange, SphericalHarmonicModes.ModeRange}}) where {T,N}
Return an SHArray
wrapper around a parent array of the appropriate size with N
dimensions and elements of type T
, such that the indices of modes
that are of a ModeRange
type may be indexed using Tuples
of spherical harmonic degrees. The elements of the parent array are set according to the initializer init
.
Examples
julia> using SphericalHarmonicModes: LM
julia> SHArray{Missing}(undef, (LM(0:1, 0:0), 2))
2×2 SHArray(::Matrix{Missing}, (LM(0:1, 0:0), Base.OneTo(2))):
missing missing
missing missing
SHArray{T}(modes::NTuple{N,Union{Integer, AbstractUnitRange, SphericalHarmonicModes.ModeRange}}) where {T,N}
Return an SHArray
of the appropriate size with N
dimensions and elements of type T
. The elements are set to zero.
Examples
julia> using SphericalHarmonicModes: LM
julia> SHArray{Float64}((LM(1:1, 0:1), LM(0:0, 0:0)))
2×1 SHArray(::Matrix{Float64}, (LM(1:1, 0:1), LM(0:0, 0:0))):
0.0
0.0
julia> SHArray{Float64}((LM(1:1, 0:1), 2))
2×2 SHArray(::Matrix{Float64}, (LM(1:1, 0:1), Base.OneTo(2))):
0.0 0.0
0.0 0.0
SphericalHarmonicArrays.SHMatrix
— TypeSHMatrix(arr::AbstractMatrix, modes::NTuple{2,SphericalHarmonicModes.ModeRange})
SHMatrix(arr::AbstractMatrix, modes::Vararg{SphericalHarmonicModes.ModeRange,2})
Return a wrapper that maps the indices of the parent matrix along each axis to a Tuple
of spherical harmonic degrees. Often these Tuple
s would be pairs of spherical harmonic degrees (l,m)
.
Examples
julia> using SphericalHarmonicModes: LM
julia> s = SHMatrix(reshape(1:4, 2,2), (LM(0:1, 0:0), LM(1:2,0:0)))
2×2 SHArray(reshape(::UnitRange{Int64}, 2, 2), (LM(0:1, 0:0), LM(1:2, 0:0))):
1 3
2 4
julia> s[(1,0),(2,0)]
4
SphericalHarmonicArrays.SHMatrix
— MethodSHMatrix{T}(init, modes::NTuple{2,SphericalHarmonicModes.ModeRange}) where {T}
SHMatrix{T}(init, modes::Vararg{SphericalHarmonicModes.ModeRange, 2}) where {T}
Return a SHMatrix
wrapper, with the parent Matrix
having elements of type T
. The default value is set by the initializer init
.
Examples
julia> using SphericalHarmonicModes: LM
julia> SHMatrix{Missing}(undef, LM(1:1), LM(0:1, 0:0))
3×2 SHArray(::Matrix{Missing}, (LM(1:1, -1:1), LM(0:1, 0:0))):
missing missing
missing missing
missing missing
SHMatrix{T}(modes::Vararg{SphericalHarmonicModes.ModeRange,2}) where {T}
SHMatrix{T}(modes::NTuple{2,SphericalHarmonicModes.ModeRange}) where {T}
Return an SHMatrix
of the appropriate size and with elements of type T
. The elements are set to zero.
Examples
julia> using SphericalHarmonicModes: LM
julia> SHMatrix{ComplexF64}(LM(0:0, 0:0), LM(0:0, 0:0))
1×1 SHArray(::Matrix{ComplexF64}, (LM(0:0, 0:0), LM(0:0, 0:0))):
0.0 + 0.0im
SphericalHarmonicArrays.SHVector
— TypeSHVector(arr::AbstractVector, modes::SphericalHarmonicModes.ModeRange)
Return a wrapper that maps the indices of the parent Vector
to a Tuple
of spherical harmonic degrees. Often the Tuple
would be a pair of spherical harmonic degrees (l,m)
.
Examples
julia> using SphericalHarmonicModes: LM
julia> s = SHVector(1:3, LM(1:1))
3-element SHArray(::UnitRange{Int64}, (LM(1:1, -1:1),)):
1
2
3
julia> s.modes[1] |> collect
3-element Vector{Tuple{Int64, Int64}}:
(1, -1)
(1, 0)
(1, 1)
julia> s[(1,0)]
2
SphericalHarmonicArrays.SHVector
— MethodSHVector{T}(init, modes::SphericalHarmonicModes.ModeRange) where {T}
SHVector{T}(init, modes::Tuple{SphericalHarmonicModes.ModeRange}) where {T}
Return a SHVector
wrapper, with the parent Vector
having an element type of T
. The default value is set by the initializer init
.
Examples
julia> using SphericalHarmonicModes: LM
julia> SHVector{Missing}(undef, LM(1:1, -1:1))
3-element SHArray(::Vector{Missing}, (LM(1:1, -1:1),)):
missing
missing
missing
SHVector{T}(modes::SphericalHarmonicModes.ModeRange) where {T}
SHVector{T}(modes::Tuple{SphericalHarmonicModes.ModeRange}) where {T}
Return an SHVector
of the appropriate size and with elements of type T
. The elements are set to zero.
Examples
julia> using SphericalHarmonicModes: LM
julia> SHVector{ComplexF64}(LM(0:0, 0:0))
1-element SHArray(::Vector{ComplexF64}, (LM(0:0, 0:0),)):
0.0 + 0.0im
SphericalHarmonicArrays.permuteflipmodes
— Methodpermuteflipmodes(v::AbstractVector, p::Union{LM, ML})
Permute v
with the map obtained by flipping the order of modes in p
.
SphericalHarmonicArrays.shdims
— Methodshdims(arr::SHArray)
Return the dimensions of arr
that may be indexed using ModeRange
s. This is type-stable even if arr.modes
contains inhomogeneous types.
Examples
julia> using SphericalHarmonicModes: LM
julia> s = SHArray{Float64}((LM(1:1,0:1), LM(0:0)));
julia> SphericalHarmonicArrays.shdims(s)
(1, 2)
julia> s = SHArray{Float64}((LM(1:1,0:1), 2));
julia> SphericalHarmonicArrays.shdims(s)
(1,)
See also: shmodes
SphericalHarmonicArrays.shmodes
— MethodSphericalHarmonicArrays.shmodes(arr::SHArray)
Returns a Tuple
containing the elements of arr.modes
that are of a SphericalHarmonicModes.ModeRange
type. This is type-stable even if arr.modes
contains inhomogeneous types.
Examples
julia> using SphericalHarmonicModes: LM
julia> sa = SHArray{ComplexF64}((2,2));
julia> SphericalHarmonicArrays.shmodes(sa)
()
julia> sa = SHArray{ComplexF64}((LM(1:1, 0:0),2));
julia> SphericalHarmonicArrays.shmodes(sa)
(LM(1:1, 0:0),)
julia> sa = SHArray{ComplexF64}((LM(1:1, 0:0), LM(2:2)));
julia> SphericalHarmonicArrays.shmodes(sa)
(LM(1:1, 0:0), LM(2:2, -2:2))
See also: shdims