def test_oap(self):
        """Tests functionality of off_axis_projection and write_projection."""

        # args for off_axis_projection
        test_ds = fake_random_ds(64)
        c = test_ds.domain_center
        norm = [0.5, 0.5, 0.5]
        W = test_ds.arr([0.5, 0.5, 1.0], "unitary")
        N = 256
        field = ("gas", "density")
        oap_args = [test_ds, c, norm, W, N, field]

        # kwargs for off_axis_projection
        oap_kwargs = {}
        oap_kwargs["weight"] = (None, "cell_mass")
        oap_kwargs["no_ghost"] = (True, False)
        oap_kwargs["interpolated"] = (False,)
        oap_kwargs["north_vector"] = ((1, 0, 0), (0, 0.5, 1.0))
        oap_kwargs_list = expand_keywords(oap_kwargs)

        # args or write_projection
        fn = "test_%d.png"

        # kwargs for write_projection
        wp_kwargs = {}
        wp_kwargs["colorbar"] = (True, False)
        wp_kwargs["colorbar_label"] = "test"
        wp_kwargs["title"] = "test"
        wp_kwargs["vmin"] = (None,)
        wp_kwargs["vmax"] = (1e3, 1e5)
        wp_kwargs["take_log"] = (True, False)
        wp_kwargs["figsize"] = ((8, 6), [1, 1])
        wp_kwargs["dpi"] = (100, 50)
        wp_kwargs["cmap_name"] = ("cmyt.arbre", "cmyt.kelp")
        wp_kwargs_list = expand_keywords(wp_kwargs)

        # test all off_axis_projection kwargs and write_projection kwargs
        # make sure they are able to be projected, then remove and try next
        # iteration
        for i, oap_kwargs in enumerate(oap_kwargs_list):
            image = off_axis_projection(*oap_args, **oap_kwargs)
            for wp_kwargs in wp_kwargs_list:
                write_projection(image, fn % i, **wp_kwargs)
                assert_fname(fn % i)

        # Test remaining parameters of write_projection
        write_projection(image, "test_2", xlabel="x-axis", ylabel="y-axis")
        assert_fname("test_2.png")

        write_projection(image, "test_3.pdf", xlabel="x-axis", ylabel="y-axis")
        assert_fname("test_3.pdf")

        write_projection(image, "test_4.eps", xlabel="x-axis", ylabel="y-axis")
        assert_fname("test_4.eps")
Exemple #2
0
def test_oap(tmpdir=True):
    """Tests functionality of off_axis_projection and write_projection."""
    # Perform I/O in safe place instead of yt main dir
    if tmpdir:
        tmpdir = tempfile.mkdtemp()
        curdir = os.getcwd()
        os.chdir(tmpdir)

    # args for off_axis_projection
    test_ds = fake_random_ds(64)
    c = test_ds.domain_center
    norm = [0.5, 0.5, 0.5]
    W = test_ds.arr([0.5, 0.5, 1.0], 'unitary')
    N = 256
    field = ("gas", "density")
    oap_args = [test_ds, c, norm, W, N, field]

    # kwargs for off_axis_projection
    oap_kwargs = {}
    oap_kwargs['weight'] = (None, 'cell_mass')
    oap_kwargs['no_ghost'] = (True, False)
    oap_kwargs['interpolated'] = (False, )
    oap_kwargs['north_vector'] = ((1, 0, 0), (0, 0.5, 1.0))
    oap_kwargs_list = expand_keywords(oap_kwargs)

    # args or write_projection
    fn = "test_%d.png"

    # kwargs for write_projection
    wp_kwargs = {}
    wp_kwargs['colorbar'] = (True, False)
    wp_kwargs['colorbar_label'] = ('test')
    wp_kwargs['title'] = ('test')
    wp_kwargs['limits'] = (None, (1e3, 1e5))
    wp_kwargs['take_log'] = (True, False)
    wp_kwargs['figsize'] = ((8, 6), [1, 1])
    wp_kwargs['dpi'] = (100, 50)
    wp_kwargs['cmap_name'] = ('arbre', 'kelp')
    wp_kwargs_list = expand_keywords(wp_kwargs)

    # test all off_axis_projection kwargs and write_projection kwargs
    # make sure they are able to be projected, then remove and try next
    # iteration
    for i, oap_kwargs in enumerate(oap_kwargs_list):
        image = off_axis_projection(*oap_args, **oap_kwargs)
        for wp_kwargs in wp_kwargs_list:
            write_projection(image, fn % i, **wp_kwargs)
            yield assert_equal, os.path.exists(fn % i), True

    if tmpdir:
        os.chdir(curdir)
        # clean up
        shutil.rmtree(tmpdir)
