Posts Plotly: Spherical Harmonics
Post
Cancel

Plotly: Spherical Harmonics

Introduction

In mathematics and physical science, spherical harmonics are special functions defined on the surface of a sphere. The spherical harmonics form a complete set of orthogonal functions and thus an orthonormal basis, each function defined on the surface of a sphere can be written as a sum of these spherical harmonics.

Table of spherical harmonics

A more comploete list of spherical harmonics can be found here.

Complex spherical harmonics $Y_l^m(\theta, \phi)$

  • $l=0$
\[Y_0^0(\theta, \phi) = {1\over2}\sqrt{1\over\pi}\]
  • $l=1$
\[\begin{alignat*}{2} Y_1^{-1} &= {1\over2} \sqrt{3\over2\pi} \cdot e^{-i\phi} \cdot \sin{\theta} & &= {1\over2} \sqrt{3\over2\pi} \cdot {(x-iy) \over r} \\[6pt] Y_1^{0} &= {1\over2} \sqrt{3\over\pi} \cdot \cos{\theta} & &= {1\over2} \sqrt{3\over\pi} \cdot {z \over r} \\[6pt] Y_1^{1} &= -{1\over2} \sqrt{3\over2\pi} \cdot e^{i\phi} \cdot \sin{\theta} & &= -{1\over2} \sqrt{3\over2\pi} \cdot {(x+iy) \over r} \\[6pt] \end{alignat*}\]
  • $l=2$
\[\begin{alignat*}{2} Y_2^{-2} &= {1\over4} \sqrt{15\over2\pi} \cdot e^{-i2\phi} \cdot \sin^2{\theta} & &= {1\over4} \sqrt{15\over2\pi} \cdot {(x - iy)^2 \over r^2} \\[6pt] Y_2^{-1} &= {1\over2} \sqrt{15\over2\pi} \cdot e^{-i\phi} \cdot \sin{\theta} \cos\theta & &= {1\over2} \sqrt{15\over2\pi} \cdot {(x - iy) z \over r^2} \\[6pt] Y_2^{0} &= {1\over4} \sqrt{5\over\pi} \cdot (3\cos^2\theta - 1) & &= {1\over4} \sqrt{5\over\pi} \cdot {(3z^2 - r^2) \over r^2} \\[6pt] Y_2^{1} &=-{1\over2} \sqrt{15\over2\pi} \cdot e^{i\phi} \cdot \sin{\theta} \cos\theta & &=-{1\over2} \sqrt{15\over2\pi} \cdot {(x + iy) z \over r^2} \\[6pt] Y_2^{2} &= {1\over4} \sqrt{15\over2\pi} \cdot e^{-i2\phi} \cdot \sin^2{\theta} & &= {1\over4} \sqrt{15\over2\pi} \cdot {(x + iy)^2 \over r^2} \end{alignat*}\]
  • $l=3$
\[\begin{alignat*}{2} Y_3^{-3} &= {1\over8} \sqrt{35\over\pi} \cdot e^{-i3\phi} \cdot \sin^3{\theta} & &= {1\over8} \sqrt{35\over\pi} \cdot {(x - iy)^3 \over r^3} \\[6pt] Y_3^{-2} &= {1\over4} \sqrt{105\over2\pi} \cdot e^{-i2\phi} \cdot \sin^2{\theta} \cos\theta & &= {1\over4} \sqrt{105\over2\pi} \cdot {(x - iy)^2z \over r^3} \\[6pt] Y_3^{-1} &= {1\over8} \sqrt{21\over\pi} \cdot e^{-i\phi} \cdot \sin{\theta} (5\cos^2\theta - 1) & &= {1\over8} \sqrt{21\over\pi} \cdot {(x - iy) (5z^2-r^2) \over r^3} \\[6pt] Y_3^{0} &= {1\over4} \sqrt{7\over\pi} \cdot (5\cos^3\theta - 3\cos\theta) & &= {1\over4} \sqrt{7\over\pi} \cdot {z(5z^2 - 3r^2) \over r^3} \\[6pt] Y_3^{1} &=-{1\over8} \sqrt{21\over\pi} \cdot e^{i\phi} \cdot \sin{\theta} (5\cos^2\theta - 1) & &=-{1\over8} \sqrt{21\over\pi} \cdot {(x + iy)(5z^2-r^2) \over r^3} \\[6pt] Y_3^{2} &= {1\over4} \sqrt{105\over2\pi} \cdot e^{i2\phi} \cdot \sin^2{\theta} \cos\theta & &= {1\over4} \sqrt{105\over2\pi} \cdot {(x + iy)^2z \over r^2} \\[6pt] Y_3^{3} &=-{1\over8} \sqrt{35\over\pi} \cdot e^{i3\phi} \cdot \sin^3{\theta} & &=-{1\over8} \sqrt{35\over\pi} \cdot {(x + iy)^3 \over r^2} \end{alignat*}\]

