1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
"""
3
- This version of the `moon` module contains temporary solutions to calculating
4
- the position of the moon using astropy.coordinates.get_moon, awaiting solutions
5
- to the astropy issue [#5069](https://github.com/astropy/astropy/issues/5069).
3
+ This version of the `moon` module calculates lunar phase angle for a geocentric
6
4
"""
7
5
8
6
from __future__ import (absolute_import , division , print_function ,
9
7
unicode_literals )
10
8
11
9
# Third-party
12
10
import numpy as np
13
- from astropy .coordinates import ( get_moon , get_sun , AltAz , Angle )
11
+ from astropy .coordinates import get_moon , get_sun
14
12
15
13
__all__ = ["moon_phase_angle" , "moon_illumination" ]
16
14
17
15
18
- def moon_phase_angle (time , location , ephemeris = None ):
16
+ def moon_phase_angle (time , ephemeris = None ):
19
17
"""
20
- Calculate lunar orbital phase [ radians] .
18
+ Calculate lunar orbital phase in radians.
21
19
22
20
Parameters
23
21
----------
@@ -29,7 +27,7 @@ def moon_phase_angle(time, location, ephemeris=None):
29
27
30
28
ephemeris : str, optional
31
29
Ephemeris to use. If not given, use the one set with
32
- `` astropy.coordinates.solar_system_ephemeris.set` ` (which is
30
+ `~ astropy.coordinates.solar_system_ephemeris` (which is
33
31
set to 'builtin' by default).
34
32
35
33
Returns
@@ -39,35 +37,16 @@ def moon_phase_angle(time, location, ephemeris=None):
39
37
"""
40
38
# TODO: cache these sun/moon SkyCoord objects
41
39
42
- # TODO: when astropy/astropy#5069 is resolved, replace this workaround which
43
- # handles scalar and non-scalar time inputs differently
44
-
45
- if time .isscalar :
46
- altaz_frame = AltAz (location = location , obstime = time )
47
- sun = get_sun (time ).transform_to (altaz_frame )
48
-
49
- moon = get_moon (time , location = location , ephemeris = ephemeris ).transform_to (altaz_frame )
50
- elongation = sun .separation (moon )
51
- return np .arctan2 (sun .distance * np .sin (elongation ),
52
- moon .distance - sun .distance * np .cos (elongation ))
53
-
54
- else :
55
- phase_angles = []
56
- for t in time :
57
- altaz_frame = AltAz (location = location , obstime = t )
58
- moon_coord = get_moon (t , location = location , ephemeris = ephemeris ).transform_to (altaz_frame )
59
- sun_coord = get_sun (t ).transform_to (altaz_frame )
60
- elongation = sun_coord .separation (moon_coord )
61
- phase_angle = np .arctan2 (sun_coord .distance * np .sin (elongation ),
62
- moon_coord .distance -
63
- sun_coord .distance * np .cos (elongation ))
64
- phase_angles .append (phase_angle )
65
- return Angle (phase_angles )
66
-
67
-
68
- def moon_illumination (time , location , ephemeris = None ):
40
+ sun = get_sun (time )
41
+ moon = get_moon (time , ephemeris = ephemeris )
42
+ elongation = sun .separation (moon )
43
+ return np .arctan2 (sun .distance * np .sin (elongation ),
44
+ moon .distance - sun .distance * np .cos (elongation ))
45
+
46
+
47
+ def moon_illumination (time , ephemeris = None ):
69
48
"""
70
- Calculate fraction of the moon illuminated
49
+ Calculate fraction of the moon illuminated.
71
50
72
51
Parameters
73
52
----------
@@ -79,14 +58,14 @@ def moon_illumination(time, location, ephemeris=None):
79
58
80
59
ephemeris : str, optional
81
60
Ephemeris to use. If not given, use the one set with
82
- `` astropy.coordinates.solar_system_ephemeris.set` ` (which is
61
+ `~ astropy.coordinates.solar_system_ephemeris` (which is
83
62
set to 'builtin' by default).
84
63
85
64
Returns
86
65
-------
87
66
k : float
88
67
Fraction of moon illuminated
89
68
"""
90
- i = moon_phase_angle (time , location , ephemeris = ephemeris )
69
+ i = moon_phase_angle (time , ephemeris = ephemeris )
91
70
k = (1 + np .cos (i ))/ 2.0
92
71
return k .value
0 commit comments