def test_orientation():
    ds = fake_vr_orientation_test_ds()

    sc = Scene()

    vol = create_volume_source(ds, field=("gas", "density"))
    sc.add_source(vol)

    tf = vol.transfer_function
    tf = ColorTransferFunction((0.1, 1.0))
    tf.sample_colormap(1.0, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.8, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.6, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.3, 0.01, colormap="coolwarm")

    n_frames = 1
    orientations = [[-0.3, -0.1, 0.8]]

    theta = np.pi / n_frames
    test_name = "vr_orientation"

    for lens_type, decimals in [("perspective", 12), ("plane-parallel", 2)]:
        # set a much lower precision for plane-parallel tests, see
        # https://github.com/yt-project/yt/issue/3069
        # https://github.com/yt-project/yt/pull/3068
        # https://github.com/yt-project/yt/pull/3294
        frame = 0

        cam = sc.add_camera(ds, lens_type=lens_type)
        cam.resolution = (1000, 1000)
        cam.position = ds.arr(np.array([-4.0, 0.0, 0.0]), "code_length")
        cam.switch_orientation(normal_vector=[1.0, 0.0, 0.0],
                               north_vector=[0.0, 0.0, 1.0])
        cam.set_width(ds.domain_width * 2.0)
        desc = "%s_%04d" % (lens_type, frame)
        test1 = VRImageComparisonTest(sc, ds, desc, decimals)
        test1.answer_name = test_name
        yield test1

        for _ in range(n_frames):
            frame += 1
            center = ds.arr([0, 0, 0], "code_length")
            cam.yaw(theta, rot_center=center)
            desc = "yaw_%s_%04d" % (lens_type, frame)
            test2 = VRImageComparisonTest(sc, ds, desc, decimals)
            test2.answer_name = test_name
            yield test2

        for _ in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], "code_length")
            cam.pitch(theta, rot_center=center)
            desc = "pitch_%s_%04d" % (lens_type, frame)
            test3 = VRImageComparisonTest(sc, ds, desc, decimals)
            test3.answer_name = test_name
            yield test3

        for _ in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], "code_length")
            cam.roll(theta, rot_center=center)
            desc = "roll_%s_%04d" % (lens_type, frame)
            test4 = VRImageComparisonTest(sc, ds, desc, decimals)
            test4.answer_name = test_name
            yield test4

    center = [0.5, 0.5, 0.5]
    width = [1.0, 1.0, 1.0]

    for i, orientation in enumerate(orientations):
        image = off_axis_projection(ds,
                                    center,
                                    orientation,
                                    width,
                                    512, ("gas", "density"),
                                    no_ghost=False)

        def offaxis_image_func(filename_prefix):
            return image.write_image(filename_prefix)

        test5 = GenericImageTest(ds, offaxis_image_func, decimals)
        test5.prefix = f"oap_orientation_{i}"
        test5.answer_name = test_name
        yield test5
