예제 #1
0
def test_magnetic_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density", "magnetic_field_x",
          "magnetic_field_y", "magnetic_field_z"))
        for ax in 'xyz':
            p = ProjectionPlot(ds, ax, "density", weight_field="density")
            p.annotate_magnetic_field()
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, "density")
            p.annotate_magnetic_field()
            assert_fname(p.save(prefix)[0])
        # Test for OffAxis Slice
        p = SlicePlot(ds, [1, 1, 0], 'density', north_vector=[0, 0, 1])
        p.annotate_magnetic_field(factor=40, normalize=True)
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_magnetic_field(factor=8, scale=0.5,
            scale_units="inches", normalize = True)
        assert_fname(p.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = load(cyl_2d)
        slc = ProjectionPlot(ds, "theta", "density")
        slc.annotate_magnetic_field()
        assert_fname(slc.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density", "magnetic_field_r",
          "magnetic_field_theta", "magnetic_field_phi"),
          geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_magnetic_field(factor=8, scale=0.5,
            scale_units="inches", normalize = True)
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
예제 #2
0
 def test_profile_plot(self):
     fields = ('density', 'temperature', 'velocity_x', 'velocity_y',
               'velocity_z')
     units = ('g/cm**3', 'K', 'cm/s', 'cm/s', 'cm/s')
     test_ds = fake_random_ds(16, fields=fields, units=units)
     regions = [
         test_ds.region([0.5] * 3, [0.4] * 3, [0.6] * 3),
         test_ds.all_data()
     ]
     pr_fields = [('density', 'temperature'), ('density', 'velocity_x'),
                  ('temperature', 'cell_mass'), ('density', 'radius'),
                  ('velocity_magnitude', 'cell_mass')]
     profiles = []
     for reg in regions:
         for x_field, y_field in pr_fields:
             profiles.append(ProfilePlot(reg, x_field, y_field))
             profiles.append(
                 ProfilePlot(reg,
                             x_field,
                             y_field,
                             fractional=True,
                             accumulation=True))
             p1d = create_profile(reg, x_field, y_field)
             profiles.append(ProfilePlot.from_profiles(p1d))
     p1 = create_profile(test_ds.all_data(), 'density', 'temperature')
     p2 = create_profile(test_ds.all_data(), 'density', 'velocity_x')
     profiles.append(
         ProfilePlot.from_profiles([p1, p2],
                                   labels=['temperature', 'velocity']))
     profiles[0]._repr_html_()
     for p in profiles:
         for fname in TEST_FLNMS:
             assert_fname(p.save(fname)[0])
예제 #3
0
def test_timestamp_callback_code_units():
    # see https://github.com/yt-project/yt/issues/3869
    with _cleanup_fname() as prefix:
        ds = fake_random_ds(2, unit_system="code")
        p = SlicePlot(ds, "z", ("gas", "density"))
        p.annotate_timestamp()
        assert_fname(p.save(prefix)[0])
예제 #4
0
    def test_camera_movement(self):
        ds = self.ds
        tf = self.setup_transfer_function('camera')

        cam = ds.camera(self.c, self.L, self.W, self.N, transfer_function=tf,
                        log_fields=[False], north_vector=[0., 0., 1.0])
        cam.zoom(0.5)
        for snap in cam.zoomin(2.0, 3):
            snap
        for snap in cam.move_to(np.array(self.c) + 0.1, 3,
                                final_width=None, exponential=False):
            snap
        for snap in cam.move_to(np.array(self.c) - 0.1, 3,
                                final_width=2.0*self.W, exponential=False):
            snap
        for snap in cam.move_to(np.array(self.c), 3,
                                final_width=1.0*self.W, exponential=True):
            snap
        cam.rotate(np.pi/10)
        cam.pitch(np.pi/10)
        cam.yaw(np.pi/10)
        cam.roll(np.pi/10)
        for snap in cam.rotation(np.pi, 3, rot_vector=None):
            snap
        for snap in cam.rotation(np.pi, 3, rot_vector=np.random.random(3)):
            snap
        cam.snapshot('final.png')
        assert_fname('final.png')
예제 #5
0
def test_particles_callback():
    with _cleanup_fname() as prefix:
        ax = 'z'
        ds = fake_amr_ds(fields=("density", ), particles=1)
        p = ProjectionPlot(ds, ax, "density")
        p.annotate_particles((10, "Mpc"))
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, "density")
        p.annotate_particles((10, "Mpc"))
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        ad = ds.all_data()
        p.annotate_particles((10, "Mpc"),
                             p_size=1.0,
                             col="k",
                             marker="o",
                             stride=1,
                             ptype="all",
                             alpha=1.0,
                             data_source=ad)
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density", ), geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_particles((10, "Mpc"))
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
예제 #6
0
    def test_projection_camera(self):
        ds = self.ds

        cam = ProjectionCamera(self.c, self.L, self.W, self.N, ds=ds,
                               field=self.field)
        cam.snapshot('projection.png')
        assert_fname('projection.png')
