Exemplo n.º 1
0
 def _create_ortho_ray(self, ray_tuple):
     axis = None
     new_slice = []
     coord = []
     npoints = 0
     start_point = []
     end_point = []
     for ax, v in enumerate(ray_tuple):
         if not isinstance(v, slice):
             val = self._spec_to_value(v)
             coord.append(val)
             new_slice.append(slice(None, None, None))
             start_point.append(val)
             end_point.append(val)
         else:
             if axis is not None: raise RuntimeError
             if getattr(v.step, "imag", 0.0) != 0.0:
                 npoints = int(v.step.imag)
                 xi = self._spec_to_value(v.start)
                 xf = self._spec_to_value(v.stop)
                 dx = (xf - xi) / npoints
                 start_point.append(xi + 0.5 * dx)
                 end_point.append(xf - 0.5 * dx)
             else:
                 axis = ax
                 new_slice.append(v)
     if npoints > 0:
         ray = LineBuffer(self.ds, start_point, end_point, npoints)
     else:
         if axis == 1:
             coord = [coord[1], coord[0]]
         source = self._create_region(new_slice)
         ray = self.ds.ortho_ray(axis, coord, data_source=source)
     return ray
Exemplo n.º 2
0
 def _create_ray(self, ray_slice):
     start_point = [self._spec_to_value(v) for v in ray_slice.start]
     end_point = [self._spec_to_value(v) for v in ray_slice.stop]
     if getattr(ray_slice.step, "imag", 0.0) != 0.0:
         return LineBuffer(self.ds, start_point, end_point,
                           int(ray_slice.step.imag))
     else:
         return self.ds.ray(start_point, end_point)
Exemplo n.º 3
0
def test_ortho_ray_from_r():
    ds = fake_amr_ds(fields=["density"])
    ray1 = ds.r[:, 0.3, 0.2]
    ray2 = ds.ortho_ray("x", [0.3, 0.2])
    assert_equal(ray1["density"], ray2["density"])

    # the y-coord is funny so test it too
    ray3 = ds.r[0.3, :, 0.2]
    ray4 = ds.ortho_ray("y", [0.2, 0.3])
    assert_equal(ray3["density"], ray4["density"])

    # Test ray which doesn't cover the whole domain
    box = ds.box([0.25, 0.0, 0.0], [0.75, 1.0, 1.0])
    ray5 = ds.r[0.25:0.75, 0.3, 0.2]
    ray6 = ds.ortho_ray("x", [0.3, 0.2], data_source=box)
    assert_equal(ray5["density"], ray6["density"])

    # Test fixed-resolution rays
    ray7 = ds.r[0.25:0.75:100j, 0.3, 0.2]
    ray8 = LineBuffer(ds, [0.2525, 0.3, 0.2], [0.7475, 0.3, 0.2], 100)
    assert_equal(ray7["density"], ray8["density"])
Exemplo n.º 4
0
def test_ray_from_r():
    ds = fake_amr_ds(fields=["density"])
    ray1 = ds.r[(0.1, 0.2, 0.3):(0.4, 0.5, 0.6)]
    ray2 = ds.ray((0.1, 0.2, 0.3), (0.4, 0.5, 0.6))
    assert_equal(ray1["density"], ray2["density"])

    ray3 = ds.r[0.5 * ds.domain_left_edge:0.5 * ds.domain_right_edge]
    ray4 = ds.ray(0.5 * ds.domain_left_edge, 0.5 * ds.domain_right_edge)
    assert_equal(ray3["density"], ray4["density"])

    start = [(0.1, "cm"), 0.2, (0.3, "cm")]
    end = [(0.5, "cm"), (0.4, "cm"), 0.6]
    ray5 = ds.r[start:end]
    start_arr = [ds.quan(0.1, "cm"), ds.quan(0.2, "cm"), ds.quan(0.3, "cm")]
    end_arr = [ds.quan(0.5, "cm"), ds.quan(0.4, "cm"), ds.quan(0.6, "cm")]
    ray6 = ds.ray(start_arr, end_arr)
    assert_equal(ray5["density"], ray6["density"])

    ray7 = ds.r[start:end:500j]
    ray8 = LineBuffer(ds, [0.1, 0.2, 0.3], [0.5, 0.4, 0.6], 500)
    assert_equal(ray7["density"], ray8["density"])