Esempio n. 1
0
def phase_plot(halo, output_dir=".", phase_args=None, phase_kwargs=None):
    r"""
    Make a phase plot for the halo object.

    Parameters
    ----------
    halo : Halo object
        The Halo object to be provided by the HaloCatalog.
    output_dir : string
        Name of directory where profile data will be written.  The full path will be
        the output_dir of the halo catalog concatenated with this directory.
        Default : "."
    phase_args : list
        List of arguments to be given to PhasePlot.
    phase_kwargs : dict
        Dictionary of keyword arguments to be given to PhasePlot.

    """

    if phase_args is None:
        phase_args = []
    if phase_kwargs is None:
        phase_kwargs = {}

    try:
        plot = PhasePlot(halo.data_object, *phase_args, **phase_kwargs)
        plot.save(os.path.join(halo.halo_catalog.output_dir, output_dir,
                               "halo_%06d" % halo.quantities["particle_identifier"]))
    except ValueError:
        return
Esempio n. 2
0
def test_profile_data():
    tmpdir = make_tempdir()
    curdir = os.getcwd()
    os.chdir(tmpdir)
    ds = data_dir_load(enzotiny)
    ad = ds.all_data()
    profile_1d = create_profile(ad,
                                "density",
                                "temperature",
                                weight_field="cell_mass")
    fn = profile_1d.save_as_dataset()
    full_fn = os.path.join(tmpdir, fn)
    prof_1d_ds = load(full_fn)
    compare_unit_attributes(ds, prof_1d_ds)
    assert isinstance(prof_1d_ds, YTProfileDataset)

    for field in profile_1d.standard_deviation:
        assert_array_equal(
            profile_1d.standard_deviation[field],
            prof_1d_ds.profile.standard_deviation["data", field[1]],
        )

    p1 = ProfilePlot(prof_1d_ds.data,
                     "density",
                     "temperature",
                     weight_field="cell_mass")
    p1.save()

    yield YTDataFieldTest(full_fn, "temperature", geometric=False)
    yield YTDataFieldTest(full_fn, "x", geometric=False)
    yield YTDataFieldTest(full_fn, "density", geometric=False)
    profile_2d = create_profile(
        ad,
        ["density", "temperature"],
        "cell_mass",
        weight_field=None,
        n_bins=(128, 128),
    )
    fn = profile_2d.save_as_dataset()
    full_fn = os.path.join(tmpdir, fn)
    prof_2d_ds = load(full_fn)
    compare_unit_attributes(ds, prof_2d_ds)
    assert isinstance(prof_2d_ds, YTProfileDataset)

    p2 = PhasePlot(prof_2d_ds.data,
                   "density",
                   "temperature",
                   "cell_mass",
                   weight_field=None)
    p2.save()

    yield YTDataFieldTest(full_fn, "density", geometric=False)
    yield YTDataFieldTest(full_fn, "x", geometric=False)
    yield YTDataFieldTest(full_fn, "temperature", geometric=False)
    yield YTDataFieldTest(full_fn, "y", geometric=False)
    yield YTDataFieldTest(full_fn, "cell_mass", geometric=False)
    os.chdir(curdir)
    if tmpdir != ".":
        shutil.rmtree(tmpdir)
Esempio n. 3
0
def test_old_profile_data():
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)
    ds = data_dir_load(enzotiny)
    ad = ds.all_data()
    profile_1d = create_profile(
        ad,
        ("gas", "density"),
        ("gas", "temperature"),
        weight_field=("gas", "cell_mass"),
    )
    fn = "DD0046_Profile1D.h5"
    full_fn = os.path.join(ytdata_dir, fn)
    prof_1d_ds = data_dir_load(full_fn)
    compare_unit_attributes(ds, prof_1d_ds)
    assert isinstance(prof_1d_ds, YTProfileDataset)

    for field in profile_1d.standard_deviation:
        assert_array_equal(
            profile_1d.standard_deviation[field],
            prof_1d_ds.profile.standard_deviation["data", field[1]],
        )

    p1 = ProfilePlot(
        prof_1d_ds.data,
        ("gas", "density"),
        ("gas", "temperature"),
        weight_field=("gas", "cell_mass"),
    )
    p1.save()

    yield YTDataFieldTest(full_fn, ("gas", "temperature"), geometric=False)
    yield YTDataFieldTest(full_fn, ("index", "x"), geometric=False)
    yield YTDataFieldTest(full_fn, ("gas", "density"), geometric=False)
    fn = "DD0046_Profile2D.h5"
    full_fn = os.path.join(ytdata_dir, fn)
    prof_2d_ds = data_dir_load(full_fn)
    compare_unit_attributes(ds, prof_2d_ds)
    assert isinstance(prof_2d_ds, YTProfileDataset)

    p2 = PhasePlot(
        prof_2d_ds.data,
        ("gas", "density"),
        ("gas", "temperature"),
        ("gas", "cell_mass"),
        weight_field=None,
    )
    p2.save()

    yield YTDataFieldTest(full_fn, ("gas", "density"), geometric=False)
    yield YTDataFieldTest(full_fn, ("index", "x"), geometric=False)
    yield YTDataFieldTest(full_fn, ("gas", "temperature"), geometric=False)
    yield YTDataFieldTest(full_fn, ("index", "y"), geometric=False)
    yield YTDataFieldTest(full_fn, ("gas", "cell_mass"), geometric=False)
    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 4
