def rhealpix_ellipsoid(lam, phi, e=0, north_square=0, south_square=0): r""" Compute the signature functions of the rHEALPix map projection of an oblate ellipsoid with eccentricity `e` whose authalic sphere is the unit sphere. The north polar square is put in position `north_square`, and the south polar square is put in position `south_square`. Works when `e` = 0 (spherical case) too. INPUT: - `lam, phi` - Geographic longitude-latitude coordinates in radian. Assume -pi <= `lam` < pi and -pi/2 <= `phi` <= pi/2. - `e` - Eccentricity of the ellipsoid. - `north_square, south_square` - (Optional; defaults = 0, 0) Integers between 0 and 3 indicating positions of north polar and south polar squares, respectively. See rhealpix_sphere() docstring for a diagram. EXAMPLES:: >>> from numpy import arcsin >>> print(my_round(rhealpix_ellipsoid(0, arcsin(2.0/3)), 15)) (0, 0.78539816339744795) """ # Ensure north_square and south_square lie in {0, 1,2, 3}. x, y = healpix_ellipsoid(lam, phi, e) return combine_triangles(x, y, north_square=north_square, south_square=south_square)
def rhealpix_ellipsoid(lam, phi, e=0, north_square=0, south_square=0): r""" Compute the signature functions of the rHEALPix map projection of an oblate ellipsoid with eccentricity `e` whose authalic sphere is the unit sphere. The north polar square is put in position `north_square`, and the south polar square is put in position `south_square`. Works when `e` = 0 (spherical case) too. INPUT: - `lam, phi` - Geographic longitude-latitude coordinates in radian. Assume -pi <= `lam` < pi and -pi/2 <= `phi` <= pi/2. - `e` - Eccentricity of the ellipsoid. - `north_square, south_square` - (Optional; defaults = 0, 0) Integers between 0 and 3 indicating positions of north polar and south polar squares, respectively. See rhealpix_sphere() docstring for a diagram. EXAMPLES:: >>> from numpy import arcsin >>> print(rhealpix_ellipsoid(0, arcsin(2.0/3))) (0, 0.78539816339744828) """ # Ensure north_square and south_square lie in {0, 1,2, 3}. x, y = healpix_ellipsoid(lam, phi, e) return combine_triangles(x, y, north_square=north_square, south_square=south_square)
def test_rhealpix_ellipsoid(self): # Test map projection. # Should return the same output as healpix_ellipsoid(), followed # by a scaling down, followed by combine_triangles(), # followed by a scaling up. e = 0.8 for (ns, ss) in product(list(range(4)), repeat=2): for p in inputs: q = pjr.rhealpix_ellipsoid(*p, north_square=ns, south_square=ss, e=e) qq = pjh.healpix_ellipsoid(*p, e=e) qq = pjr.combine_triangles(*qq, north_square=ns, south_square=ss) self.assertEqual(q, qq) # Test inverse projection. # The inverse of the projection of a point p should yield p. # 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), e, inverse=True) error = 10*rel_err(alpha_, alpha) for (ns, ss) in product(list(range(4)), repeat=2): for p in inputs: q = pjr.rhealpix_ellipsoid(*p, north_square=ns, south_square=ss, e=e) pp = pjr.rhealpix_ellipsoid_inverse(*q, north_square=ns, south_square=ss, e=e) self.assertTrue(rel_err(p, pp) < error)
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 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)
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)
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])