Commit 366355c2 authored by Wu You's avatar Wu You
Browse files

Upload New File

parent 93da7e73
import numpy as np
import healpy as hp
def angular_distance(ra1, dec1, ra2, dec2):
"""
Calculate the angular distance between two points on a sphere.
Parameters
----------
ra1 : float
Right Ascension of the first point (radians).
dec1 : float
Declination of the first point (radians).
ra2 : float
Right Ascension of the second point (radians).
dec2 : float
Declination of the second point (radians).
Returns
-------
float
Angular distance between the two points (radians).
"""
return np.arccos(
np.sin(dec1) * np.sin(dec2) +
np.cos(dec1) * np.cos(dec2) * np.cos(ra1 - ra2)
)
def radius_exact(nside, pix_id):
"""
Compute the exact minimum enclosing circle radius of a HEALPix pixel.
Parameters
----------
nside : int
HEALPix resolution parameter.
pix_id : int
HEALPix pixel ID.
Returns
-------
float
Exact minimum enclosing circle radius of the pixel (degrees).
"""
theta_c, phi_c = hp.pix2ang(nside, pix_id)
verts = hp.boundaries(nside, pix_id, step=1)
ra_v = np.arctan2(verts[1], verts[0])
dec_v = np.arcsin(verts[2])
rads = [angular_distance(phi_c, np.pi/2 - theta_c, rv, dv)
for rv, dv in zip(ra_v, dec_v)]
return np.degrees(max(rads))
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment