Example #1
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])
    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')
    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')
    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')
    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')
    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])
    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')
Example #8
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])
Example #9
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])
Example #10
0
 def test_phase_plot(self, fname):
     for p in self.phases:
         assert assert_fname(p.save(fname)[0])
Example #11
0
 def test_profile_plot(self, fname):
     for p in self.profiles:
         yield assert_fname(p.save(fname)[0])
Example #12
0
 def test_particle_plot(self, dim, fname):
     assert assert_fname(self.pplots[dim].save(fname)[0])
 def test_phase_plot(self, fname):
     for p in self.phases:
         assert assert_fname(p.save(fname)[0])
 def test_profile_plot(self, fname):
     for p in self.profiles:
         yield assert_fname(p.save(fname)[0])
Example #15
0
 def test_particle_plot(self):
     test_ds = fake_particle_ds()
     for dim in range(3):
         pplot = ParticleProjectionPlot(test_ds, dim, "particle_mass")
         for fname in TEST_FLNMS:
             assert assert_fname(pplot.save(fname)[0])
 def test_particle_plot(self, dim, fname):
     assert assert_fname(self.pplots[dim].save(fname)[0])