Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.add_field(name=name, sampling_type="cell", function=_func,
units=unit)
#Load cooling files
avals = {}
tvals = {}
with FortranFile(filename) as fd:
n1, n2 = fd.read_vector('i')
for ax in _cool_axes:
avals[ax] = fd.read_vector('d')
for i,(tname, unit) in enumerate(_cool_arrs):
var = fd.read_vector('d')
if var.size==n1 and i==0:
#If this case occurs, the cooling files were produced pre-2010 in a format
#that is no longer supported
mylog.warning('This cooling file format is no longer supported. Cooling field loading skipped.')
return
if var.size == n1*n2:
tvals[tname] = dict(data=var.reshape((n1, n2), order='F'), unit=unit)
else:
var = var.reshape((n1, n2, var.size // (n1*n2)), order='F')
for i in range(var.shape[-1]):
tvals[_cool_species[i]] = dict(data=var[:,:,i], unit="1/cm**3")
#Add the mu field first, as it is needed for the number density
interp = BilinearFieldInterpolator(tvals['mu']['data'],
(avals["lognH"], avals["logT"]),
["lognH", "logT"], truncate = True)
_create_field(("gas", 'mu'), interp, tvals['mu']['unit'])
#Add the number density field, based on mu
def _number_density(field,data):
print( '-------------------------------------------------------------------\n' )
idx_start = args.idx_start
idx_end = args.idx_end
didx = args.didx
prefix = args.prefix
field = 'density'
#field = [ 'density', 'Cloud0', 'Cloud1' ]
dpi = 150
yt.enable_parallelism()
ts = yt.load( [ prefix+'/Data_%06d'%idx for idx in range(idx_start, idx_end+1, didx) ] )
for ds in ts.piter():
pz_dens = yt.ProjectionPlot( ds, 'z', field )
pz_dens.set_zlim( field, 1.0e-5, 5.0e-2 )
pz_dens.set_font( {'size':16} )
pz_dens.set_axes_unit( 'code_length' )
pz_dens.set_unit( field, 'code_mass/code_length**2' )
pz_dens.annotate_timestamp( time_unit='code_time', corner='upper_right' )
pz_dens.save( mpl_kwargs={"dpi":dpi} )
def generate_tasks_input():
pyver = "py{}{}".format(sys.version_info.major, sys.version_info.minor)
if sys.version_info < (3, 0, 0):
DROP_TAG = "py3"
else:
DROP_TAG = "py2"
test_dir = ytcfg.get("yt", "test_data_dir")
answers_dir = os.path.join(test_dir, "answers")
with open('tests/tests.yaml', 'r') as obj:
lines = obj.read()
data = '\n'.join([line for line in lines.split('\n')
if DROP_TAG not in line])
tests = yaml.load(data)
base_argv = ['-s', '--nologcapture', '--with-xunit']
base_answer_argv = ['--local-dir=%s' % answers_dir, '--with-answer-testing',
'--answer-big-data', '--local']
args = []
for test in list(tests["other_tests"].keys()):
args.append(([test] + base_argv + tests["other_tests"][test], True))
def test_unit_systems():
goofy_unit_system = UnitSystem("goofy", "ly", "lbm", "hr", temperature_unit="R",
angle_unit="arcsec", current_mks_unit="mA")
assert goofy_unit_system["temperature"] == Unit("R")
assert goofy_unit_system[dimensions.solid_angle] == Unit("arcsec**2")
assert goofy_unit_system["energy"] == Unit("lbm*ly**2/hr**2")
goofy_unit_system["energy"] = "eV"
assert goofy_unit_system["energy"] == Unit("eV")
assert goofy_unit_system["magnetic_field_mks"] == Unit("lbm/(hr**2*mA)")
assert "goofy" in unit_system_registry
def test_create_from_string():
"""
Create units with strings and check attributes.
"""
u1 = Unit("g * cm**2 * s**-2")
assert_true(u1.dimensions == energy)
assert_true(u1.base_value == 1.0)
# make sure order doesn't matter
u2 = Unit("cm**2 * s**-2 * g")
assert_true(u2.dimensions == energy)
assert_true(u2.base_value == 1.0)
# Test rationals
u3 = Unit("g**0.5 * cm**-0.5 * s**-1")
assert_true(u3.dimensions == magnetic_field)
assert_true(u3.base_value == 1.0)
# sqrt functions
u4 = Unit("sqrt(g)/sqrt(cm)/s")
assert_true(u4.dimensions == magnetic_field)
assert_true(u4.base_value == 1.0)
# commutative sqrt function
u5 = Unit("sqrt(g/cm)/s")
assert_true(u5.dimensions == magnetic_field)
def test_is_code_unit():
ds = fake_random_ds(64, nprocs=1)
u1 = Unit('code_mass', registry=ds.unit_registry)
u2 = Unit('code_mass/code_length', registry=ds.unit_registry)
u3 = Unit('code_velocity*code_mass**2', registry=ds.unit_registry)
u4 = Unit('code_time*code_mass**0.5', registry=ds.unit_registry)
u5 = Unit('code_mass*g', registry=ds.unit_registry)
u6 = Unit('g/cm**3')
assert_true(u1.is_code_unit)
assert_true(u2.is_code_unit)
assert_true(u3.is_code_unit)
assert_true(u4.is_code_unit)
assert_true(not u5.is_code_unit)
assert_true(not u6.is_code_unit)
def test_division():
"""
Divide two units.
"""
pc_cgs = cm_per_pc
km_cgs = cm_per_km
# Create symbols
pc_sym = Symbol("pc", positive=True)
km_sym = Symbol("km", positive=True)
s_sym = Symbol("s", positive=True)
# Create units
u1 = Unit("pc")
u2 = Unit("km * s")
u3 = u1 / u2
assert_true(u3.expr == pc_sym / (km_sym * s_sym))
assert_allclose_units(u3.base_value, pc_cgs / km_cgs, 1e-12)
assert_true(u3.dimensions == 1 / time)
a2 = array([4., 5., 6.])
a3 = [4, 5, 6]
answer1 = YTArray([0.25, 0.4, 0.5], 'cm')
answer2 = YTArray([4, 2.5, 2], '1/cm')
operate_and_compare(a1, a2, op, answer1)
operate_and_compare(a2, a1, op, answer2)
operate_and_compare(a1, a3, op, answer1)
operate_and_compare(a3, a1, op, answer2)
operate_and_compare(a1, a2, np.divide, answer1)
operate_and_compare(a2, a1, np.divide, answer2)
operate_and_compare(a1, a3, np.divide, answer1)
operate_and_compare(a3, a1, np.divide, answer2)
# Both dimensionless quantities
a1 = YTArray([1., 2., 3.])
a2 = array([4., 5., 6.])
a3 = [4, 5, 6]
answer1 = YTArray([0.25, 0.4, 0.5])
answer2 = YTArray([4, 2.5, 2])
operate_and_compare(a1, a2, op, answer1)
operate_and_compare(a2, a1, op, answer2)
operate_and_compare(a1, a3, op, answer1)
operate_and_compare(a3, a1, op, answer2)
operate_and_compare(a1, a3, np.divide, answer1)
operate_and_compare(a3, a1, np.divide, answer2)
operate_and_compare(a1, a3, np.divide, answer1)
operate_and_compare(a3, a1, np.divide, answer2)
def test_ones_and_zeros_like():
data = YTArray([1, 2, 3], 'cm')
zd = np.zeros_like(data)
od = np.ones_like(data)
assert_equal(zd, YTArray([0, 0, 0], 'cm'))
assert_equal(zd.units, data.units)
assert_equal(od, YTArray([1, 1, 1], 'cm'))
assert_equal(od.units, data.units)
def test_copy():
quan = YTQuantity(1, 'g')
arr = YTArray([1, 2, 3], 'cm')
assert_equal(copy.copy(quan), quan)
assert_array_equal(copy.copy(arr), arr)
assert_equal( copy.deepcopy(quan), quan)
assert_array_equal(copy.deepcopy(arr), arr)
assert_equal(quan.copy(), quan)
assert_array_equal(arr.copy(), arr)
assert_equal(np.copy(quan), quan)
assert_array_equal(np.copy(arr), arr)