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 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))
Example #3
0
    def _spherical_theta_component(field, data):
        """The spherical theta 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 = resize_vector(data["index", "spherical_theta"], vectors)
        phi = resize_vector(data["index", "spherical_phi"], vectors)
        return get_sph_theta_component(vectors, theta, phi, normal)
Example #4
0
    def _magnetic_field_poloidal(field, data):
        normal = data.get_field_parameter("normal")
        d = data[ftype, 'magnetic_field_x']
        Bfields = data.ds.arr([
            data[ftype, 'magnetic_field_x'], data[ftype, 'magnetic_field_y'],
            data[ftype, 'magnetic_field_z']
        ], d.units)

        theta = data["index", 'spherical_theta']
        phi = data["index", 'spherical_phi']

        return get_sph_theta_component(Bfields, theta, phi, normal)
    def _spherical_theta_component(field, data):
        """The spherical theta 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 = resize_vector(data["index", "spherical_theta"], vectors)
        phi = resize_vector(data["index", "spherical_phi"], vectors)
        return get_sph_theta_component(vectors, theta, phi, normal)
Example #6
0
        def _magnetic_field_poloidal(field, data):
            normal = data.get_field_parameter("normal")

            Bfields = ustack([
                data[ftype, "relative_magnetic_field_x"],
                data[ftype, "relative_magnetic_field_y"],
                data[ftype, "relative_magnetic_field_z"],
            ])

            theta = data["index", "spherical_theta"]
            phi = data["index", "spherical_phi"]

            return get_sph_theta_component(Bfields, theta, phi, normal)
Example #7
0
        def _magnetic_field_poloidal(field, data):
            normal = data.get_field_parameter("normal")

            Bfields = ustack([
                data[ftype, 'relative_magnetic_field_x'],
                data[ftype, 'relative_magnetic_field_y'],
                data[ftype, 'relative_magnetic_field_z']
            ])

            theta = data["index", 'spherical_theta']
            phi = data["index", 'spherical_phi']

            return get_sph_theta_component(Bfields, theta, phi, normal)
Example #8
0
    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
Example #9
0
 def _particle_spherical_position_theta(field, data):
     """
     Theta 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))
     spht = get_sph_theta_component(pos, theta, phi, normal)
     return spht
Example #10
0
    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')
        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)
        spht = get_sph_theta_component(vel, theta, phi, normal)
        return spht
    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')
        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))
        spht = get_sph_theta_component(vel, theta, phi, normal)
        return spht