# Struggling to interpret spherical harmonic transforms from FastTransforms.jl

**URL:** https://discourse.julialang.org/t/struggling-to-interpret-spherical-harmonic-transforms-from-fasttransforms-jl/45986
**Category:** General Usage
**Tags:** question, package
**Created:** [September 3, 2020, 6:06am UTC](https://discourse.julialang.org/t/struggling-to-interpret-spherical-harmonic-transforms-from-fasttransforms-jl/45986 "2020-09-03T06:06:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [September 3, 2020, 6:06am UTC](https://discourse.julialang.org/t/struggling-to-interpret-spherical-harmonic-transforms-from-fasttransforms-jl/45986/1 "2020-09-03T06:06:04Z")

</div>

I am trying to compute the spherical harmonic transform of a function that is given by `sin(θ)cos(ϕ)` on the face of the sphere facing us, and zero on the other face that is away from us. I am attempting to use `FastTransforms.jl` ans follow [this example](https://github.com/JuliaApproximation/FastTransforms.jl/blob/master/examples/sphere.jl) as

```julia
julia> f_test(θ, ϕ) = (π/2 <= ϕ <= 3π/2) ? zero(Float64) : Float64(sin(θ)cos(ϕ))
f_test (generic function with 1 method)

julia> function threshold!(A::AbstractArray, ϵ)
           for i in eachindex(A)
               if abs(A[i]) < ϵ A[i] = 0 end
           end
           A
       end
threshold! (generic function with 1 method)

julia> lmax = 3
3

julia> N = lmax + 1
4

julia> θ = ((0.5:N-0.5)/N) .* pi
0.39269908169872414:0.7853981633974483:2.748893571891069

julia> M = 2N-1
7

julia> ϕ = ((0:M-1)/M) .* 2pi
0.0:0.8975979010256552:5.385587406153931

julia> F = [f_test(θ,ϕ) for θ in θ, ϕ in ϕ]
4×7 Array{Float64,2}:
 0.382683 0.238599 0.0 0.0 0.0 0.0 0.238599
 0.92388 0.576029 0.0 0.0 0.0 0.0 0.576029
 0.92388 0.576029 0.0 0.0 0.0 0.0 0.576029
 0.382683 0.238599 0.0 0.0 0.0 0.0 0.238599

julia> using FastTransforms

julia> P = plan_sph2fourier(F);

julia> PA = plan_sph_analysis(F);

julia> V = PA*F;

julia> threshold!(P\V, 400*eps())
4×7 Array{Float64,2}:
  0.888525 0.0 1.0394 0.0 0.417051 0.0 -0.0697631
  0.0 0.0 0.0 0.0 0.0 0.0 0.0
 -0.259657 0.0 0.0 0.0 0.0571638 0.0 -0.018645
  0.0 0.0 0.0 0.0 0.0 0.0 0.0

```

However I do not understand this result. Going by the [storage](https://mikaelslevinsky.github.io/FastTransforms/transforms.html) of the spherical harmonic coefficients, the last column should only have the top row filled. The element at index `[3,7]` should be zero (at least within floating-point tolerance). Also, why is there no conjugate symmetry?

Am I misunderstanding something here? Some help would be welcome!

---

<div class="post-metadata">

### Author: ![stst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stst/32/17252_2.png) [@stst](https://discourse.julialang.org/u/stst)
#### Post date: [September 3, 2020, 7:57am UTC](https://discourse.julialang.org/t/struggling-to-interpret-spherical-harmonic-transforms-from-fasttransforms-jl/45986/2 "2020-09-03T07:57:36Z")

</div>

Have you tried to use a single spherical harmonic in `f_test` and see if your script recovers that as a single number in your final array?

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [September 3, 2020, 8:53am UTC](https://discourse.julialang.org/t/struggling-to-interpret-spherical-harmonic-transforms-from-fasttransforms-jl/45986/3 "2020-09-03T08:53:45Z")

</div>

This is what is demonstrated in the example that I was trying to follow, and it does seem to work.

---

<div class="post-metadata">

### Author: ![MikaelSlevinsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikaelslevinsky/32/38545_2.png) [@MikaelSlevinsky](https://discourse.julialang.org/u/MikaelSlevinsky)
#### Post date: [September 5, 2020, 3:30pm UTC](https://discourse.julialang.org/t/struggling-to-interpret-spherical-harmonic-transforms-from-fasttransforms-jl/45986/4 "2020-09-05T15:30:57Z")

</div>

The discussion is continued in the issue [https://github.com/JuliaApproximation/FastTransforms.jl/issues/120](https://github.com/JuliaApproximation/FastTransforms.jl/issues/120).
