-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
147 lines (119 loc) · 4.28 KB
/
main.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
'''
----------------------------------------------------------------------------------------------------
Python main script for sunlit_surface
----------------------------------------------------------------------------------------------------
'''
import scmod, animod, datetime, os, numpy as np
import math
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def writing_output_text_file(
start_date,
end_date,
NUMBER_OF_ITERATIONS,
DELTA_T,
SPATIAL_RESOLUTION
):
"""
writing output text file
input:
- start_date datetime.datetime
- end_date datetime.datetime
- NUMBER_OF_ITERATIONS integer
- DELTA_T float
- SPATIAL_RESOLUTION integer
"""
output_directory = "output_directory"
if not os.path.exists(output_directory):
os.makedirs(output_directory)
with open(
"{0}/sunlit_surface_output_{1}.txt".format(
output_directory,
end_date.strftime("%Y%m%d_%H%M")
),
"w"
) as file:
file.write(
"----------------------------------------------\n"
+ "Results of sunlit_surface \n"
+ "Date {}\n".format(end_date.strftime("%Y%m%d_%H%M"))
+ "----------------------------------------------\n\n"
+ "Input parameters:\n"
+ " - computation time (h:m:s) {}\n".format(end_date - start_date)
+ " - simulation time (s) {}\n".format(NUMBER_OF_ITERATIONS * DELTA_T)
+ " - spatial resolution (degrees) {}\n".format(SPATIAL_RESOLUTION)
+ "----------------------------------------------\n\n"
)
start_date = datetime.datetime.now()
SAVE_VIDEO = False
PLANET_DISPLAY_RADIUS = 15.0e6 # km
# Declaring planet surface spatial resolution in degrees
SPATIAL_RESOLUTION = 10
# Declaring planet's orbital parameters
PLANET_SEMI_MAJOR_AXIS = 57909176 # in km
PLANET_ECCENTRICITY = 0.20563069
PLANET_INCLINATION = 0 # in degrees
PLANET_RAAN = 0 # in degrees
PLANET_ARGUMENT_OF_PERIAPSIS = 0 # in degrees
# Declaring planetary constants
MU_SUN = 1.32712440018E11 # in km3/s2
PLANET_RADIUS = 2440 # in km
PLANET_SIDEREAL_PERIOD = 58.646 * 86400 # in seconds
PLANET_ROTATIONAL_VELOCITY = 360 / PLANET_SIDEREAL_PERIOD # in degrees per second
PLANET_AXIAL_TILT = 2 # in degrees
# Declaring time variables
NUMBER_OF_ITERATIONS = int(round(9 * PLANET_SIDEREAL_PERIOD / 86400))
DELTA_T = 86400 # in seconds
# Declaring time, latitude and longitude arrays
time = list(range(0, NUMBER_OF_ITERATIONS * DELTA_T, DELTA_T))
lat = list(range(-90, 91, SPATIAL_RESOLUTION))
lon = list(range(0, 361, SPATIAL_RESOLUTION))
# Declaring array that contains sunlight time over planet's surface
sunlight = np.zeros((len(time) + 1, len(lat), len(lon)))
# Declaring planet's positions arrays
planet_position_vector = np.zeros((len(time), 3))
# computiong planet positions and sunlight times
for j in range(len(time)):
planet_position_vector[j, :] = scmod.from_orbital_to_cartesian_coordinates(
PLANET_SEMI_MAJOR_AXIS,
PLANET_ECCENTRICITY,
PLANET_INCLINATION,
PLANET_RAAN,
PLANET_ARGUMENT_OF_PERIAPSIS,
time[j],
MU_SUN
)
for k in range(len(lat)):
for l in range(len(lon)):
scmod.prompt_progress(
j * len(lon) * len(lat) + k * len(lon) + l,
len(time) * len(lat) * len(lon)
)
surface_position_vector = scmod.geographic_to_cartesian_coord(lat[k], lon[l], PLANET_RADIUS)
# planet rotation
surface_position_vector = scmod.rotate_frame_around_z(
surface_position_vector, PLANET_ROTATIONAL_VELOCITY * time[j]
)
sunlight_time = scmod.compute_sunlight(
surface_position_vector, planet_position_vector[j, :], DELTA_T
)
sunlight[j + 1, k, l] = sunlight[j, k, l] + sunlight_time
sunlight = scmod.normalize_np_array(sunlight)
end_date = datetime.datetime.now()
writing_output_text_file(
start_date,
end_date,
NUMBER_OF_ITERATIONS,
DELTA_T,
SPATIAL_RESOLUTION
)
animod.display_animation(
time,
lat,
lon,
PLANET_ROTATIONAL_VELOCITY,
PLANET_DISPLAY_RADIUS,
planet_position_vector,
sunlight,
SAVE_VIDEO
)