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]))
def _get_sampler_params(self, camera, render_source): if self.disparity is None: self.disparity = camera.width[0] / 1000. single_resolution_y = int(np.floor(camera.resolution[1]) / 2) px = np.linspace(-np.pi, np.pi, camera.resolution[0], endpoint=True)[:, None] py = np.linspace(-np.pi / 2., np.pi / 2., single_resolution_y, endpoint=True)[None, :] vectors = np.zeros((camera.resolution[0], single_resolution_y, 3), dtype='float64', order='C') vectors[:, :, 0] = np.cos(px) * np.cos(py) vectors[:, :, 1] = np.sin(px) * np.cos(py) vectors[:, :, 2] = np.sin(py) # The maximum possible length of ray max_length = (unorm(camera.position - camera._domain_center) + 0.5 * unorm(camera._domain_width) + np.abs(self.disparity)) # Rescale the ray to be long enough to cover the entire domain vectors = vectors * max_length R1 = get_rotation_matrix(0.5 * np.pi, [1, 0, 0]) R2 = get_rotation_matrix(0.5 * np.pi, [0, 0, 1]) uv = np.dot(R1, camera.unit_vectors) uv = np.dot(R2, uv) vectors.reshape((camera.resolution[0] * single_resolution_y, 3)) vectors = np.dot(vectors, uv) vectors.reshape((camera.resolution[0], single_resolution_y, 3)) vectors2 = np.zeros((camera.resolution[0], single_resolution_y, 3), dtype='float64', order='C') vectors2[:, :, 0] = -np.sin(px) * np.ones((1, single_resolution_y)) vectors2[:, :, 1] = np.cos(px) * np.ones((1, single_resolution_y)) vectors2[:, :, 2] = 0 vectors2.reshape((camera.resolution[0] * single_resolution_y, 3)) vectors2 = np.dot(vectors2, uv) vectors2.reshape((camera.resolution[0], single_resolution_y, 3)) positions = np.tile(camera.position, camera.resolution[0] * single_resolution_y) positions = positions.reshape(camera.resolution[0], single_resolution_y, 3) # The left and right are switched here since VR is in LHS. positions_left = positions + vectors2 * self.disparity positions_right = positions + vectors2 * (-self.disparity) if render_source.zbuffer is not None: image = render_source.zbuffer.rgba else: image = self.new_image(camera) dummy = np.ones(3, dtype='float64') vectors_comb = uhstack([vectors, vectors]) positions_comb = uhstack([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=dummy, y_vec=dummy, width=np.zeros(3, dtype="float64"), image=image, lens_type="stereo-spherical") return sampler_params