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))
Exemplo n.º 2
0
 def _radial(field, data):
     normal = data.get_field_parameter("normal")
     vectors = obtain_rv_vec(data, (xn, yn, zn), "bulk_%s" % basename)
     theta = data['index', 'spherical_theta']
     phi = data['index', 'spherical_phi']
     rv = get_sph_r_component(vectors, theta, phi, normal)
     # Now, anywhere that radius is in fact zero, we want to zero out our
     # return values.
     rv[np.isnan(theta)] = 0.0
     return rv
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))
Exemplo n.º 4
0
    def _particle_velocity_spherical_radius(field, data):
        """The spherical radius 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)
        sphr = get_sph_r_component(vel, theta, phi, normal)
        return sphr
Exemplo n.º 5
0
    def _spherical_radius_component(field, data):
        """The spherical radius component of the vector field

        Relative to the coordinate system defined by the *normal* vector,
        *center*, and *bulk_* field parameters.
        """
        normal = data.get_field_parameter("normal")
        vectors = obtain_rv_vec(data, (xn, yn, zn), "bulk_%s" % basename)
        theta = data['index', 'spherical_theta']
        phi = data['index', 'spherical_phi']
        rv = get_sph_r_component(vectors, theta, phi, normal)
        # Now, anywhere that radius is in fact zero, we want to zero out our
        # return values.
        rv[np.isnan(theta)] = 0.0
        return rv
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 def _particle_spherical_position_radius(field, data):
     """
     Radial 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))
     sphr = get_sph_r_component(pos, theta, phi, normal)
     return sphr
    def _spherical_radius_component(field, data):
        """The spherical radius component of the vector field

        Relative to the coordinate system defined by the *normal* vector,
        *center*, and *bulk_* field parameters.
        """
        normal = data.get_field_parameter("normal")
        vectors = obtain_rv_vec(data, (xn, yn, zn),
                                "bulk_%s" % basename)
        theta = data['index', 'spherical_theta']
        phi = data['index', 'spherical_phi']
        rv = get_sph_r_component(vectors, theta, phi, normal)
        # Now, anywhere that radius is in fact zero, we want to zero out our
        # return values.
        rv[np.isnan(theta)] = 0.0
        return rv
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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
Exemplo n.º 11
0
    def _particle_velocity_spherical_radius(field, data):
        """The spherical radius 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')
        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"])
        pos = pos - np.reshape(center, (3, 1))
        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_velocity_spherical_radius(field, data):
        """The spherical radius 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')
        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"])
        theta = get_sph_theta(pos, normal)
        phi = get_sph_phi(pos, normal)
        pos = pos - np.reshape(center, (3, 1))
        vel = vel - np.reshape(bv, (3, 1))
        sphr = get_sph_r_component(vel, theta, phi, normal)
        return sphr
Exemplo n.º 13
0
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