예제 #7
0
    def test_perspective_camera(self):
        ds = self.ds
        tf = self.setup_transfer_function('camera')

        cam = PerspectiveCamera(self.c, self.L, self.W, self.N, ds=ds,
                                transfer_function=tf, log_fields=[False])
        cam.snapshot('perspective.png')
        assert_fname('perspective.png')
예제 #8
0
    def test_data_source_camera(self):
        ds = self.ds
        tf = self.setup_transfer_function('camera')
        data_source = ds.sphere(ds.domain_center, ds.domain_width[0]*0.5)

        cam = ds.camera(self.c, self.L, self.W, self.N, log_fields=[False],
                          transfer_function=tf, data_source=data_source)
        cam.snapshot('data_source_camera.png')
        assert_fname('data_source_camera.png')
예제 #9
0
    def test_camera(self):
        tf = self.setup_transfer_function('camera')
        cam = self.ds.camera(self.c, self.L, self.W, self.N,
                               transfer_function=tf, log_fields=[False])
        cam.snapshot('camera.png')
        assert_fname('camera.png')

        im = cam.snapshot()
        im = cam.draw_domain(im)
        cam.draw_coordinate_vectors(im)
        cam.draw_line(im, [0,0,0], [1,1,0])
예제 #10
0
    def test_stereo_camera(self):
        ds = self.ds
        tf = self.setup_transfer_function('camera')

        cam = ds.camera(self.c, self.L, self.W, self.N, transfer_function=tf,
                          log_fields=[False])
        stereo_cam = StereoPairCamera(cam)
        # Take image
        cam1, cam2 = stereo_cam.split()
        cam1.snapshot(fn='stereo1.png')
        cam2.snapshot(fn='stereo2.png')
        assert_fname('stereo1.png')
        assert_fname('stereo2.png')
예제 #11
0
 def test_phase_plot(self):
     fields = ('density', 'temperature', 'velocity_x', 'velocity_y',
               'velocity_z')
     units = ('g/cm**3', 'K', 'cm/s', 'cm/s', 'cm/s')
     test_ds = fake_random_ds(16, fields=fields, units=units)
     regions = [
         test_ds.region([0.5] * 3, [0.4] * 3, [0.6] * 3),
         test_ds.all_data()
     ]
     phases = []
     ph_fields = [('density', 'temperature', 'cell_mass'),
                  ('density', 'velocity_x', 'cell_mass'),
                  ('radius', 'temperature', 'velocity_magnitude')]
     for reg in regions:
         for x_field, y_field, z_field in ph_fields:
             # set n_bins to [16, 16] since matplotlib's postscript
             # renderer is slow when it has to write a lot of polygons
             phases.append(
                 PhasePlot(reg,
                           x_field,
                           y_field,
                           z_field,
                           x_bins=16,
                           y_bins=16))
             phases.append(
                 PhasePlot(reg,
                           x_field,
                           y_field,
                           z_field,
                           fractional=True,
                           accumulation=True,
                           x_bins=16,
                           y_bins=16))
             p2d = create_profile(reg, [x_field, y_field],
                                  z_field,
                                  n_bins=[16, 16])
             phases.append(PhasePlot.from_profile(p2d))
     pp = PhasePlot(test_ds.all_data(), 'density', 'temperature',
                    'cell_mass')
     pp.set_xlim(0.3, 0.8)
     pp.set_ylim(0.4, 0.6)
     pp._setup_plots()
     xlim = pp.plots['cell_mass'].axes.get_xlim()
     ylim = pp.plots['cell_mass'].axes.get_ylim()
     assert_array_almost_equal(xlim, (0.3, 0.8))
     assert_array_almost_equal(ylim, (0.4, 0.6))
     phases.append(pp)
     phases[0]._repr_html_()
     for p in phases:
         for fname in TEST_FLNMS:
             assert_fname(p.save(fname)[0])
