-
Notifications
You must be signed in to change notification settings - Fork 1
/
best_dates.py
194 lines (153 loc) · 5.92 KB
/
best_dates.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
191
192
import numpy as np
import astropy.units as u
from astropy.time import Time
from astropy.coordinates import SkyCoord, EarthLocation, AltAz, get_moon
from pytz import timezone
from astroplan import Observer
from astroplan import FixedTarget
import matplotlib.pyplot as plt
from bokeh.plotting import figure, show, output_file, save
def observer_function(name_of_the_observatory, name_timezone):
return Observer.at_site(name_of_the_observatory, timezone=name_timezone)
def target_wanted(RA, DEC, name_target='Target'):
coordinates = SkyCoord(RA, DEC, unit="deg")
return FixedTarget(name=name_target, coord=coordinates)
def target_coord(RA, DEC):
return SkyCoord(RA, DEC, unit="deg")
def targeting_moon(observe_time):
coordinates_moon = get_moon(observe_time)
coordinates_moon = coordinates_moon.icrs
return FixedTarget(name='Moon', coord=coordinates_moon)
def getting_good_airmass(target_coords, time, obs_location):
#Getting airmass
target_altaz = target_coords.transform_to(AltAz(obstime=time,location=obs_location))
target_airmass = target_altaz.secz
good_airmass = []
for index in range(0,len(target_airmass)):
if target_airmass[index] <= 1.5:
eh_obs = 1
#print(target_airmass[index])
else:
eh_obs = 0
good_airmass.append(eh_obs)
return good_airmass
def night_is_good(observer,time):
nights = []
for index in range(0,len(time)):
if observer.is_night(time[index]):
night = 1
print(index)
else:
night = 0
nights.append(night)
return nights
def save_night(observer,time):
nights = night_is_good(observer,time)
path = open('it_is_night.txt','w')
print("aqui")
night_time = []
for index in range(0,len(nights)):
if nights[index] == 1:
print(index)
path.write(str(time[index])+"\n")
path.close()
return None
def read_night(file_path='it_is_night.txt'):
file = open(file_path,'r')
tempo =[]
for line in file:
line = line.replace("\n","")
tempo.append(Time(line))
file.close()
return tempo
def gerando_noites():
#================ADD HERE THE DETAILS OF YOUR OBSERVATION
name_of_the_observatory = 'ctio'
name_timezone = 'America/Santiago'
utcoffset = -3*u.hour
time_str = '2020-02-01 17:00:00'
#/\ The code uses in UTC, so here is still your timezone if you fix in the utcoffset
observe_time = Time(time_str) - utcoffset
print(observe_time)
#time window
delta_time = np.linspace(0, 181.6, 5200)*u.day
time = observe_time + delta_time
print(time)
#to_be_plot = time.plot_date
observer = observer_function(name_of_the_observatory,name_timezone)
save_night(observer,time)
def main():
#=================ADD HERE YOUR .TXT FILE WITH THE ID OF YOUR TARGETS
file_read = np.loadtxt('TIC_output.txt', skiprows = 1)
ID_array = file_read[:,0]
RA_array = file_read[:,1]
DEC_array = file_read[:,2]
#================ADD HERE THE DETAILS OF YOUR OBSERVATION
name_of_the_observatory = 'ctio'
name_timezone = 'America/Santiago'
utcoffset = -3*u.hour
time_str = '2020-02-01 17:00:00'
#/\ The code uses in UTC, so here is still your timezone if you fix in the utcoffset
how_many_targets = len(ID_array)
observe_time = Time(time_str) - utcoffset
print(observe_time)
#time window
delta_time = np.linspace(0, 181.6, 36200)*u.day
#============ACTIVATE IF YOU DONT HAVE THE TABLE:
#time = observe_time + delta_time
#print(time)
observer = observer_function(name_of_the_observatory,name_timezone)
obs_location = observer.location
#nights = night_is_good(observer,time)
#night_time = []
#for index in range(0,len(nights)):
# if nights[index] == 1: night_time.append(time[index])
#===================================== TILL HERE
night_time = read_night('it_is_night.txt')
time = Time(night_time)
#TARGET DATA
good_airmass={}
for i in range(0,len(RA_array)):
RA = str(RA_array[i])
DEC = str(DEC_array[i])
NAME = str(int(ID_array[i]))
#frame = 'icrs'
target = target_wanted(RA, DEC, NAME)
target_coords = target_coord(RA,DEC)
good_airmass[NAME] = getting_good_airmass(target_coords, time, obs_location)
#good_airmass = getting_good_airmass(target_coords, time, obs_location)
#print(good_airmass)
#TOTAL
total_of_targets = []
for index in range(0, len(night_time)):
result = 0
for i in range(0,len(RA_array)):
NAME = str(int(ID_array[i]))
result = result + good_airmass[NAME][index]
total_of_targets.append(result)
good_time = open('observation.txt','w')
good_time.write('Time in UTC/TIC_ID')
for i in range(0,len(RA_array)):
good_time.write(f'\t{int(ID_array[i])}' )
good_time.write('\tTOTAL OF TARGETS\n')
for index in range(0, len(night_time)):
good_time.write(str(time[index]))
for i in range(0,len(RA_array)):
NAME = str(int(ID_array[i]))
good_time.write(f'\t{good_airmass[NAME][index]}' )
good_time.write(f'\t{total_of_targets[index]}\n')
time_string = [str(x) for x in night_time]
#PLOTTING
output_file("observable_time.html")
p = figure(title = "When can we maximize the targets?",x_range=time_string)
p.xaxis.major_label_orientation = np.pi/4
p.xaxis.axis_label = 'Days and Hours in UTC'
p.yaxis.axis_label = 'Number of targets that are observable'
p.circle(time_string, total_of_targets, fill_alpha=0.2, size=5)
save(p)
plt.figure(figsize=(7,7))
plt.plot(time_string, total_of_targets,'o', markersize=2)
plt.xlabel('Hours in UTC')
plt.ylabel('How many targets are observable?')
plt.show()
main()