# How do I call FastTransforms.jl to get a complex spherical harmonics

**URL:** <https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [July 15, 2022, 8:44am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258 "2022-07-15T08:44:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![F-YF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/f-yf/32/17363_2.png) [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Post date:** [July 15, 2022, 8:44am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/1 "2022-07-15T08:44:30Z")

</div>

I am looking for a package that can calculate the spherical harmonic function, and I expect it to be able to directly give the value of the spherical harmonic function Y\_{l,m}(\theta,\phi) , when given input l, m ,\theta , \phi .

Then I found that there was a function [FastTransforms.sphevaluate](https://docs.juliahub.com/FastTransforms/5Lm8s/0.13.2/#FastTransforms.sphevaluate)) in [JuliaApproximation/FastTransforms.jl](https://github.com/JuliaApproximation/FastTransforms.jl) that could compute the real orthonormal spherical harmonic, but I didn’t find how to compute the complex orthonormal spherical harmonic

[SphericalHarmonics.jl](https://github.com/jishnub/SphericalHarmonics.jl) seems to meet my needs, but it only has six stars, I’m not sure about its performance and stability.

Do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [July 15, 2022, 8:50am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/2 "2022-07-15T08:50:28Z")

</div>

does [FastSphericalHarmonics.jl](https://github.com/eschnett/FastSphericalHarmonics.jl) do what you want?  
Sure its star count is 9 \>\> 0 for a specialty package. note the version – it is stable.  
The author is respected. I do not know about the other pkg.

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [July 15, 2022, 9:05am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/3 "2022-07-15T09:05:58Z")

</div>

Yeah, the number of stars is not a particularly reliable indicator. My heuristics : are there automatic tests, is there a commit in the last N months, is there any important PR unmerged, is there any scary issue without comment from the maintainers, have the committers authored other julia packages.

---

<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:** [July 15, 2022, 9:18am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/4 "2022-07-15T09:18:00Z")

</div>

`SphericalHarmonics.jl` should give you what you want. I’m the person maintaining it, but I haven’t had time to get around to it recently. Nevertheless, it should give you what you want, although the API would change with the next breaking release. It should be performant as well.

In any case, the way to go from real to complex harmonics is to compute something like `Complex(Ylm(l,m), Ylm(l,-m))/sqrt(2)` for `m > 0`, and `Ylm(l,m)` for `m==0`.

```julia
julia> ylmFT(θ, ϕ, l, m) = Complex(FastTransforms.sphevaluate(θ, ϕ, l, m), FastTransforms.sphevaluate(θ, ϕ, l, -m))/√2
ylmFT (generic function with 1 method)

julia> ylmFT(pi/3, pi/6, 100, 20)
-0.06360367043855313 - 0.11016478874744044im

julia> SphericalHarmonics.sphericalharmonic(pi/3, pi/6, 100, 20)
-0.06360367043855136 - 0.11016478874743722im

julia> SphericalHarmonics.sphericalharmonic(pi/3, pi/4, 100, 0)
-0.24203482021358494

julia> FastTransforms.sphevaluate(pi/3, pi/4, 100, 0)
-0.24203482021358141

```

---

<div class="post-metadata">

**Author:** ![F-YF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/f-yf/32/17363_2.png) [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Post date:** [July 15, 2022, 9:36am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/5 "2022-07-15T09:36:41Z")

</div>

> [@JeffreySarnoff](#):
>
> does [FastSphericalHarmonics.jl](https://github.com/eschnett/FastSphericalHarmonics.jl) do what you want?  
> Sure its star count is 9 \>\> 0 for a specialty package. note the version – it is stable.  
> The author is respected. I do not know about the other pkg.

To be honest, I can’t quite understand how to use this package.

---

<div class="post-metadata">

**Author:** ![F-YF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/f-yf/32/17363_2.png) [@F-YF](https://discourse.julialang.org/u/F-YF)\
**Post date:** [July 15, 2022, 9:55am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/6 "2022-07-15T09:55:32Z")

</div>

> [@jishnub](#):
>
> In any case, the way to go from real to complex harmonics is to compute something like `Complex(Ylm(l,m), Ylm(l,-m))/sqrt(2)` for `m > 0`, and `Ylm(l,m)` for `m==0`.

This is a nice idea, but I was curious that FastTransforms.jl could compute the real Orthonormal Harmonic, but there is no interface for complex spherical harmonics.

> [@jishnub](#):
>
> `SphericalHarmonics.jl` should give you what you want. I’m the person maintaining it, but I haven’t had time to get around to it recently. Nevertheless, it should give you what you want, although the API would change with the next breaking release. It should be performant as well.

Yes, it can give me what I want, but I don’t know if it’s reliable

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 15, 2022, 10:29am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/7 "2022-07-15T10:29:20Z")

</div>

> [@F-YF](#):
>
> it can give me what I want, but I don’t know if it’s reliable

If you don’t know, then you shouldn’t care.

---

<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:** [July 15, 2022, 10:46am UTC](https://discourse.julialang.org/t/how-do-i-call-fasttransforms-jl-to-get-a-complex-spherical-harmonics/84258/8 "2022-07-15T10:46:51Z")

</div>

> [@F-YF](#):
>
> was curious that FastTransforms.jl could compute the real Orthonormal Harmonic, but there is no interface for complex spherical harmonics.

I think they have special algorithms that compute spherical harmonic transforms for real harmonics, so they also have a function to compute these harmonics. It can definitely be extended to complex harmonics, and this would be quite convenient. I guess no one has done it yet.
