-
Notifications
You must be signed in to change notification settings - Fork 25
/
obs_scheduler.py
253 lines (214 loc) · 5.91 KB
/
obs_scheduler.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import requests
from time import sleep
from datetime import datetime
import argparse
import os
PICTOR = "https://pictortelescope.com/observe" # pictor url
"""
To make continuous observations, the step (time from last observation)
should be half the telsescope's beamwidth (~10 deg => step = 5 deg)
Time interval is calculated from the earth's rotation frequency:
The Earth completes one full rotation on its axis approximately every 24 hours.
Therefore, the Earth spins through 360 degrees in 24 hours.
To determine when it would spin 5 degrees,we can calculate the time
it takes for the Earth to rotate through that angle.
First, we need to calculate the fraction of time it takes for the Earth to rotate 1 degree.
Since the Earth takes 24 hours (or 1440 minutes) to complete a full rotation of 360 degrees,
the fraction of time it takes for the Earth to rotate 1 degree is:
1 degree / 360 degrees = 1/360
To find the time it takes for the Earth to rotate 5 degrees,
we can multiply the fraction we calculated by 5:
(1/360) x 5 = 5/360 = 1/72
Therefore, the Earth will spin 5 degrees in approximately 1/72 of a day
or about 20 minutes and 53 seconds.
"""
STEP = 21 * 60 # turn to seconds by doing minutes*60
# init datetime
dt = datetime.now()
parser = argparse.ArgumentParser(
description="PICTOR Radio-telescope Observation Scheduler",
add_help=False
)
# help parameter
parser.add_argument('--help',
'-h',
action='help'
)
# observation name parameter
parser.add_argument(
"-n",
metavar="name",
type=str,
required=False,
help="Observation name: Any String",
default="demo",
)
# cetner frequency parameter
parser.add_argument(
"-cf",
metavar="frequency",
type=str,
required=False,
help="Frequency to observe at: 1300-1700 (MHz)",
default="1420",
)
# bandwidth parameter
parser.add_argument(
"-bw",
metavar="bandwidth",
type=str,
required=False,
help="Frequency range: {500, 1, 2, 2.4, 3.2}",
default="2.4",
)
# bins parameter
parser.add_argument(
"-b",
metavar="bins",
type=str,
required=False,
help="Duration of each sample: Up to 20000",
default="100",
)
# channels parameter
parser.add_argument(
"-ch",
metavar="channels",
type=str,
required=False,
help="Data points in frequency axis: {256, 512, 1024, 2048}",
default="2048",
)
# duration parameter
parser.add_argument(
"-du",
metavar="duration",
type=str,
required=False,
help="Duration of observation: Up to 600",
default="10",
)
# raw data parameter
parser.add_argument(
"-rd",
metavar="data",
type=str,
required=False,
help="Sends raw data from observation: {0, 1}",
default="0",
)
# email parameter
parser.add_argument(
"-e",
metavar="email",
type=str,
required=False,
help="email address to deliver the data: Any existing email",
default="[email protected]",
)
# day parameter
parser.add_argument(
"-d",
metavar="day",
type=int,
required=False,
help="Day to execute observation: {01, … , 31} ",
default=dt.day,
)
# hour parameter
parser.add_argument(
"-hr",
metavar="hour",
type=int,
required=False,
help="Hour to execute observation: {00, … , 23}",
default=dt.hour,
)
# minute parameter
parser.add_argument(
"-mn",
metavar="minute",
type=int,
required=False,
help="Minute to execute observation: {00, …, 59} ",
default=dt.minute,
)
# repeat times parameter
parser.add_argument(
"-rt",
metavar="repeat",
type=int,
required=False,
help="Times to repeat observaton: An integer ",
default=1,
)
# interval parameter
parser.add_argument(
"-i",
metavar="interval",
type=int,
required=False,
help="Time between observations: An integer ",
default=STEP,
)
args = parser.parse_args()
def send_data(
name="", freq="", bandwidth="", bins="", channels="", duration="", raw="", email=""
):
"""
Create payload and send HTTP Post request
"""
if bandwidth == "500":
bandwidth = bandwidth + "khz"
else:
bandwidth = bandwidth + "mhz"
payload = {
"obs_name": name,
"f_center": freq,
"bandwidth": bandwidth,
"channels": channels,
"nbins": bins,
"duration": duration,
"raw_data": raw,
"email": email,
"submit_btn": "1",
}
requests.post(PICTOR, payload)
# set target date and time
target_dt = datetime(
dt.year, dt.month, args.d, args.hr, args.mn
) # target datetime year, month, day, hours, minutes
print("Waiting....")
# get current date and time
current_dt = datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute)
# wait until time has come
while target_dt != current_dt:
dt = datetime.now()
current_dt = datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute)
sleep(1)
print("Starting Datetime:", datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute))
for i in range(args.rt):
name = args.n + "_" + str(i + 1) # create name
# call send_data function
send_data(
name=name,
freq=args.cf,
bandwidth=args.bw,
bins=args.b,
channels=args.ch,
duration=args.du,
raw=args.rd,
email=args.e,
)
# print the progress
progress = ((i + 1) / args.rt) * 100
print("Done interation: ", i + 1, "of:", args.rt, ", ", "%.2f" % progress, "%")
# wait for the next iteration
if args.rt > 1 and i+1 != args.rt:
if args.i > 60:
print("Next Observation in: ", args.i//60, "minutes")
else:
print("Next Observation in: ", args.i, "seconds")
sleep(args.i)
# print ok message
print("Observation Request Sent!")