sphrand#

torchspin.sphrand(N, k=4)[source]#

Generate N random orientations uniformly distributed on the sphere.

Port of EasySpin’s sphrand.m.

Parameters:
  • N (int) – Number of orientations to generate.

  • k (int) –

    Octant coverage:

    • 1 — full sphere (4π sr)

    • 2 — upper hemisphere (θ ∈ [0, π/2])

    • 4 — upper octant (φ ∈ [0, π/2], θ ∈ [0, π/2]) [default]

    • 8 — single spherical triangle (φ ∈ [0, π/4], θ ∈ [0, π/2])

Returns:

  • phi (ndarray, shape (N,)) – Azimuthal angles in radians.

  • theta (ndarray, shape (N,)) – Polar angles in radians (from +z axis).

Notes

Orientations are drawn from a uniform distribution on the sphere restricted to the requested octant. cos(theta) is drawn from a uniform distribution (not theta itself) to avoid polar crowding.

Examples

>>> phi, theta = sphrand(1000)          # 1000 orientations, upper octant
>>> phi, theta = sphrand(500, k=2)     # upper hemisphere
>>> phi, theta = sphrand(200, k=1)     # full sphere