-
Notifications
You must be signed in to change notification settings - Fork 1
/
__constants_conversions.py
190 lines (158 loc) · 5.81 KB
/
__constants_conversions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# PROJECT JULY-SEPTEMBRE 2019
# SOLVING THE N-BODIES PROBLEM / FUNCTIONS
# By Enguerran VIDAL
# This .py file contains constants calling functions as well as regular conversions of time
# and distances in order to facilitate the mention and vizualisation of the results of our algorithms
###############################################################
# FUNCTIONS #
###############################################################
#---------------CONSTANTS
def constant(name):
'''returns constnts from given names'''
if name=='G':
return 6.67430*10**(-11)
#---------------TIME CONVERSIONS
def Gy_to_seconds(t):
return years_to_seconds(t)*1000000000
def My_to_seconds(t):
return years_to_seconds(t)*1000000
def Ky_to_seconds(t):
return years_to_seconds(t)*1000
def years_to_seconds(t):
return t*31536000
def hours_to_seconds(t):
return t*3600
def minutes_to_seconds(t):
return t*60
def days_to_seconds(t):
return t*86400
def time_stamp(t,stamp_type='barren'):
time_value,time_unit=time(t)
if stamp_type=='barren':
return str(time_value)+' '+time_unit
if stamp_type=='time_passed':
return 'Time since t=0 : '+str(time_value)+' '+time_unit
if stamp_type=='frame_length':
return 'Frame Length : '+str(time_value)+' '+time_unit+'/f'
def time(t):
if t>=Gy_to_seconds(1):
return round(t/Gy_to_seconds(1),2),'G years'
else:
if t>=My_to_seconds(1):
return round(t/My_to_seconds(1),2),'M years'
else:
if t>=Ky_to_seconds(1):
return round(t/Ky_to_seconds(1),2),'K years'
else:
if t>=years_to_seconds(1):
return round(t/years_to_seconds(1),2),'years'
else:
if t>=days_to_seconds(1):
return round(t/days_to_seconds(1),2),'days'
else:
if t>=hours_to_seconds(1):
return round(t/hours_to_seconds(1),2),'hours'
else:
if t>=minutes_to_seconds(1):
return round(t/minutes_to_seconds(1),2),'minutes'
else:
return round(t,2),'seconds'
def reverse_time_conversion(t):
'''returns t in a useful and meaningful unit
t is initially in seconds'''
if t>=Gy_to_seconds(1):
return t/Gy_to_seconds(1),'Gy'
else:
if t>=My_to_seconds(1):
return t/My_to_seconds(1),'My'
else:
if t>=Ky_to_seconds(1):
return t/Ky_to_seconds(1),'Ky'
else:
if t>=years_to_seconds(1):
return t/years_to_seconds(1),'y'
else:
if t>=days_to_seconds(1):
return t/days_to_seconds(1),'d'
else:
if t>=hours_to_seconds(1):
return t/hours_to_seconds(1),'h'
else:
if t>=minutes_to_seconds(1):
return t/minutes_to_seconds(1),'min'
else:
return t,'s'
def time_conversion(value,unit):
if unit=='Gy' or unit=='gy':
return Gy_to_seconds(value)
if unit=='My' or unit=='my':
return My_to_seconds(value)
if unit=='Ky' or unit=='ky':
return Ky_to_seconds(value)
if unit=='y':
return years_to_seconds(value)
if unit=='d':
return days_to_seconds(value)
if unit=='h':
return hours_to_seconds(value)
if unit=='min':
return minutes_to_seconds(value)
if unit=='s':
return value
def unit_time_list():
'''returns a list of usual time units'''
return ['s','min','h','d','y','Ky','My','Gy']
def multiples(i):
'''returns a useful multiple for scale units'''
multiple_array=[[1,2,5,10,30],
[1,15,20,30],
[1,2,3,6,12],
[1,7,15,30,60,180],
[1,2,5,10,20,50,100,150,200,500],
[1,2,5,10,20,50,100,150,200,500],
[1,2,5,10,20,50,100,150,200,500],
[1,2,5,10,20,50,100,150,200,500]]
return multiple_array[i]
#------------------DISTANCE CONVERSIONS
def ly_to_meters(length):
'''transforms light years into meters'''
return length*9.4607*10**(15)
def parsec_to_meters(length):
'''transforms parsecs into meters'''
return length*3.0857*10**(16)
def au_to_meters(length):
'''transforms astronomical units into meters'''
return length*149597870700
def Kparsec_to_meters(length):
'''transforms Kpc into meters'''
return length*parsec_to_meters(1000)
def Mparsec_to_meters(length):
'''transforms Mpc units into meters'''
return length*parsec_to_meters(1000000)
def Gparsec_to_meters(length):
'''transforms Gpc into meters'''
return length*parsec_to_meters(1000000000)
def distance_conversion(value,unit):
if unit=='ly':
return value/ly_to_meters(1)
if unit=='pc':
return value/parsec_to_meters(1)
if unit=='au':
return value/au_to_meters(1)
if unit=='Kpc' or unit=='kpc':
return value/Kparsec_to_meters(1)
if unit=='m':
return value
if unit=='Mpc' or unit=='mpc':
return value/Mparsec_to_meters(1)
if unit=='Gpc' or unit=='gpc':
return value/Gparsec_to_meters(1)
if unit=='km':
return value/1000
#------------------BASES CONVERSIONS
def spheric_to_cartesian(r,phi,theta):
'''transforms spherical coordinates into cartesian cooridnates'''
x=r*np.sin(theta)*np.cos(phi)
y=r*np.sin(theta)*np.sin(phi)
z=r*np.cos(theta)
return x,y,z