[yt-svn] commit/yt: 9 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Dec 20 10:47:41 PST 2016


9 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/33b70c4c8d16/
Changeset:   33b70c4c8d16
Branch:      yt
User:        chummels
Date:        2016-12-20 01:27:49+00:00
Summary:     Moving Logical Operator functions from YTSelectionContainer3D to YTSelectionContainer
Affected #:  1 file

diff -r 88e4005be561a5f8647e4efcf3bd8467b39671c8 -r 33b70c4c8d168c3422480cb32305e66eae0b8ac4 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1390,6 +1390,43 @@
                         if f not in fields_to_generate:
                             fields_to_generate.append(f)
 
+    def __or__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        # Should maybe do something with field parameters here
+        return YTBooleanContainer("OR", self, other, ds = self.ds)
+
+    def __invert__(self):
+        # ~obj
+        asel = yt.geometry.selection_routines.AlwaysSelector(self.ds)
+        return YTBooleanContainer("NOT", self, asel, ds = self.ds)
+
+    def __xor__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        return YTBooleanContainer("XOR", self, other, ds = self.ds)
+
+    def __and__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        return YTBooleanContainer("AND", self, other, ds = self.ds)
+
+    def __add__(self, other):
+        return self.__or__(other)
+
+    def __sub__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        return YTBooleanContainer("NEG", self, other, ds = self.ds)
+
     @contextmanager
     def _field_lock(self):
         self._locked = True
@@ -1474,6 +1511,13 @@
         self._sortkey = None
         self._sorted = {}
 
+    def __and__(self, other):
+        #if not isinstance(other, YTSelectionContainer3D):
+        #    raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        return YTBooleanContainer("AND", self, other, ds = self.ds)
+
 class YTSelectionContainer2D(YTSelectionContainer):
     _key_fields = ['px','py','pdx','pdy']
     _dimensionality = 2
@@ -1913,42 +1957,6 @@
         """
         return self.quantities.total_quantity(("index", "cell_volume"))
 
-    def __or__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        # Should maybe do something with field parameters here
-        return YTBooleanContainer("OR", self, other, ds = self.ds)
-
-    def __invert__(self):
-        # ~obj
-        asel = yt.geometry.selection_routines.AlwaysSelector(self.ds)
-        return YTBooleanContainer("NOT", self, asel, ds = self.ds)
-
-    def __xor__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        return YTBooleanContainer("XOR", self, other, ds = self.ds)
-
-    def __and__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        return YTBooleanContainer("AND", self, other, ds = self.ds)
-
-    def __add__(self, other):
-        return self.__or__(other)
-
-    def __sub__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        return YTBooleanContainer("NEG", self, other, ds = self.ds)
 
 class YTBooleanContainer(YTSelectionContainer3D):
     """
@@ -1964,9 +1972,9 @@
     ----------
     op : string
         Can be AND, OR, XOR, NOT or NEG.
-    dobj1 : YTSelectionContainer3D
+    dobj1 : YTSelectionContainer
         The first selection object
-    dobj2 : YTSelectionContainer3D
+    dobj2 : YTSelectionContainer
         The second object
 
     Examples


https://bitbucket.org/yt_analysis/yt/commits/1a3a29548dd8/
Changeset:   1a3a29548dd8
Branch:      yt
User:        chummels
Date:        2016-12-20 02:13:36+00:00
Summary:     Adding region and ray tests to boolean tests.
Affected #:  1 file

diff -r 33b70c4c8d168c3422480cb32305e66eae0b8ac4 -r 1a3a29548dd8fe103030c5d3602048562a05a3f0 yt/data_objects/tests/test_boolean_regions.py
--- a/yt/data_objects/tests/test_boolean_regions.py
+++ b/yt/data_objects/tests/test_boolean_regions.py
@@ -427,3 +427,95 @@
     b6.sort()
     assert_array_equal(b6, np.setxor1d(np.setxor1d(rei, spi), cyli))
 
