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 _spherical_radius(field, data):
        """The spherical radius component of the positions of the mesh cells.

        Relative to the coordinate system defined by the *center* field
        parameter.
        """
        coords = get_periodic_rvec(data)
        return data.ds.arr(get_sph_r(coords), "code_length").in_cgs()
Example #4
0
 def _spherical_r(field, data):
     coords = get_periodic_rvec(data)
     return data.ds.arr(get_sph_r(coords), "code_length").in_cgs()