def dump_images(new_result, old_result, decimals=10): tmpfd, old_image = tempfile.mkstemp(suffix=".png") os.close(tmpfd) tmpfd, new_image = tempfile.mkstemp(suffix=".png") os.close(tmpfd) image_writer.write_projection(new_result, new_image) image_writer.write_projection(old_result, old_image) results = compare_images(old_image, new_image, 10 ** (-decimals)) if results is not None: tempfiles = [ line.strip() for line in results.split("\n") if line.endswith(".png") ] for fn in tempfiles: sys.stderr.write(f"\n[[ATTACHMENT|{fn}]]") sys.stderr.write("\n")
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")