def test_spherical_coordinate_conversion(): normal = [0, 0, 1] real_r = [ 0.72950559, 0.99384957, 1.13047198, 0.97696269, 1.09807968, 1.12445067, 1.10788685, 1.38843954] real_theta = [ 2.44113629, 0.87012028, 2.14891444, 1.4032274 , 0.80979483, 2.10280198, 1.13507735, 1.85068416] real_phi = [-2.65224483, -0.23804243, -1.47641858, -1.46498842, -0.40172325, -0.4422801 , 0.95466734, -2.31085392] calc_r = get_sph_r(coords) calc_theta = get_sph_theta(coords, normal) calc_phi = get_sph_phi(coords, normal) assert_array_almost_equal(calc_r, real_r) assert_array_almost_equal(calc_theta, real_theta) assert_array_almost_equal(calc_phi, real_phi) normal = [1, 0, 0] real_theta = [ 2.17598842, 0.73347681, 1.49179079, 1.46647589, 0.8412984 , 0.67793705, 1.0193883 , 2.27586987] real_phi = [-1.94809584, 1.843405, -2.56143151, 2.97309903, 1.96037671, -2.1995016, 0.51841239, -2.77038877] calc_theta = get_sph_theta(coords, normal) calc_phi = get_sph_phi(coords, normal) assert_array_almost_equal(calc_theta, real_theta) assert_array_almost_equal(calc_phi, real_phi)
def test_spherical_coordinate_conversion(): normal = [0, 0, 1] real_r = [ 0.72950559, 0.99384957, 1.13047198, 0.97696269, 1.09807968, 1.12445067, 1.10788685, 1.38843954] real_theta = [ 2.44113629, 0.87012028, 2.14891444, 1.4032274 , 0.80979483, 2.10280198, 1.13507735, 1.85068416] real_phi = [-2.65224483, -0.23804243, -1.47641858, -1.46498842, -0.40172325, -0.4422801 , 0.95466734, -2.31085392] calc_r = get_sph_r(coords) calc_theta = get_sph_theta(coords, normal) calc_phi = get_sph_phi(coords, normal) assert_array_almost_equal(calc_r, real_r) assert_array_almost_equal(calc_theta, real_theta) assert_array_almost_equal(calc_phi, real_phi) normal = [1, 0, 0] real_theta = [ 2.17598842, 0.73347681, 1.49179079, 1.46647589, 0.8412984 , 0.67793705, 1.0193883 , 2.27586987] real_phi = [-0.37729951, -2.86898397, -0.99063518, -1.73928995, -2.75201227,-0.62870527, 2.08920872, -1.19959244] calc_theta = get_sph_theta(coords, normal) calc_phi = get_sph_phi(coords, normal) assert_array_almost_equal(calc_theta, real_theta) assert_array_almost_equal(calc_phi, real_phi)
def test_spherical_coordinate_projections(): normal = [0, 0, 1] theta = get_sph_theta(coords, normal) phi = get_sph_phi(coords, normal) zero = np.tile(0, coords.shape[1]) # Purely radial field vecs = np.array([ np.sin(theta) * np.cos(phi), np.sin(theta) * np.sin(phi), np.cos(theta) ]) assert_array_almost_equal( zero, get_sph_theta_component(vecs, theta, phi, normal)) assert_array_almost_equal(zero, get_sph_phi_component(vecs, phi, normal)) # Purely toroidal field vecs = np.array([-np.sin(phi), np.cos(phi), zero]) assert_array_almost_equal( zero, get_sph_theta_component(vecs, theta, phi, normal)) assert_array_almost_equal(zero, get_sph_r_component(vecs, theta, phi, normal)) # Purely poloidal field vecs = np.array([ np.cos(theta) * np.cos(phi), np.cos(theta) * np.sin(phi), -np.sin(theta) ]) assert_array_almost_equal(zero, get_sph_phi_component(vecs, phi, normal)) assert_array_almost_equal(zero, get_sph_r_component(vecs, theta, phi, normal))
def _particle_position_spherical_phi(field, data): """The spherical phi component of the particle positions Relative to the coordinate system defined by the *normal* vector and *center* field parameters. """ normal = data.get_field_parameter("normal") pos = data["relative_particle_position"].T return data.ds.arr(get_sph_phi(pos, normal), "")
def _particle_position_spherical_phi(field, data): """The spherical phi component of the particle positions Relative to the coordinate system defined by the *normal* vector and *center* field parameters. """ normal = data.get_field_parameter("normal") center = data.get_field_parameter("center") pos = data.ds.arr([data[ptype, spos % ax] for ax in "xyz"]) pos = pos - np.reshape(center, (3, 1)) return data.ds.arr(get_sph_phi(pos, normal), "")
def _spherical_phi(field, data): """The spherical phi component of the positions of the mesh cells. phi is the azimuthal position angle in the plane perpendicular to the *normal* vector Relative to the coordinate system defined by the *center* and *normal* field parameters. """ normal = data.get_field_parameter("normal") coords = get_periodic_rvec(data) return get_sph_phi(coords, normal)
def _particle_velocity_spherical_phi(field, data): """The spherical phi component of the particle velocities Relative to the coordinate system defined by the *normal* vector, *bulk_velocity* vector and *center* field parameters. """ normal = data.get_field_parameter("normal") pos = data["relative_particle_position"].T vel = data["relative_particle_velocity"].T phi = get_sph_phi(pos, normal) sphp = get_sph_phi_component(vel, phi, normal) return sphp
def _particle_velocity_spherical_theta(field, data): """The spherical theta component of the particle velocities in an arbitrary coordinate system Relative to the coordinate system defined by the *normal* vector, *bulk_velocity* vector and *center* field parameters. """ normal = data.get_field_parameter("normal") pos = data["relative_particle_position"].T vel = data["relative_particle_velocity"].T theta = get_sph_theta(pos, normal) phi = get_sph_phi(pos, normal) spht = get_sph_theta_component(vel, theta, phi, normal) return spht
def _particle_velocity_spherical_phi(field, data): """The spherical phi component of the particle velocities Relative to the coordinate system defined by the *normal* vector, *bulk_velocity* vector and *center* field parameters. """ normal = data.get_field_parameter('normal') center = data.get_field_parameter('center') bv = data.get_field_parameter("bulk_velocity") pos = data.ds.arr([data[ptype, spos % ax] for ax in "xyz"]) vel = data.ds.arr([data[ptype, svel % ax] for ax in "xyz"]) phi = get_sph_phi(pos, normal) pos = pos - np.reshape(center, (3, 1)) vel = vel - np.reshape(bv, (3, 1)) sphp = get_sph_phi_component(vel, phi, normal) return sphp
def _particle_spherical_position_phi(field, data): """ Phi component of the particles' position vectors in spherical coords on the provided field parameters for 'normal', 'center', and 'bulk_velocity', """ normal = data.get_field_parameter('normal') center = data.get_field_parameter('center') bv = data.get_field_parameter("bulk_velocity") pos = spos pos = YTArray([data[ptype, pos % ax] for ax in "xyz"]) theta = get_sph_theta(pos, center) phi = get_sph_phi(pos, center) pos = pos - np.reshape(center, (3, 1)) sphp = get_sph_phi_component(pos, phi, normal) return sphp
def _ENZOTEST_gas_radial_velocity(field, data): normal = data.get_field_parameter('normal') center = data.get_field_parameter('center') bv = data.get_field_parameter("bulk_velocity") #pos = "%" pos = YTArray([data['index', ax].in_units('cm') for ax in "xyz"], 'cm') vel = "velocity_%s" vel = YTArray([data['gas', vel % ax].in_units('km/s') for ax in "xyz"], 'km/s') pos = np.reshape(pos, (3, pos.size/3)) pos = pos - np.reshape(center, (3, 1)) vel = np.reshape(vel, (3, vel.size/3)) vel = vel - np.reshape(bv, (3, 1)) theta = get_sph_theta(pos, normal) phi = get_sph_phi(pos, normal) sphr = get_sph_r_component(vel, theta, phi, normal) return sphr
def _ENZOTEST_gas_radial_velocity(field, data): normal = data.get_field_parameter('normal') center = data.get_field_parameter('center') bv = data.get_field_parameter("bulk_velocity") #pos = "%" pos = YTArray([data['index', ax].in_units('cm') for ax in "xyz"], 'cm') vel = "velocity_%s" vel = YTArray([data['gas', vel % ax].in_units('km/s') for ax in "xyz"], 'km/s') pos = np.reshape(pos, (3, pos.size / 3)) pos = pos - np.reshape(center, (3, 1)) vel = np.reshape(vel, (3, vel.size / 3)) vel = vel - np.reshape(bv, (3, 1)) theta = get_sph_theta(pos, normal) phi = get_sph_phi(pos, normal) sphr = get_sph_r_component(vel, theta, phi, normal) return sphr
def _particle_radial_velocity(field, data): ptype="all" normal = data.get_field_parameter('normal') center = data.get_field_parameter('center') bv = data.get_field_parameter("bulk_velocity") pos = "particle_position_%s" pos = YTArray([data[ptype, pos % ax].in_units('cm') for ax in "xyz"], 'cm') vel = "particle_velocity_%s" vel = YTArray([data[ptype, vel % ax].in_units('km/s') for ax in "xyz"], 'km/s') pos = np.reshape(pos, (3, pos.size/3)) pos = pos - np.reshape(center, (3, 1)) vel = np.reshape(vel, (3, vel.size/3)) vel = vel - np.reshape(bv, (3, 1)) theta = get_sph_theta(pos, normal) phi = get_sph_phi(pos, normal) sphr = get_sph_r_component(vel, theta, phi, normal) return sphr
def _particle_radial_velocity(field, data): ptype = "all" normal = data.get_field_parameter('normal') center = data.get_field_parameter('center') bv = data.get_field_parameter("bulk_velocity") pos = "particle_position_%s" pos = YTArray([data[ptype, pos % ax].in_units('cm') for ax in "xyz"], 'cm') vel = "particle_velocity_%s" vel = YTArray([data[ptype, vel % ax].in_units('km/s') for ax in "xyz"], 'km/s') pos = np.reshape(pos, (3, pos.size / 3)) pos = pos - np.reshape(center, (3, 1)) vel = np.reshape(vel, (3, vel.size / 3)) vel = vel - np.reshape(bv, (3, 1)) theta = get_sph_theta(pos, normal) phi = get_sph_phi(pos, normal) sphr = get_sph_r_component(vel, theta, phi, normal) return sphr
def _particle_spherical_velocity_theta(field, data): """ Theta component of the particles' velocity vectors in spherical coords based on the provided field parameters for 'normal', 'center', and 'bulk_velocity', """ normal = data.get_field_parameter('normal') center = data.get_field_parameter('center') bv = data.get_field_parameter("bulk_velocity") pos = spos pos = YTArray([data[ptype, pos % ax] for ax in "xyz"]) vel = svel vel = YTArray([data[ptype, vel % ax] for ax in "xyz"]) theta = get_sph_theta(pos, center) phi = get_sph_phi(pos, center) pos = pos - np.reshape(center, (3, 1)) vel = vel - np.reshape(bv, (3, 1)) spht = get_sph_theta_component(vel, theta, phi, normal) return spht
def test_spherical_coordinate_projections(): normal = [0, 0, 1] theta = get_sph_theta(coords, normal) phi = get_sph_phi(coords, normal) zero = np.tile(0,coords.shape[1]) # Purely radial field vecs = np.array([np.sin(theta)*np.cos(phi), np.sin(theta)*np.sin(phi), np.cos(theta)]) assert_array_almost_equal(zero, get_sph_theta_component(vecs, theta, phi, normal)) assert_array_almost_equal(zero, get_sph_phi_component(vecs, phi, normal)) # Purely toroidal field vecs = np.array([-np.sin(phi), np.cos(phi), zero]) assert_array_almost_equal(zero, get_sph_theta_component(vecs, theta, phi, normal)) assert_array_almost_equal(zero, get_sph_r_component(vecs, theta, phi, normal)) # Purely poloidal field vecs = np.array([np.cos(theta)*np.cos(phi), np.cos(theta)*np.sin(phi), -np.sin(theta)]) assert_array_almost_equal(zero, get_sph_phi_component(vecs, phi, normal)) assert_array_almost_equal(zero, get_sph_r_component(vecs, theta, phi, normal))
def _spherical_phi(field, data): normal = data.get_field_parameter("normal") coords = get_periodic_rvec(data) return get_sph_phi(coords, normal)