diff options
author | Arun Isaac | 2021-03-15 15:25:48 +0530 |
---|---|---|
committer | Arun Isaac | 2021-03-15 15:27:40 +0530 |
commit | c50fc913662a88995f5e338764dbf4efcfa71f45 (patch) | |
tree | 1668fea764993bd45cbf572ca089d07a655c2d5b /contrib | |
parent | 73cae57f5fab5e92032916c61523ec79427e8335 (diff) | |
download | nsmc-c50fc913662a88995f5e338764dbf4efcfa71f45.tar.gz nsmc-c50fc913662a88995f5e338764dbf4efcfa71f45.tar.lz nsmc-c50fc913662a88995f5e338764dbf4efcfa71f45.zip |
Add function docstrings.
* contrib/cone-vector.py (random_vector_on_sphere,
planar_angle2solid_angle_fraction, solid_angle_fraction2planar_angle,
rotate_from_nth_canonical, random_vector_on_spherical_cap): Add
docstrings.
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/cone-vector.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/contrib/cone-vector.py b/contrib/cone-vector.py index 9501464..676750f 100644 --- a/contrib/cone-vector.py +++ b/contrib/cone-vector.py @@ -22,10 +22,12 @@ from numpy.linalg import norm from scipy.special import betainc, betaincinv, gamma def random_vector_on_sphere(dim): + """Return a random vector uniformly distributed on the unit sphere.""" x = randn(dim) return x / norm(x) def planar_angle2solid_angle_fraction(planar_angle, dim): + """Return the solid angle fraction for a given planar angle.""" alpha = (dim - 1) / 2 beta = 1/2 return where(planar_angle < pi/2, @@ -33,6 +35,7 @@ def planar_angle2solid_angle_fraction(planar_angle, dim): 1 - 0.5*betainc(alpha, beta, sin(planar_angle)**2)) def solid_angle_fraction2planar_angle(solid_angle_fraction, dim): + """Return the planar angle for a given solid angle fraction.""" alpha = (dim - 1) / 2 beta = 1/2 return where(solid_angle_fraction < 1/2, @@ -40,6 +43,8 @@ def solid_angle_fraction2planar_angle(solid_angle_fraction, dim): pi - arcsin(sqrt(betaincinv(alpha, beta, 2*(1-solid_angle_fraction))))) def rotate_from_nth_canonical(x, axis): + """Rotate vector from around the nth canonical axis to the given axis. + """ xn = x[-1] axisn = axis[-1] if axisn != 1: @@ -52,6 +57,7 @@ def rotate_from_nth_canonical(x, axis): return x def random_vector_on_spherical_cap(axis, maximum_planar_angle): + """Return a random vector uniformly distributed on a spherical cap.""" dim = axis.size maximum_solid_angle_fraction = planar_angle2solid_angle_fraction(maximum_planar_angle, dim) solid_angle_fraction = maximum_solid_angle_fraction*random() |