0
 def setUpClass(cls):
     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(64, fields=fields, units=units)
     regions = [
         test_ds.region([0.5] * 3, [0.4] * 3, [0.6] * 3),
         test_ds.all_data()
     ]
     profiles = []
     phases = []
     pr_fields = [('density', 'temperature'), ('density', 'velocity_x'),
                  ('temperature', 'cell_mass'), ('density', 'radius'),
                  ('velocity_magnitude', 'cell_mass')]
     ph_fields = [('density', 'temperature', 'cell_mass'),
                  ('density', 'velocity_x', 'cell_mass'),
                  ('radius', 'temperature', 'velocity_magnitude')]
     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))
         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))
     cls.profiles = profiles
     cls.phases = phases
     cls.ds = test_ds
def test_profile_data():
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)
    ds = data_dir_load(enzotiny)
    ad = ds.all_data()
    profile_1d = create_profile(ad,
                                "density",
                                "temperature",
                                weight_field="cell_mass")
    fn = profile_1d.save_as_dataset()
    full_fn = os.path.join(tmpdir, fn)
    prof_1d_ds = load(full_fn)
    compare_unit_attributes(ds, prof_1d_ds)
    assert isinstance(prof_1d_ds, YTProfileDataset)

    p1 = ProfilePlot(prof_1d_ds.data,
                     "density",
                     "temperature",
                     weight_field="cell_mass")
    p1.save()

    yield YTDataFieldTest(full_fn, "temperature", geometric=False)
    yield YTDataFieldTest(full_fn, "x", geometric=False)
    yield YTDataFieldTest(full_fn, "density", geometric=False)
    profile_2d = create_profile(ad, ["density", "temperature"],
                                "cell_mass",
                                weight_field=None,
                                n_bins=(128, 128))
    fn = profile_2d.save_as_dataset()
    full_fn = os.path.join(tmpdir, fn)
    prof_2d_ds = load(full_fn)
    compare_unit_attributes(ds, prof_2d_ds)
    assert isinstance(prof_2d_ds, YTProfileDataset)

    p2 = PhasePlot(prof_2d_ds.data,
                   "density",
                   "temperature",
                   "cell_mass",
                   weight_field=None)
    p2.save()

    yield YTDataFieldTest(full_fn, "density", geometric=False)
    yield YTDataFieldTest(full_fn, "x", geometric=False)
    yield YTDataFieldTest(full_fn, "temperature", geometric=False)
    yield YTDataFieldTest(full_fn, "y", geometric=False)
    yield YTDataFieldTest(full_fn, "cell_mass", geometric=False)
    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 6
0
 def plot(self):
     r"""
     This returns a :class:~yt.visualization.profile_plotter.PhasePlot with
     the fields that have been added to this object.
     """
     from yt.visualization.profile_plotter import PhasePlot
     return PhasePlot.from_profile(self)
Esempio n. 7
0
def test_field_access():
    ds = fake_random_ds(16)

    ad = ds.all_data()
    sp = ds.sphere(ds.domain_center, 0.25)
    cg = ds.covering_grid(0, ds.domain_left_edge, ds.domain_dimensions)
    scg = ds.smoothed_covering_grid(0, ds.domain_left_edge,
                                    ds.domain_dimensions)
    sl = ds.slice(0, ds.domain_center[0])
    proj = ds.proj(("gas", "density"), 0)
    prof = create_profile(ad, ("index", "radius"), ("gas", "density"))

    for data_object in [ad, sp, cg, scg, sl, proj, prof]:
        assert_equal(data_object["gas", "density"],
                     data_object[ds.fields.gas.density])

    for field in [("gas", "density"), ds.fields.gas.density]:
        ad = ds.all_data()
        prof = ProfilePlot(ad, ("index", "radius"), field)
        phase = PhasePlot(ad, ("index", "radius"), field, ("gas", "cell_mass"))
        s = SlicePlot(ds, 2, field)
        oas = SlicePlot(ds, [1, 1, 1], field)
        p = ProjectionPlot(ds, 2, field)
        oap = OffAxisProjectionPlot(ds, [1, 1, 1], field)

        for plot_object in [s, oas, p, oap, prof, phase]:
            plot_object._setup_plots()
            if hasattr(plot_object, "_frb"):
                plot_object._frb[field]
 def setUpClass(cls):
     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(64, fields=fields, units=units)
     regions = [test_ds.region([0.5]*3, [0.4]*3, [0.6]*3), test_ds.all_data()]
     profiles = []
     phases = []
     pr_fields = [('density', 'temperature'), ('density', 'velocity_x'),
                  ('temperature', 'cell_mass'), ('density', 'radius'),
                  ('velocity_magnitude', 'cell_mass')]
     ph_fields = [('density', 'temperature', 'cell_mass'),
                  ('density', 'velocity_x', 'cell_mass'),
                  ('radius', 'temperature', 'velocity_magnitude')]
     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))
         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))
     cls.profiles = profiles
     cls.phases = phases
     cls.ds = test_ds
Esempio n. 9
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])
Esempio n. 10
0
    def setUpClass(cls):
        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(64, fields=fields, units=units)
        regions = [
            test_ds.region([0.5] * 3, [0.4] * 3, [0.6] * 3),
            test_ds.all_data()
        ]
        profiles = []
        phases = []
        pr_fields = [('density', 'temperature'), ('density', 'velocity_x'),
                     ('temperature', 'cell_mass'), ('density', 'radius'),
                     ('velocity_magnitude', 'cell_mass')]
        ph_fields = [('density', 'temperature', 'cell_mass'),
                     ('density', 'velocity_x', 'cell_mass'),
                     ('radius', 'temperature', 'velocity_magnitude')]
        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))
            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)

        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']))

        cls.profiles = profiles
        cls.phases = phases
        cls.ds = test_ds
def test_phase_plot():
    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 idx, plot in enumerate(phases):
        test_prefix = f"{plot.plots.keys()}_{idx}"
        yield compare(test_ds,
                      plot,
                      test_prefix=test_prefix,
                      test_name="phase_plots")