Created
April 20, 2017 12:43
-
-
Save davidgardenier/fa6abd8768054494e1be3cde58745059 to your computer and use it in GitHub Desktop.
Calculate area/fraction on sky
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_sky_frac(self): | |
frac = go.sky_frac(-90, 90, 0, 360) | |
self.assertTrue(frac > 0.99999999999) | |
frac = go.sky_frac(0, 90, 0, 360) | |
self.assertTrue(0.49 < frac < 0.51) | |
frac = go.sky_frac(0, 90, 0, 90) | |
self.assertTrue(0.124 < frac < 0.126) | |
frac = go.sky_frac(-90, 90, 0, 180) | |
self.assertTrue(0.49 < frac < 0.51) | |
def sky_frac(d_min, d_max, r_min, r_max): | |
""" | |
Calculate the fraction of the sky that an area subtends | |
""" | |
d_min = math.radians(d_min) | |
d_max = math.radians(d_max) | |
r_min = math.radians(r_min) | |
r_max = math.radians(r_max) | |
# Calculate fractional surface area | |
def area(d_min, d_max, r_min, r_max): | |
return (-math.cos(d_max)+math.cos(d_min))*(r_max-r_min)/(4*math.pi) | |
if d_min < 0: | |
top = area(0, d_max, r_min, r_max) | |
bottom = area(0, abs(d_min), r_min, r_max) | |
a = top + bottom | |
else: | |
a = area(d_min, d_max, r_min, r_max) | |
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment