Skip to content

Commit

Permalink
Example and docs for rotate_sh()
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hld committed Jan 12, 2024
1 parent 7f9901a commit c160033
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions spaudiopy/sph.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,30 @@ def sh_rotation_matrix(N_sph, yaw, pitch, roll, sh_type='real',
Rotation around Y axis.
roll: float
Rotation around X axis.
sh_type : 'complex' or 'real' spherical harmonics. Currently only 'real' is
supported.
return_as_blocks: return full block diagonal matrix, or a list of blocks
sh_type : 'complex' or 'real' spherical harmonics.
Currently only 'real' is supported.
return_as_blocks: optional, default is False.
Return full block diagonal matrix, or a list of blocks if True.
Returns
-------
A block diagonal matrix R with shape (..., (N_sph+1)**2, (N_sph+1)**2), or
a list r_blocks of numpy arrays [r(n) for n in range(N_sph)], where the
shape of r is (..., 2*n-1, 2*n-1)
R: (..., (N_sph+1)**2, (N_sph+1)**2) numpy.ndarray
A block diagonal matrix R with shape (..., (N_sph+1)**2, (N_sph+1)**2),
or a list r_blocks of numpy arrays [r(n) for n in range(N_sph)],
where the shape of r is (..., 2*n-1, 2*n-1).
See Also
--------
:py:func:`spaudiopy.sph.rotate_sh` : Apply rotation to SH signals.
References
----------
Implemented according to: Ivanic, Joseph, and Klaus Ruedenberg. "Rotation
matrices for real spherical harmonics. Direct determination by recursion."
The Journal of Physical Chemistry 100.15 (1996): 6342-6347.
Ported from https://git.iem.at/audioplugins/IEMPluginSuite .
Ported from https://git.iem.at/audioplugins/IEMPluginSuite
"""

if sh_type == 'complex':
Expand Down Expand Up @@ -380,14 +386,27 @@ def rotate_sh(F_nm, yaw, pitch, roll, sh_type='real'):
Rotation around Y axis.
roll: float
Rotation around X axis.
sh_type : 'complex' or 'real' spherical harmonics. Currently only 'real' is
supported.
sh_type : 'complex' or 'real' spherical harmonics.
Currently only 'real' is supported.
Returns
-------
F_nm_rot : (..., (N_sph+1)**2) numpy.ndarray
Rotated spherical harmonics coefficients.
Examples
--------
.. plot::
:context: close-figs
N_sph = 5
y1 = spa.sph.sh_matrix(N_sph, 0, np.pi/2, 'real')
y2 = 0.5 * spa.sph.sh_matrix(N_sph, np.pi/3, np.pi/2, 'real')
y_org = (4 * np.pi) / (N_sph + 1)**2 * (y1 + y2)
y_rot = spa.sph.rotate_sh(y_org, -np.pi/2, np.pi/8, np.pi/4)
spa.plot.sh_coeffs_subplot([y_org, y_rot])
"""
if sh_type == 'complex':
raise NotImplementedError(
Expand All @@ -403,7 +422,7 @@ def rotate_sh(F_nm, yaw, pitch, roll, sh_type='real'):

R = sh_rotation_matrix(N_sph, yaw, pitch, roll, sh_type)

return F_nm @ R.T
return np.atleast_2d(F_nm) @ R.T


def check_cond_sht(N_sph, azi, colat, sh_type, lim=None):
Expand Down

0 comments on commit c160033

Please sign in to comment.