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])
Example #2
0
def test_profile_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()]
    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 idx, plot in enumerate(profiles):
        test_prefix = "%s_%s" % (plot.plots.keys(), idx)
        yield compare(test_ds, plot, test_prefix=test_prefix,
                      test_name="profile_plots")
Example #3
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
Example #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))
        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
Example #5
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]
Example #6
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)
Example #7
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)
Example #8
0
def test_profile_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()
    ]
    pr_fields = [
        [("gas", "density"), ("gas", "temperature")],
        [("gas", "density"), ("gas", "velocity_x")],
        [("gas", "temperature"), ("gas", "mass")],
        [("gas", "density"), ("index", "radius")],
        [("gas", "velocity_magnitude"), ("gas", "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(), ("gas", "density"),
                        ("gas", "temperature"))
    p2 = create_profile(test_ds.all_data(), ("gas", "density"),
                        ("gas", "velocity_x"))
    profiles.append(
        ProfilePlot.from_profiles([p1, p2], labels=["temperature",
                                                    "velocity"]))
    profiles[0]._repr_html_()
    for idx, plot in enumerate(profiles):
        test_prefix = f"{plot.plots.keys()}_{idx}"
        yield compare(test_ds,
                      plot,
                      test_prefix=test_prefix,
                      test_name="profile_plots")
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)