Working with real spherical harmonics
20/09/22
This notebook gives a brief introduction to some of the conventions and functionality for handling real spherical harmonics and related functions, using low-level ePSproc routines. For complex spherical harmonics, and more general method notes, see ‘working with complex harmonics’ - note the complex forms are generally used in ePSproc, and general correct handling for cases using real spherical harmonics is not currently implemented/guaranteed.
Note some higher-level routines are available in the base class.
Definitions
Per the Wikipaedia definitions, the real spherical harmonics can be defined as:
Where \(Y_{\ell m}\) are real harmonics, and \(Y_{\ell }^{m}\) are complex.
And the inverse relations:
The real harmonics can also be written explicitly as:
For futher information, see wikipeadia or the SHtools introduction to real spherical harmonics.
Numerical implementation
ePSproc currently (Sept. 2022) implements:
Generation of real harmonics.
Conversion of real harmonic coefficients to complex harmonic coefficients.
General handling for real spherical harmonics is not guaranteed however, although - as per above - they can be defined simply by suitable combinations of complex harmonics. Note that the default routines in ePSproc make use of scipy.special.sph_harm as the default calculation routine, this is implemented with a default \((\theta, \phi)\) definition, and normalisation, corresponding to the usual “physics” convention (\(\theta\) defined from the z-axis, includes the Condon-Shortley phase, and orthonormalised). See ‘working with complex harmonics’ for further discussion; the real harmonics are then defined from the complex forms following the final definition given above, where the Condon-Shortley phase is already included in the \(Y_{\ell }^{|m|}\) terms:
(For a basic python routine, see Visualizing the real forms of the spherical harmonics.)
Imports
[1]:
import xarray as xr
import pandas as pd
import numpy as np
import epsproc as ep
# Set compact XR repr
xr.set_options(display_expand_data = False)
OMP: Info #273: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
* sparse not found, sparse matrix forms not available.
* natsort not found, some sorting functions not available.
* Hvplot not found, some hvPlotters may not be available. See https://hvplot.holoviz.org/user_guide/Gridded_Data.html for package details.
* Setting plotter defaults with epsproc.basicPlotters.setPlotters(). Run directly to modify, or change options in local env.
* Set Holoviews with bokeh.
* pyevtk not found, VTK export not available.
[1]:
<xarray.core.options.set_options at 0x7f879072f400>
Computing spherical harmonics on a grid
A basic wrapper for the backends is provided by ep.sphCalc. This computes spherical harmonics for all orders up to Lmax, for a given angular resolution or set of angles, and returns an Xarray. Set fnType = 'real' for real harmonics.
[2]:
# Compute harmonics for 50x50 (theta,phi) grid
Ire = ep.sphCalc(Lmax = 2, res = 50, fnType = 'real')
Ire
[2]:
<xarray.DataArray 'YLM' (LM: 9, Phi: 50, Theta: 50)>
0.2821 0.2821 0.2821 0.2821 0.2821 ... 0.03515 0.01996 0.008933 0.002242 0.0
Coordinates:
* LM (LM) object MultiIndex
* l (LM) int64 0 1 1 1 2 2 2 2 2
* m (LM) int64 0 -1 0 1 -2 -1 0 1 2
* Phi (Phi) float64 0.0 0.1282 0.2565 0.3847 ... 5.899 6.027 6.155 6.283
* Theta (Theta) float64 0.0 0.06411 0.1282 0.1923 ... 3.013 3.077 3.142
Attributes:
dataType: YLM
long_name: Spherical harmonics
harmonics: {'dtype': 'Real harmonics', 'kind': 'real', 'normType': 'orth...
units: arb[3]:
# Plot some components
# Ire = ep.sphCalc(Lmax = 2, res = 50, fnType = 'real')
ep.sphSumPlotX(Ire.sel(l=2), facetDim = 'm', backend = 'pl');
*** WARNING: plot dataset has min value < 0, min = -0.5459935484542385. This may be unphysical and/or result in plotting issues.
Sph plots:
Plotting with facetDims=m, pType=a with backend=pl.
*** Plotting for [1,1,0]
*** Plotting for [1,2,1]
*** Plotting for [1,3,2]
*** Plotting for [1,4,3]
*** Plotting for [1,5,4]