solarsystem 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ """
2
+ ===========
3
+ SolarSystem
4
+ ===========
5
+
6
+ * Planets positions around Sun.
7
+ * Planets positions around Earth.
8
+ * Moon positions around Earth.
9
+ * Sunrise/Sunset.
10
+ * Moonrise/Moonset, Moon Phase.
11
+ * Convert between different coordinate systems.
12
+
13
+ """
14
+
15
+ __version__='0.1.6'
16
+
17
+ from .heliocentric import Heliocentric
18
+ from .geocentric import Geocentric
19
+ from .sunriseset import Sunriseset
20
+ from .moon import Moon
21
+
22
+ from .functions import normalize
23
+ from .functions import demical2clock, demical2arcs, demical2hms
24
+ from .functions import spherical2rectangular, rectangular2spherical
25
+ from .functions import ecliptic2equatorial, equatorial2ecliptic
26
+ from .functions import spherical_ecliptic2equatorial, spherical_equatorial2ecliptic
@@ -0,0 +1,312 @@
1
+ # -*- coding: utf-8 -*-
2
+ import math
3
+
4
+
5
+ #degree_sign= u'\N{DEGREE SIGN}'
6
+
7
+ def normalize(degrees):
8
+ """
9
+ set degrees always between 0 - 360
10
+
11
+ Args:
12
+ degrees (float): degrees to be adjusted
13
+
14
+ Returns:
15
+ float: degrees between 0-360
16
+
17
+ """
18
+ return degrees % 360
19
+
20
+
21
+
22
+ def spherical2rectangular(RA, Decl, r):
23
+ """Transform spherical to rectangular projection.
24
+
25
+ From spherical (RA,Decl) coordinates system to rectangular(x,y,z) or
26
+ by replacing RA with longitude and Decl with latitude we can tranform
27
+ ecliptic coordinates to horizontal (azimuth,altitude).
28
+
29
+ Args:
30
+ RA: Right Ascension.
31
+ Decl: Declination.
32
+ r: Distance in astronomical units.
33
+
34
+ Returns:
35
+ tuple: x, y, z rectangular coordinate system.
36
+
37
+ """
38
+
39
+ RA = math.radians(RA)
40
+ Decl = math.radians(Decl)
41
+ x = r * math.cos(RA) * math.cos(Decl)
42
+ y = r * math.sin(RA) * math.cos(Decl)
43
+ z = r * math.sin(Decl)
44
+
45
+ return (x, y, z)
46
+
47
+
48
+ def rectangular2spherical(x, y, z):
49
+ """Transform rectangular to spherical projection.
50
+
51
+ From rectangular(x,y,z) coordinates system to spherical (RA,Decl, r) or
52
+ by replacing x with azimuth and y with altitude we can tranform
53
+ horizontal coordinates to ecliptic (longitude, latitude).
54
+
55
+ Args:
56
+ x: value on x axis of a rectangular projection.
57
+ y: value on y axis of a rectangular projection.
58
+ z: value on z axis of a rectangular projection.
59
+
60
+ Returns:
61
+ tuple: RA, Decl, r spherical coordinate system.
62
+
63
+ """
64
+
65
+ r = math.sqrt( x*x + y*y + z*z )
66
+ RA = math.atan2( y, x )
67
+ # Decl = math.asin( z / r )
68
+ Decl = math.atan2( z, math.sqrt( x*x + y*y ) )
69
+
70
+ RA = normalize(math.degrees(RA))
71
+ Decl = (math.degrees(Decl))
72
+ return (RA, Decl, r)
73
+
74
+
75
+
76
+ def ecliptic2equatorial(xeclip, yeclip, zeclip, oblecl):
77
+ """Transform ecliptic to equatorial projection.
78
+
79
+ Args:
80
+ xeclip: value on x axis of ecliptic plane.
81
+ yeclip: value on y axis of ecliptic plane.
82
+ zeclip: value on z axis of ecliptic plane.
83
+ oblecl: obliquity of the ecliptic, approximately 23.4 degrees for earth
84
+
85
+ Returns:
86
+ tuple: x, y, z equatorial projection
87
+
88
+ """
89
+ # oblecl = math.radians(oblecl)
90
+
91
+ xequat = xeclip
92
+ yequat = yeclip * math.cos(oblecl) - zeclip * math.sin(oblecl)
93
+ zequat = yeclip * math.sin(oblecl) + zeclip * math.cos(oblecl)
94
+
95
+ return (xequat, yequat, zequat)
96
+
97
+
98
+
99
+ def equatorial2ecliptic(xequat, yequat, zequat, oblecl):
100
+ """Transform equatorial to ecliptic projection.
101
+
102
+ Args:
103
+ xequat: value on x axis of equatorial plane
104
+ yequat: value on y axis of equatorial plane
105
+ zequat: value on z axis of equatorial plane
106
+ oblecl: obliquity of the ecliptic, approximately 23.4 degrees for earth
107
+
108
+ Returns:
109
+ tuple: x, y, z ecliptic projection
110
+
111
+ """
112
+
113
+ # oblecl = math.radians(oblecl)
114
+ xeclip = xequat
115
+ yeclip = yequat * math.cos(-oblecl) - zequat * math.sin(-oblecl)
116
+ zeclip = yequat * math.sin(-oblecl) + zequat * math.cos(-oblecl)
117
+ return (xeclip, yeclip, zeclip)
118
+
119
+
120
+
121
+ def spherical_ecliptic2equatorial(long, lat, distance, oblecl):
122
+ """Transform eclipitc to spherical projection for given obliquity.
123
+
124
+ From spherical (RA, Decl, distance) coordinates system to
125
+ eclipitc(long, lat, distance).
126
+
127
+ Args:
128
+ long: Longitude.
129
+ last: Latitude.
130
+ distance: Distance in astronomical units.
131
+ oblecl: obliquity (axial tilt).
132
+
133
+ Returns:
134
+ tuple: RA, Decl, distance spherical coordinate system.
135
+
136
+ """
137
+
138
+ b = spherical2rectangular(long,lat,distance)
139
+ c = ecliptic2equatorial(b[0],b[1],b[2], oblecl)
140
+ return rectangular2spherical(c[0],c[1],c[2])
141
+
142
+
143
+ def spherical_equatorial2ecliptic(RA, Decl, distance, oblecl):
144
+ """Transform spherical to eclipitc projection for given obliquity.
145
+
146
+ From spherical (RA, Decl, distance) coordinates system to
147
+ eclipitc(long, lat, distance).
148
+
149
+ Args:
150
+ RA: Right Ascension.
151
+ Decl: Declination.
152
+ distance: Distance in astronomical units.
153
+ oblecl: obliquity (axial tilt).
154
+
155
+ Returns:
156
+ tuple: long, lat, distance eclipitc coordinate system.
157
+
158
+ """
159
+
160
+ b = spherical2rectangular(RA, Decl,distance)
161
+ c = equatorial2ecliptic(b[0],b[1],b[2], oblecl)
162
+ return rectangular2spherical(c[0],c[1],c[2])
163
+
164
+
165
+ def demical2clock(demicaltime):
166
+ """
167
+ Convert demical time view to Hours, Minutes and Seconds.
168
+
169
+ Args:
170
+ demicaltime (float): time to be converted.
171
+
172
+ Returns:
173
+ str: one string representation in hours, minutes format.
174
+
175
+ """
176
+ h = int(demicaltime)
177
+ m = int((demicaltime - h) * 60)
178
+ s = int(((demicaltime-h)*60 - m ) * 60)
179
+ h=str(h)
180
+ m=str(m)
181
+ s=str(s)
182
+ if len(h)==1: h = '0' + h
183
+ if len(m)==1: m = '0' + m
184
+ if len(s)==1: s = '0' + s
185
+ res = h + ':'+ m + ':'+ s
186
+ return res
187
+
188
+
189
+ def demical2arcs(num):
190
+ """
191
+ Convert Demical view to Degrees and minutes.
192
+
193
+ Args:
194
+ num (float): degrees to be converted.
195
+
196
+ Returns:
197
+ str: one string representation in degrees and minutes format.
198
+
199
+ """
200
+ # return(str(int(num))+u"\u00b0 "+str(round(abs(num - int(num))*60,2))+"'")
201
+ return(str(int(num))+"° "+str(round(abs(num - int(num))*60,2))+"'")
202
+
203
+ #def degrees2hours(degrees):
204
+ # """
205
+ # Convert degrees to string representation of hours, minutes and seconds.
206
+ #
207
+ # Args:
208
+ # degrees (float): degrees to be converted.
209
+ #
210
+ # Returns:
211
+ # str: one string representation in hours, minutes and seconds format.
212
+ #
213
+ # """
214
+ # h=degrees//15
215
+ # r=(degrees%15)*4
216
+ # m=int(r)
217
+ # s=int((r-m)*60)
218
+ # return (str(h)+'h '+str(m)+'m '+str(s)+'s')
219
+
220
+ def demical2hms(degrees):
221
+ """
222
+ Convert degrees to string representation of hours, minutes and seconds.
223
+
224
+ Args:
225
+ degrees (float): degrees to be converted.
226
+
227
+ Returns:
228
+ str: one string representation in hours, minutes and seconds format.
229
+
230
+ """
231
+
232
+ h = int(degrees/15)
233
+ m = int((degrees/15 - h) * 60)
234
+ s = int(((degrees/15-h)*60 - m ) * 60)
235
+ h=str(h)
236
+ m=str(m)
237
+ s=str(s)
238
+ if len(h)==1: h = h
239
+ if len(m)==1: m = m
240
+ if len(s)==1: s = s
241
+ res = h + 'h '+ m + 'm '+ s +'s'
242
+ return res
243
+
244
+
245
+ def Planet_Sun(M, e, a, N, w, i):
246
+ """
247
+ Helper Function. From planet's trajectory elements to position around sun
248
+
249
+ Returns:
250
+ tuple: position elements
251
+
252
+ """
253
+ M2=math.radians(M)
254
+ E0=M + (180/math.pi)*e*math.sin(M2)*(1+e*math.cos(M2))
255
+ E0=normalize(E0)
256
+ E02=math.radians(E0)
257
+ E1=E0 - (E0 - (180/math.pi)*e*math.sin(E02)-M)/(1-e*math.cos(E02))
258
+ E1=normalize(E1)
259
+ E=math.radians(E1)
260
+ x=a*(math.cos(E)-e)
261
+ y=a*(math.sqrt(1 - e*e))*math.sin(E)
262
+
263
+ r=math.sqrt(x*x+y*y)
264
+ v=math.atan2(y, x)
265
+ v=normalize(math.degrees(v))
266
+
267
+ xeclip=r*(math.cos(math.radians(N))*math.cos(math.radians(v+w)) - math.sin(math.radians(N))*math.sin(math.radians(v+w))*math.cos(math.radians(i)))
268
+ yeclip=r*(math.sin(math.radians(N))*math.cos(math.radians(v+w)) + math.cos(math.radians(N))*math.sin(math.radians(v+w))*math.cos(math.radians(i)))
269
+ zeclip=r*math.sin(math.radians(v+w))*math.sin(math.radians(i))
270
+ long2 = math.atan2( yeclip, xeclip )
271
+ long2=normalize(math.degrees(long2))
272
+ lat2 = math.atan2( zeclip, math.sqrt( xeclip*xeclip +yeclip*yeclip ) )
273
+ lat2=math.degrees(lat2)
274
+ return (xeclip,yeclip,zeclip, long2, lat2, r)
275
+
276
+
277
+ def sun2planet(xeclip, yeclip, zeclip, x, y, z):
278
+ """
279
+ Helper Function. From Hliocentric to Geocentric position
280
+
281
+ Returns:
282
+ tuple: geocentric view of object.
283
+
284
+ """
285
+ x_geoc=(x+xeclip)
286
+ y_geoc=(y+yeclip)
287
+ z_geoc=(z+zeclip)
288
+
289
+ return rectangular2spherical(x_geoc, y_geoc, z_geoc)
290
+ # t = ecliptic2equatorial(x_geoc, y_geoc, z_geoc, 23.4)
291
+ # return rectangular2spherical(t[0],t[1],t[2])
292
+
293
+ def precession_longitude_correction(jd):
294
+ """
295
+ Helper Function. From Hliocentric to Geocentric position
296
+
297
+ Args:
298
+ jd (float): julian date
299
+
300
+ Returns:
301
+ p_arcsec (float): degrees of latitude correction
302
+
303
+ """
304
+
305
+ T = (jd - 2451543.5) / 36525.0
306
+
307
+ # general precession in longitude (arcsec)
308
+ p_arcsec = 5028.796195 * T
309
+
310
+ # convert to degrees
311
+ return p_arcsec / 3600.0
312
+
@@ -0,0 +1,93 @@
1
+ from .functions import sun2planet, spherical2rectangular, ecliptic2equatorial
2
+ from .functions import rectangular2spherical
3
+ from .heliocentric import Heliocentric
4
+
5
+ class Geocentric():
6
+ """Import date data outputs planets positions around Earth.
7
+
8
+ Args:
9
+ year (int): Year (4 digits) ex. 2020
10
+ month (int): Month (1-12)
11
+ day (int): Day (1-31)
12
+ hour (int): Hour (0-23)
13
+ minute (int): Minute (0-60)
14
+ UT: Time Zone (deviation from UT, -12:+14), ex. for Greece (GMT + 2)
15
+ enter UT = 2
16
+ dst (int): daylight saving time (0 or 1). Wheather dst is applied at
17
+ given time and place
18
+ plane: desired output format. Should be one of: ecliptic, equatorial.
19
+ Default: ecliptic
20
+ precession (boolean): True or False. Apply corrections to object's
21
+ Longitude due to Earth's axis rotation.
22
+ Default: True
23
+
24
+ """
25
+
26
+ def __init__(self, year, month, day, hour, minute, UT=0, dst=0,
27
+ plane='ecliptic', precession=True):
28
+ self.plane=plane
29
+ self.planetoncenter = 'Earth'
30
+ objectlist = [ "Mercury","Venus","Earth","Mars","Jupiter","Saturn"
31
+ ,"Uranus","Neptune","Pluto","Ceres","Chiron","Eris"]
32
+ h = Heliocentric(year=year, month=month, day=day, hour=hour,
33
+ minute=minute, UT=UT, dst=dst, view='rectangular', precession=precession )
34
+ hplanets = h.planets()
35
+ planets=[]
36
+ for key in objectlist:
37
+ if key != "Earth":
38
+ planets.append(hplanets[key])
39
+ else:
40
+ planets.append((h.x2, h.y2, h.z2))
41
+ self.objectlist = objectlist
42
+ self.planets = planets
43
+ self.oblecl = h.oblecl
44
+ self.precession=precession
45
+
46
+
47
+ def position(self):
48
+ """Main method which returns a dictionary of geocentric positions.
49
+
50
+ Returns:
51
+ dictionary: Planet positions around earth: Each row represents a
52
+ planet and each column the position of that planet.
53
+
54
+ """
55
+ c = self.planets[2]
56
+ RA, Decl, r = rectangular2spherical(c[0],c[1],c[2])
57
+ planetccentric_pos={'Sun':(RA, Decl, r)}
58
+
59
+ for i in range(len(self.planets)):
60
+ if i != 2:
61
+ planetccentric_pos[self.objectlist[i]] = sun2planet(self.planets[i][0],
62
+ self.planets[i][1], self.planets[i][2],
63
+ self.planets[2][0], self.planets[2][1],
64
+ self.planets[2][2])
65
+
66
+ if self.plane=='equatorial':
67
+ v1,v2,v3=planetccentric_pos['Sun']
68
+ vv1,vv2,vv3 = spherical2rectangular(v1,v2,v3)
69
+ vvv1,vvv2,vvv3 = ecliptic2equatorial(vv1,vv2,vv3, self.oblecl)
70
+ vvvv1,vvvv2,vvvv3 = rectangular2spherical(vvv1,vvv2,vvv3)
71
+ planetccentric_pos['Sun'] = (vvvv1,vvvv2,vvvv3)
72
+
73
+ for i in range(len(self.objectlist)):
74
+ if i != 2:
75
+ v1,v2,v3=planetccentric_pos[self.objectlist[i]]
76
+ vv1,vv2,vv3 = spherical2rectangular(v1,v2,v3)
77
+ vvv1,vvv2,vvv3 = ecliptic2equatorial(vv1,vv2,vv3,
78
+ self.oblecl)
79
+ vvvv1,vvvv2,vvvv3 = rectangular2spherical(vvv1,vvv2,vvv3)
80
+ planetccentric_pos[self.objectlist[i]] =(vvvv1,vvvv2,vvvv3)
81
+
82
+ return planetccentric_pos
83
+
84
+ def objectnames(self):
85
+ """Names of solar system objects used.
86
+
87
+ Returns:
88
+ list: A list of solar system objects
89
+
90
+ """
91
+ orderedobjects= ["Sun", "Mercury","Venus","Mars","Jupiter","Saturn","Uranus",
92
+ "Neptune","Pluto","Ceres","Chiron","Eris"]
93
+ return( orderedobjects )