Beispiel #1
0
def rhealpix_sphere_inverse(x, y, north_square=0, south_square=0):
    r"""
    Compute the inverse of rhealpix_sphere().
    
    EXAMPLES::
    
        >>> p = (0, pi/4)
        >>> q = rhealpix_sphere(*p)
        >>> print(my_round(rhealpix_sphere_inverse(*q), 15))
        (0.0, 0.78539816339744795)
        >>> print(my_round(p, 15))
        (0, 0.785398163397448)

    """
    # Throw error if input coordinates are out of bounds.
    if not in_rhealpix_image(
            x, y, south_square=south_square, north_square=north_square):
        print("Error: input coordinates (%f,%f) are out of bounds" % (x, y))
        return
    x, y = combine_triangles(x,
                             y,
                             north_square=north_square,
                             south_square=south_square,
                             inverse=True)
    return healpix_sphere_inverse(x, y)
    def test_healpix_sphere(self):
        # Expected outputs of healpix_sphere() applied to inputs.
        sigma_a = sqrt(3 - 3*sin(a[1]))
        ha = (pi/4*(1 - sigma_a), pi/4*(2 - sigma_a))  
        hb = (ha[0], -ha[1])
        healpix_sphere_outputs = [
            (0, 0), 
            (0, pi/4), 
            (0, -pi/4), 
            (pi/2, 0), 
            (-pi/2, 0), 
            (-pi, 0),
            (-3*pi/4, pi/2), 
            (-3*pi/4, -pi/2), 
            ha, 
            hb
        ]        

        # Forward projection should be correct on test points.
        given = inputs
        get = [pjh.healpix_sphere(*p) for p in given]
        expect = healpix_sphere_outputs
        # Fuzz to allow for rounding errors:
        error = 1e-12
        for i in range(len(get)):
            self.assertTrue(rel_err(get[i], expect[i]) < error)
         
        # Inverse of projection of a point p should yield p.
        given = get
        get = [pjh.healpix_sphere_inverse(*q) for q in given]
        expect = inputs
        for i in range(len(get)):
            self.assertTrue(rel_err(get[i], expect[i]) < error)
            
        # Inverse projection of p below should return longitude of -pi.
        # Previously, it was returning a number slightly less than pi
        # because of a rounding error, which get magnified by
        # wrap_lon())
        p = (-7*pi/8, 3*pi/8)
        get = pjh.healpix_sphere_inverse(*p)
        expect = (-pi, arcsin(1 - 1.0/12))   
        self.assertEqual(get, expect)
        q = (-5*pi/6, 5*pi/12)
        get = pjh.healpix_sphere_inverse(*q)
        expect = (-pi, arcsin(1 - 1.0/27))
        self.assertEqual(get, expect)
Beispiel #3
0
    def test_healpix_sphere(self):
        # Expected outputs of healpix_sphere() applied to inputs.
        sigma_a = sqrt(3 - 3 * sin(a[1]))
        ha = (pi / 4 * (1 - sigma_a), pi / 4 * (2 - sigma_a))
        hb = (ha[0], -ha[1])
        healpix_sphere_outputs = [(0, 0), (0, pi / 4),
                                  (0, -pi / 4), (pi / 2, 0), (-pi / 2, 0),
                                  (-pi, 0), (-3 * pi / 4, pi / 2),
                                  (-3 * pi / 4, -pi / 2), ha, hb]

        # Forward projection should be correct on test points.
        given = inputs
        get = [pjh.healpix_sphere(*p) for p in given]
        expect = healpix_sphere_outputs
        # Fuzz to allow for rounding errors:
        error = 1e-12
        for i in range(len(get)):
            self.assertTrue(rel_err(get[i], expect[i]) < error)

        # Inverse of projection of a point p should yield p.
        given = get
        get = [pjh.healpix_sphere_inverse(*q) for q in given]
        expect = inputs
        for i in range(len(get)):
            self.assertTrue(rel_err(get[i], expect[i]) < error)

        # Inverse projection of p below should return longitude of -pi.
        # Previously, it was returning a number slightly less than pi
        # because of a rounding error, which get magnified by
        # wrap_lon())
        p = (-7 * pi / 8, 3 * pi / 8)
        get = pjh.healpix_sphere_inverse(*p)
        expect = (-pi, arcsin(1 - 1.0 / 12))
        self.assertEqual(get, expect)
        q = (-5 * pi / 6, 5 * pi / 12)
        get = pjh.healpix_sphere_inverse(*q)
        expect = (-pi, arcsin(1 - 1.0 / 27))
        self.assertEqual(get, expect)
def rhealpix_sphere_inverse(x, y, north_square=0, south_square=0):
    r"""
    Compute the inverse of rhealpix_sphere().
    
    EXAMPLES::
    
        >>> p = (0, pi/4)
        >>> q = rhealpix_sphere(*p)
        >>> print(my_round(rhealpix_sphere_inverse(*q), 15))
        (0.0, 0.78539816339744795)
        >>> print(my_round(p, 15))
        (0, 0.785398163397448)

    """
    # Throw error if input coordinates are out of bounds.
    if not in_rhealpix_image(x, y, south_square=south_square,
                             north_square=north_square):
        print("Error: input coordinates (%f,%f) are out of bounds" % (x, y))
        return
    x, y = combine_triangles(x, y, north_square=north_square, 
                        south_square=south_square, inverse=True)
    return healpix_sphere_inverse(x, y)
Beispiel #5
0
def rhealpix_sphere_inverse(x, y, north_square=0, south_square=0):
    r"""
    Compute the inverse of rhealpix_sphere().
    
    EXAMPLES::
    
        >>> p = (0, pi/4)
        >>> q = rhealpix_sphere(*p)
        >>> print rhealpix_sphere_inverse(*q), p
        (2.2204460492503131e-16, 0.78539816339744806) (0, 0.7853981633974483)
    """
    # Throw error if input coordinates are out of bounds.
    if not in_rhealpix_image(
            x, y, south_square=south_square, north_square=north_square):
        print "Error: input coordinates (%f,%f) are out of bounds" % (x, y)
        return
    x, y = combine_triangles(x,
                             y,
                             north_square=north_square,
                             south_square=south_square,
                             inverse=True)
    return healpix_sphere_inverse(x, y)