+def test_boolean_ray_region_no_overlap():
+    r"""Test to make sure that boolean objects (ray, region, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping ray and region. This also checks that the original 
+    objects don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    re = ds.box([0.25]*3, [0.75]*3)
+    ra = ds.ray([0.1]*3, [0.1, 0.1, 0.9])
+    # Store the original indices
+    i1 = re["index","morton_index"]
+    i1.sort()
+    i2 = ra["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = re & ra
+    bo2 = re - ra
+    bo3 = re | ra
+    bo4 = ds.union([re, ra])
+    bo5 = ds.intersection([re, ra])
+    # This makes sure the original containers didn't change.
+    new_i1 = re["index","morton_index"]
+    new_i1.sort()
+    new_i2 = ra["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = re ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_regions_overlap():
+    r"""Test to make sure that boolean objects (ray, region, overlap)
+    behave the way we expect.
+
+    Test overlapping ray and region. This also checks that the original 
+    objects don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    re = ds.box([0.25]*3, [0.75]*3)
+    ra = ds.ray([0]*3, [1]*3)
+    # Get indices of both.
+    i1 = re["index","morton_index"]
+    i2 = ra["index","morton_index"]
+    # Make some booleans
+    bo1 = re & ra
+    bo2 = re - ra
+    bo3 = re | ra
+    bo4 = ds.union([re, ra])
+    bo5 = ds.intersection([re, ra])
+    # Now make sure the indices also behave as we expect.
+    short_line = np.intersect1d(i1, i2)
+    cube_minus_line = np.setdiff1d(i1, i2)
+    both = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, short_line)
+    assert_array_equal(b2, cube_minus_line)
+    assert_array_equal(b3, both)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = re ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))


https://bitbucket.org/yt_analysis/yt/commits/8c8c64bb0ccb/
Changeset:   8c8c64bb0ccb
Branch:      yt
User:        chummels
Date:        2016-12-20 02:31:12+00:00
Summary:     Adding boolean ray tests
Affected #:  1 file

diff -r 1a3a29548dd8fe103030c5d3602048562a05a3f0 -r 8c8c64bb0ccb154fa491af5fc01f09470c4069cd yt/data_objects/tests/test_boolean_regions.py
--- a/yt/data_objects/tests/test_boolean_regions.py
+++ b/yt/data_objects/tests/test_boolean_regions.py
@@ -477,7 +477,7 @@
     b6.sort()
     assert_array_equal(b6, np.setxor1d(i1, i2))
 
