def test_ellipsoid_selector(): # generate fake data with a number of non-cubical grids ds = fake_random_ds(64, nprocs=51) assert all(ds.periodicity) ellipsoids = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.25, 0.75, 0.25]] # spherical ellipsoid tests ratios = 3 * [0.25] for center in ellipsoids: data = ds.ellipsoid(center, ratios[0], ratios[1], ratios[2], np.array([1.0, 0.0, 0.0]), 0.0) data.get_data() dd = ds.all_data() dd.set_field_parameter("center", ds.arr(center, "code_length")) n_outside = (dd["radius"] >= ratios[0]).sum() assert_equal(data["radius"].size + n_outside, dd["radius"].size) positions = np.array([data[ax] for ax in "xyz"]) centers = np.tile(data.center, data.shape[0]).reshape(data.shape[0], 3).transpose() dist = periodic_dist(positions, centers, ds.domain_right_edge - ds.domain_left_edge, ds.periodicity) # WARNING: this value has not been externally verified yield assert_array_less, dist, ratios[0] # aligned ellipsoid tests ratios = [0.25, 0.1, 0.1] for center in ellipsoids: data = ds.ellipsoid(center, ratios[0], ratios[1], ratios[2], np.array([1.0, 0.0, 0.0]), 0.0) # hack to compute elliptic distance dist2 = np.zeros(data["ones"].shape[0]) for i, ax in enumerate("xyz"): positions = np.zeros((3, data["ones"].shape[0])) positions[i, :] = data[ax] centers = np.zeros((3, data["ones"].shape[0])) centers[i, :] = center[i] dist2 += ( periodic_dist(positions, centers, ds.domain_right_edge - ds.domain_left_edge, ds.periodicity) / ratios[i] ) ** 2 # WARNING: this value has not been externally verified yield assert_array_less, dist2, 1.0
def test_write_gdf(): """Main test suite for write_gdf""" tmpdir = tempfile.mkdtemp() tmpfile = os.path.join(tmpdir, 'test_gdf.h5') try: test_ds = fake_random_ds(64) write_to_gdf(test_ds, tmpfile, data_author=TEST_AUTHOR, data_comment=TEST_COMMENT) del test_ds assert isinstance(load(tmpfile), GDFDataset) h5f = h5.File(tmpfile, 'r') gdf = h5f['gridded_data_format'].attrs assert_equal(gdf['data_author'], TEST_AUTHOR) assert_equal(gdf['data_comment'], TEST_COMMENT) h5f.close() finally: shutil.rmtree(tmpdir)
def test_sphere_selector(): # generate fake data with a number of non-cubical grids ds = fake_random_ds(64, nprocs=51) assert all(ds.periodicity) # aligned tests spheres = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0], [0.25, 0.75, 0.25]] for center in spheres: data = ds.sphere(center, 0.25) # WARNING: this value has not be externally verified dd = ds.all_data() dd.set_field_parameter("center", ds.arr(center, "code_length")) n_outside = (dd["radius"] >= 0.25).sum() assert_equal(data["radius"].size + n_outside, dd["radius"].size) positions = np.array([data[ax] for ax in "xyz"]) centers = np.tile(data.center, data["x"].shape[0]).reshape(data["x"].shape[0], 3).transpose() dist = periodic_dist(positions, centers, ds.domain_right_edge - ds.domain_left_edge, ds.periodicity) # WARNING: this value has not been externally verified yield assert_array_less, dist, 0.25
def test_point_selector(): # generate fake amr data ds = fake_random_ds(64, nprocs=51) assert all(ds.periodicity) dd = ds.all_data() positions = np.array([dd[ax] for ax in "xyz"]) delta = 0.5 * np.array([dd["d" + ax] for ax in "xyz"]) # ensure cell centers and corners always return one and # only one point object for p in positions: data = ds.point(p) assert_equal(data["ones"].shape[0], 1) for p in positions - delta: data = ds.point(p) assert_equal(data["ones"].shape[0], 1) for p in positions + delta: data = ds.point(p) assert_equal(data["ones"].shape[0], 1)
def compare(self, new_result, old_result): err_msg = ("Simulated halo mass functions not equation for " + "%s halo finder.") % self.finder assert_equal(new_result, old_result, err_msg=err_msg, verbose=True)
def test_set_width_one(self): assert_equal([self.slc.xlim, self.slc.ylim, self.slc.width], [(0.0, 1.0), (0.0, 1.0), (1.0, 1.0)]) assert_true(self.slc._axes_unit_names is None)
def test_kh2d(): ds = data_dir_load(kh2d) assert_equal(str(ds), 'DD0011') for test in small_patch_amr(ds, ds.field_list): test_toro1d.__name__ = test.description yield test
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: assert_equal(new_result[k], old_result[k])
def test_warpx_particle_io(): ds = data_dir_load(plasma) grid = ds.index.grids[0] # read directly from the header npart0_grid_0 = 344 npart1_grid_0 = 69632 assert_equal(grid['particle0', 'particle_position_x'].size, npart0_grid_0) assert_equal(grid['particle1', 'particle_position_y'].size, npart1_grid_0) assert_equal(grid['all', 'particle_position_z'].size, npart0_grid_0 + npart1_grid_0) # read directly from the header npart0 = 1360 npart1 = 802816 ad = ds.all_data() assert_equal(ad['particle0', 'particle_velocity_x'].size, npart0) assert_equal(ad['particle1', 'particle_velocity_y'].size, npart1) assert_equal(ad['all', 'particle_velocity_z'].size, npart0 + npart1) np.all(ad['particle1', 'particle_mass'] == ad['particle1', 'particle_mass'][0]) np.all(ad['particle0', 'particle_mass'] == ad['particle0', 'particle_mass'][0]) left_edge = ds.arr([-7.5e-5, -7.5e-5, -7.5e-5], 'code_length') right_edge = ds.arr([2.5e-5, 2.5e-5, 2.5e-5], 'code_length') center = 0.5 * (left_edge + right_edge) reg = ds.region(center, left_edge, right_edge) assert (np.all( np.logical_and(reg['particle_position_x'] <= right_edge[0], reg['particle_position_x'] >= left_edge[0]))) assert (np.all( np.logical_and(reg['particle_position_y'] <= right_edge[1], reg['particle_position_y'] >= left_edge[1]))) assert (np.all( np.logical_and(reg['particle_position_z'] <= right_edge[2], reg['particle_position_z'] >= left_edge[2])))
def test_star(): ds = data_dir_load(star) assert_equal(str(ds), "plrd01000") for test in small_patch_amr(ds, _orion_fields): test_star.__name__ = test.description yield test
def test_set_width_one(self): assert_equal( [self.slc.xlim, self.slc.ylim, self.slc.width], [(0.0, 1.0), (0.0, 1.0), (1.0, 1.0)], ) assert_true(self.slc._axes_unit_names is None)
def test_RT_particles(): ds = data_dir_load(RT_particles) assert_equal(str(ds), "plt00050") for test in small_patch_amr(ds, _castro_fields): test_RT_particles.__name__ = test.description yield test
def test_cutting_plane(): fns = [] for nprocs in [8, 1]: # We want to test both 1 proc and 8 procs, to make sure that # parallelism isn't broken ds = fake_random_ds(64, nprocs=nprocs) center = [0.5, 0.5, 0.5] normal = [1, 1, 1] cut = ds.cutting(normal, center) assert_equal(cut[("index", "ones")].sum(), cut[("index", "ones")].size) assert_equal(cut[("index", "ones")].min(), 1.0) assert_equal(cut[("index", "ones")].max(), 1.0) pw = cut.to_pw(fields=("gas", "density")) for p in pw.plots.values(): tmpfd, tmpname = tempfile.mkstemp(suffix=".png") os.close(tmpfd) p.save(name=tmpname) fns.append(tmpname) for width in [(1.0, "unitary"), 1.0, ds.quan(0.5, "code_length")]: frb = cut.to_frb(width, 64) for cut_field in [("index", "ones"), ("gas", "density")]: fi = ds._get_field_info("unknown", cut_field) data = frb[cut_field] assert_equal(data.info["data_source"], cut.__str__()) assert_equal(data.info["axis"], 4) assert_equal(data.info["field"], str(cut_field)) assert_equal(data.units, Unit(fi.units)) assert_equal(data.info["xlim"], frb.bounds[:2]) assert_equal(data.info["ylim"], frb.bounds[2:]) assert_equal(data.info["length_to_cm"], ds.length_unit.in_cgs()) assert_equal(data.info["center"], cut.center) teardown_func(fns)
def test_blast_override(): # verify that overriding units causes derived unit values to be updated. # see issue #1259 ds = load(blast, units_override=uo_blast) assert_equal(float(ds.magnetic_unit.in_units('gauss')), 5.478674679698131e-07)
def test_d9p_global_values(): ds = data_dir_load(d9p) ad = ds.all_data() # 'Ana' variable values output from the ART Fortran 'ANA' analysis code AnaNStars = 6255 assert_equal(ad[("stars", "particle_type")].size, AnaNStars) assert_equal(ad[("specie4", "particle_type")].size, AnaNStars) # The *real* asnwer is 2833405, but yt misses one particle since it lives # on a domain boundary. See issue 814. When that is fixed, this test # will need to be updated AnaNDM = 2833404 assert_equal(ad[("darkmatter", "particle_type")].size, AnaNDM) assert_equal( (ad[("specie0", "particle_type")].size + ad[("specie1", "particle_type")].size + ad[("specie2", "particle_type")].size + ad[("specie3", "particle_type")].size), AnaNDM, ) for spnum in range(5): npart_read = ad[f"specie{spnum}", "particle_type"].size npart_header = ds.particle_type_counts[f"specie{spnum}"] if spnum == 3: # see issue 814 npart_read += 1 assert_equal(npart_read, npart_header) AnaBoxSize = YTQuantity(7.1442196564, "Mpc") AnaVolume = YTQuantity(364.640074656, "Mpc**3") Volume = 1 for i in ds.domain_width.in_units("Mpc"): assert_almost_equal(i, AnaBoxSize) Volume *= i assert_almost_equal(Volume, AnaVolume) AnaNCells = 4087490 assert_equal(len(ad[("index", "cell_volume")]), AnaNCells) AnaTotDMMass = YTQuantity(1.01191786808255e14, "Msun") assert_almost_equal( ad[("darkmatter", "particle_mass")].sum().in_units("Msun"), AnaTotDMMass) AnaTotStarMass = YTQuantity(1776701.3990607238, "Msun") assert_almost_equal(ad[("stars", "particle_mass")].sum().in_units("Msun"), AnaTotStarMass) AnaTotStarMassInitial = YTQuantity(2423468.2801332865, "Msun") assert_almost_equal( ad[("stars", "particle_mass_initial")].sum().in_units("Msun"), AnaTotStarMassInitial, ) AnaTotGasMass = YTQuantity(1.7826982029216785e13, "Msun") assert_almost_equal(ad[("gas", "cell_mass")].sum().in_units("Msun"), AnaTotGasMass) AnaTotTemp = YTQuantity(150219844793.3907, "K") # just leaves assert_almost_equal(ad[("gas", "temperature")].sum().in_units("K"), AnaTotTemp)
def test_projection(): fns = [] for nprocs in [8, 1]: # We want to test both 1 proc and 8 procs, to make sure that # parallelism isn't broken fields = ("density", "temperature", "velocity_x", "velocity_y", "velocity_z") units = ('g/cm**3', 'K', 'cm/s', 'cm/s', 'cm/s') ds = fake_random_ds(64, fields=fields, units=units, nprocs=nprocs, length_unit=LENGTH_UNIT) dims = ds.domain_dimensions xn, yn, zn = ds.domain_dimensions xi, yi, zi = ds.domain_left_edge.to_ndarray() + \ 1.0 / (ds.domain_dimensions * 2) xf, yf, zf = ds.domain_right_edge.to_ndarray() - \ 1.0 / (ds.domain_dimensions * 2) dd = ds.all_data() coords = np.mgrid[xi:xf:xn * 1j, yi:yf:yn * 1j, zi:zf:zn * 1j] uc = [np.unique(c) for c in coords] # test if projections inherit the field parameters of their data sources dd.set_field_parameter("bulk_velocity", np.array([0, 1, 2])) proj = ds.proj("density", 0, data_source=dd) assert_equal(dd.field_parameters["bulk_velocity"], proj.field_parameters["bulk_velocity"]) # Some simple projection tests with single grids for ax, an in enumerate("xyz"): xax = ds.coordinates.x_axis[ax] yax = ds.coordinates.y_axis[ax] for wf in ['density', ("gas", "density"), None]: proj = ds.proj(["ones", "density"], ax, weight_field=wf) if wf is None: assert_equal(proj["ones"].sum(), LENGTH_UNIT * proj["ones"].size) assert_equal(proj["ones"].min(), LENGTH_UNIT) assert_equal(proj["ones"].max(), LENGTH_UNIT) else: assert_equal(proj["ones"].sum(), proj["ones"].size) assert_equal(proj["ones"].min(), 1.0) assert_equal(proj["ones"].max(), 1.0) assert_equal(np.unique(proj["px"]), uc[xax]) assert_equal(np.unique(proj["py"]), uc[yax]) assert_equal(np.unique(proj["pdx"]), 1.0 / (dims[xax] * 2.0)) assert_equal(np.unique(proj["pdy"]), 1.0 / (dims[yax] * 2.0)) plots = [proj.to_pw(fields='density'), proj.to_pw()] for pw in plots: for p in pw.plots.values(): tmpfd, tmpname = tempfile.mkstemp(suffix='.png') os.close(tmpfd) p.save(name=tmpname) fns.append(tmpname) frb = proj.to_frb((1.0, 'unitary'), 64) for proj_field in ['ones', 'density', 'temperature']: fi = ds._get_field_info(proj_field) assert_equal(frb[proj_field].info['data_source'], proj.__str__()) assert_equal(frb[proj_field].info['axis'], ax) assert_equal(frb[proj_field].info['field'], proj_field) field_unit = Unit(fi.units) if wf is not None: assert_equal( frb[proj_field].units, Unit(field_unit, registry=ds.unit_registry)) else: if frb[proj_field].units.is_code_unit: proj_unit = "code_length" else: proj_unit = "cm" if field_unit != '' and field_unit != Unit(): proj_unit = \ "({0}) * {1}".format(field_unit, proj_unit) assert_equal( frb[proj_field].units, Unit(proj_unit, registry=ds.unit_registry)) assert_equal(frb[proj_field].info['xlim'], frb.bounds[:2]) assert_equal(frb[proj_field].info['ylim'], frb.bounds[2:]) assert_equal(frb[proj_field].info['center'], proj.center) if wf is None: assert_equal(frb[proj_field].info['weight_field'], wf) else: assert_equal(frb[proj_field].info['weight_field'], proj.data_source._determine_fields(wf)[0]) # wf == None assert_equal(wf, None) v1 = proj["density"].sum() v2 = (dd["density"] * dd["d%s" % an]).sum() assert_rel_equal(v1, v2.in_units(v1.units), 10) teardown_func(fns)
def test_smoothed_covering_grid_2d_dataset(): ds = load(ekh) ds.periodicity = (True, True, True) scg = ds.smoothed_covering_grid(1, [0, 0, 0], [128, 128, 1]) assert_equal(scg['density'].shape, [128, 128, 1])
import yt from yt.testing import fake_random_ds, assert_equal def _test(field, data): return data[('stream', 'velocity_x')] ds = fake_random_ds() ds.add_field(('stream, density'), function=_test, units='cm/s', force_override=True) assert_equal(ds.all_data()[('stream', 'density')], ds.all_data()[('stream', 'velocity_x')])
def test_units(self): from unyt import Unit assert_equal(self.slc.frb["gas", "density"].units, Unit("mile*lb/yd**3")) assert_equal(self.slc.frb["gas", "temperature"].units, Unit("cm*K")) assert_equal(self.slc.frb["gas", "pressure"].units, Unit("dyn/cm"))
def test_domain_sphere(): # Now we test that we can get different radial velocities based on field # parameters. # Get the first sphere ds = fake_random_ds( 16, fields=("density", "velocity_x", "velocity_y", "velocity_z") ) sp0 = ds.sphere(ds.domain_center, 0.25) # Compute the bulk velocity from the cells in this sphere bulk_vel = sp0.quantities.bulk_velocity() # Get the second sphere sp1 = ds.sphere(ds.domain_center, 0.25) # Set the bulk velocity field parameter sp1.set_field_parameter("bulk_velocity", bulk_vel) assert_equal(np.any(sp0["radial_velocity"] == sp1["radial_velocity"]), False) # Radial profile without correction # Note we set n_bins = 8 here. rp0 = create_profile( sp0, "radius", "radial_velocity", units={"radius": "kpc"}, logs={"radius": False}, n_bins=8, ) # Radial profile with correction for bulk velocity rp1 = create_profile( sp1, "radius", "radial_velocity", units={"radius": "kpc"}, logs={"radius": False}, n_bins=8, ) assert_equal(rp0.x_bins, rp1.x_bins) assert_equal(rp0.used, rp1.used) assert_equal(rp0.used.sum() > rp0.used.size / 2.0, True) assert_equal( np.any(rp0["radial_velocity"][rp0.used] == rp1["radial_velocity"][rp1.used]), False, ) ref_sp = ds.sphere("c", 0.25) for f in _fields_to_compare: ref_sp[f].sort() for center in periodicity_cases(ds): sp = ds.sphere(center, 0.25) for f in _fields_to_compare: sp[f].sort() assert_equal(sp[f], ref_sp[f])
def test_scale(self): assert_equal(self.slc._field_transform["gas", "density"].name, "linear") assert_equal(self.slc._field_transform["gas", "temperature"].name, "symlog") assert_equal(self.slc._field_transform["gas", "temperature"].func, 100) assert_equal(self.slc._field_transform["gas", "pressure"].name, "log10") assert_equal(self.slc._field_transform["index", "radius"].name, "log10")
def test_castro_particle_io(): ds = data_dir_load(RT_particles) grid = ds.index.grids[2] npart_grid_2 = 49 # read directly from the header assert_equal(grid['particle_position_x'].size, npart_grid_2) assert_equal(grid['Tracer', 'particle_position_y'].size, npart_grid_2) assert_equal(grid['all', 'particle_position_y'].size, npart_grid_2) ad = ds.all_data() npart = 49 # read directly from the header assert_equal(ad['particle_velocity_x'].size, npart) assert_equal(ad['Tracer', 'particle_velocity_y'].size, npart) assert_equal(ad['all', 'particle_velocity_y'].size, npart) left_edge = ds.arr([0.0, 0.0, 0.0], 'code_length') right_edge = ds.arr([0.25, 1.0, 1.0], 'code_length') center = 0.5 * (left_edge + right_edge) reg = ds.region(center, left_edge, right_edge) assert (np.all( np.logical_and(reg['particle_position_x'] <= right_edge[0], reg['particle_position_x'] >= left_edge[0]))) assert (np.all( np.logical_and(reg['particle_position_y'] <= right_edge[1], reg['particle_position_y'] >= left_edge[1])))
def test_cmap(self): assert_equal(self.slc._colormap_config["gas", "density"], "plasma") assert_equal(self.slc._colormap_config["gas", "temperature"], "hot") assert_equal(self.slc._colormap_config["gas", "pressure"], "viridis")
def test_radtube(): ds = data_dir_load(rt) assert_equal(str(ds), "plt00500") for test in small_patch_amr(ds, _orion_fields): test_radtube.__name__ = test.description yield test
def test_fields_g1(): ds = data_dir_load(g1) assert_equal(str(ds), os.path.basename(g1)) for field in _fields: yield FieldValuesTest(g1, field, particle_type=True)
def test_nyx_particle_io(): ds = data_dir_load(LyA) grid = ds.index.grids[0] npart_grid_0 = 7908 # read directly from the header assert_equal(grid['particle_position_x'].size, npart_grid_0) assert_equal(grid['DM', 'particle_position_y'].size, npart_grid_0) assert_equal(grid['all', 'particle_position_z'].size, npart_grid_0) ad = ds.all_data() npart = 32768 # read directly from the header assert_equal(ad['particle_velocity_x'].size, npart) assert_equal(ad['DM', 'particle_velocity_y'].size, npart) assert_equal(ad['all', 'particle_velocity_z'].size, npart) assert (np.all(ad['particle_mass'] == ad['particle_mass'][0])) left_edge = ds.arr([0.0, 0.0, 0.0], 'code_length') right_edge = ds.arr([4.0, 4.0, 4.0], 'code_length') center = 0.5 * (left_edge + right_edge) reg = ds.region(center, left_edge, right_edge) assert (np.all( np.logical_and(reg['particle_position_x'] <= right_edge[0], reg['particle_position_x'] >= left_edge[0]))) assert (np.all( np.logical_and(reg['particle_position_y'] <= right_edge[1], reg['particle_position_y'] >= left_edge[1]))) assert (np.all( np.logical_and(reg['particle_position_z'] <= right_edge[2], reg['particle_position_z'] >= left_edge[2])))
def test_add_field_unit_semantics(): ds = fake_random_ds(16) ad = ds.all_data() def density_alias(field, data): return data['density'].in_cgs() def unitless_data(field, data): return np.ones(data['density'].shape) ds.add_field(('gas', 'density_alias_no_units'), sampling_type='cell', function=density_alias) ds.add_field(('gas', 'density_alias_auto'), sampling_type='cell', function=density_alias, units='auto', dimensions='density') ds.add_field(('gas', 'density_alias_wrong_units'), function=density_alias, sampling_type='cell', units='m/s') ds.add_field(('gas', 'density_alias_unparseable_units'), sampling_type='cell', function=density_alias, units='dragons') ds.add_field(('gas', 'density_alias_auto_wrong_dims'), function=density_alias, sampling_type='cell', units='auto', dimensions="temperature") assert_raises(YTFieldUnitError, get_data, ds, 'density_alias_no_units') assert_raises(YTFieldUnitError, get_data, ds, 'density_alias_wrong_units') assert_raises(YTFieldUnitParseError, get_data, ds, 'density_alias_unparseable_units') assert_raises(YTDimensionalityError, get_data, ds, 'density_alias_auto_wrong_dims') dens = ad['density_alias_auto'] assert_equal(str(dens.units), 'g/cm**3') ds.add_field(('gas', 'dimensionless'), sampling_type='cell', function=unitless_data) ds.add_field(('gas', 'dimensionless_auto'), function=unitless_data, sampling_type='cell', units='auto', dimensions='dimensionless') ds.add_field(('gas', 'dimensionless_explicit'), function=unitless_data, sampling_type='cell', units='') ds.add_field(('gas', 'dimensionful'), sampling_type='cell', function=unitless_data, units='g/cm**3') assert_equal(str(ad['dimensionless'].units), 'dimensionless') assert_equal(str(ad['dimensionless_auto'].units), 'dimensionless') assert_equal(str(ad['dimensionless_explicit'].units), 'dimensionless') assert_raises(YTFieldUnitError, get_data, ds, 'dimensionful')
def test_moving7(): ds = data_dir_load(m7) assert_equal(str(ds), "moving7_0010") for test in small_patch_amr(m7, _fields): test_moving7.__name__ = test.description yield test
def test_field_inference(): ds = fake_random_ds(16) ds.index # If this is not true this means the result of field inference depends # on the order we did field detection, which is random in Python3 assert_equal(ds._last_freq, (None, None))
def compare(self, new_result, old_result): for k in new_result: assert_equal(new_result[k], old_result[k])
def test_covering_grid(): # We decompose in different ways for level in [0, 1, 2]: for nprocs in [1, 2, 4, 8]: ds = fake_random_ds(16, nprocs=nprocs) axis_name = ds.coordinates.axis_name dn = ds.refine_by**level cg = ds.covering_grid(level, [0.0, 0.0, 0.0], dn * ds.domain_dimensions) # Test coordinate generation assert_equal(np.unique(cg[f"d{axis_name[0]}"]).size, 1) xmi = cg[axis_name[0]].min() xma = cg[axis_name[0]].max() dx = cg[f"d{axis_name[0]}"].flat[0:1] edges = ds.arr([[0, 1], [0, 1], [0, 1]], "code_length") assert_equal(xmi, edges[0, 0] + dx / 2.0) assert_equal(xmi, cg[axis_name[0]][0, 0, 0]) assert_equal(xmi, cg[axis_name[0]][0, 1, 1]) assert_equal(xma, edges[0, 1] - dx / 2.0) assert_equal(xma, cg[axis_name[0]][-1, 0, 0]) assert_equal(xma, cg[axis_name[0]][-1, 1, 1]) assert_equal(np.unique(cg[f"d{axis_name[1]}"]).size, 1) ymi = cg[axis_name[1]].min() yma = cg[axis_name[1]].max() dy = cg[f"d{axis_name[1]}"][0] assert_equal(ymi, edges[1, 0] + dy / 2.0) assert_equal(ymi, cg[axis_name[1]][0, 0, 0]) assert_equal(ymi, cg[axis_name[1]][1, 0, 1]) assert_equal(yma, edges[1, 1] - dy / 2.0) assert_equal(yma, cg[axis_name[1]][0, -1, 0]) assert_equal(yma, cg[axis_name[1]][1, -1, 1]) assert_equal(np.unique(cg[f"d{axis_name[2]}"]).size, 1) zmi = cg[axis_name[2]].min() zma = cg[axis_name[2]].max() dz = cg[f"d{axis_name[2]}"][0] assert_equal(zmi, edges[2, 0] + dz / 2.0) assert_equal(zmi, cg[axis_name[2]][0, 0, 0]) assert_equal(zmi, cg[axis_name[2]][1, 1, 0]) assert_equal(zma, edges[2, 1] - dz / 2.0) assert_equal(zma, cg[axis_name[2]][0, 0, -1]) assert_equal(zma, cg[axis_name[2]][1, 1, -1]) # Now we test other attributes assert_equal(cg["ones"].max(), 1.0) assert_equal(cg["ones"].min(), 1.0) assert_equal(cg["grid_level"], level) assert_equal(cg["cell_volume"].sum(), ds.domain_width.prod()) for g in ds.index.grids: di = g.get_global_startindex() dd = g.ActiveDimensions for i in range(dn): f = cg["density"][dn * di[0] + i:dn * (di[0] + dd[0]) + i:dn, dn * di[1] + i:dn * (di[1] + dd[1]) + i:dn, dn * di[2] + i:dn * (di[2] + dd[2]) + i:dn, ] assert_equal(f, g["density"]) # More tests for cylindrical geometry for fn in [cyl_2d, cyl_3d]: ds = load(fn) ad = ds.all_data() upper_ad = ad.cut_region(["obj['z'] > 0"]) sp = ds.sphere((0, 0, 0), 0.5 * ds.domain_width[0], data_source=upper_ad) sp.quantities.total_mass()
def test_gc(): ds = data_dir_load(gc) assert_equal(str(ds), "data.0077.3d.hdf5") for test in small_patch_amr(ds, _fields): test_gc.__name__ = test.description yield test
def test_velocity_field(): ds = data_dir_load(vf, cls=FITSDataset) assert_equal(str(ds), "velocity_field_20.fits") for test in small_patch_amr(ds, _fields_vels, input_center="c", input_weight="ones"): test_velocity_field.__name__ = test.description yield test
def fail_for_different_source(): sp = ds.sphere(ds.domain_center, (2, 'kpc')) proj2_c = ds.proj(field, "z", data_source=sp, method="integrate") return assert_equal(proj2_c[field], proj2[field])
def test_A2052(): ds = data_dir_load(A2052, cls=SkyDataFITSDataset) assert_equal(str(ds), "A2052_merged_0.3-2_match-core_tmap_bgecorr.fits") for test in small_patch_amr(ds, _fields_A2052, input_center="c", input_weight="ones"): test_A2052.__name__ = test.description yield test
def test_grs(): ds = data_dir_load(grs, cls=SpectralCubeFITSDataset, kwargs={"nan_mask":0.0}) assert_equal(str(ds), "grs-50-cube.fits") for test in small_patch_amr(ds, _fields_grs, input_center="c", input_weight="ones"): test_grs.__name__ = test.description yield test
def test_covering_grid(): # We decompose in different ways for level in [0, 1, 2]: for nprocs in [1, 2, 4, 8]: ds = fake_random_ds(16, nprocs=nprocs) dn = ds.refine_by**level cg = ds.covering_grid(level, [0.0, 0.0, 0.0], dn * ds.domain_dimensions) # Test coordinate generation assert_equal(np.unique(cg["dx"]).size, 1) xmi = cg["x"].min() xma = cg["x"].max() dx = cg["dx"].flat[0:1] edges = ds.arr([[0, 1], [0, 1], [0, 1]], 'code_length') assert_equal(xmi, edges[0, 0] + dx / 2.0) assert_equal(xmi, cg["x"][0, 0, 0]) assert_equal(xmi, cg["x"][0, 1, 1]) assert_equal(xma, edges[0, 1] - dx / 2.0) assert_equal(xma, cg["x"][-1, 0, 0]) assert_equal(xma, cg["x"][-1, 1, 1]) assert_equal(np.unique(cg["dy"]).size, 1) ymi = cg["y"].min() yma = cg["y"].max() dy = cg["dy"][0] assert_equal(ymi, edges[1, 0] + dy / 2.0) assert_equal(ymi, cg["y"][0, 0, 0]) assert_equal(ymi, cg["y"][1, 0, 1]) assert_equal(yma, edges[1, 1] - dy / 2.0) assert_equal(yma, cg["y"][0, -1, 0]) assert_equal(yma, cg["y"][1, -1, 1]) assert_equal(np.unique(cg["dz"]).size, 1) zmi = cg["z"].min() zma = cg["z"].max() dz = cg["dz"][0] assert_equal(zmi, edges[2, 0] + dz / 2.0) assert_equal(zmi, cg["z"][0, 0, 0]) assert_equal(zmi, cg["z"][1, 1, 0]) assert_equal(zma, edges[2, 1] - dz / 2.0) assert_equal(zma, cg["z"][0, 0, -1]) assert_equal(zma, cg["z"][1, 1, -1]) # Now we test other attributes assert_equal(cg["ones"].max(), 1.0) assert_equal(cg["ones"].min(), 1.0) assert_equal(cg["grid_level"], level) assert_equal(cg["cell_volume"].sum(), ds.domain_width.prod()) for g in ds.index.grids: di = g.get_global_startindex() dd = g.ActiveDimensions for i in range(dn): f = cg["density"][dn * di[0] + i:dn * (di[0] + dd[0]) + i:dn, dn * di[1] + i:dn * (di[1] + dd[1]) + i:dn, dn * di[2] + i:dn * (di[2] + dd[2]) + i:dn] assert_equal(f, g["density"])