예제 #12
0
def test_marker_callback():
    with _cleanup_fname() as prefix:
        ax = 'z'
        vector = [1.0,1.0,1.0]
        ds = fake_amr_ds(fields = ("density",))
        p = ProjectionPlot(ds, ax, "density")
        p.annotate_marker([0.5,0.5,0.5])
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, "density")
        p.annotate_marker([0.5,0.5,0.5])
        assert_fname(p.save(prefix)[0])
        p = OffAxisSlicePlot(ds, vector, "density")
        p.annotate_marker([0.5,0.5,0.5])
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        coord = ds.arr([0.75, 0.75, 0.75], 'unitary')
        coord.convert_to_units('kpc')
        p.annotate_marker(coord, coord_system='data')
        p.annotate_marker([0.5,0.5], coord_system='axis', marker='*')
        p.annotate_marker([[0.5,0.6],[0.5,0.6],[0.5,0.6]], coord_system='data')
        p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='data')
        p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='axis')
        p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='figure')
        p.annotate_marker([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='plot')
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density",), geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_marker([0.5,0.5,0.5])
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_marker([0.5,0.5], coord_system="axis")
        assert_fname(p.save(prefix)[0])
예제 #13
0
def test_arrow_callback():
    with _cleanup_fname() as prefix:
        ax = 'z'
        vector = [1.0,1.0,1.0]
        ds = fake_amr_ds(fields = ("density",))
        p = ProjectionPlot(ds, ax, "density")
        p.annotate_arrow([0.5,0.5,0.5])
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, "density")
        p.annotate_arrow([0.5,0.5,0.5])
        assert_fname(p.save(prefix)[0])
        p = OffAxisSlicePlot(ds, vector, "density")
        p.annotate_arrow([0.5,0.5,0.5])
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_arrow([0.5,0.5], coord_system='axis', length=0.05)
        p.annotate_arrow([[0.5,0.6],[0.5,0.6],[0.5,0.6]], coord_system='data', length=0.05)
        p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='data', length=0.05)
        p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='axis', length=0.05)
        p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='figure', length=0.05)
        p.annotate_arrow([[0.5,0.6,0.8],[0.5,0.6,0.8]], coord_system='plot', length=0.05)
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density",), geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_arrow([0.5,0.5,0.5])
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_arrow([0.5,0.5], coord_system="axis")
        assert_fname(p.save(prefix)[0])
예제 #14
0
def test_line_callback():
    with _cleanup_fname() as prefix:
        ax = "z"
        vector = [1.0, 1.0, 1.0]
        ds = fake_amr_ds(fields=("density",), units=("g/cm**3",))
        p = ProjectionPlot(ds, ax, ("gas", "density"))
        p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5])
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, ("gas", "density"))
        p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5])
        assert_fname(p.save(prefix)[0])
        p = OffAxisSlicePlot(ds, vector, ("gas", "density"))
        p.annotate_line([0.1, 0.1, 0.1], [0.5, 0.5, 0.5])
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", ("gas", "density"))
        p.annotate_line([0.1, 0.1], [0.5, 0.5], coord_system="axis", color="red")
        p.save(prefix)
        check_axis_manipulation(p, prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density",), units=("g/cm**3",), geometry="spherical")
        p = ProjectionPlot(ds, "r", ("gas", "density"))
        assert_raises(
            YTDataTypeUnsupported, p.annotate_line, [0.1, 0.1, 0.1], [0.5, 0.5, 0.5]
        )
        p.annotate_line([0.1, 0.1], [0.5, 0.5], coord_system="axis")
        assert_fname(p.save(prefix)[0])
예제 #15
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])
예제 #16
0
def test_timestamp_callback():
    with _cleanup_fname() as prefix:
        ax = 'z'
        vector = [1.0, 1.0, 1.0]
        ds = fake_amr_ds(fields=("density", ))
        p = ProjectionPlot(ds, ax, "density")
        p.annotate_timestamp()
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, "density")
        p.annotate_timestamp()
        assert_fname(p.save(prefix)[0])
        p = OffAxisSlicePlot(ds, vector, "density")
        p.annotate_timestamp()
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_timestamp(corner='lower_right',
                             redshift=True,
                             draw_inset_box=True)
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density", ), geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_timestamp(coord_system="data")
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_timestamp(coord_system="axis")
        assert_fname(p.save(prefix)[0])
예제 #17
0
def test_text_callback():
    with _cleanup_fname() as prefix:
        ax = 'z'
        vector = [1.0, 1.0, 1.0]
        ds = fake_amr_ds(fields=("density", ))
        p = ProjectionPlot(ds, ax, "density")
        p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!')
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, "density")
        p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!')
        assert_fname(p.save(prefix)[0])
        p = OffAxisSlicePlot(ds, vector, "density")
        p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!')
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_text([0.5, 0.5],
                        'dinosaurs!',
                        coord_system='axis',
                        text_args={'color': 'red'})
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density", ), geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_text([0.5, 0.5, 0.5], 'dinosaurs!')
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_text([0.5, 0.5],
                        'dinosaurs!',
                        coord_system='axis',
                        text_args={'color': 'red'})
        assert_fname(p.save(prefix)[0])
예제 #18
0
def test_cell_edges_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density", ))
        for ax in 'xyz':
            p = ProjectionPlot(ds, ax, "density")
            p.annotate_cell_edges()
            assert_fname(p.save(prefix)[0])
            p = ProjectionPlot(ds, ax, "density", weight_field="density")
            p.annotate_cell_edges()
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, "density")
            p.annotate_cell_edges()
            assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_cell_edges(alpha=0.7, line_width=0.9, color=(0.0, 1.0, 1.0))
        p.save(prefix)

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

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density", ), geometry="spherical")
        p = SlicePlot(ds, "r", "density")
        p.annotate_cell_edges()
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
예제 #19
0
def test_text_callback():
    with _cleanup_fname() as prefix:
        ax = "z"
        vector = [1.0, 1.0, 1.0]
        ds = fake_amr_ds(fields=("density",), units=("g/cm**3",))
        p = ProjectionPlot(ds, ax, ("gas", "density"))
        p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!")
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, ("gas", "density"))
        p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!")
        assert_fname(p.save(prefix)[0])
        p = OffAxisSlicePlot(ds, vector, ("gas", "density"))
        p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!")
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", ("gas", "density"))
        p.annotate_text(
            [0.5, 0.5], "dinosaurs!", coord_system="axis", text_args={"color": "red"}
        )
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density",), units=("g/cm**3",), geometry="spherical")
        p = ProjectionPlot(ds, "r", ("gas", "density"))
        p.annotate_text([0.5, 0.5, 0.5], "dinosaurs!")
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
        p = ProjectionPlot(ds, "r", ("gas", "density"))
        p.annotate_text(
            [0.5, 0.5], "dinosaurs!", coord_system="axis", text_args={"color": "red"}
        )
        assert_fname(p.save(prefix)[0])
예제 #20
0
def test_sphere_callback():
    with _cleanup_fname() as prefix:
        ax = "z"
        vector = [1.0, 1.0, 1.0]
        ds = fake_amr_ds(fields=("density",))
        p = ProjectionPlot(ds, ax, "density")
        p.annotate_sphere([0.5, 0.5, 0.5], 0.1)
        assert_fname(p.save(prefix)[0])
        p = SlicePlot(ds, ax, "density")
        p.annotate_sphere([0.5, 0.5, 0.5], 0.1)
        assert_fname(p.save(prefix)[0])
        p = OffAxisSlicePlot(ds, vector, "density")
        p.annotate_sphere([0.5, 0.5, 0.5], 0.1)
        assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_sphere([0.5, 0.5], 0.1, coord_system="axis", text="blah")
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density",), geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_sphere([0.5, 0.5, 0.5], 0.1)
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_sphere([0.5, 0.5], 0.1, coord_system="axis", text="blah")
        assert_fname(p.save(prefix)[0])
