24
24
Parts taken from http://www.geoastro.de/elevaz/basics/index.htm
25
25
"""
26
26
27
- import datetime
28
27
import numpy as np
29
28
29
+ from pyorbital import dt2np
30
+
31
+ F = 1 / 298.257223563 # Earth flattening WGS-84
32
+ A = 6378.137 # WGS84 Equatorial radius
33
+ MFACTOR = 7.292115E-5
30
34
31
- F = 1 / 298.257223563 # Earth flattening WGS-84
32
- A = 6378.137 # WGS84 Equatorial radius
33
- MFACTOR = 7.292115E-5
34
35
35
36
def jdays2000 (utc_time ):
36
37
"""Get the days since year 2000.
37
38
"""
38
- return _days (utc_time - datetime . datetime ( 2000 , 1 , 1 , 12 , 0 ))
39
-
39
+ return _days (dt2np ( utc_time ) - np . datetime64 ( ' 2000-01-01T12:00' ))
40
+
40
41
41
42
def jdays (utc_time ):
42
43
"""Get the julian day of *utc_time*.
43
44
"""
44
45
return jdays2000 (utc_time ) + 2451545
45
46
46
- def _fdays (dt ):
47
- """Get the days (floating point) from *d_t*.
48
- """
49
- return (dt .days +
50
- (dt .seconds +
51
- dt .microseconds / (1000000.0 )) / (24 * 3600.0 ))
52
-
53
- _vdays = np .vectorize (_fdays )
54
47
55
48
def _days (dt ):
56
49
"""Get the days (floating point) from *d_t*.
57
50
"""
58
- try :
59
- return _fdays (dt )
60
- except AttributeError :
61
- return _vdays (dt )
51
+ return dt / np .timedelta64 (1 , 'D' )
62
52
63
53
64
54
def gmst (utc_time ):
65
55
"""Greenwich mean sidereal utc_time, in radians.
66
-
56
+
67
57
As defined in the AIAA 2006 implementation:
68
58
http://www.celestrak.com/publications/AIAA/2006-6753/
69
59
"""
@@ -86,24 +76,25 @@ def sun_ecliptic_longitude(utc_time):
86
76
jdate = jdays2000 (utc_time ) / 36525.0
87
77
# mean anomaly, rad
88
78
m_a = np .deg2rad (357.52910 +
89
- 35999.05030 * jdate -
90
- 0.0001559 * jdate * jdate -
91
- 0.00000048 * jdate * jdate * jdate )
79
+ 35999.05030 * jdate -
80
+ 0.0001559 * jdate * jdate -
81
+ 0.00000048 * jdate * jdate * jdate )
92
82
# mean longitude, deg
93
- l_0 = 280.46645 + 36000.76983 * jdate + 0.0003032 * jdate * jdate
94
- d_l = ((1.914600 - 0.004817 * jdate - 0.000014 * jdate * jdate )* np .sin (m_a ) +
95
- (0.019993 - 0.000101 * jdate )* np .sin (2 * m_a ) + 0.000290 * np .sin (3 * m_a ))
83
+ l_0 = 280.46645 + 36000.76983 * jdate + 0.0003032 * jdate * jdate
84
+ d_l = ((1.914600 - 0.004817 * jdate - 0.000014 * jdate * jdate ) * np .sin (m_a ) +
85
+ (0.019993 - 0.000101 * jdate ) * np .sin (2 * m_a ) + 0.000290 * np .sin (3 * m_a ))
96
86
# true longitude, deg
97
87
l__ = l_0 + d_l
98
88
return np .deg2rad (l__ )
99
89
90
+
100
91
def sun_ra_dec (utc_time ):
101
92
"""Right ascension and declination of the sun at *utc_time*.
102
93
"""
103
94
jdate = jdays2000 (utc_time ) / 36525.0
104
- eps = np .deg2rad (23.0 + 26.0 / 60.0 + 21.448 / 3600.0 -
105
- (46.8150 * jdate + 0.00059 * jdate * jdate -
106
- 0.001813 * jdate * jdate * jdate ) / 3600 )
95
+ eps = np .deg2rad (23.0 + 26.0 / 60.0 + 21.448 / 3600.0 -
96
+ (46.8150 * jdate + 0.00059 * jdate * jdate -
97
+ 0.001813 * jdate * jdate * jdate ) / 3600 )
107
98
eclon = sun_ecliptic_longitude (utc_time )
108
99
x__ = np .cos (eclon )
109
100
y__ = np .cos (eps ) * np .sin (eclon )
@@ -115,13 +106,15 @@ def sun_ra_dec(utc_time):
115
106
right_ascension = 2 * np .arctan2 (y__ , (x__ + r__ ))
116
107
return right_ascension , declination
117
108
109
+
118
110
def _local_hour_angle (utc_time , longitude , right_ascension ):
119
111
"""Hour angle at *utc_time* for the given *longitude* and
120
112
*right_ascension*
121
113
longitude in radians
122
114
"""
123
115
return _lmst (utc_time , longitude ) - right_ascension
124
116
117
+
125
118
def get_alt_az (utc_time , lon , lat ):
126
119
"""Return sun altitude and azimuth from *utc_time*, *lon*, and *lat*.
127
120
lon,lat in degrees
@@ -132,10 +125,11 @@ def get_alt_az(utc_time, lon, lat):
132
125
133
126
ra_ , dec = sun_ra_dec (utc_time )
134
127
h__ = _local_hour_angle (utc_time , lon , ra_ )
135
- return (np .arcsin (np .sin (lat )* np .sin (dec ) +
128
+ return (np .arcsin (np .sin (lat ) * np .sin (dec ) +
136
129
np .cos (lat ) * np .cos (dec ) * np .cos (h__ )),
137
- np .arctan2 (- np .sin (h__ ), (np .cos (lat )* np .tan (dec ) -
138
- np .sin (lat )* np .cos (h__ ))))
130
+ np .arctan2 (- np .sin (h__ ), (np .cos (lat ) * np .tan (dec ) -
131
+ np .sin (lat ) * np .cos (h__ ))))
132
+
139
133
140
134
def cos_zen (utc_time , lon , lat ):
141
135
"""Cosine of the sun-zenith angle for *lon*, *lat* at *utc_time*.
@@ -147,7 +141,8 @@ def cos_zen(utc_time, lon, lat):
147
141
148
142
r_a , dec = sun_ra_dec (utc_time )
149
143
h__ = _local_hour_angle (utc_time , lon , r_a )
150
- return (np .sin (lat )* np .sin (dec ) + np .cos (lat ) * np .cos (dec ) * np .cos (h__ ))
144
+ return (np .sin (lat ) * np .sin (dec ) + np .cos (lat ) * np .cos (dec ) * np .cos (h__ ))
145
+
151
146
152
147
def sun_zenith_angle (utc_time , lon , lat ):
153
148
"""Sun-zenith angle for *lon*, *lat* at *utc_time*.
@@ -156,6 +151,7 @@ def sun_zenith_angle(utc_time, lon, lat):
156
151
"""
157
152
return np .rad2deg (np .arccos (cos_zen (utc_time , lon , lat )))
158
153
154
+
159
155
def sun_earth_distance_correction (utc_time ):
160
156
"""Calculate the sun earth distance correction, relative to 1 AU.
161
157
"""
@@ -170,19 +166,20 @@ def sun_earth_distance_correction(utc_time):
170
166
# corr_me = (r / AU) ** 2
171
167
172
168
# from known software.
173
- corr = 1 - 0.0334 * np .cos (2 * np .pi * (jdays2000 (utc_time ) - 2 ) / year )
169
+ corr = 1 - 0.0334 * np .cos (2 * np .pi * (jdays2000 (utc_time ) - 2 ) / year )
174
170
175
171
return corr
176
172
173
+
177
174
def observer_position (time , lon , lat , alt ):
178
175
"""Calculate observer ECI position.
179
176
180
177
http://celestrak.com/columns/v02n03/
181
178
"""
182
-
179
+
183
180
lon = np .deg2rad (lon )
184
181
lat = np .deg2rad (lat )
185
-
182
+
186
183
theta = (gmst (time ) + lon ) % (2 * np .pi )
187
184
c = 1 / np .sqrt (1 + F * (F - 2 ) * np .sin (lat )** 2 )
188
185
sq = c * (1 - F )** 2
@@ -192,9 +189,8 @@ def observer_position(time, lon, lat, alt):
192
189
y = achcp * np .sin (theta )
193
190
z = (A * sq + alt ) * np .sin (lat )
194
191
195
- vx = - MFACTOR * y # kilometers/second
196
- vy = MFACTOR * x
192
+ vx = - MFACTOR * y # kilometers/second
193
+ vy = MFACTOR * x
197
194
vz = 0
198
195
199
196
return (x , y , z ), (vx , vy , vz )
200
-
0 commit comments