def test_noh2d(): sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) sim.get_time_series() pf = sim[-1] yield TestShockImage(pf) yield TestRadialDensity(pf)
def test_gardiner(): sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) sim.get_time_series() pf = sim[-1] for field in _fields: yield TestGardinerImage(pf, field)
def test_briowu(): sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) sim.get_time_series() tolerance = ytcfg.getint("yt", "answer_testing_tolerance") pf = sim[-1] for field in _fields: yield AllFieldValuesTest(pf, field, decimals=tolerance)
def test_total_baryon_mass(): # gather most recent data set sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) if (sim.parameters['CosmologySimulationOmegaBaryonNow'] == 0.0): return sim.get_time_series() ds = sim[-1] data = ds.all_data() # sum masses Mstar = np.sum( data['particle_mass'][data['particle_type'] == 2].to('Msun')) Mgas = np.sum(data['cell_mass'].to('Msun')) output_data = {'masses': Mstar + Mgas} # save filename = "baryon_mass_results.h5" save_filename = os.path.join(_dir_name, filename) yt.save_as_dataset(ds, save_filename, output_data) compare_filename = os.path.join(test_data_dir, filename) if generate_answers: os.rename(save_filename, compare_filename) return ds_comp = yt.load(compare_filename) assert_rel_equal(output_data['masses'], ds_comp.data['masses'], tolerance)
def test_dark_matter_mass(): # gather most recent data set sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) sim.get_time_series() ds = sim[-1] data = ds.all_data() # sum masses MDM = np.sum( data[('all', 'particle_mass')][data[('all', 'particle_type')] == 1].to('Msun')) output_data = {('data', 'mass'): MDM} # save filename = "DM_mass_results.h5" save_filename = os.path.join(_dir_name, filename) yt.save_as_dataset(ds, save_filename, output_data) compare_filename = os.path.join(test_data_dir, filename) if generate_answers: os.rename(save_filename, compare_filename) return ds_comp = yt.load(compare_filename) assert_rel_equal(output_data[('data', 'mass')], ds_comp.data[('data', 'mass')], tolerance)
def test_standard(): sim = sim_dir_load("AMRZeldovichPancake.enzo", path="./Cosmology/AMRZeldovichPancake", find_outputs=True) sim.get_time_series() yield VerifySimulationSameTest(sim) base_pf = sim[0] fields = [f for f in _base_fields if f in base_pf.field_list] # Only test the last output. pf = sim[-1] for test in standard_small_simulation(pf, fields): yield test
def test_almost_standard(): sim = sim_dir_load("Toro-6-ShockTube.enzo", path="./Hydro/Hydro-1D/Toro-6-ShockTube", find_outputs=True) sim.get_time_series() yield VerifySimulationSameTest(sim) base_pf = sim[0] fields = [f for f in _base_fields if ("enzo", f) in base_pf.field_list] # Only test the last output. pf = sim[-1] for test in standard_small_simulation(pf, fields): yield test
def test_standard(): sim = sim_dir_load("MHD2DRotorTest.enzo", path="./MHD/2D/MHD2DRotorTest", find_outputs=True) sim.get_time_series() yield VerifySimulationSameTest(sim) base_pf = sim[0] fields = [f for f in _base_fields if f in base_pf.h.field_list] # Only test the last output. pf = sim[-1] for test in standard_small_simulation(pf, fields): yield test
def test_DivB_CT(): """ Make sure that Divergence of B is zero everywhere. """ sim = sim_dir_load("MHDCTOrszagTangAMR.enzo", path="./MHD/2D/MHDCTOrszagTangAMR", find_outputs=True) sim.get_time_series() yield VerifySimulationSameTest(sim) # Only test the last output. pf = sim[-1] max_value = pf.find_max(('enzo', 'DivB')) max_value = float(max_value[0]) assert (max_value < 1e-10)
def test_phase(): es = sim_dir_load(_pf_name, path=_dir_name) es.get_time_series(redshifts=[0]) ds = es[-1] ad = ds.all_data() profile = ad.profile([("gas", "density")], [("gas", "temperature"), ("gas", "cell_mass")]) profile1 = ad.profile([("gas", "density")], [("gas", "temperature"), ("gas", "cooling_time")], weight_field=('gas', 'cell_mass')) density = profile.x temperature = profile[('gas', 'temperature')] cooling_time = profile1[('gas', 'cooling_time')] cell_mass = profile[('gas', 'cell_mass')] filename = 'phase_data.h5' save_filename = os.path.join(_dir_name, filename) data = { ('data', 'density'): density, ('data', 'temperature'): temperature, ('data', 'cooling_time'): cooling_time, ('data', 'cell_mass'): cell_mass } yt.save_as_dataset(ds, save_filename, data) pp = yt.PhasePlot(ad, ('gas', 'density'), ('gas', 'temperature'), ('gas', 'cell_mass')) pp.set_unit(('gas', 'cell_mass'), 'Msun') pp.save(_dir_name) pp1 = yt.PhasePlot(ad, ('gas', 'density'), ('gas', 'temperature'), ('gas', 'cooling_time'), weight_field=('gas', 'cell_mass')) pp1.save(_dir_name) compare_filename = os.path.join(test_data_dir, filename) if generate_answers: os.rename(save_filename, compare_filename) return # do the comparison ds_comp = yt.load(compare_filename) # assert quality to 8 decimals assert_rel_equal(data[('data', 'density')], ds_comp.data[('data', 'density')], 8) assert_rel_equal(data[('data', 'temperature')], ds_comp.data[('data', 'temperature')], 8) assert_rel_equal(data[('data', 'cooling_time')], ds_comp.data[('data', 'cooling_time')], 8) assert_rel_equal(data[('data', 'cell_mass')], ds_comp.data[('data', 'cell_mass')], 8)
def test_hmf(): es = sim_dir_load(_pf_name, path=_dir_name) es.get_time_series() ds = es[-1] hc = HaloCatalog(data_ds=ds, finder_method='fof', output_dir=os.path.join(_dir_name, "halo_catalogs/catalog")) hc.create() masses = hc.data_source['particle_mass'].in_units('Msun') h = ds.hubble_constant mtot = np.log10(masses * 1.2) - np.log10(h) masses_sim = np.sort(mtot) sim_volume = ds.domain_width.in_units('Mpccm').prod() n_cumulative_sim = np.arange(len(mtot), 0, -1) masses_sim, unique_indices = np.unique(masses_sim, return_index=True) n_cumulative_sim = n_cumulative_sim[unique_indices] / sim_volume filename = 'hmf.h5' save_filename = os.path.join(_dir_name, filename) data = {'masses': masses_sim, 'n_sim': n_cumulative_sim} yt.save_as_dataset(ds, save_filename, data) # make a plot fig = plt.figure(figsize=(8, 8)) plt.semilogy(masses_sim, n_cumulative_sim, '-') plt.ylabel('Cumulative Halo Number Density $\mathrm{Mpc}^{-3}$', fontsize=16) plt.xlabel('log Mass/$\mathrm{M}_{\odot}$', fontsize=16) plt.tick_params(labelsize=16) plt.savefig(os.path.join(_dir_name, 'hmf.png'), format='png') compare_filename = os.path.join(test_data_dir, filename) if generate_answers: os.rename(save_filename, compare_filename) return # do the comparison ds_comp = yt.load(compare_filename) # assert quality to 8 decimals assert_rel_equal(data['masses'], ds_comp.data['masses'], 8) assert_rel_equal(data['n_sim'], ds_comp.data['n_sim'], 8)
def test_collapse_max_value(): sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) sim.get_time_series() pf = sim[-1] yield TestFreeExpansionDistance(pf)
def test_photon_shadowing(): sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) sim.get_time_series() pf = sim[-1] for field in _fields: yield TestPhotonShadowing(pf, field)
def test_rotating_cylinder(): sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) sim.get_time_series() pf = sim[-1] yield TestLVariation(pf)
def test_phase(): es = sim_dir_load(_pf_name, path=_dir_name)
def test_total_baryon_mass(): # gather most recent data set sim = sim_dir_load(_pf_name, path=_dir_name, find_outputs=True) if (sim.parameters['CosmologySimulationOmegaBaryonNow'] == 0.0):