예제 #1
0
def test_mesh_slices():
    # This test is temporarily disabled because it is seg faulty,
    # see #1394
    return

    # Perform I/O in safe place instead of yt main dir
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    np.random.seed(0x4d3d3d3)

    # tetrahedral ds
    ds = fake_tetrahedral_ds()

    for field in ds.field_list:
        for idir in [0, 1, 2]:
            sl = yt.SlicePlot(ds, idir, field)
            sl.annotate_mesh_lines()
            sl.save()

    # hexahedral ds
    ds = fake_hexahedral_ds()

    for field in ds.field_list:
        for idir in [0, 1, 2]:
            sl = yt.SlicePlot(ds, idir, field)
            sl.annotate_mesh_lines()
            sl.save()

    os.chdir(curdir)
    # clean up
    shutil.rmtree(tmpdir)
예제 #2
0
def test_velocity_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(
            fields=("density", "velocity_x", "velocity_y", "velocity_z"),
            units=("g/cm**3", "cm/s", "cm/s", "cm/s"),
        )
        for ax in "xyz":
            p = ProjectionPlot(ds,
                               ax, ("gas", "density"),
                               weight_field=("gas", "density"))
            p.annotate_velocity()
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, ("gas", "density"))
            p.annotate_velocity()
            assert_fname(p.save(prefix)[0])
        # Test for OffAxis Slice
        p = SlicePlot(ds, [1, 1, 0], ("gas", "density"),
                      north_vector=[0, 0, 1])
        p.annotate_velocity(factor=40, normalize=True)
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", ("gas", "density"))
        p.annotate_velocity(factor=8,
                            scale=0.5,
                            scale_units="inches",
                            normalize=True)
        assert_fname(p.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = fake_hexahedral_ds(fields=[f"velocity_{ax}" for ax in "xyz"])
        sl = SlicePlot(ds, 1, ("connect1", "test"))
        sl.annotate_velocity()
        assert_fname(sl.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = load(cyl_2d)
        slc = SlicePlot(ds, "theta", ("gas", "velocity_magnitude"))
        slc.annotate_velocity()
        assert_fname(slc.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = load(cyl_3d)
        for ax in ["r", "z", "theta"]:
            slc = SlicePlot(ds, ax, ("gas", "velocity_magnitude"))
            slc.annotate_velocity()
            assert_fname(slc.save(prefix)[0])
            slc = ProjectionPlot(ds, ax, ("gas", "velocity_magnitude"))
            slc.annotate_velocity()
            assert_fname(slc.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(
            fields=("density", "velocity_r", "velocity_theta", "velocity_phi"),
            units=("g/cm**3", "cm/s", "cm/s", "cm/s"),
            geometry="spherical",
        )
        p = ProjectionPlot(ds, "r", ("gas", "density"))
        p.annotate_velocity(factor=40, normalize=True)
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
예제 #3
0
def test_fake_hexahedral_ds_render():
    ds = fake_hexahedral_ds()
    field_list = [("connect1", "elem"), ("connect1", "test")]
    for field in field_list:
        sc = create_scene(ds, field)
        im = sc.render()
        test_prefix = "yt_render_fake_hexahedral_%s_%s" % (field[0], field[1])
        yield compare(
            ds, im, test_prefix=test_prefix, test_name="fake_hexahedral_ds_render"
        )
def test_mesh_slices_hexahedral():
    ds = fake_hexahedral_ds()
    for field in ds.field_list:
        for idir in [0, 1, 2]:
            prefix = "%s_%s_%s" % (field[0], field[1], idir)
            yield compare(ds,
                          field,
                          idir,
                          test_prefix=prefix,
                          test_name="mesh_slices_hexahedral",
                          annotate=True)
예제 #5
0
def test_mesh_lines_callback():
    with _cleanup_fname() as prefix:

        ds = fake_hexahedral_ds()
        for field in ds.field_list:
            sl = SlicePlot(ds, 1, field)
            sl.annotate_mesh_lines(plot_args={'color': 'black'})
            assert_fname(sl.save(prefix)[0])

        ds = fake_tetrahedral_ds()
        for field in ds.field_list:
            sl = SlicePlot(ds, 1, field)
            sl.annotate_mesh_lines(plot_args={'color': 'black'})
            assert_fname(sl.save(prefix)[0])
예제 #6
0
def test_mesh_lines_callback():
    with _cleanup_fname() as prefix:

        ds = fake_hexahedral_ds()
        for field in ds.field_list:
            sl = SlicePlot(ds, 1, field)
            sl.annotate_mesh_lines(color="black")
            assert_fname(sl.save(prefix)[0])

        ds = fake_tetrahedral_ds()
        for field in ds.field_list:
            sl = SlicePlot(ds, 1, field)
            sl.annotate_mesh_lines(color="black")
            assert_fname(sl.save(prefix)[0])
        check_axis_manipulation(sl, prefix)  # only test the final field
예제 #7
0
def test_mesh_slices_hexahedral():
    # hexahedral ds
    ds = fake_hexahedral_ds()
    ad = ds.all_data()
    mesh = ds.index.meshes[0]

    for field in ds.field_list:
        for idir in [0, 1, 2]:
            prefix = "%s_%s_%s" % (field[0], field[1], idir)
            yield compare(ds,
                          field,
                          idir,
                          test_prefix=prefix,
                          test_name="mesh_slices_hexahedral",
                          annotate=True)

            sl_obj = ds.slice(idir, ds.domain_center[idir])
            assert sl_obj[field].shape[0] == mesh.count(sl_obj.selector)
            assert sl_obj[field].shape[0] < ad[field].shape[0]
예제 #8
0
def surface_mesh_render():
    images = []

    ds = fake_tetrahedral_ds()
    for field in ds.field_list:
        sc = Scene()
        sc.add_source(MeshSource(ds, field))
        sc.add_camera()
        im = sc.render()
        images.append(im)

    ds = fake_hexahedral_ds()
    for field in ds.field_list:
        sc = Scene()
        sc.add_source(MeshSource(ds, field))
        sc.add_camera()
        im = sc.render()
        images.append(im)

    return images
예제 #9
0
def test_vertex_fields_only_in_unstructured_ds():
    def get_vertex_fields(ds):
        return [(ft, fn) for ft, fn in ds.derived_field_list if "vertex" in fn]

    ds = fake_amr_ds()
    vertex_fields = get_vertex_fields(ds)
    assert not vertex_fields

    ds = fake_hexahedral_ds()
    actual = get_vertex_fields(ds)
    expected = [
        ("all", "vertex_x"),
        ("all", "vertex_y"),
        ("all", "vertex_z"),
        ("connect1", "vertex_x"),
        ("connect1", "vertex_y"),
        ("connect1", "vertex_z"),
        ("index", "vertex_x"),
        ("index", "vertex_y"),
        ("index", "vertex_z"),
    ]
    assert actual == expected
예제 #10
0
import yt
from yt.testing import fake_hexahedral_ds

ds = fake_hexahedral_ds()

sc = yt.create_scene(ds)
cam = sc.camera
cam.focus = ds.arr([0.0, 0.0, 0.0], 'code_length')
cam_pos = ds.arr([-3.0, 3.0, -3.0], 'code_length')
north_vector = ds.arr([0.0, -1.0, -1.0], 'dimensionless')
cam.set_position(cam_pos, north_vector)

# increase the default resolution
cam.resolution = (800, 800)

sc.show()