irfpy.util.isotropy

Functions for isotropic distribution

getRandom([size])

Return the randomly generated distribution

getRandom_tp([size])

Return the randomly generated distribution in \(\theta\) and \(\phi\)

irfpy.util.isotropy.getRandom_tp(size=None)[source]

Return the randomly generated distribution in \(\theta\) and \(\phi\)

Parameters:

size – The size of the array.

Returns:

Randomly generated isotropic distribution. (theta, phi) = retval in radians

Return type:

(2, size[0], size[1], …)-shaped numpy array.

>>> rnd = getRandom_tp()
>>> rnd.shape
(2,)
>>> rnd = getRandom_tp(size=(2, 4))   # (3, 2, 4) array will be returned.
>>> rnd.shape
(2, 2, 4)

Way of generation

The polar angle, \(\theta\), should distribute considering the area at spherical surface, namely depending on \(\sin\theta\). To realize this, one can start from uniform random, convert it according to

\[\theta = \cos^{-1} (1-2P)\]

where P is the (array of) value generated from random distribution.

The azimuth angle, \(\phi\), is random in the range of (0, 2 \(\pi\)).

irfpy.util.isotropy.getRandom(size=None)[source]

Return the randomly generated distribution

Parameters:

size – The size of the array.

Returns:

Randomly generated isotropic distribution. Unit vector.

Return type:

(3, size[0], size[1], …)-shaped numpy array.

>>> np.random.seed(0)   # Set the random seed.
>>> rnd = getRandom()
>>> rnd.shape
(3,)
>>> print('{:.3f}'.format((rnd ** 2).sum()))
1.000
>>> rnd = getRandom(size=(2, 4))   # (3, 2, 4) array will be returned.
>>> rnd.shape
(3, 2, 4)

Way of generation

The polar angle, \(\theta\), should distribute considering the area at spherical surface, namely depending on \(\sin\theta\). To realize this, one can start from uniform random, convert it according to

\[\theta = \cos^{-1} (1-2P)\]

where P is the (array of) value generated from random distribution.

The azimuth angle, \(\phi\), is random in the range of (0, 2 \(\pi\)).