1import os.path 2 3import yt 4from yt.config import ytcfg 5from yt.testing import assert_equal, assert_raises, requires_file 6 7G30 = "IsolatedGalaxy/galaxy0030/galaxy0030" 8 9 10def setup(): 11 ytcfg["yt", "serialize"] = True 12 13 14def teardown(): 15 ytcfg["yt", "serialize"] = False 16 17 18@requires_file(G30) 19def test_store(): 20 ds = yt.load(G30) 21 store = ds.parameter_filename + ".yt" 22 field = "density" 23 if os.path.isfile(store): 24 os.remove(store) 25 26 proj1 = ds.proj(field, "z") 27 sp = ds.sphere(ds.domain_center, (4, "kpc")) 28 proj2 = ds.proj(field, "z", data_source=sp) 29 30 proj1_c = ds.proj(field, "z") 31 assert_equal(proj1[field], proj1_c[field]) 32 33 proj2_c = ds.proj(field, "z", data_source=sp) 34 assert_equal(proj2[field], proj2_c[field]) 35 36 def fail_for_different_method(): 37 proj2_c = ds.proj(field, "z", data_source=sp, method="mip") 38 assert_equal(proj2[field], proj2_c[field]) 39 40 # A note here: a unyt.exceptions.UnitOperationError is raised 41 # and caught by numpy, which reraises a ValueError 42 assert_raises(ValueError, fail_for_different_method) 43 44 def fail_for_different_source(): 45 sp = ds.sphere(ds.domain_center, (2, "kpc")) 46 proj2_c = ds.proj(field, "z", data_source=sp, method="integrate") 47 assert_equal(proj2_c[field], proj2[field]) 48 49 assert_raises(AssertionError, fail_for_different_source) 50