Commits

Matthew Turk  committed 565f638

Sort ray objects.

  • Participants
  • Parent commits 63ac8c1
  • Branches yt-3.0

Comments (0)

Files changed (2)

File yt/data_objects/selection_data_containers.py

     _key_fields = ['x','y','z','dx','dy','dz']
     _type_name = "ortho_ray"
     _con_args = ('axis', 'coords')
+    _sort_ind = None
     def __init__(self, axis, coords, pf=None, field_parameters=None):
         super(YTOrthoRayBase, self).__init__(pf, field_parameters)
         self.axis = axis
         self.px_dx = 'd%s'%('xyz'[self.px_ax])
         self.py_dx = 'd%s'%('xyz'[self.py_ax])
         self.px, self.py = coords
-        self.sort_by = 'xyz'[self.axis]
+        self._sort_by = 'xyz'[self.axis]
+
+    def __getitem__(self, key):
+        if self._sort_ind is None:
+            sv = super(YTOrthoRayBase, self).__getitem__(self._sort_by)
+            self._sort_ind = np.argsort(sv)
+        v = super(YTOrthoRayBase, self).__getitem__(key)
+        return v[self._sort_ind]
 
     @property
     def coords(self):
     _type_name = "ray"
     _con_args = ('start_point', 'end_point')
     _container_fields = ("t", "dts")
+    _sort_by = "t"
+    _sort_ind = None
     def __init__(self, start_point, end_point, pf=None, field_parameters=None):
         super(YTRayBase, self).__init__(pf, field_parameters)
         self.start_point = self.pf.arr(start_point,
         else:
             raise KeyError(field)
 
+    def __getitem__(self, key):
+        if self._sort_ind is None:
+            sv = super(YTRayBase, self).__getitem__(self._sort_by)
+            self._sort_ind = np.argsort(sv)
+        v = super(YTRayBase, self).__getitem__(key)
+        return v[self._sort_ind]
+
 class YTSliceBase(YTSelectionContainer2D):
     """
     This is a data object corresponding to a slice through the simulation

File yt/data_objects/tests/test_rays.py

 
 def test_amr_ray():
     pf = fake_amr_pf()
+    s = pf.slice(0, 0.5)
     ray = pf.ray(pf.domain_left_edge, pf.domain_right_edge)
     yield assert_equal, (np.diff(ray["t"]) >= 0).all(), True
+    ray = pf.ortho_ray(0, (0.5, 0.5))
+    yield assert_equal, (np.diff(ray["x"]) >= 0).all(), True