-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobserve_target_v2.py
116 lines (90 loc) · 4.07 KB
/
observe_target_v2.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
import numpy as np
import matplotlib.pyplot as plt
import astropy.units as u
from astropy.coordinates import EarthLocation, SkyCoord, get_moon, solar_system_ephemeris, get_sun
from pytz import timezone
from astropy.time import Time
from astroplan import Observer
from astroplan import FixedTarget
from astroplan.plots import plot_airmass, plot_sky
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 targeting_moon(observe_time):
coordinates_moon = get_moon(observe_time)
coordinates_moon = coordinates_moon.icrs
return FixedTarget(name='Moon', coord=coordinates_moon)
def targeting_sun(observe_time):
coordinates_sun = get_sun(observe_time)
coordinates_sun = coordinates_sun.icrs
return FixedTarget(name='Sun', coord=coordinates_sun)
def main():
#=================ADD HERE YOUR .TXT FILE WITH THE ID OF YOUR TARGETS
file_read = np.loadtxt('list_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'
time_str = '2019-07-25 04:00:00'
#/\ Here is in UTC
#IF YOU WANT TO PLOT THE MOON/SUN AIRMASS + MOON/SUN IN SKY
see_moon = 'yes'
see_sun = 'no'
how_many_targets = len(ID_array)
observe_time = Time(time_str)
#time window
time = observe_time + np.linspace(-12, 12, 100)*u.hour
to_be_plot = time.plot_date
observer = observer_function(name_of_the_observatory,name_timezone)
i = 0
while how_many_targets > 0 :
fig = plt.figure(figsize=(11,7))
fig.subplots_adjust(hspace=0.5)
if see_sun == 'yes':
sun = targeting_sun(observe_time)
ax = plt.subplot(1, 2, 1)
plot_airmass(sun, observer, observe_time,brightness_shading=True,style_kwargs={'color': 'r'}, min_airmass=0.5, max_airmass=3.5)
ax.set_title('Airmass')
plt.legend(shadow=True, loc=2)
ax = plt.subplot(1, 2, 2, projection='polar')
plot_sky(sun, observer, observe_time,style_kwargs={'color': 'r'})
ax.set_title('Position at time: '+time_str+'[UTC]\n \n')
else:
pass
if see_moon == 'yes':
moon = targeting_moon(observe_time)
ax = plt.subplot(1, 2, 1)
plot_airmass(moon, observer, observe_time,brightness_shading=True, min_airmass=0.5,max_airmass=3.5)
ax.set_title('Airmass')
plt.legend(shadow=True, loc=2)
ax = plt.subplot(1, 2, 2, projection='polar')
plot_sky(moon, observer, observe_time)
ax.set_title('Position at time: '+time_str+'[UTC]\n \n')
else:
pass
#TARGET DATA
RA = str(RA_array[i])
DEC = str(DEC_array[i])
NAME = str(int(ID_array[i]))
#frame = 'icrs'
target = target_wanted(RA, DEC, NAME)
ax = plt.subplot(1, 2, 1)
plot_airmass(target, observer, observe_time,brightness_shading=True, min_airmass=0.5,max_airmass=3.5)
plt.text(0.5, 0.9, 'Observatory: '+name_of_the_observatory+'\n Timezone: '+name_timezone, horizontalalignment='center',
verticalalignment='center', transform=ax.transAxes)
ax.set_title('Airmass')
plt.legend(shadow=True, loc=2)
ax = plt.subplot(1, 2, 2, projection='polar')
plot_sky(target, observer, observe_time)
ax.set_title('Position at time: '+time_str+'[UTC]\n \n')
how_many_targets -= 1
i += 1
plt.legend(shadow=True, loc=2)
plt.tight_layout()
#CHANGE HERE THE PATH AND NAME YOUR DIRECTORY SHOULD BE SAVED IN/AS
plt.savefig('graph_representation/'+NAME+'.png')
main()