def test_symlog_colorbar(): ds = fake_random_ds(16) def _thresh_density(field, data): wh = data[("gas", "density")] < 0.5 ret = data[("gas", "density")] ret[wh] = 0 return ret def _neg_density(field, data): return -data[("gas", "threshold_density")] ds.add_field( ("gas", "threshold_density"), function=_thresh_density, units="g/cm**3", sampling_type="cell", ) ds.add_field( ("gas", "negative_density"), function=_neg_density, units="g/cm**3", sampling_type="cell", ) for field in [ ("gas", "density"), ("gas", "threshold_density"), ("gas", "negative_density"), ]: plot = SlicePlot(ds, 2, field) plot.set_log(field, True, linthresh=0.1) with tempfile.NamedTemporaryFile(suffix="png") as f: plot.save(f.name)
class TestHideAxesColorbar(unittest.TestCase): ds = None def setUp(self): if self.ds is None: self.ds = fake_random_ds(64) self.slc = SlicePlot(self.ds, 0, ("gas", "density")) self.tmpdir = tempfile.mkdtemp() self.curdir = os.getcwd() os.chdir(self.tmpdir) def tearDown(self): os.chdir(self.curdir) shutil.rmtree(self.tmpdir) del self.ds del self.slc def test_hide_show_axes(self): self.slc.hide_axes() self.slc.save() self.slc.show_axes() self.slc.save() def test_hide_show_colorbar(self): self.slc.hide_colorbar() self.slc.save() self.slc.show_colorbar() self.slc.save() def test_hide_axes_colorbar(self): self.slc.hide_colorbar() self.slc.hide_axes() self.slc.save()
def test_plot_data(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) ds = fake_random_ds(16) plot = SlicePlot(ds, 'z', 'density') plot.data_source.save_as_dataset('slice.h5') ds_slice = load('slice.h5') p = SlicePlot(ds_slice, 'z', 'density') fn = p.save() assert_fname(fn[0]) plot = ProjectionPlot(ds, 'z', 'density') plot.data_source.save_as_dataset('proj.h5') ds_proj = load('slice.h5') p = ProjectionPlot(ds_proj, 'z', 'density') fn = p.save() assert_fname(fn[0]) plot = SlicePlot(ds, [1, 1, 1], 'density') plot.data_source.save_as_dataset('oas.h5') ds_oas = load('oas.h5') p = SlicePlot(ds_oas, [1, 1, 1], 'density') fn = p.save() assert_fname(fn[0]) os.chdir(curdir) shutil.rmtree(tmpdir)
def test_plot_data(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) ds = fake_random_ds(16) plot = SlicePlot(ds, "z", ("gas", "density")) fn = plot.data_source.save_as_dataset("slice.h5") ds_slice = load(fn) p = SlicePlot(ds_slice, "z", ("gas", "density")) fn = p.save() assert_fname(fn[0]) plot = ProjectionPlot(ds, "z", ("gas", "density")) fn = plot.data_source.save_as_dataset("proj.h5") ds_proj = load(fn) p = ProjectionPlot(ds_proj, "z", ("gas", "density")) fn = p.save() assert_fname(fn[0]) plot = SlicePlot(ds, [1, 1, 1], ("gas", "density")) fn = plot.data_source.save_as_dataset("oas.h5") ds_oas = load(fn) p = SlicePlot(ds_oas, [1, 1, 1], ("gas", "density")) fn = p.save() assert_fname(fn[0]) os.chdir(curdir) if tmpdir != ".": shutil.rmtree(tmpdir)
def test_old_plot_data(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) fn = "slice.h5" full_fn = os.path.join(ytdata_dir, fn) ds_slice = data_dir_load(full_fn) p = SlicePlot(ds_slice, "z", ("gas", "density")) fn = p.save() assert_fname(fn[0]) fn = "proj.h5" full_fn = os.path.join(ytdata_dir, fn) ds_proj = data_dir_load(full_fn) p = ProjectionPlot(ds_proj, "z", ("gas", "density")) fn = p.save() assert_fname(fn[0]) fn = "oas.h5" full_fn = os.path.join(ytdata_dir, fn) ds_oas = data_dir_load(full_fn) p = SlicePlot(ds_oas, [1, 1, 1], ("gas", "density")) fn = p.save() assert_fname(fn[0]) os.chdir(curdir) shutil.rmtree(tmpdir)
def test_nan_data(): data = np.random.random((16, 16, 16)) - 0.5 data[:9, :9, :9] = np.nan data = {"density": data} ds = load_uniform_grid(data, [16, 16, 16]) plot = SlicePlot(ds, "z", ("gas", "density")) with tempfile.NamedTemporaryFile(suffix="png") as f: plot.save(f.name)
def test_slice_plot(self): test_ds = fake_random_ds(16) for dim in range(3): slc = SlicePlot(test_ds, dim, ("gas", "density")) for fname in TEST_FLNMS: assert_fname(slc.save(fname)[0])