Real spherical harmonics $Y_{lm}(\theta, \phi)$

  • $l=0$
\[Y_{00} = s = Y_0^0 = {1\over2}\sqrt{1\over\pi}\]
  • $l=1$
\[\begin{align*} Y_{1,-1} &= p_y = i\sqrt{1\over2}(Y_1^{-1} + Y_1^{1}) = \sqrt{3\over4\pi}\cdot{y\over r} \\[6pt] Y_{1,0} &= p_z = Y_1^0 = \sqrt{3\over4\pi}\cdot{z\over r} \\[6pt] Y_{1,1} &= p_x = \sqrt{1\over2}(Y_1^{-1} + Y_1^{1}) = \sqrt{3\over4\pi}\cdot{x\over r} \end{align*}\]
  • $l=2$
\[\begin{align*} Y_{2,-2} &= d_{xy} = i\sqrt{1\over2}(Y_2^{-2} - Y_2^{2}) = {1\over2}\sqrt{15\over\pi}\cdot{xy\over r^2} \\[6pt] Y_{2,-1} &= d_{yz} = i\sqrt{1\over2}(Y_2^{-1} + Y_2^{1}) = {1\over2}\sqrt{15\over\pi}\cdot{yz\over r^2} \\[6pt] Y_{2,0} &= d_{z^2} = Y_2^0 = {1\over4}\sqrt{5\over\pi}\cdot {-x^2-y^2+2z^2\over r^2} \\[6pt] Y_{2,1} &= d_{xz} = \sqrt{1\over2}(Y_2^{-1} - Y_2^{1}) = {1\over2}\sqrt{15\over\pi}\cdot{xz\over r^2} \\[6pt] Y_{2,2} &= d_{x^2-y^2} = \sqrt{1\over2}(Y_2^{-2} + Y_2^{2}) = {1\over4}\sqrt{15\over\pi}\cdot{x^2 - y^2\over r^2} \end{align*}\]
  • $l=3$
\[\begin{align*} Y_{3,-3} &= f_{y(3x^2-y^2)} = i\sqrt{1\over2}(Y_3^{-3} + Y_3^{3}) = {1\over4}\sqrt{35\over2\pi}\cdot{(3x^2-y^2)y\over r^3} \\[6pt] Y_{3,-2} &= f_{xyz} = i\sqrt{1\over2}(Y_3^{-2} - Y_3^{2}) = {1\over2}\sqrt{105\over\pi}\cdot{xyz\over r^3} \\[6pt] Y_{3,-1} &= f_{yz^2} = i\sqrt{1\over2}(Y_3^{-1} + Y_3^{1}) = {1\over4}\sqrt{21\over2\pi}\cdot{y(4z^2-x^2-y^2)\over r^3} \\[6pt] Y_{3,0} &= f_{z^3} = Y_3^0 = {1\over4}\sqrt{7\over\pi}\cdot{z(2z^2-3x^2-3y^2)\over r^3} \\[6pt] Y_{3,1} &= f_{xz^2} = \sqrt{1\over2}(Y_3^{-1} - Y_3^{1}) = {1\over4}\sqrt{21\over2\pi}\cdot{x(4z^2-x^2-y^2)\over r^3} \\[6pt] Y_{3,2} &= f_{z(x^2-y^2)} = \sqrt{1\over2}(Y_3^{-2} + Y_3^{2}) = {1\over2}\sqrt{105\over\pi}\cdot{(x^2-y^2)z\over r^3} \\[6pt] Y_{3,3} &= f_{x(x^2-3y^2)} = \sqrt{1\over2}(Y_3^{-3} - Y_3^{3}) = {1\over4}\sqrt{35\over2\pi}\cdot{(x^2-3y^2)x\over r^3} \end{align*}\]

