[yt-svn] commit/yt: xarthisius: Merged in atmyers/yt (pull request #2151)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Apr 29 09:49:35 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/0daf747c5d00/
Changeset:   0daf747c5d00
Branch:      yt
User:        xarthisius
Date:        2016-04-29 16:49:23+00:00
Summary:     Merged in atmyers/yt (pull request #2151)

Print an error message in Orientation if the requested vectors are aligned. Closes Issue #1189.
Affected #:  1 file

diff -r a3c2f4884d539e346255fbbb84117980d8d7719e -r 0daf747c5d006d087f132b62d750c61874a76e19 yt/utilities/orientation.py
--- a/yt/utilities/orientation.py
+++ b/yt/utilities/orientation.py
@@ -18,6 +18,28 @@
 
 from yt.funcs import mylog
 from yt.units.yt_array import YTArray
+from yt.utilities.exceptions import YTException
+
+def _aligned(a, b):
+    aligned_component = np.abs(np.dot(a, b) / np.linalg.norm(a) / np.linalg.norm(b))
+    return np.isclose(aligned_component, 1.0, 1.0e-13)
+    
+
+def _validate_unit_vectors(normal_vector, north_vector):
+
+    # Make sure vectors are unitless
+    if north_vector is not None:
+        north_vector = YTArray(north_vector, "", dtype='float64')
+    if normal_vector is not None:
+        normal_vector = YTArray(normal_vector, "", dtype='float64')
+
+    if not np.dot(normal_vector, normal_vector) > 0:
+        raise YTException("normal_vector cannot be the zero vector.")
+
+    if north_vector is not None and _aligned(north_vector, normal_vector):
+        raise YTException("normal_vector and north_vector cannot be aligned.")
+
+    return normal_vector, north_vector
 
 
 class Orientation(object):
@@ -41,18 +63,9 @@
 
         """
 
-        # Make sure vectors are unitless
-        if north_vector is not None:
-            north_vector = YTArray(north_vector, "", dtype='float64')
-        if normal_vector is not None:
-            normal_vector = YTArray(normal_vector, "", dtype='float64')
-
+        normal_vector, north_vector = _validate_unit_vectors(normal_vector,
+                                                             north_vector)
         self.steady_north = steady_north
-        if not np.dot(normal_vector, normal_vector) > 0:
-            mylog.error("Normal vector is null")
-        if np.all(north_vector == normal_vector):
-            mylog.error("North vector and normal vector are the same.  Disregarding north vector.")
-            north_vector = None
         if north_vector is not None:
             self.steady_north = True
         self.north_vector = north_vector
@@ -61,15 +74,10 @@
             self.north_vector = self.unit_vectors[1]
 
     def _setup_normalized_vectors(self, normal_vector, north_vector):
+        normal_vector, north_vector = _validate_unit_vectors(normal_vector,
+                                                             north_vector)
         mylog.debug('Setting normalized vectors' + str(normal_vector)
                     + str(north_vector))
-
-        # Make sure vectors are unitless
-        if north_vector is not None:
-            north_vector = YTArray(north_vector, "", dtype='float64')
-        if normal_vector is not None:
-            normal_vector = YTArray(normal_vector, "", dtype='float64')
-
         # Now we set up our various vectors
         normal_vector /= np.sqrt(np.dot(normal_vector, normal_vector))
         if north_vector is None:

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160429/d2e4dbf5/attachment-0001.htm>


More information about the yt-svn mailing list