예제 #21
0
def test_line_integral_convolution_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields =
            ("density", "velocity_x", "velocity_y", "velocity_z"))
        for ax in 'xyz':
            p = ProjectionPlot(ds, ax, "density")
            p.annotate_line_integral_convolution("velocity_x", "velocity_y")
            assert_fname(p.save(prefix)[0])
            p = ProjectionPlot(ds, ax, "density", weight_field="density")
            p.annotate_line_integral_convolution("velocity_x", "velocity_y")
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, "density")
            p.annotate_line_integral_convolution("velocity_x", "velocity_y")
            assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_line_integral_convolution("velocity_x", "velocity_y",
                                             kernellen=100., lim=(0.4,0.7),
                                             cmap=ytcfg.get("yt", "default_colormap"),
                                             alpha=0.9, const_alpha=True)
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = load(cyl_2d)
        slc = SlicePlot(ds, "theta", "density")
        slc.annotate_line_integral_convolution("magnetic_field_r", "magnetic_field_z")
        assert_fname(slc.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = 
            ("density", "velocity_r", "velocity_theta", "velocity_phi"),
            geometry="spherical")
        p = SlicePlot(ds, "r", "density")
        p.annotate_line_integral_convolution("velocity_theta", "velocity_phi")
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
예제 #22
0
def test_grids_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density",))
        for ax in 'xyz':
            p = ProjectionPlot(ds, ax, "density")
            p.annotate_grids()
            assert_fname(p.save(prefix)[0])
            p = ProjectionPlot(ds, ax, "density", weight_field="density")
            p.annotate_grids()
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, "density")
            p.annotate_grids()
            assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_grids(alpha=0.7, min_pix=10, min_pix_ids=30,
            draw_ids=True, periodic=False, min_level=2,
            max_level=3, cmap="gist_stern")
        p.save(prefix)

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

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density",), geometry="spherical")
        p = SlicePlot(ds, "r", "density")
        p.annotate_grids(alpha=0.7, min_pix=10, min_pix_ids=30,
            draw_ids=True, periodic=False, min_level=2,
            max_level=3, cmap="gist_stern")
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
예제 #23
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
예제 #24
0
    def test_particle_phase_plot(self):
        test_ds = fake_particle_ds()
        data_sources = [test_ds.region([0.5] * 3, [0.4] * 3, [0.6] * 3),
                        test_ds.all_data()]
        particle_phases = []

        for source in data_sources:
            for x_field, y_field, z_fields in PHASE_FIELDS:
                particle_phases.append(ParticlePhasePlot(source,
                                                         x_field,
                                                         y_field,
                                                         z_fields,
                                                         x_bins=16,
                                                         y_bins=16))

                particle_phases.append(ParticlePhasePlot(source,
                                                         x_field,
                                                         y_field,
                                                         z_fields,
                                                         x_bins=16,
                                                         y_bins=16,
                                                         deposition='cic'))

                pp = create_profile(source, [x_field, y_field], z_fields,
                                    weight_field='particle_ones',
                                    n_bins=[16, 16])

                particle_phases.append(ParticlePhasePlot.from_profile(pp))
        particle_phases[0]._repr_html_()
        for p in particle_phases:
            for fname in TEST_FLNMS:
                assert assert_fname(p.save(fname)[0])
예제 #25
0
def check_axis_manipulation(plot_obj, prefix):
    # convenience function for testing functionality of axis manipulation
    # callbacks. Can use in any of the other test functions.

    # test individual callbacks
    for cb in ("swap_axes", "flip_horizontal", "flip_vertical"):
        callback_handle = getattr(plot_obj, cb)
        callback_handle()  # toggles on for axis operation
        assert_fname(plot_obj.save(prefix)[0])
        callback_handle()  # toggle off

    # test all at once
    for cb in ("swap_axes", "flip_horizontal", "flip_vertical"):
        callback_handle = getattr(plot_obj, cb)
        callback_handle()

    assert_fname(plot_obj.save(prefix)[0])
def test_quiver_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_y",
                                 "velocity_z"))
        for ax in 'xyz':
            p = ProjectionPlot(ds, ax, "density")
            p.annotate_quiver("velocity_x", "velocity_y")
            assert_fname(p.save(prefix)[0])
            p = ProjectionPlot(ds, ax, "density", weight_field="density")
            p.annotate_quiver("velocity_x", "velocity_y")
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, "density")
            p.annotate_quiver("velocity_x", "velocity_y")
            assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_quiver("velocity_x",
                          "velocity_y",
                          factor=8,
                          scale=0.5,
                          scale_units="inches",
                          normalize=True,
                          bv_x=0.5 * u.cm / u.s,
                          bv_y=0.5 * u.cm / u.s)
        assert_fname(p.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = load(cyl_2d)
        slc = SlicePlot(ds, "theta", "density")
        slc.annotate_quiver("velocity_x", "velocity_y")
        assert_fname(slc.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density", "velocity_x", "velocity_theta",
                                 "velocity_phi"),
                         geometry="spherical")
        p = ProjectionPlot(ds, "r", "density")
        p.annotate_quiver("velocity_theta",
                          "velocity_phi",
                          factor=8,
                          scale=0.5,
                          scale_units="inches",
                          normalize=True,
                          bv_x=0.5 * u.cm / u.s,
                          bv_y=0.5 * u.cm / u.s)
        assert_raises(YTDataTypeUnsupported, p.save, prefix)