Conversion matrix

  • Complex to real
\[\begin{align*} Y_{lm} &= \begin{cases} {i\over\sqrt{2}} [Y_l^m - (-1)^mY_l^{-m}], & \quad\text{if } m < 0 \\[6pt] Y_l^0, & \quad\text{if } m = 0 \\[6pt] {1\over\sqrt{2}} [Y_l^{-m} + (-1)^mY_l^{m}], & \quad\text{if } m > 0 \end{cases} \\[12pt] &= \begin{cases} {i\over\sqrt{2}} [Y_l^{-|m|} - (-1)^mY_l^{|m|}], & \quad\text{if } m < 0 \\[6pt] Y_l^0, & \quad\text{if } m = 0 \\[6pt] {1\over\sqrt{2}} [Y_l^{-|m|} + (-1)^mY_l^{|m|}], & \quad\text{if } m > 0 \end{cases} \\[12pt] &= \begin{cases} \sqrt{2}(-1)^m \Im[Y_l^{|m|}], & \quad\text{if } m < 0 \\[6pt] Y_l^0, & \quad\text{if } m = 0 \\[6pt] \sqrt{2}(-1)^m \Re[Y_l^{m}], & \quad\text{if } m > 0 \\ \end{cases} \\ \end{align*}\]
  • Real to complex
\[\begin{equation*} Y_l^m = \begin{cases} {1\over\sqrt{2}} (Y_{l|m|} - i Y_{l,-|m|}), & \quad\text{if } m < 0 \\[6pt] Y_{l0}, & \quad\text{if } m = 0 \\[6pt] {(-1)^m\over\sqrt{2}} (Y_{lm} + iY_{l,-m}), & \quad\text{if } m > 0 \end{cases} \end{equation*}\]

Spherical harmonics visualization

The complex spherical harmonics can be computed by scipy.special.sph_harm. I also wrote a small helping script to convert from the complex spherical harmonics to real ones. For example, with my little script

1
2
3
4
from sph_harm import show_sph_harm

# available plotting methods are 'mpl', 'mayavi' and 'plotly'
show_sph_harm(l=2, m=1, real=True, plot='mpl')

shows the real spherical harmonics $Y_{lm}(\theta, \phi)$ with $l=2, m=1$ on a sphere, the resulting figure

Figure. Visual representations of the real spherical harmonics on a sphere with radius 1.0.

Or we can use another method to better visualize the nodes.

1
2
3
4
from sph_harm import show_sph_harm

# available plotting methods are 'mpl', 'mayavi' and 'plotly'
show_sph_harm(l=2, m=1, real=True, use_sphere=False, plot='mpl')
Figure. Visual representations of the real spherical harmonics. The distance of the surface from the origin indicate the absolute value of $Y_{lm}(\theta, \phi)$ in angular direction $(\theta, \phi)$, i.e. $|Y_{lm}(\theta, \phi)|$. The color represents the value of $Y_{lm}(\theta, \phi)$.

Below, I used Plotly to list the real spherical harmonics up to $l = 3$

This script plot the complex spherical harmonics.

If you don’t see the plot, try to use other web browser, e.g. Firefox, to open this site.

This post is licensed under CC BY 4.0 by the author.