Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 4
0
 def test_rhealpix_sphere(self):
     # Test forward projection.
     # Should return the same output as healpix_sphere() of the unit
     # sphere, followed by combine_triangles(), followed by a scaling up.
     for (ns, ss) in product(list(range(4)), repeat=2): 
         for p in inputs:
             q = pjr.rhealpix_sphere(*p, north_square=ns, south_square=ss)
             qq = pjr.combine_triangles(*pjh.healpix_sphere(*p), 
                    north_square=ns, south_square=ss)
             qq = tuple(qq)
             self.assertEqual(q, qq)
 
     # Test inverse projection.
     # The inverse of the projection of a point p should yield p.
     error = 1e-15   # Fuzz to handle small rounding errors.
     for (ns, ss) in product(list(range(4)), repeat=2): 
         for p in inputs:
             q = pjr.rhealpix_sphere(*p, north_square=ns, south_square=ss)
             pp = pjr.rhealpix_sphere_inverse(*q, north_square=ns, 
                                              south_square=ss)        
             self.assertTrue(euclidean(p, pp) < error)
Exemplo n.º 5
0
def rhealpix_sphere(lam, phi, north_square=0, south_square=0):
    r"""
    Compute the signature functions of the rHEALPix map projection of 
    the unit sphere. 
    The north polar square is put in position `north_square`, and the 
    south polar square is put in position `south_square`.
        
    INPUT:
    
    - `lam, phi` -Geographic longitude-latitude coordinates in radians.
      Assume -pi <= `lam` < pi and -pi/2 <= `phi` <= pi/2.
    - `north_square, south_square` - (Optional; defaults = 0, 0) Integers 
      between 0 and 3 indicating positions of north polar and 
      south polar squares, respectively.
    
    EXAMPLES::
    
        >>> print(rhealpix_sphere(0, pi/4))
        (-1.6199786334139372, 2.3070121835733044)

    NOTE:
    
    The polar squares are labeled 0, 1, 2, 3 from east to west like this::
        
        east         west        
        *---*---*---*---*
        | 0 | 1 | 2 | 3 |
        *---*---*---*---*
        |   |   |   |   |
        *---*---*---*---*
        | 0 | 1 | 2 | 3 |
        *---*---*---*---*    
    """
    x, y = healpix_sphere(lam, phi)
    return combine_triangles(x,
                             y,
                             north_square=north_square,
                             south_square=south_square)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def rhealpix_sphere(lam, phi, north_square=0, south_square=0):
    r"""
    Compute the signature functions of the rHEALPix map projection of 
    the unit sphere. 
    The north polar square is put in position `north_square`, and the 
    south polar square is put in position `south_square`.
        
    INPUT:
    
    - `lam, phi` -Geographic longitude-latitude coordinates in radians.
      Assume -pi <= `lam` < pi and -pi/2 <= `phi` <= pi/2.
    - `north_square, south_square` - (Optional; defaults = 0, 0) Integers 
      between 0 and 3 indicating positions of north polar and 
      south polar squares, respectively.
    
    EXAMPLES::
    
        >>> print(my_round(rhealpix_sphere(0, pi/4), 15))
        (-1.619978633413937, 2.307012183573304)

    NOTE:
    
    The polar squares are labeled 0, 1, 2, 3 from east to west like this::
        
        east         west        
        *---*---*---*---*
        | 0 | 1 | 2 | 3 |
        *---*---*---*---*
        |   |   |   |   |
        *---*---*---*---*
        | 0 | 1 | 2 | 3 |
        *---*---*---*---*    
    """
    x, y = healpix_sphere(lam, phi)
    return combine_triangles(x, y, north_square=north_square, 
                        south_square=south_square)