def test_mag_factor(): ds1 = load(sloshing, units_override=uo_sloshing, magnetic_normalization="gaussian") assert ds1.magnetic_unit == np.sqrt(4.0 * np.pi * ds1.mass_unit / (ds1.time_unit**2 * ds1.length_unit)) sp1 = ds1.sphere("c", (100.0, "kpc")) pB1a = (sp1["athena", "cell_centered_B_x"]**2 + sp1["athena", "cell_centered_B_y"]**2 + sp1["athena", "cell_centered_B_z"]**2) / (8.0 * np.pi) pB1b = (sp1["gas", "magnetic_field_x"]**2 + sp1["gas", "magnetic_field_y"] **2 + sp1["gas", "magnetic_field_z"]**2) / (8.0 * np.pi) pB1a.convert_to_units("dyn/cm**2") pB1b.convert_to_units("dyn/cm**2") assert_allclose_units(pB1a, pB1b) assert_allclose_units(pB1a, sp1["magnetic_pressure"]) ds2 = load(sloshing, units_override=uo_sloshing, magnetic_normalization="lorentz_heaviside") assert ds2.magnetic_unit == np.sqrt(ds2.mass_unit / (ds2.time_unit**2 * ds2.length_unit)) sp2 = ds2.sphere("c", (100.0, "kpc")) pB2a = (sp2["athena", "cell_centered_B_x"]**2 + sp2["athena", "cell_centered_B_y"]**2 + sp2["athena", "cell_centered_B_z"]**2) / 2.0 pB2b = (sp2["gas", "magnetic_field_x"]**2 + sp2["gas", "magnetic_field_y"] **2 + sp2["gas", "magnetic_field_z"]**2) / 2.0 pB2a.convert_to_units("dyn/cm**2") pB2b.convert_to_units("dyn/cm**2") assert_allclose_units(pB2a, pB2b) assert_allclose_units(pB2a, sp2["magnetic_pressure"]) assert_allclose_units(pB1a, pB2a)
def test_multiplication(): """ Multiply two units. """ msun_cgs = mass_sun_grams pc_cgs = cm_per_pc # Create symbols msun_sym = Symbol("Msun", positive=True) pc_sym = Symbol("pc", positive=True) s_sym = Symbol("s", positive=True) # Create units u1 = Unit("Msun") u2 = Unit("pc") # Mul operation u3 = u1 * u2 assert_true(u3.expr == msun_sym * pc_sym) assert_allclose_units(u3.base_value, msun_cgs * pc_cgs, 1e-12) assert_true(u3.dimensions == mass * length) # Pow and Mul operations u4 = Unit("pc**2") u5 = Unit("Msun * s") u6 = u4 * u5 assert_true(u6.expr == pc_sym**2 * msun_sym * s_sym) assert_allclose_units(u6.base_value, pc_cgs**2 * msun_cgs, 1e-12) assert_true(u6.dimensions == length**2 * mass * time)
def test_nprocs(): ds1 = load(sloshing, units_override=uo_sloshing) sp1 = ds1.sphere("c", (100.0, "kpc")) prj1 = ds1.proj("density", 0) ds2 = load(sloshing, units_override=uo_sloshing, nprocs=8) sp2 = ds2.sphere("c", (100.0, "kpc")) prj2 = ds1.proj("density", 0) ds3 = load(sloshing, parameters=uo_sloshing) assert_equal(ds3.length_unit, 1.0 * u.Mpc) assert_equal(ds3.time_unit, 1.0 * u.Myr) assert_equal(ds3.mass_unit, 1e14 * u.Msun) assert_equal(sp1.quantities.extrema("pressure"), sp2.quantities.extrema("pressure")) assert_allclose_units( sp1.quantities.total_quantity("pressure"), sp2.quantities.total_quantity("pressure"), ) for ax in "xyz": assert_equal( sp1.quantities.extrema(f"velocity_{ax}"), sp2.quantities.extrema(f"velocity_{ax}"), ) assert_allclose_units(sp1.quantities.bulk_velocity(), sp2.quantities.bulk_velocity()) assert_equal(prj1["density"], prj2["density"])
def test_nprocs(): ds1 = load(sloshing, units_override=uo_sloshing) sp1 = ds1.sphere("c", (100.0, "kpc")) prj1 = ds1.proj(("gas", "density"), 0) ds2 = load(sloshing, units_override=uo_sloshing, nprocs=8) sp2 = ds2.sphere("c", (100.0, "kpc")) prj2 = ds1.proj(("gas", "density"), 0) assert_equal( sp1.quantities.extrema(("gas", "pressure")), sp2.quantities.extrema(("gas", "pressure")), ) assert_allclose_units( sp1.quantities.total_quantity(("gas", "pressure")), sp2.quantities.total_quantity(("gas", "pressure")), ) for ax in "xyz": assert_equal( sp1.quantities.extrema(("gas", f"velocity_{ax}")), sp2.quantities.extrema(("gas", f"velocity_{ax}")), ) assert_allclose_units( sp1.quantities.bulk_velocity(), sp2.quantities.bulk_velocity() ) assert_equal(prj1[("gas", "density")], prj2[("gas", "density")])
def test_old_grid_datacontainer_data(): ds = data_dir_load(enzotiny) fn = "DD0046_covering_grid.h5" full_fn = os.path.join(ytdata_dir, fn) cg_ds = data_dir_load(full_fn) compare_unit_attributes(ds, cg_ds) assert isinstance(cg_ds, YTGridDataset) yield YTDataFieldTest(full_fn, ("grid", "density")) yield YTDataFieldTest(full_fn, ("all", "particle_mass")) fn = "DD0046_arbitrary_grid.h5" full_fn = os.path.join(ytdata_dir, fn) ag_ds = data_dir_load(full_fn) compare_unit_attributes(ds, ag_ds) assert isinstance(ag_ds, YTGridDataset) yield YTDataFieldTest(full_fn, ("grid", "density")) yield YTDataFieldTest(full_fn, ("all", "particle_mass")) my_proj = ds.proj("density", "x", weight_field="density") frb = my_proj.to_frb(1.0, (800, 800)) fn = "DD0046_proj_frb.h5" full_fn = os.path.join(ytdata_dir, fn) frb_ds = data_dir_load(full_fn) assert_allclose_units(frb["density"], frb_ds.data["density"], 1e-7) compare_unit_attributes(ds, frb_ds) assert isinstance(frb_ds, YTGridDataset) yield YTDataFieldTest(full_fn, "density", geometric=False)
def compare(self, new_result, old_result): if new_result is None: return assert(len(new_result) == len(old_result)) nind, oind = None, None for k in new_result: assert (k in old_result) if oind is None: oind = np.array(np.isnan(old_result[k])) np.logical_or(oind, np.isnan(old_result[k]), oind) if nind is None: nind = np.array(np.isnan(new_result[k])) np.logical_or(nind, np.isnan(new_result[k]), nind) oind = ~oind nind = ~nind for k in new_result: err_msg = "%s values of %s (%s weighted) projection (axis %s) not equal." % \ (k, self.field, self.weight_field, self.axis) if k == 'weight_field': # Our weight_field can vary between unit systems, whereas we # can do a unitful comparison for the other fields. So we do # not do the test here. continue nres, ores = new_result[k][nind], old_result[k][oind] if self.decimals is None: assert_equal(nres, ores, err_msg=err_msg) else: assert_allclose_units(nres, ores, 10.**-(self.decimals), err_msg=err_msg)
def compare(self, new_result, old_result): if new_result is None: return assert (len(new_result) == len(old_result)) nind, oind = None, None for k in new_result: assert (k in old_result) if oind is None: oind = np.array(np.isnan(old_result[k])) np.logical_or(oind, np.isnan(old_result[k]), oind) if nind is None: nind = np.array(np.isnan(new_result[k])) np.logical_or(nind, np.isnan(new_result[k]), nind) oind = ~oind nind = ~nind for k in new_result: err_msg = "%s values of %s (%s weighted) projection (axis %s) not equal." % \ (k, self.field, self.weight_field, self.axis) if k == 'weight_field' and self.weight_field is None: continue nres, ores = new_result[k][nind], old_result[k][oind] if self.decimals is None: assert_equal(nres, ores, err_msg=err_msg) else: assert_allclose_units(nres, ores, 10.**-(self.decimals), err_msg=err_msg)
def test_nprocs(): ytcfg["yt", "skip_dataset_cache"] = "True" ds1 = load(sloshing, units_override=uo_sloshing) sp1 = ds1.sphere("c", (100., "kpc")) prj1 = ds1.proj("density", 0) ds2 = load(sloshing, units_override=uo_sloshing, nprocs=8) sp2 = ds2.sphere("c", (100., "kpc")) prj2 = ds1.proj("density", 0) ds3 = load(sloshing, parameters=uo_sloshing) assert_equal(ds3.length_unit, u.Mpc) assert_equal(ds3.time_unit, u.Myr) assert_equal(ds3.mass_unit, 1e14 * u.Msun) assert_equal(sp1.quantities.extrema("pressure"), sp2.quantities.extrema("pressure")) assert_allclose_units(sp1.quantities.total_quantity("pressure"), sp2.quantities.total_quantity("pressure")) for ax in "xyz": assert_equal(sp1.quantities.extrema("velocity_%s" % ax), sp2.quantities.extrema("velocity_%s" % ax)) assert_allclose_units(sp1.quantities.bulk_velocity(), sp2.quantities.bulk_velocity()) assert_equal(prj1["density"], prj2["density"]) ytcfg["yt", "skip_dataset_cache"] = "False"
def test_ppv_nothermalbroad(): np.random.seed(seed=0x4D3D3D3) dims = (16, 16, 128) v_shift = 1.0e6 * u.cm / u.s sigma_v = 2.0e6 * u.cm / u.s data = { "density": (np.ones(dims), "g/cm**3"), "velocity_x": (np.zeros(dims), "cm/s"), "velocity_y": (np.zeros(dims), "cm/s"), "velocity_z": ( np.random.normal(loc=v_shift.v, scale=sigma_v.v, size=dims), "cm/s", ), } ds = load_uniform_grid(data, dims) cube = PPVCube( ds, "z", ("stream", "density"), (-100.0, 100.0, 128, "km/s"), dims=16, thermal_broad=False, ) dv = cube.dv v_noth = np.sqrt(2) * (sigma_v).in_units("km/s") a = cube.data.mean(axis=(0, 1)).v b = (dv * np.exp(-(((cube.vmid + v_shift) / v_noth)**2)) / (np.sqrt(np.pi) * v_noth)) assert_allclose_units(a, b, atol=5.0e-3)
def test_base_equivalent(): """ Check base equivalent of a unit. """ Msun_cgs = mass_sun_grams Mpc_cgs = cm_per_mpc u1 = Unit("Msun * Mpc**-3") u2 = Unit("g * cm**-3") u3 = u1.get_base_equivalent() assert_true(u2.expr == u3.expr) assert_true(u2 == u3) assert_allclose_units(u1.base_value, Msun_cgs / Mpc_cgs**3, 1e-12) assert_true(u2.base_value == 1) assert_true(u3.base_value == 1) mass_density = mass / length**3 assert_true(u1.dimensions == mass_density) assert_true(u2.dimensions == mass_density) assert_true(u3.dimensions == mass_density) assert_allclose_units( get_conversion_factor(u1, u3)[0], Msun_cgs / Mpc_cgs**3, 1e-12)
def compare(self, new_result, old_result): assert(len(new_result) == len(old_result)) for k in new_result: assert (k in old_result) for k in new_result: # weight_field does not have units, so we do not directly compare them if k == "weight_field_sum": continue assert_allclose_units(new_result[k], old_result[k], 1e-10)
def compare(self, new_result, old_result): err_msg = "Field values for %s not equal." % (self.field, ) if self.decimals is None: assert_equal(new_result, old_result, err_msg=err_msg, verbose=True) else: assert_allclose_units(new_result, old_result, 10.**(-self.decimals), err_msg=err_msg, verbose=True)
def compare(self, new_result, old_result): assert_equal(len(new_result), len(old_result), err_msg="Number of outputs not equal.", verbose=True) for k in new_result: if self.decimals is None: assert_almost_equal(new_result[k], old_result[k]) else: assert_allclose_units(new_result[k], old_result[k], 10**(-self.decimals))
def test_relative_particle_fields(): ds = data_dir_load(g30) offset = ds.arr([0.1, -0.2, 0.3], "code_length") c = ds.domain_center + offset sp = ds.sphere(c, (10, "kpc")) bv = ds.arr([1.0, 2.0, 3.0], "code_velocity") sp.set_field_parameter("bulk_velocity", bv) assert_allclose_units(sp[("all", "relative_particle_position")], sp[("all", "particle_position")] - c) assert_allclose_units(sp[("all", "relative_particle_velocity")], sp[("all", "particle_velocity")] - bv)
def compare(self, new_result, old_result): err_msg = f"YTData field values for {self.field} not equal." if self.decimals is None: assert_equal(new_result, old_result, err_msg=err_msg, verbose=True) else: assert_allclose_units( new_result, old_result, 10.0**(-self.decimals), err_msg=err_msg, verbose=True, )
def compare(self, new_result, old_result): assert len(new_result) == len(old_result) for k in new_result: assert k in old_result for k in new_result: # weight_field does not have units, so we do not directly compare them if k == "weight_field_sum": continue try: assert_allclose_units(new_result[k], old_result[k], 1e-10) except AssertionError: dump_images(new_result[k], old_result[k]) raise
def compare(self, new_result, old_result): err_msg = "Field values for %s not equal." % (self.field,) if self.decimals is None: assert_equal(new_result, old_result, err_msg=err_msg, verbose=True) else: # What we do here is check if the old_result has units; if not, we # assume they will be the same as the units of new_result. if isinstance(old_result, np.ndarray) and not hasattr(old_result, "in_units"): # coerce it here to the same units old_result = old_result * new_result[0].uq assert_allclose_units(new_result, old_result, 10.**(-self.decimals), err_msg=err_msg, verbose=True)
def test_ppv(): np.random.seed(seed=0x4D3D3D3) dims = (8, 8, 128) v_shift = 1.0e7 * u.cm / u.s sigma_v = 2.0e7 * u.cm / u.s T_0 = 1.0e8 * u.Kelvin data = { "density": (np.ones(dims), "g/cm**3"), "temperature": (T_0.v * np.ones(dims), "K"), "velocity_x": (np.zeros(dims), "cm/s"), "velocity_y": (np.zeros(dims), "cm/s"), "velocity_z": ( np.random.normal(loc=v_shift.v, scale=sigma_v.v, size=dims), "cm/s", ), } ds = load_uniform_grid(data, dims) cube = PPVCube( ds, "z", ("stream", "density"), (-300.0, 300.0, 1024, "km/s"), dims=8, thermal_broad=True, ) dv = cube.dv v_th = np.sqrt(2.0 * kboltz * T_0 / (56.0 * mh) + 2.0 * sigma_v**2).in_units("km/s") a = cube.data.mean(axis=(0, 1)).v b = dv * np.exp(-(( (cube.vmid + v_shift) / v_th)**2)) / (np.sqrt(np.pi) * v_th) assert_allclose_units(a, b, 1.0e-2) E_0 = 6.8 * u.keV cube.transform_spectral_axis(E_0.v, str(E_0.units)) dE = -cube.dv delta_E = E_0 * v_th.in_cgs() / clight E_shift = E_0 * (1.0 + v_shift / clight) c = (dE * np.exp(-(((cube.vmid - E_shift) / delta_E)**2)) / (np.sqrt(np.pi) * delta_E)) assert_allclose_units(a, c, 1.0e-2)
def test_vector_component_conversions(): for bv in [[0, 0, 0], [1e5, 1e5, 1e5]]: ds = fake_random_ds(16) ad = ds.all_data() bulk = bv * km / s ad.set_field_parameter('bulk_velocity', bulk) vmag = ad['velocity_magnitude'] vmag_cart = np.sqrt((ad['velocity_x'] - bulk[0])**2 + (ad['velocity_y'] - bulk[1])**2 + (ad['velocity_z'] - bulk[2])**2) assert_allclose_units(vmag, vmag_cart) vmag_cyl = np.sqrt(ad['velocity_cylindrical_radius']**2 + ad['velocity_cylindrical_theta']**2 + ad['velocity_cylindrical_z']**2) assert_allclose_units(vmag, vmag_cyl) vmag_sph = np.sqrt(ad['velocity_spherical_radius']**2 + ad['velocity_spherical_theta']**2 + ad['velocity_spherical_phi']**2) assert_allclose_units(vmag, vmag_sph) for d in 'xyz': assert_allclose_units(ad['velocity_%s' % d] - bulk[0], ad['relative_velocity_%s' % d])
def test_create_from_expr(): """ Create units from sympy Exprs and check attributes. """ pc_cgs = cm_per_pc yr_cgs = sec_per_year # Symbol expr s1 = Symbol("pc", positive=True) s2 = Symbol("yr", positive=True) # Mul expr s3 = s1 * s2 # Pow expr s4 = s1**2 * s2**(-1) u1 = Unit(s1) u2 = Unit(s2) u3 = Unit(s3) u4 = Unit(s4) assert_true(u1.expr == s1) assert_true(u2.expr == s2) assert_true(u3.expr == s3) assert_true(u4.expr == s4) assert_allclose_units(u1.base_value, pc_cgs, 1e-12) assert_allclose_units(u2.base_value, yr_cgs, 1e-12) assert_allclose_units(u3.base_value, pc_cgs * yr_cgs, 1e-12) assert_allclose_units(u4.base_value, pc_cgs**2 / yr_cgs, 1e-12) assert_true(u1.dimensions == length) assert_true(u2.dimensions == time) assert_true(u3.dimensions == length * time) assert_true(u4.dimensions == length**2 / time)
def test_particle_derived_field(): def star_age_alias(field, data): # test to make sure we get back data in the correct units # during field detection return data['STAR', 'age'].in_units('Myr') ds = load(sizmbhloz) ds.add_field(("STAR", "new_field"), function=star_age_alias, units='Myr', sampling_type="particle") ad = ds.all_data() assert_allclose_units(ad['STAR', 'age'].in_units("Myr"), ad["STAR", "new_field"])
def test_export_frb(): test_ds = fake_random_ds(128) slc = test_ds.slice(0, 0.5) frb = slc.to_frb((0.5, "unitary"), 64) frb_ds = frb.export_dataset(fields=["density"], nprocs=8) dd_frb = frb_ds.all_data() assert_equal(frb_ds.domain_left_edge.v, np.array([0.25, 0.25, 0.0])) assert_equal(frb_ds.domain_right_edge.v, np.array([0.75, 0.75, 1.0])) assert_equal(frb_ds.domain_width.v, np.array([0.5, 0.5, 1.0])) assert_equal(frb_ds.domain_dimensions, np.array([64, 64, 1], dtype="int64")) assert_allclose_units(frb["density"].sum(), dd_frb.quantities.total_quantity("density")) assert_equal(frb_ds.index.num_grids, 8)
def test_create_with_duplicate_dimensions(): """ Create units with overlapping dimensions. Ex: km/Mpc. """ u1 = Unit("erg * s**-1") u2 = Unit("km/s/Mpc") km_cgs = cm_per_km Mpc_cgs = cm_per_mpc assert_true(u1.base_value == 1) assert_true(u1.dimensions == power) assert_allclose_units(u2.base_value, km_cgs / Mpc_cgs, 1e-12) assert_true(u2.dimensions == rate)
def test_AM_value(): ds = fake_amr_ds(fields=("Density", "velocity_x", "velocity_y", "velocity_z"), length_unit=0.5) sp = ds.sphere([.5] * 3, (0.1, 'code_length')) x0 = sp.center v0 = ds.arr([1, 2, 3], 'km/s') sp.set_field_parameter('bulk_velocity', v0) X = (ds.arr([sp[k] for k in 'xyz']) - x0[:, None]).T V = (ds.arr([sp['velocity_' + k] for k in 'xyz']) - v0[:, None]).T sAM_manual = ds.arr(np.cross(X, V), X.units * V.units) sAM = ds.arr([sp['specific_angular_momentum_' + k] for k in 'xyz']).T assert_allclose_units(sAM_manual, sAM)
def compare(self, new_result, old_result): if not isinstance(new_result, dict): new_result = {"answer": new_result} old_result = {"answer": old_result} assert_equal( len(new_result), len(old_result), err_msg="Number of outputs not equal.", verbose=True, ) for k in new_result: if hasattr(new_result[k], "d"): new_result[k] = new_result[k].d if hasattr(old_result[k], "d"): old_result[k] = old_result[k].d if self.decimals is None: assert_almost_equal(new_result[k], old_result[k]) else: assert_allclose_units(new_result[k], old_result[k], 10**(-self.decimals))
def test_deeply_nested_zoom(): ds = data_dir_load(dnz) # carefully chosen to just barely miss a grid in the middle of the image center = [0.4915073260199302, 0.5052605316800006, 0.4905805557500548] plot = SlicePlot(ds, 'z', 'density', width=(0.001, 'pc'), center=center) image = plot.frb['density'] assert (image > 0).all() v, c = ds.find_max('density') assert_allclose_units(v, ds.quan(0.005879315652144976, 'g/cm**3')) c_actual = [0.49150732540021, 0.505260532936791, 0.49058055816398] c_actual = ds.arr(c_actual, 'code_length') assert_allclose_units(c, c_actual) assert_equal(max([g['density'].max() for g in ds.index.grids]), v)
def test_deeply_nested_zoom(): ds = data_dir_load(dnz) # carefully chosen to just barely miss a grid in the middle of the image center = [0.4915073260199302, 0.5052605316800006, 0.4905805557500548] plot = SlicePlot(ds, "z", "density", width=(0.001, "pc"), center=center) image = plot.frb[("gas", "density")] assert (image > 0).all() v, c = ds.find_max(("gas", "density")) assert_allclose_units(v, ds.quan(0.005878286377124154, "g/cm**3")) c_actual = [0.49150732540021, 0.505260532936791, 0.49058055816398] c_actual = ds.arr(c_actual, "code_length") assert_allclose_units(c, c_actual) assert_equal(max([g[("gas", "density")].max() for g in ds.index.grids]), v)
def test_AM_value(): ds = fake_amr_ds( fields=("Density", "velocity_x", "velocity_y", "velocity_z"), units=("g/cm**3", "cm/s", "cm/s", "cm/s"), length_unit=0.5, ) sp = ds.sphere([0.5] * 3, (0.1, "code_length")) x0 = sp.center v0 = ds.arr([1, 2, 3], "km/s") sp.set_field_parameter("bulk_velocity", v0) X = (ds.arr([sp[k] for k in "xyz"]) - x0[:, None]).T V = (ds.arr([sp["velocity_" + k] for k in "xyz"]) - v0[:, None]).T sAM_manual = ds.arr(np.cross(X, V), X.units * V.units) sAM = ds.arr([sp["specific_angular_momentum_" + k] for k in "xyz"]).T assert_allclose_units(sAM_manual, sAM)
def test_create_from_dataset(): ds = fake_random_ds(16) plot1 = yt.ProfilePlot( ds, ("index", "radius"), [("gas", "velocity_x"), ("gas", "density")], weight_field=None, ) plot2 = yt.ProfilePlot( ds.all_data(), ("index", "radius"), [("gas", "velocity_x"), ("gas", "density")], weight_field=None, ) assert_allclose_units(plot1.profiles[0][("gas", "density")], plot2.profiles[0][("gas", "density")]) assert_allclose_units(plot1.profiles[0]["velocity_x"], plot2.profiles[0]["velocity_x"]) plot1 = yt.PhasePlot(ds, ("gas", "density"), ("gas", "velocity_x"), ("gas", "cell_mass")) plot2 = yt.PhasePlot(ds.all_data(), ("gas", "density"), ("gas", "velocity_x"), ("gas", "cell_mass")) assert_allclose_units(plot1.profile["cell_mass"], plot2.profile["cell_mass"])
def test_default_species_fields(): ds = data_dir_load(sloshing) sp = ds.sphere("c", (0.2, "unitary")) amu_cgs = ds.units.physical_constants.amu_cgs mueinv = 1.0 * _primordial_mass_fraction["H"] / ChemicalFormula("H").weight mueinv *= sp["index", "ones"] mueinv += 2.0 * _primordial_mass_fraction["He"] / ChemicalFormula( "He").weight mupinv = _primordial_mass_fraction["H"] / ChemicalFormula("H").weight mupinv *= sp["index", "ones"] muainv = _primordial_mass_fraction["He"] / ChemicalFormula("He").weight muainv *= sp["index", "ones"] mueinv2 = sp["gas", "El_number_density"] * amu_cgs / sp["gas", "density"] mupinv2 = sp["gas", "H_p1_number_density"] * amu_cgs / sp["gas", "density"] muainv2 = sp["gas", "He_p2_number_density"] * amu_cgs / sp["gas", "density"] assert_allclose_units(mueinv, mueinv2) assert_allclose_units(mupinv, mupinv2) assert_allclose_units(muainv, muainv2) assert_equal(sp["gas", "H_p1_number_density"], sp["gas", "H_nuclei_density"]) assert_equal(sp["gas", "He_p2_number_density"], sp["gas", "He_nuclei_density"])