Exemple #4
0
def test_orientation():
    ds = fake_vr_orientation_test_ds()

    sc = Scene()

    vol = VolumeSource(ds, field=('gas', 'density'))
    sc.add_source(vol)

    tf = vol.transfer_function
    tf = ColorTransferFunction((0.1, 1.0))
    tf.sample_colormap(1.0, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.8, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.6, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.3, 0.01, colormap="coolwarm")

    n_frames = 1
    orientations = [[-0.3, -0.1, 0.8]]

    theta = np.pi / n_frames
    decimals = 12
    test_name = "vr_orientation"

    for lens_type in ['plane-parallel', 'perspective']:
        frame = 0

        cam = sc.add_camera(ds, lens_type=lens_type)
        cam.resolution = (1000, 1000)
        cam.position = ds.arr(np.array([-4., 0., 0.]), 'code_length')
        cam.switch_orientation(normal_vector=[1., 0., 0.],
                               north_vector=[0., 0., 1.])
        cam.set_width(ds.domain_width * 2.)
        desc = '%s_%04d' % (lens_type, frame)
        test1 = VRImageComparisonTest(sc, ds, desc, decimals)
        test1.answer_name = test_name
        yield test1

        for i in range(n_frames):
            frame += 1
            center = ds.arr([0, 0, 0], 'code_length')
            cam.yaw(theta, rot_center=center)
            desc = 'yaw_%s_%04d' % (lens_type, frame)
            test2 = VRImageComparisonTest(sc, ds, desc, decimals)
            test2.answer_name = test_name
            yield test2

        for i in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], 'code_length')
            cam.pitch(theta, rot_center=center)
            desc = 'pitch_%s_%04d' % (lens_type, frame)
            test3 = VRImageComparisonTest(sc, ds, desc, decimals)
            test3.answer_name = test_name
            yield test3

        for i in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], 'code_length')
            cam.roll(theta, rot_center=center)
            desc = 'roll_%s_%04d' % (lens_type, frame)
            test4 = VRImageComparisonTest(sc, ds, desc, decimals)
            test4.answer_name = test_name
            yield test4

    center = [0.5, 0.5, 0.5]
    width = [1.0, 1.0, 1.0]

    for i, orientation in enumerate(orientations):
        image = off_axis_projection(ds,
                                    center,
                                    orientation,
                                    width,
                                    512,
                                    "density",
                                    no_ghost=False)

        def offaxis_image_func(filename_prefix):
            return image.write_image(filename_prefix)

        test5 = GenericImageTest(ds, offaxis_image_func, decimals)
        test5.prefix = "oap_orientation_{}".format(i)
        test5.answer_name = test_name
        yield test5
def test_orientation():
    ds = fake_vr_orientation_test_ds()

    sc = Scene()

    vol = create_volume_source(ds, field=("gas", "density"))
    sc.add_source(vol)

    tf = vol.transfer_function
    tf = ColorTransferFunction((0.1, 1.0))
    tf.sample_colormap(1.0, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.8, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.6, 0.01, colormap="coolwarm")
    tf.sample_colormap(0.3, 0.01, colormap="coolwarm")

    n_frames = 1
    orientations = [[-0.3, -0.1, 0.8]]

    theta = np.pi / n_frames
    decimals = 12
    test_name = "vr_orientation"

    for lens_type in [
            "perspective",
            # final name VRImageComparison_UniformGridData_vr_pitch_plane-parallel_0002
            # deactivated because of a random failure since numpy 0.20.0 and 0.20.1
            # "plane-parallel"
    ]:
        frame = 0

        cam = sc.add_camera(ds, lens_type=lens_type)
        cam.resolution = (1000, 1000)
        cam.position = ds.arr(np.array([-4.0, 0.0, 0.0]), "code_length")
        cam.switch_orientation(normal_vector=[1.0, 0.0, 0.0],
                               north_vector=[0.0, 0.0, 1.0])
        cam.set_width(ds.domain_width * 2.0)
        desc = "%s_%04d" % (lens_type, frame)
        test1 = VRImageComparisonTest(sc, ds, desc, decimals)
        test1.answer_name = test_name
        yield test1

        for _ in range(n_frames):
            frame += 1
            center = ds.arr([0, 0, 0], "code_length")
            cam.yaw(theta, rot_center=center)
            desc = "yaw_%s_%04d" % (lens_type, frame)
            test2 = VRImageComparisonTest(sc, ds, desc, decimals)
            test2.answer_name = test_name
            yield test2

        for _ in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], "code_length")
            cam.pitch(theta, rot_center=center)
            desc = "pitch_%s_%04d" % (lens_type, frame)
            test3 = VRImageComparisonTest(sc, ds, desc, decimals)
            test3.answer_name = test_name
            yield test3

        for _ in range(n_frames):
            frame += 1
            theta = np.pi / n_frames
            center = ds.arr([0, 0, 0], "code_length")
            cam.roll(theta, rot_center=center)
            desc = "roll_%s_%04d" % (lens_type, frame)
            test4 = VRImageComparisonTest(sc, ds, desc, decimals)
            test4.answer_name = test_name
            yield test4

    center = [0.5, 0.5, 0.5]
    width = [1.0, 1.0, 1.0]

    for i, orientation in enumerate(orientations):
        image = off_axis_projection(ds,
                                    center,
                                    orientation,
                                    width,
                                    512,
                                    "density",
                                    no_ghost=False)

        def offaxis_image_func(filename_prefix):
            return image.write_image(filename_prefix)

        test5 = GenericImageTest(ds, offaxis_image_func, decimals)
        test5.prefix = f"oap_orientation_{i}"
        test5.answer_name = test_name
        yield test5