def test_healpix(self):
        inputs = [(-pi, pi/3), (0, pi/4), (pi/2, -pi/6)]

        # Should agree with healpix_ellipsoid and healpix_ellipsoid_inverse.
        e = 0.5
        a = 7
        R_A = auth_rad(a, e)
        f = pjh.healpix(a=a, e=e)
        for p in inputs:
            get = f(*p, radians=True)
            expect = tuple(R_A*array(pjh.healpix_ellipsoid(*p, e=e)))
            for i in range(len(expect)):
                self.assertAlmostEqual(get[i], expect[i])
            get = f(*get, radians=True, inverse=True)
            expect = tuple(array(expect)/R_A)
            expect = pjh.healpix_ellipsoid_inverse(*expect, e=e)
            for i in range(len(expect)):
                self.assertAlmostEqual(get[i], expect[i])
        
        # Should work in degrees mode.
        for p in inputs:
            get = f(*rad2deg(p), radians=False)
            expect = f(*p, radians=True)
            for i in range(len(expect)):
                self.assertAlmostEqual(get[i], expect[i])
Example #2
0
def rhealpix_ellipsoid_inverse(x, y, e=0, north_square=0, south_square=0):
    r"""
    Compute the inverse of rhealpix_ellipsoid.
    
    EXAMPLES::
    
        >>> p = (0, pi/4)
        >>> q = rhealpix_ellipsoid(*p)
        >>> print(my_round(rhealpix_ellipsoid_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_ellipsoid_inverse(x, y, e=e)
    def test_healpix_ellipsoid(self):
        # Expected output of healpix_ellipsoid() applied to inputs.
        e = 0.8
        healpix_ellipsoid_outputs = []
        for p in inputs:
            lam, phi = p
            beta = auth_lat(phi, e=e, radians=True)
            q = pjh.healpix_sphere(lam, beta)
            healpix_ellipsoid_outputs.append(q)

        # Forward projection should be correct on test points.
        given = inputs
        get = [pjh.healpix_ellipsoid(*p, e=e) for p in given]
        expect = healpix_ellipsoid_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_ellipsoid_inverse(*q, e=e) for q in given]
        expect = inputs
        # Fuzz for rounding errors based on the error of the approximation to
        # the inverse authalic latitude function:
        alpha = pi/4
        alpha_ = auth_lat(auth_lat(alpha, e, radians=True), e, radians=True, 
                          inverse=True)
        error = 10*rel_err(alpha_, alpha)        
        for i in range(len(get)):
            self.assertTrue(rel_err(get[i], expect[i]) < error)
Example #4
0
    def test_healpix_ellipsoid(self):
        # Expected output of healpix_ellipsoid() applied to inputs.
        e = 0.8
        healpix_ellipsoid_outputs = []
        for p in inputs:
            lam, phi = p
            beta = auth_lat(phi, e=e, radians=True)
            q = pjh.healpix_sphere(lam, beta)
            healpix_ellipsoid_outputs.append(q)

        # Forward projection should be correct on test points.
        given = inputs
        get = [pjh.healpix_ellipsoid(*p, e=e) for p in given]
        expect = healpix_ellipsoid_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_ellipsoid_inverse(*q, e=e) for q in given]
        expect = inputs
        # Fuzz for rounding errors based on the error of the approximation to
        # the inverse authalic latitude function:
        alpha = pi / 4
        alpha_ = auth_lat(auth_lat(alpha, e, radians=True),
                          e,
                          radians=True,
                          inverse=True)
        error = 10 * rel_err(alpha_, alpha)
        for i in range(len(get)):
            self.assertTrue(rel_err(get[i], expect[i]) < error)
Example #5
0
    def test_healpix(self):
        inputs = [(-pi, pi / 3), (0, pi / 4), (pi / 2, -pi / 6)]

        # Should agree with healpix_ellipsoid and healpix_ellipsoid_inverse.
        e = 0.5
        a = 7
        R_A = auth_rad(a, e)
        f = pjh.healpix(a=a, e=e)
        for p in inputs:
            get = f(*p, radians=True)
            expect = tuple(R_A * array(pjh.healpix_ellipsoid(*p, e=e)))
            for i in range(len(expect)):
                self.assertAlmostEqual(get[i], expect[i])
            get = f(*get, radians=True, inverse=True)
            expect = tuple(array(expect) / R_A)
            expect = pjh.healpix_ellipsoid_inverse(*expect, e=e)
            for i in range(len(expect)):
                self.assertAlmostEqual(get[i], expect[i])

        # Should work in degrees mode.
        for p in inputs:
            get = f(*rad2deg(p), radians=False)
            expect = f(*p, radians=True)
            for i in range(len(expect)):
                self.assertAlmostEqual(get[i], expect[i])
def rhealpix_ellipsoid_inverse(x, y, e=0, north_square=0, south_square=0):
    r"""
    Compute the inverse of rhealpix_ellipsoid.
    
    EXAMPLES::
    
        >>> p = (0, pi/4)
        >>> q = rhealpix_ellipsoid(*p)
        >>> print(my_round(rhealpix_ellipsoid_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_ellipsoid_inverse(x, y, e=e)   
Example #7
0
def rhealpix_ellipsoid_inverse(x, y, e=0, north_square=0, south_square=0):
    r"""
    Compute the inverse of rhealpix_ellipsoid.
    
    EXAMPLES::
    
        >>> p = (0, pi/4)
        >>> q = rhealpix_ellipsoid(*p)
        >>> print rhealpix_ellipsoid_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_ellipsoid_inverse(x, y, e=e)