예제 #27
0
    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")
예제 #28
0
    def test_profile_plot_multiple_field_multiple_plot(self):
        ds = yt.load(ETC46)
        sphere = ds.sphere("max", (1.0, "Mpc"))
        profiles = []
        profiles.append(
            yt.create_profile(sphere, ["radius"],
                              fields=["density"],
                              n_bins=32))
        profiles.append(
            yt.create_profile(sphere, ["radius"],
                              fields=["density"],
                              n_bins=64))
        profiles.append(
            yt.create_profile(sphere, ["radius"],
                              fields=["dark_matter_density"],
                              n_bins=64))

        plot = yt.ProfilePlot.from_profiles(profiles)
        assert_fname(plot.save()[0])
예제 #29
0
def test_grids_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density",), units=("g/cm**3",))
        for ax in "xyz":
            p = ProjectionPlot(ds, ax, ("gas", "density"))
            p.annotate_grids()
            assert_fname(p.save(prefix)[0])
            p = ProjectionPlot(
                ds, ax, ("gas", "density"), weight_field=("gas", "density")
            )
            p.annotate_grids()
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, ("gas", "density"))
            p.annotate_grids()
            assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", ("gas", "density"))
        p.annotate_grids(
            alpha=0.7,
            min_pix=10,
            min_pix_ids=30,
            draw_ids=True,
            id_loc="upper right",
            periodic=False,
            min_level=2,
            max_level=3,
            cmap="gist_stern",
        )
        p.save(prefix)

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

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields=("density",), units=("g/cm**3",), geometry="spherical")
        p = SlicePlot(ds, "r", ("gas", "density"))
        kwargs = dict(
            alpha=0.7,
            min_pix=10,
            min_pix_ids=30,
            draw_ids=True,
            id_loc="upper right",
            periodic=False,
            min_level=2,
            max_level=3,
            cmap="gist_stern",
        )
        assert_raises(YTDataTypeUnsupported, p.annotate_grids, **kwargs)
예제 #30
0
def test_contour_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density", "temperature"))
        for ax in 'xyz':
            p = ProjectionPlot(ds, ax, "density")
            p.annotate_contour("temperature")
            assert_fname(p.save(prefix)[0])
            p = ProjectionPlot(ds, ax, "density", weight_field="density")
            p.annotate_contour("temperature")
            assert_fname(p.save(prefix)[0])
            p = SlicePlot(ds, ax, "density")
            p.annotate_contour("temperature") # BREAKS WITH ndarray
            assert_fname(p.save(prefix)[0])
        # Now we'll check a few additional minor things
        p = SlicePlot(ds, "x", "density")
        p.annotate_contour("temperature", ncont=10, factor=8,
            take_log=False, clim=(0.4, 0.6),
            plot_args={'linewidths':2.0}, label=True,
            text_args={'text-size':'x-large'})
        p.save(prefix)

        p = SlicePlot(ds, "x", "density")
        s2 = ds.slice(0, 0.2)
        p.annotate_contour("temperature", ncont=10, factor=8,
            take_log=False, clim=(0.4, 0.6),
            plot_args={'linewidths':2.0}, label=True,
            text_args={'text-size':'x-large'},
            data_source=s2)
        p.save(prefix)

    with _cleanup_fname() as prefix:
        ds = load(cyl_2d)
        slc = SlicePlot(ds, "theta", "plasma_beta")
        slc.annotate_contour("plasma_beta",
                             ncont=2,
                             factor=7.,
                             take_log=False,
                             clim=(1.e-1,1.e1),
                             label=True, 
                             plot_args={"colors": ("c","w"), "linewidths": 1},
                             text_args={"fmt": "%1.1f"})
        assert_fname(slc.save(prefix)[0])

    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields = ("density", "temperature"),
                         geometry="spherical")
        p = SlicePlot(ds, "r", "density")
        p.annotate_contour("temperature", ncont=10, factor=8,
            take_log=False, clim=(0.4, 0.6),
            plot_args={'linewidths':2.0}, label=True,
            text_args={'text-size':'x-large'})
        assert_raises(YTDataTypeUnsupported, p.save, prefix)