Esempio n. 1
0
def _sample_ray(ray, npoints, field):
    """
    Private function that uses a ray object for calculating the field values
    that will be the y-axis values in a LinePlot object.

    Parameters
    ----------
    ray : YTOrthoRay, YTRay, or LightRay
        Ray object from which to sample field values
    npoints : int
        The number of points to sample
    field : str or field tuple
        The name of the field to sample
    """
    start_point = ray.start_point
    end_point = ray.end_point
    sample_dr = (end_point - start_point) / (npoints - 1)
    sample_points = [np.arange(npoints) * sample_dr[i] for i in range(3)]
    sample_points = uvstack(sample_points).T + start_point
    ray_coordinates = uvstack([ray[d] for d in "xyz"]).T
    ray_dds = uvstack([ray["d" + d] for d in "xyz"]).T
    ray_field = ray[field]
    field_values = ray.ds.arr(np.zeros(npoints), ray_field.units)
    for i, sample_point in enumerate(sample_points):
        ray_contains = (sample_point >= (ray_coordinates - ray_dds / 2)) & (
            sample_point <= (ray_coordinates + ray_dds / 2))
        ray_contains = ray_contains.all(axis=-1)
        # use argmax to find the first nonzero index, sometimes there
        # are two indices if the sampling point happens to fall exactly at
        # a cell boundary
        field_values[i] = ray_field[np.argmax(ray_contains)]
    dr = np.sqrt((sample_dr**2).sum())
    x = np.arange(npoints) / (npoints - 1) * (dr * npoints)
    return x, field_values
def test_numpy_wrappers():
    a1 = YTArray([1, 2, 3], 'cm')
    a2 = YTArray([2, 3, 4, 5, 6], 'cm')
    a3 = YTArray([7, 8, 9, 10, 11], 'cm')
    catenate_answer = [1, 2, 3, 2, 3, 4, 5, 6]
    intersect_answer = [2, 3]
    union_answer = [1, 2, 3, 4, 5, 6]
    vstack_answer = [[2, 3, 4, 5, 6], [7, 8, 9, 10, 11]]

    assert_array_equal(YTArray(catenate_answer, 'cm'), uconcatenate((a1, a2)))
    assert_array_equal(catenate_answer, np.concatenate((a1, a2)))

    assert_array_equal(YTArray(intersect_answer, 'cm'), uintersect1d(a1, a2))
    assert_array_equal(intersect_answer, np.intersect1d(a1, a2))

    assert_array_equal(YTArray(union_answer, 'cm'), uunion1d(a1, a2))
    assert_array_equal(union_answer, np.union1d(a1, a2))

    assert_array_equal(YTArray(catenate_answer, 'cm'), uhstack([a1, a2]))
    assert_array_equal(catenate_answer, np.hstack([a1, a2]))

    assert_array_equal(YTArray(vstack_answer, 'cm'), uvstack([a2, a3]))
    assert_array_equal(vstack_answer, np.vstack([a2, a3]))

    assert_array_equal(YTArray(vstack_answer, 'cm'), ustack([a2, a3]))
    assert_array_equal(vstack_answer, np.stack([a2, a3]))
Esempio n. 3
0
    def _get_sampler_params(self, camera, render_source):
        # Enforce width[1] / width[0] = 2 * resolution[1] / resolution[0]
        # For stereo-type lens, images for left and right eye are pasted together,
        # so the resolution of single-eye image will be 50% of the whole one.
        camera.width[1] = camera.width[0] * (
            2.0 * camera.resolution[1] / camera.resolution[0]
        )

        if self.disparity is None:
            self.disparity = 3.0 * camera.width[0] / camera.resolution[0]

        if render_source.zbuffer is not None:
            image = render_source.zbuffer.rgba
        else:
            image = self.new_image(camera)

        vectors_left, positions_left = self._get_positions_vectors(
            camera, -self.disparity
        )
        vectors_right, positions_right = self._get_positions_vectors(
            camera, self.disparity
        )

        uv = np.ones(3, dtype="float64")

        image = self.new_image(camera)
        vectors_comb = uvstack([vectors_left, vectors_right])
        positions_comb = uvstack([positions_left, positions_right])

        image.shape = (camera.resolution[0], camera.resolution[1], 4)
        vectors_comb.shape = (camera.resolution[0], camera.resolution[1], 3)
        positions_comb.shape = (camera.resolution[0], camera.resolution[1], 3)

        sampler_params = dict(
            vp_pos=positions_comb,
            vp_dir=vectors_comb,
            center=self.back_center,
            bounds=(0.0, 1.0, 0.0, 1.0),
            x_vec=uv,
            y_vec=uv,
            width=np.zeros(3, dtype="float64"),
            image=image,
            lens_type="stereo-perspective",
        )

        return sampler_params
Esempio n. 4
0
 def _yield_coordinates(self, data_file):
     pn = "particle_position_%s"
     with h5py.File(data_file.filename, 'r') as f:
         units = parse_h5_attr(f[pn % "x"], "units")
         x, y, z = (self.ds.arr(f[pn % ax].value.astype("float64"), units)
                    for ax in 'xyz')
         pos = uvstack([x, y, z]).T
         pos.convert_to_units('code_length')
         yield 'halos', pos
Esempio n. 5
0
 def _yield_coordinates(self, data_file):
     pn = "particle_position_%s"
     with h5py.File(data_file.filename, mode="r") as f:
         units = parse_h5_attr(f[pn % "x"], "units")
         x, y, z = (self.ds.arr(f[pn % ax][()].astype("float64"), units)
                    for ax in "xyz")
         pos = uvstack([x, y, z]).T
         pos.convert_to_units("code_length")
         yield "halos", pos
Esempio n. 6
0
File: io.py Progetto: pshriwise/yt
 def _yield_coordinates(self, data_file):
     with h5py.File(data_file.filename, "r") as f:
         for ptype in f.keys():
             if "x" not in f[ptype].keys():
                 continue
             units = _get_position_array_units(ptype, f, "x")
             x, y, z = (self.ds.arr(_get_position_array(ptype, f, ax),
                                    units) for ax in "xyz")
             pos = uvstack([x, y, z]).T
             pos.convert_to_units("code_length")
             yield ptype, pos
Esempio n. 7
0
    def project_to_plane(self, camera, pos, res=None):
        if res is None:
            res = camera.resolution

        # Enforce width[1] / width[0] = 2 * resolution[1] / resolution[0]
        # For stereo-type lens, images for left and right eye are pasted together,
        # so the resolution of single-eye image will be 50% of the whole one.
        camera.width[1] = camera.width[0] * (2. * res[1] / res[0])

        if self.disparity is None:
            self.disparity = 3. * camera.width[0] / camera.resolution[0]

        px_left, py_left, dz_left = self._get_px_py_dz(camera, pos, res,
                                                       -self.disparity)
        px_right, py_right, dz_right = self._get_px_py_dz(
            camera, pos, res, self.disparity)

        px = uvstack([px_left, px_right])
        py = uvstack([py_left, py_right])
        dz = uvstack([dz_left, dz_right])

        return px, py, dz