-def test_boolean_regions_overlap():
+def test_boolean_ray_region_overlap():
     r"""Test to make sure that boolean objects (ray, region, overlap)
     behave the way we expect.
 
@@ -519,3 +519,100 @@
     b6 = bo6["index", "morton_index"]
     b6.sort()
     assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_rays_no_overlap():
+    r"""Test to make sure that boolean objects (rays, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping rays.
+    """
+    ds = fake_amr_ds()
+    ra1 = ds.ray([0, 0, 0], [0, 0, 1])
+    ra2 = ds.ray([1, 0, 0], [1, 0, 1])
+    # Store the original indices
+    i1 = ra1["index","morton_index"]
+    i1.sort()
+    i2 = ra2["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = ra1 & ra2
+    bo2 = ra1 - ra2
+    bo3 = ra1 | ra2
+    bo4 = ds.union([ra1, ra2])
+    bo5 = ds.intersection([ra1, ra2])
+    # This makes sure the original containers didn't change.
+    new_i1 = ra1["index","morton_index"]
+    new_i1.sort()
+    new_i2 = ra2["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = ra1 ^ ra2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_rays_overlap():
+    r"""Test to make sure that boolean objects (rays, overlap)
+    behave the way we expect.
+
+    Test non-overlapping rays.
+    """
+    ds = fake_amr_ds()
+    ra1 = ds.ray([0]*3, [1]*3)
+    ra2 = ds.ray([0]*3, [0.5]*3)
+    # Get indices of both.
+    i1 = ra1["index","morton_index"]
+    i1.sort()
+    i2 = ra2["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = ra1 & ra2
+    bo2 = ra1 - ra2
+    bo3 = ra1 | ra2
+    bo4 = ds.union([ra1, ra2])
+    bo5 = ds.intersection([ra1, ra2])
+    # Now make sure the indices also behave as we expect.
+    short_line = np.intersect1d(i1, i2)
+    short_line_b = np.setdiff1d(i1, i2)
+    full_line = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, short_line)
+    assert_array_equal(b2, short_line_b)
+    assert_array_equal(b3, full_line)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, i1)
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = ra1 ^ ra2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+


https://bitbucket.org/yt_analysis/yt/commits/e4d5ade53344/
Changeset:   e4d5ade53344
Branch:      yt
User:        chummels
Date:        2016-12-20 02:41:10+00:00
Summary:     Adding boolean slices tests
Affected #:  1 file

diff -r 8c8c64bb0ccb154fa491af5fc01f09470c4069cd -r e4d5ade53344e0af4fb09c9d0a19b0893cebac15 yt/data_objects/tests/test_boolean_regions.py
--- a/yt/data_objects/tests/test_boolean_regions.py
+++ b/yt/data_objects/tests/test_boolean_regions.py
@@ -616,3 +616,95 @@
     b6.sort()
     assert_array_equal(b6, np.setxor1d(i1, i2))
 
+def test_boolean_slices_no_overlap():
+    r"""Test to make sure that boolean objects (slices, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping slices. This also checks that the original regions
+    don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    sl1 = ds.r[:,:,0.25]
+    sl2 = ds.r[:,:,0.75]
+    # Store the original indices
+    i1 = sl1["index","morton_index"]
+    i1.sort()
+    i2 = sl2["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = sl1 & sl2
+    bo2 = sl1 - sl2
+    bo3 = sl1 | sl2
+    bo4 = ds.union([sl1, sl2])
+    bo5 = ds.intersection([sl1, sl2])
+    # This makes sure the original containers didn't change.
+    new_i1 = sl1["index","morton_index"]
+    new_i1.sort()
+    new_i2 = sl2["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = sl1 ^ sl2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_slices_overlap():
+    r"""Test to make sure that boolean objects (slices, overlap)
+    behave the way we expect.
+
+    Test overlapping slices.
+    """
+    ds = fake_amr_ds()
+    sl1 = ds.r[:,:,0.25]
+    sl2 = ds.r[:,0.75,:]
+    # Get indices of both.
+    i1 = sl1["index","morton_index"]
+    i2 = sl2["index","morton_index"]
+    # Make some booleans
+    bo1 = sl1 & sl2
+    bo2 = sl1 - sl2
+    bo3 = sl1 | sl2
+    bo4 = ds.union([sl1, sl2])
+    bo5 = ds.intersection([sl1, sl2])
+    # Now make sure the indices also behave as we expect.
+    line = np.intersect1d(i1, i2)
+    orig = np.setdiff1d(i1, i2)
+    both = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, line)
+    assert_array_equal(b2, orig)
+    assert_array_equal(b3, both)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = sl1 ^ sl2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+


https://bitbucket.org/yt_analysis/yt/commits/a41abec70d14/
Changeset:   a41abec70d14
Branch:      yt
User:        chummels
Date:        2016-12-20 02:52:02+00:00
Summary:     Adding boolean tests for rays and slices
Affected #:  1 file

diff -r e4d5ade53344e0af4fb09c9d0a19b0893cebac15 -r a41abec70d14324adb4fc79be9c32fe998786cd0 yt/data_objects/tests/test_boolean_regions.py
--- a/yt/data_objects/tests/test_boolean_regions.py
+++ b/yt/data_objects/tests/test_boolean_regions.py
@@ -708,3 +708,99 @@
     b6.sort()
     assert_array_equal(b6, np.setxor1d(i1, i2))
 
+def test_boolean_ray_slice_no_overlap():
+    r"""Test to make sure that boolean objects (ray, slice, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping ray and slice. This also checks that the original 
+    regions don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    sl = ds.r[:,:,0.25]
+    ra = ds.ray([0]*3, [0, 1, 0])
+    # Store the original indices
+    i1 = sl["index","morton_index"]
+    i1.sort()
+    i2 = ra["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = sl & ra
+    bo2 = sl - ra
+    bo3 = sl | ra
+    bo4 = ds.union([sl, ra])
+    bo5 = ds.intersection([sl, ra])
+    # This makes sure the original containers didn't change.
+    new_i1 = sl["index","morton_index"]
+    new_i1.sort()
+    new_i2 = ra["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = sl ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_slices_overlap():
+    r"""Test to make sure that boolean objects (rays and slices, overlap)
+    behave the way we expect.
+
+    Test overlapping rays and slices.
+    """
+    ds = fake_amr_ds()
+    sl = ds.r[:,:,0.25]
+    ra = ds.ray([0, 0, 0.25], [0, 1, 0.25])
+    # Get indices of both.
+    i1 = sl["index","morton_index"]
+    i1.sort()
+    i2 = ra["index","morton_index"]
+    i1.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = sl & ra
+    bo2 = sl - ra
+    bo3 = sl | ra
+    bo4 = ds.union([sl, ra])
+    bo5 = ds.intersection([sl, ra])
+    # Now make sure the indices also behave as we expect.
+    line = np.intersect1d(i1, i2)
+    sheet_minus_line = np.setdiff1d(i1, i2)
+    sheet = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, line)
+    assert_array_equal(b2, sheet_minus_line)
+    assert_array_equal(b3, sheet)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, i1)
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = sl ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))


https://bitbucket.org/yt_analysis/yt/commits/8f78df1543b4/
Changeset:   8f78df1543b4
Branch:      yt
User:        chummels
Date:        2016-12-20 03:00:54+00:00
Summary:     Removing extraneous __and__ function
Affected #:  1 file

diff -r a41abec70d14324adb4fc79be9c32fe998786cd0 -r 8f78df1543b4e8f60531ab71d2c737ea98e5671a yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1511,13 +1511,6 @@
         self._sortkey = None
         self._sorted = {}
 
-    def __and__(self, other):
-        #if not isinstance(other, YTSelectionContainer3D):
-        #    raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        return YTBooleanContainer("AND", self, other, ds = self.ds)
-
 class YTSelectionContainer2D(YTSelectionContainer):
     _key_fields = ['px','py','pdx','pdy']
     _dimensionality = 2


https://bitbucket.org/yt_analysis/yt/commits/9b0b0d4e56be/
Changeset:   9b0b0d4e56be
Branch:      yt
User:        chummels
Date:        2016-12-20 04:23:16+00:00
Summary:     Correcting flake8 error
Affected #:  1 file

diff -r 8f78df1543b4e8f60531ab71d2c737ea98e5671a -r 9b0b0d4e56be812887c3a0c5c4d630d0035be0e4 yt/data_objects/tests/test_boolean_regions.py
--- a/yt/data_objects/tests/test_boolean_regions.py
+++ b/yt/data_objects/tests/test_boolean_regions.py
@@ -758,7 +758,7 @@
     b6.sort()
     assert_array_equal(b6, np.setxor1d(i1, i2))
 
-def test_boolean_slices_overlap():
+def test_boolean_ray_slice_overlap():
     r"""Test to make sure that boolean objects (rays and slices, overlap)
     behave the way we expect.
 


https://bitbucket.org/yt_analysis/yt/commits/89a85a4d55b7/
Changeset:   89a85a4d55b7
Branch:      yt
User:        chummels
Date:        2016-12-20 04:28:06+00:00
Summary:     Updating docs regarding boolean operators.
Affected #:  1 file

diff -r 9b0b0d4e56be812887c3a0c5c4d630d0035be0e4 -r 89a85a4d55b761cc3f96c13bde03a35524a0acd2 doc/source/analyzing/objects.rst
--- a/doc/source/analyzing/objects.rst
+++ b/doc/source/analyzing/objects.rst
@@ -630,7 +630,7 @@
 ---------------------------------------
 
 A special type of data object is the *boolean* data object, which works with
-three-dimensional data selection.  It is built by relating already existing
+data selection objects of any dimension.  It is built by relating already existing
 data objects with the bitwise operators for AND, OR and XOR, as well as the
 subtraction operator.  These are created by using the operators ``&`` for an
 intersection ("AND"), ``|`` for a union ("OR"), ``^`` for an exclusive or


https://bitbucket.org/yt_analysis/yt/commits/9f15c5506c63/
Changeset:   9f15c5506c63
Branch:      yt
User:        ngoldbaum
Date:        2016-12-20 18:47:14+00:00
Summary:     Merged in chummels/yt (pull request #2479)

Making boolean data objects function for 0D, 1D, 2D, and 3D Selection Containers (Closes #1303)
Affected #:  3 files

diff -r 9337d37e3dabed61eea5bb7321917a695bedc072 -r 9f15c5506c6304da38dd7338b4870f1e4113ccbc doc/source/analyzing/objects.rst
--- a/doc/source/analyzing/objects.rst
+++ b/doc/source/analyzing/objects.rst
@@ -630,7 +630,7 @@
 ---------------------------------------
 
 A special type of data object is the *boolean* data object, which works with
-three-dimensional data selection.  It is built by relating already existing
+data selection objects of any dimension.  It is built by relating already existing
 data objects with the bitwise operators for AND, OR and XOR, as well as the
 subtraction operator.  These are created by using the operators ``&`` for an
 intersection ("AND"), ``|`` for a union ("OR"), ``^`` for an exclusive or

diff -r 9337d37e3dabed61eea5bb7321917a695bedc072 -r 9f15c5506c6304da38dd7338b4870f1e4113ccbc yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1390,6 +1390,43 @@
                         if f not in fields_to_generate:
                             fields_to_generate.append(f)
 
+    def __or__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        # Should maybe do something with field parameters here
+        return YTBooleanContainer("OR", self, other, ds = self.ds)
+
+    def __invert__(self):
+        # ~obj
+        asel = yt.geometry.selection_routines.AlwaysSelector(self.ds)
+        return YTBooleanContainer("NOT", self, asel, ds = self.ds)
+
+    def __xor__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        return YTBooleanContainer("XOR", self, other, ds = self.ds)
+
+    def __and__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        return YTBooleanContainer("AND", self, other, ds = self.ds)
+
+    def __add__(self, other):
+        return self.__or__(other)
+
+    def __sub__(self, other):
+        if not isinstance(other, YTSelectionContainer):
+            raise YTBooleanObjectError(other)
+        if self.ds is not other.ds:
+            raise YTBooleanObjectsWrongDataset()
+        return YTBooleanContainer("NEG", self, other, ds = self.ds)
+
     @contextmanager
     def _field_lock(self):
         self._locked = True
@@ -1913,42 +1950,6 @@
         """
         return self.quantities.total_quantity(("index", "cell_volume"))
 
-    def __or__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        # Should maybe do something with field parameters here
-        return YTBooleanContainer("OR", self, other, ds = self.ds)
-
-    def __invert__(self):
-        # ~obj
-        asel = yt.geometry.selection_routines.AlwaysSelector(self.ds)
-        return YTBooleanContainer("NOT", self, asel, ds = self.ds)
-
-    def __xor__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        return YTBooleanContainer("XOR", self, other, ds = self.ds)
-
-    def __and__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        return YTBooleanContainer("AND", self, other, ds = self.ds)
-
-    def __add__(self, other):
-        return self.__or__(other)
-
-    def __sub__(self, other):
-        if not isinstance(other, YTSelectionContainer3D):
-            raise YTBooleanObjectError(other)
-        if self.ds is not other.ds:
-            raise YTBooleanObjectsWrongDataset()
-        return YTBooleanContainer("NEG", self, other, ds = self.ds)
 
 class YTBooleanContainer(YTSelectionContainer3D):
     """
@@ -1964,9 +1965,9 @@
     ----------
     op : string
         Can be AND, OR, XOR, NOT or NEG.
-    dobj1 : YTSelectionContainer3D
+    dobj1 : YTSelectionContainer
         The first selection object
-    dobj2 : YTSelectionContainer3D
+    dobj2 : YTSelectionContainer
         The second object
 
     Examples

diff -r 9337d37e3dabed61eea5bb7321917a695bedc072 -r 9f15c5506c6304da38dd7338b4870f1e4113ccbc yt/data_objects/tests/test_boolean_regions.py
--- a/yt/data_objects/tests/test_boolean_regions.py
+++ b/yt/data_objects/tests/test_boolean_regions.py
@@ -427,3 +427,380 @@
     b6.sort()
     assert_array_equal(b6, np.setxor1d(np.setxor1d(rei, spi), cyli))
 
+def test_boolean_ray_region_no_overlap():
+    r"""Test to make sure that boolean objects (ray, region, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping ray and region. This also checks that the original 
+    objects don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    re = ds.box([0.25]*3, [0.75]*3)
+    ra = ds.ray([0.1]*3, [0.1, 0.1, 0.9])
+    # Store the original indices
+    i1 = re["index","morton_index"]
+    i1.sort()
+    i2 = ra["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = re & ra
+    bo2 = re - ra
+    bo3 = re | ra
+    bo4 = ds.union([re, ra])
+    bo5 = ds.intersection([re, ra])
+    # This makes sure the original containers didn't change.
+    new_i1 = re["index","morton_index"]
+    new_i1.sort()
+    new_i2 = ra["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = re ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_ray_region_overlap():
+    r"""Test to make sure that boolean objects (ray, region, overlap)
+    behave the way we expect.
+
+    Test overlapping ray and region. This also checks that the original 
+    objects don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    re = ds.box([0.25]*3, [0.75]*3)
+    ra = ds.ray([0]*3, [1]*3)
+    # Get indices of both.
+    i1 = re["index","morton_index"]
+    i2 = ra["index","morton_index"]
+    # Make some booleans
+    bo1 = re & ra
+    bo2 = re - ra
+    bo3 = re | ra
+    bo4 = ds.union([re, ra])
+    bo5 = ds.intersection([re, ra])
+    # Now make sure the indices also behave as we expect.
+    short_line = np.intersect1d(i1, i2)
+    cube_minus_line = np.setdiff1d(i1, i2)
+    both = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, short_line)
+    assert_array_equal(b2, cube_minus_line)
+    assert_array_equal(b3, both)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = re ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_rays_no_overlap():
+    r"""Test to make sure that boolean objects (rays, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping rays.
+    """
+    ds = fake_amr_ds()
+    ra1 = ds.ray([0, 0, 0], [0, 0, 1])
+    ra2 = ds.ray([1, 0, 0], [1, 0, 1])
+    # Store the original indices
+    i1 = ra1["index","morton_index"]
+    i1.sort()
+    i2 = ra2["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = ra1 & ra2
+    bo2 = ra1 - ra2
+    bo3 = ra1 | ra2
+    bo4 = ds.union([ra1, ra2])
+    bo5 = ds.intersection([ra1, ra2])
+    # This makes sure the original containers didn't change.
+    new_i1 = ra1["index","morton_index"]
+    new_i1.sort()
+    new_i2 = ra2["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = ra1 ^ ra2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_rays_overlap():
+    r"""Test to make sure that boolean objects (rays, overlap)
+    behave the way we expect.
+
+    Test non-overlapping rays.
+    """
+    ds = fake_amr_ds()
+    ra1 = ds.ray([0]*3, [1]*3)
+    ra2 = ds.ray([0]*3, [0.5]*3)
+    # Get indices of both.
+    i1 = ra1["index","morton_index"]
+    i1.sort()
+    i2 = ra2["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = ra1 & ra2
+    bo2 = ra1 - ra2
+    bo3 = ra1 | ra2
+    bo4 = ds.union([ra1, ra2])
+    bo5 = ds.intersection([ra1, ra2])
+    # Now make sure the indices also behave as we expect.
+    short_line = np.intersect1d(i1, i2)
+    short_line_b = np.setdiff1d(i1, i2)
+    full_line = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, short_line)
+    assert_array_equal(b2, short_line_b)
+    assert_array_equal(b3, full_line)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, i1)
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = ra1 ^ ra2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_slices_no_overlap():
+    r"""Test to make sure that boolean objects (slices, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping slices. This also checks that the original regions
+    don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    sl1 = ds.r[:,:,0.25]
+    sl2 = ds.r[:,:,0.75]
+    # Store the original indices
+    i1 = sl1["index","morton_index"]
+    i1.sort()
+    i2 = sl2["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = sl1 & sl2
+    bo2 = sl1 - sl2
+    bo3 = sl1 | sl2
+    bo4 = ds.union([sl1, sl2])
+    bo5 = ds.intersection([sl1, sl2])
+    # This makes sure the original containers didn't change.
+    new_i1 = sl1["index","morton_index"]
+    new_i1.sort()
+    new_i2 = sl2["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = sl1 ^ sl2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_slices_overlap():
+    r"""Test to make sure that boolean objects (slices, overlap)
+    behave the way we expect.
+
+    Test overlapping slices.
+    """
+    ds = fake_amr_ds()
+    sl1 = ds.r[:,:,0.25]
+    sl2 = ds.r[:,0.75,:]
+    # Get indices of both.
+    i1 = sl1["index","morton_index"]
+    i2 = sl2["index","morton_index"]
+    # Make some booleans
+    bo1 = sl1 & sl2
+    bo2 = sl1 - sl2
+    bo3 = sl1 | sl2
+    bo4 = ds.union([sl1, sl2])
+    bo5 = ds.intersection([sl1, sl2])
+    # Now make sure the indices also behave as we expect.
+    line = np.intersect1d(i1, i2)
+    orig = np.setdiff1d(i1, i2)
+    both = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, line)
+    assert_array_equal(b2, orig)
+    assert_array_equal(b3, both)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = sl1 ^ sl2
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_ray_slice_no_overlap():
+    r"""Test to make sure that boolean objects (ray, slice, no overlap)
+    behave the way we expect.
+
+    Test non-overlapping ray and slice. This also checks that the original 
+    regions don't change as part of constructing the booleans.
+    """
+    ds = fake_amr_ds()
+    sl = ds.r[:,:,0.25]
+    ra = ds.ray([0]*3, [0, 1, 0])
+    # Store the original indices
+    i1 = sl["index","morton_index"]
+    i1.sort()
+    i2 = ra["index","morton_index"]
+    i2.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = sl & ra
+    bo2 = sl - ra
+    bo3 = sl | ra
+    bo4 = ds.union([sl, ra])
+    bo5 = ds.intersection([sl, ra])
+    # This makes sure the original containers didn't change.
+    new_i1 = sl["index","morton_index"]
+    new_i1.sort()
+    new_i2 = ra["index","morton_index"]
+    new_i2.sort()
+    assert_array_equal(new_i1, i1)
+    assert_array_equal(new_i2, i2)
+    # Now make sure the indices also behave as we expect.
+    empty = np.array([])
+    assert_array_equal(bo1["index","morton_index"], empty)
+    assert_array_equal(bo5["index","morton_index"], empty)
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    assert_array_equal(b2, i1 )
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b3, ii)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, b4)
+    bo6 = sl ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))
+
+def test_boolean_ray_slice_overlap():
+    r"""Test to make sure that boolean objects (rays and slices, overlap)
+    behave the way we expect.
+
+    Test overlapping rays and slices.
+    """
+    ds = fake_amr_ds()
+    sl = ds.r[:,:,0.25]
+    ra = ds.ray([0, 0, 0.25], [0, 1, 0.25])
+    # Get indices of both.
+    i1 = sl["index","morton_index"]
+    i1.sort()
+    i2 = ra["index","morton_index"]
+    i1.sort()
+    ii = np.concatenate((i1, i2))
+    ii.sort()
+    # Make some booleans
+    bo1 = sl & ra
+    bo2 = sl - ra
+    bo3 = sl | ra
+    bo4 = ds.union([sl, ra])
+    bo5 = ds.intersection([sl, ra])
+    # Now make sure the indices also behave as we expect.
+    line = np.intersect1d(i1, i2)
+    sheet_minus_line = np.setdiff1d(i1, i2)
+    sheet = np.union1d(i1, i2)
+    b1 = bo1["index","morton_index"]
+    b1.sort()
+    b2 = bo2["index","morton_index"]
+    b2.sort()
+    b3 = bo3["index","morton_index"]
+    b3.sort()
+    assert_array_equal(b1, line)
+    assert_array_equal(b2, sheet_minus_line)
+    assert_array_equal(b3, sheet)
+    b4 = bo4["index","morton_index"]
+    b4.sort()
+    b5 = bo5["index","morton_index"]
+    b5.sort()
+    assert_array_equal(b3, i1)
+    assert_array_equal(b3, b4)
+    assert_array_equal(b1, b5)
+    bo6 = sl ^ ra
+    b6 = bo6["index", "morton_index"]
+    b6.sort()
+    assert_array_equal(b6, np.setxor1d(i1, i2))

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