[yt-svn] commit/yt: ngoldbaum: Merged in cosmosquark/yt-particles (pull request #1664)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Mar 4 11:09:15 PST 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/8ee9ef73ba2f/
Changeset:   8ee9ef73ba2f
Branch:      yt
User:        ngoldbaum
Date:        2016-03-04 19:09:10+00:00
Summary:     Merged in cosmosquark/yt-particles (pull request #1664)

[BUGFIX] normalise all normal vectors in functions that take a normal vector (for e.g get_sph_theta)
Affected #:  2 files

diff -r 8bb44733b706b98bcab4d691ab4bc207e6424a12 -r 8ee9ef73ba2f8323f3137fe5db30c212f8026fb1 yt/utilities/math_utils.py
--- a/yt/utilities/math_utils.py
+++ b/yt/utilities/math_utils.py
@@ -844,6 +844,15 @@
     else:
         res_vector = np.resize(vector,(3,1))
     return res_vector
+    
+def normalize_vector(vector):
+    # this function normalizes
+    # an input vector
+    
+    L2 = np.atleast_1d(np.linalg.norm(vector))
+    L2[L2==0] = 1.0
+    vector = vector / L2
+    return vector
 
 def get_sph_theta(coords, normal):
     # The angle (theta) with respect to the normal (J), is the arccos
@@ -852,6 +861,10 @@
     
     res_normal = resize_vector(normal, coords)
 
+    # check if the normal vector is normalized
+    # since arccos requires the vector to be normalised
+    res_normal = normalize_vector(res_normal)
+
     tile_shape = [1] + list(coords.shape)[1:]
     
     J = np.tile(res_normal,tile_shape)
@@ -871,6 +884,7 @@
     # yprime-component and the xprime-component of the coordinate 
     # vector.
 
+    normal = normalize_vector(normal)
     (xprime, yprime, zprime) = get_ortho_basis(normal)
 
     res_xprime = resize_vector(xprime, coords)
@@ -890,6 +904,7 @@
     # gives a vector of magnitude equal to the cylindrical radius.
 
     res_normal = resize_vector(normal, coords)
+    res_normal = normalize_vector(res_normal)
 
     tile_shape = [1] + list(coords.shape)[1:]
     J = np.tile(res_normal, tile_shape)
@@ -902,6 +917,7 @@
     # gives the cylindrical height.
 
     res_normal = resize_vector(normal, coords)
+    res_normal = normalize_vector(res_normal)
     
     tile_shape = [1] + list(coords.shape)[1:]
     J = np.tile(res_normal, tile_shape)
@@ -917,6 +933,7 @@
 def get_cyl_r_component(vectors, theta, normal):
     # The r of a vector is the vector dotted with rhat
 
+    normal = normalize_vector(normal)
     (xprime, yprime, zprime) = get_ortho_basis(normal)
 
     res_xprime = resize_vector(xprime, vectors)
@@ -933,6 +950,7 @@
 def get_cyl_theta_component(vectors, theta, normal):
     # The theta component of a vector is the vector dotted with thetahat
     
+    normal = normalize_vector(normal)
     (xprime, yprime, zprime) = get_ortho_basis(normal)
 
     res_xprime = resize_vector(xprime, vectors)
@@ -948,6 +966,7 @@
 
 def get_cyl_z_component(vectors, normal):
     # The z component of a vector is the vector dotted with zhat
+    normal = normalize_vector(normal)
     (xprime, yprime, zprime) = get_ortho_basis(normal)
 
     res_zprime = resize_vector(zprime, vectors)
@@ -959,7 +978,7 @@
 
 def get_sph_r_component(vectors, theta, phi, normal):
     # The r component of a vector is the vector dotted with rhat
-    
+    normal = normalize_vector(normal)
     (xprime, yprime, zprime) = get_ortho_basis(normal)
 
     res_xprime = resize_vector(xprime, vectors)
@@ -980,7 +999,7 @@
 
 def get_sph_phi_component(vectors, phi, normal):
     # The phi component of a vector is the vector dotted with phihat
-
+    normal = normalize_vector(normal)
     (xprime, yprime, zprime) = get_ortho_basis(normal)
 
     res_xprime = resize_vector(xprime, vectors)
@@ -996,7 +1015,7 @@
 
 def get_sph_theta_component(vectors, theta, phi, normal):
     # The theta component of a vector is the vector dotted with thetahat
-    
+    normal = normalize_vector(normal)
     (xprime, yprime, zprime) = get_ortho_basis(normal)
 
     res_xprime = resize_vector(xprime, vectors)

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the yt-svn mailing list