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")
def test_oap(tmpdir=True): """Tests functionality of off_axis_projection and write_projection.""" # Perform I/O in safe place instead of yt main dir if tmpdir: tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) # 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['limits'] = (None, (1e3, 1e5)) wp_kwargs['take_log'] = (True, False) wp_kwargs['figsize'] = ((8, 6), [1, 1]) wp_kwargs['dpi'] = (100, 50) wp_kwargs['cmap_name'] = ('arbre', '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) yield assert_equal, os.path.exists(fn % i), True if tmpdir: os.chdir(curdir) # clean up shutil.rmtree(tmpdir)
def test_write_projection(): """Tests functionality of off_axis_projection and write_projection.""" # Perform I/O in safe place instead of yt main dir tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) # args for off_axis_projection test_ds = fake_random_ds(64) c = [0.5, 0.5, 0.5] norm = [0.5, 0.5, 0.5] W = [0.5,0.5,1.0] N = 64 field = "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'] = (True, False) oap_kwargs['north_vector'] = ((1,0,0), (0,0.5,1.0)) oap_kwargs_list = expand_keywords(oap_kwargs) # args for write_projection fn = "test.png" # kwargs for write_projection wp_kwargs = {} wp_kwargs['colorbar'] = (True, False) wp_kwargs['colorbar_label'] = ('test') wp_kwargs['title'] = ('test') wp_kwargs['limits'] = (None, (1e3, 1e5)) wp_kwargs['take_log'] = (True, False) wp_kwargs['figsize'] = ((8,6), [1,1]) wp_kwargs['dpi'] = (100, 50) wp_kwargs['cmap_name'] = ('algae', 'jet') 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 oap_kwargs in oap_kwargs_list: image = off_axis_projection(*oap_args, **oap_kwargs) for wp_kwargs in wp_kwargs_list: write_projection(image, fn, **wp_kwargs) yield assert_equal, os.path.exists(fn), True os.remove(fn) os.chdir(curdir) # clean up shutil.rmtree(tmpdir)
def test_write_projection(): """Tests functionality of off_axis_projection and write_projection.""" # Perform I/O in safe place instead of yt main dir tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) # args for off_axis_projection test_ds = fake_random_ds(64) c = [0.5, 0.5, 0.5] norm = [0.5, 0.5, 0.5] W = [0.5, 0.5, 1.0] N = 64 field = "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'] = (True, False) oap_kwargs['north_vector'] = ((1, 0, 0), (0, 0.5, 1.0)) oap_kwargs_list = expand_keywords(oap_kwargs) # args for write_projection fn = "test.png" # kwargs for write_projection wp_kwargs = {} wp_kwargs['colorbar'] = (True, False) wp_kwargs['colorbar_label'] = ('test') wp_kwargs['title'] = ('test') wp_kwargs['limits'] = (None, (1e3, 1e5)) wp_kwargs['take_log'] = (True, False) wp_kwargs['figsize'] = ((8, 6), [1, 1]) wp_kwargs['dpi'] = (100, 50) wp_kwargs['cmap_name'] = ('algae', 'jet') 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 oap_kwargs in oap_kwargs_list: image = off_axis_projection(*oap_args, **oap_kwargs) for wp_kwargs in wp_kwargs_list: write_projection(image, fn, **wp_kwargs) yield assert_equal, os.path.exists(fn), True os.remove(fn) os.chdir(curdir) # clean up shutil.rmtree(tmpdir)