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(a=1, e=0, north_square=0, south_square=0, region="none"): """ Return a function object that wraps the rHEALPix projection and its inverse of an ellipsoid with major radius `a` and eccentricity `e`. EXAMPLES:: >>> f = rhealpix(a=2, e=0, north_square=1, south_square=2) >>> print(my_round(f(0, pi/3, radians=True), 15)) (-0.574951359778215, 2.145747686573111) >>> p = (0, 60) >>> q = f(*p, radians=False) >>> print(my_round(q, 15)) (-0.574951359778215, 2.145747686573111) >>> print(my_round(f(*q, radians=False, inverse=True), 15)) (6e-15, 59.999999999999986) >>> print(my_round(p, 15)) (0, 60) OUTPUT: - A function object of the form f(u, v, radians=False, inverse=False). """ R_A = auth_rad(a, e) def f(u, v, radians=False, inverse=False): if not inverse: lam, phi = u, v if not radians: # Convert to radians. lam, phi = deg2rad([lam, phi]) return tuple(R_A * array( rhealpix_ellipsoid( lam, phi, e=e, north_square=north_square, south_square=south_square, region=region, ))) else: # Scale down to R_A = 1. x, y = array((u, v)) / R_A lam, phi = array( rhealpix_ellipsoid_inverse( x, y, e=e, north_square=north_square, south_square=south_square, region=region, )) if not radians: # Convert to degrees. lam, phi = rad2deg([lam, phi]) return lam, phi return f
def __init__( self, R=None, a=WGS84_A, b=None, e=None, f=WGS84_F, lon_0=0, lat_0=0, radians=False, ): self.lon_0 = lon_0 self.lat_0 = lat_0 self.radians = radians if R is not None: # The ellipsoid is a sphere. # Override the other geometric parameters. self.sphere = True self.R = R self.a = R self.b = R self.e = 0 self.f = 0 self.R_A = R else: self.sphere = False self.a = a if b is not None: # Derive the other geometric parameters from a and b. self.b = b self.e = sqrt(1 - (b / a) ** 2) self.f = (a - b) / a elif e is not None: # Derive the other geometric parameters from a and e. self.e = e self.b = a * sqrt(1 - e ** 2) self.f = 1 - sqrt(1 - e ** 2) else: self.f = f self.b = self.a * (1 - f) self.e = sqrt(f * (1 - f)) self.R_A = auth_rad(self.a, self.e) self.phi_0 = auth_lat(arcsin(2.0 / 3), e=self.e, radians=True, inverse=True) if not self.radians: # Convert to degrees. self.phi_0 = rad2deg(self.phi_0)