def test_ghost_zones(): ds = yt.load(output_00080) def gen_dummy(ngz): def dummy(field, data): if not isinstance(data, FieldDetector): shape = data["gas", "mach_number"].shape[:3] np.testing.assert_equal( shape, (2 + 2 * ngz, 2 + 2 * ngz, 2 + 2 * ngz)) return data["gas", "mach_number"] return dummy fields = [] for ngz in (1, 2, 3): fname = ("gas", f"density_ghost_zone_{ngz}") ds.add_field( fname, gen_dummy(ngz), sampling_type="cell", validators=[yt.ValidateSpatial(ghost_zones=ngz)], ) fields.append(fname) box = ds.box([0, 0, 0], [0.1, 0.1, 0.1]) for f in fields: print("Getting ", f) box[f]
### THIS RECIPE IS CURRENTLY BROKEN IN YT-3.0 ### DO NOT TRUST THIS RECIPE UNTIL THIS LINE IS REMOVED import numpy as np import yt # Define the components of the gravitational acceleration vector field by # taking the gradient of the gravitational potential @yt.derived_field(name='gravitational_acceleration_x', units='cm/s**2', take_log=False, validators=[yt.ValidateSpatial(1,["gravitational_potential"])]) def gravitational_acceleration_x(field, data): # We need to set up stencils sl_left = slice(None, -2, None) sl_right = slice(2, None, None) div_fac = 2.0 dx = div_fac * data['dx'][0] gx = data["gravitational_potential"][sl_right, 1:-1, 1:-1]/dx gx -= data["gravitational_potential"][sl_left, 1:-1, 1:-1]/dx new_field = np.zeros(data["gravitational_potential"].shape, dtype='float64')*gx.uq new_field[1:-1, 1:-1, 1:-1] = -gx return new_field
def rhologrho(field, data): return data['Density'] * data['logrho'] def cs2rhologrho(field, data): cs2 = data.ds.quan(1., 'code_velocity**2') return cs2 * data['rhologrho'] def ek(field, data): return 0.5 * data['Density'] * data['absv']**2 default_validators = [yt.ValidateGridType()] density_validators = [yt.ValidateSpatial(1, ['density'])] vx_validators = [yt.ValidateSpatial(1, ['x-velocity'])] vy_validators = [yt.ValidateSpatial(1, ['y-velocity'])] vz_validators = [yt.ValidateSpatial(1, ['z-velocity'])] drho_units = "code_mass/code_length**4" dv_units = "1/code_time" a_units = "code_length/code_time**2" fields = { "drhodx": [drhodx, density_validators, drho_units, {}], "drhody": [drhody, density_validators, drho_units, {}], "drhodz": [drhodz, density_validators, drho_units, {}], "absv": [absv, "code_length/code_time", {}], "dvxdx": [dvxdx, vx_validators, dv_units, {}], "dvxdy": [dvxdy, vx_validators, dv_units, {}],
#print " search" found_any, mask = particle_ops.mask_particles( indices_late, my_indices, mask_to_get) data.set_field_parameter('mask_to_get',mask_to_get) pos_to_get = data['particle_position'][mask == 1] d = data.deposit(pos_to_get, method = "count") d = data.ds.arr(d, input_units = "cm**-3") t1 = time.time() #print " DT", t1-t0[-1] data.set_field_parameter('timer',t0+[t1]) return data.apply_units(d, field.units) yt.add_field( ("deposit","deposit_target_particles"), #yt.add_field( 'dp1', function = deposit_target_particles_1, validators = [yt.ValidateSpatial(), yt.ValidateParameter('indices_late'), yt.ValidateParameter('mask_to_get'), yt.ValidateGridType()], display_name = "target_particles") class SelectParticleCallback(PlotCallback): _type_name = "select_particles" region = None _descriptor = None def __init__(self, width, p_size=1.0, col='k', marker='o', stride=1.0, ptype='all', stars_only=False, dm_only=False, minimum_mass=None,bool=None, indices=None, xyz=None): """ Adds particle positions, based on a thick slab along *axis* with a *width* along the line of sight. *p_size* controls the number of