-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelescope.py
688 lines (531 loc) · 25.6 KB
/
Telescope.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
import Constants
from Target import TargetType, Target
from abc import ABCMeta, abstractmethod, abstractproperty
import numpy as np
import csv
# Abstract class -- not meant to be directly instantiated. Inherit from this class to implement
# another telescope. See Swope and Nickel implementations...
class Telescope(metaclass=ABCMeta):
@abstractmethod
def set_targets(self, targets):
pass
@abstractmethod
def get_targets(self):
pass
@abstractmethod
def compute_exposures(self):
pass
@abstractmethod
def write_schedule(self, observatory_name, obs_date, good_targets):
pass
def round_to_num(self, round_to_num, input_to_round):
return int(round_to_num*round(float(input_to_round)/round_to_num))
def time_to_S_N(self, desired_s_n, apparent_mag, zeropoint, px_in_aperature=20):
term1 = px_in_aperature* desired_s_n**2
term2 = 0.4*(apparent_mag - zeropoint)
exp_time = term1*10**term2
return exp_time
def compute_net_priorities(self):
targets = self.get_targets()
total_p = np.sum([t.priority for t in targets])
print("Total Priority: %s" % total_p)
total_good_time = np.sum([t.total_observable_min for t in targets])
print("Total Good Time: %s" % total_good_time)
total_exp_time = np.sum([t.total_minutes for t in targets])
print("Total Exposure Time: %s" % total_exp_time)
total_prob = 0
if (total_p > 0 and total_good_time > 0 and total_exp_time > 0):
for t in targets:
frac_p = float(t.priority) / float(total_p)
frac_time = float(t.total_observable_min)/float(total_good_time)
frac_exp_time = (1.0-float(t.total_minutes)/float(total_exp_time))
if (frac_exp_time == 0.0):
frac_exp_time = 1.0
total_prob += frac_p*frac_time*frac_exp_time
for t in targets:
frac_p = float(t.priority) / float(total_p)
frac_time = float(t.total_observable_min)/float(total_good_time)
frac_exp_time = (1.0-float(t.total_minutes)/float(total_exp_time))
t.net_priority = t.priority+((frac_p*frac_time*frac_exp_time)/total_prob)
print("Nat: %s; Net: %0.5f" % (t.priority, t.net_priority))
else:
print("No valid targets...")
# Used with Las Campanas Observatory
class Swope(Telescope):
def __init__(self):
self.targets = None
self.name = "Swope"
# Filter name: Zero-point
# self.filters = {
# Constants.u_band:21.083616,
# Constants.B_band:22.885212,
# Constants.V_band:22.992250,
# Constants.g_band:23.66132,
# Constants.r_band:23.320230,
# Constants.i_band:23.131884
# }
#change as of Jun 4 after mirror cleaning
self.filters = {
Constants.u_band:21.17887,
Constants.B_band:22.30013,
Constants.V_band:23.14361,
Constants.g_band:23.894173,
Constants.r_band:23.646687,
Constants.i_band:23.466449
}
self.exp_funcs = {
TargetType.Supernova: self.compute_sn_exposure,
TargetType.Template: self.compute_template_exposure,
TargetType.Standard: self.compute_standard_exposure
}
def set_targets(self, targets):
self.targets = targets
def get_targets(self):
return self.targets
def compute_sn_exposure(self, sn):
exposures = {}
# Compute the current guess at apparent magnitude
days_from_disc = (sn.obs_date - sn.disc_date).days
mag_reduction = days_from_disc*0.03
adj_app_mag = sn.apparent_mag + mag_reduction
print("days: %0.3f, mag red: %0.3f, adj mag: %0.3f" % (days_from_disc, mag_reduction, adj_app_mag))
# Change S/N depending on phase...
s_to_n = 30 # base signal to noise
# s_to_n = 10 # base signal to noise (old)
#for objects older than 10, the S/N decreases, so the exp times were changing significantly. Now the S/N is set to 25
# if days_from_disc <= 10:
# s_to_n = 30
# elif days_from_disc > 10 and days_from_disc <= 60:
# s_to_n = 20
g_exp = self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.g_band])
r_exp = self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.r_band])
i_exp = self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.i_band])
V_exp = self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.V_band])
# Specific to Swope -- make Vgri the same length exposure...
mean_exp = self.round_to_num(Constants.round_to, np.mean([V_exp,g_exp,r_exp,i_exp]))
exposures.update({Constants.g_band: mean_exp})
exposures.update({Constants.r_band: mean_exp})
exposures.update({Constants.i_band: mean_exp})
u_exp = self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.u_band]))
B_exp = self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.B_band]))
# print (B_exp)
# exposures.update({Constants.B_band: B_exp})
# exposures.update({Constants.V_band: mean_exp})
# exposures.update({Constants.u_band: u_exp})
# Only include these exposures if time to S/N is <= 600s
# if (B_exp <= 600):
if (mean_exp <= 450):
print("Target Name: %s; u_exp: %s, mean_exp: %s" % (sn.name, u_exp, mean_exp))
exposures.update({Constants.B_band: B_exp})
exposures.update({Constants.V_band: mean_exp})
if (mean_exp <= 300):
exposures.update({Constants.u_band: u_exp})
# if (u_exp <= 600):
# Finally, don't go less than 45s (~ readout time), don't go more than 600s on Swope
for key, value in exposures.items():
if exposures[key] < 45:
exposures[key] = 45
elif exposures[key] > 600:
exposures[key] = 600
sn.exposures = exposures
def compute_standard_exposure(self, std):
exposures = {}
s_to_n = 100
# Don't know what the apparent mag should be?
exposures.update({Constants.u_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.apparent_mag, self.filters[Constants.u_band]))})
exposures.update({Constants.B_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.apparent_mag, self.filters[Constants.B_band]))})
exposures.update({Constants.V_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.apparent_mag, self.filters[Constants.V_band]))})
exposures.update({Constants.g_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.apparent_mag, self.filters[Constants.g_band]))})
exposures.update({Constants.r_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.apparent_mag, self.filters[Constants.r_band]))})
exposures.update({Constants.i_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.apparent_mag, self.filters[Constants.i_band]))})
# Finally, for standards round exps and don't go less than 10s, don't go more than 600s on Swope
# Round to nearest "exp_round_to" secs
for key, value in exposures.items():
if exposures[key] < 10:
exposures[key] = 10
elif exposures[key] > 600:
exposures[key] = 600
std.exposures = exposures
def compute_template_exposure(self, tmp):
exposures = {}
exposures.update({Constants.u_band: 1800})
exposures.update({Constants.B_band: 1800})
exposures.update({Constants.V_band: 1200})
exposures.update({Constants.g_band: 1200})
exposures.update({Constants.r_band: 1200})
exposures.update({Constants.i_band: 1200})
tmp.exposures = exposures
def compute_exposures(self):
for tgt in self.targets:
total_possible_time = np.sum(np.where(tgt.raw_airmass_array <= Constants.airmass_threshold)[0])
if total_possible_time > 0:
tgt.total_observable_min = int(total_possible_time)
self.exp_funcs[tgt.type](tgt) # Sets exposures for each target by target type
# per observatory - LCO Swope
fudge_factor = 400 if len(tgt.exposures) > 3 else 300 # Build in a fudge factor based on # of exps
tgt.total_minutes = int(round((sum(tgt.exposures.values()) + fudge_factor)/60)) # Sum total minutes
good_airmass = tgt.raw_airmass_array[np.asarray(np.where(tgt.raw_airmass_array <= Constants.airmass_threshold))]
integrated_good_am = np.sum(good_airmass)
if integrated_good_am > 0:
tgt.total_good_air_mass = integrated_good_am
if tgt.total_observable_min > 0:
tgt.fraction_time_obs = float(tgt.total_minutes)/float(tgt.total_observable_min)
def swope_filter_row(self, exp_name, exp_time):
filter_row = []
filter_row.append(None)
filter_row.append(None)
filter_row.append(None)
filter_row.append(None)
filter_row.append(exp_name)
filter_row.append(exp_time)
return filter_row
def write_schedule(self, observatory_name, obs_date, targets):
file_to_write = "%s_%s_%s_GoodSchedule.csv" % (observatory_name, self.name, obs_date.strftime('%Y%m%d'))
with open(file_to_write,"w") as csvoutput:
writer = csv.writer(csvoutput, lineterminator="\n")
output_rows = []
header_row = []
header_row.append("Object Name")
header_row.append("Right Ascension")
header_row.append("Declination")
header_row.append("Estimated Magnitude")
header_row.append("Filter")
header_row.append("Exposure Time")
header_row.append("Exposure Start")
output_rows.append(header_row)
last_filter = Constants.r_band
for t in targets:
ra = t.coord.ra.hms
dec = t.coord.dec.dms
tgt_row = []
tgt_row.append(t.name)
tgt_row.append("=\"%02d:%02d:%0.1f\"" % (ra[0],ra[1],ra[2]))
dec_field = ("=\"%02d:%02d:%0.1f\"" % (dec[0],np.abs(dec[1]),np.abs(dec[2])))
# Python has a -0.0 object. If the deg is this (because object lies < 60 min south), the string formatter will drop the negative sign
if t.coord.dec < 0.0 and dec[0] == 0.0:
dec_field = ("=\"-0:%02d:%0.1f\"" % (np.abs(dec[1]),np.abs(dec[2])))
tgt_row.append(dec_field)
tgt_row.append(None)
# Last criterion: if previous obj had full 6 filters, but this target only has 3
if (last_filter == Constants.r_band) or \
(last_filter == Constants.i_band) or \
(last_filter == Constants.g_band) or \
(last_filter == Constants.B_band and len(t.exposures) < 6):
tgt_row.append(Constants.r_band)
tgt_row.append(10) # Acquisition in r
output_rows.append(tgt_row)
# Start in riguVB order
output_rows.append(self.swope_filter_row(Constants.r_band, t.exposures[Constants.r_band]))
output_rows.append(self.swope_filter_row(Constants.i_band, t.exposures[Constants.i_band]))
output_rows.append(self.swope_filter_row(Constants.g_band, t.exposures[Constants.g_band]))
last_filter = Constants.g_band
if len(t.exposures) > 3:
if Constants.u_band in t.exposures:
output_rows.append(self.swope_filter_row(Constants.u_band, t.exposures[Constants.u_band]))
# output_rows.append(self.swope_filter_row(Constants.u_band, t.exposures[Constants.u_band]))
output_rows.append(self.swope_filter_row(Constants.V_band, t.exposures[Constants.V_band]))
output_rows.append(self.swope_filter_row(Constants.B_band, t.exposures[Constants.B_band]))
last_filter = Constants.B_band
# Flip order: BVugir
else:
tgt_row.append(Constants.B_band)
tgt_row.append(20) # Acquisition in B
output_rows.append(tgt_row)
output_rows.append(self.swope_filter_row(Constants.B_band, t.exposures[Constants.B_band]))
output_rows.append(self.swope_filter_row(Constants.V_band, t.exposures[Constants.V_band]))
if Constants.u_band in t.exposures:
output_rows.append(self.swope_filter_row(Constants.u_band, t.exposures[Constants.u_band]))
output_rows.append(self.swope_filter_row(Constants.g_band, t.exposures[Constants.g_band]))
output_rows.append(self.swope_filter_row(Constants.i_band, t.exposures[Constants.i_band]))
output_rows.append(self.swope_filter_row(Constants.r_band, t.exposures[Constants.r_band]))
last_filter = Constants.r_band
tgt_row.append(t.obs_datetime)
writer.writerows(output_rows)
# Used with Lick Observatory
class Nickel(Telescope):
def __init__(self):
self.targets = None
self.name = "Nickel"
# Filter name: Zero-point
self.filters = {
Constants.B_band:22.58,
Constants.V_band:22.88,
Constants.r_prime:22.81,
Constants.i_prime:22.65
}
self.exp_funcs = {
TargetType.Supernova: self.compute_sn_exposure,
TargetType.Template: self.compute_template_exposure,
TargetType.Standard: self.compute_standard_exposure
}
def set_targets(self, targets):
self.targets = targets
def get_targets(self):
return self.targets
def compute_sn_exposure(self, sn):
exposures = {}
# Compute the current guess at apparent magnitude
days_from_disc = (sn.obs_date - sn.disc_date).days
mag_reduction = days_from_disc*0.03
adj_app_mag = sn.apparent_mag + mag_reduction
# Change S/N depending on phase...
s_to_n = 10 # base signal to noise
if days_from_disc <= 10:
s_to_n = 30
elif days_from_disc > 10 and days_from_disc <= 60:
s_to_n = 20
exposures.update({Constants.r_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.r_prime]))})
exposures.update({Constants.i_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.i_prime]))})
# Only include these exposures if a relatively new SN
if days_from_disc < 60:
exposures.update({Constants.B_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.B_band]))})
exposures.update({Constants.V_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.V_band]))})
# Finally, don't go less than 45s (~ readout time), don't go more than 600s on Swope
for key, value in exposures.items():
if exposures[key] < 45:
exposures[key] = 45
elif exposures[key] > 600:
exposures[key] = 600
sn.exposures = exposures
def compute_standard_exposure(self, std):
exposures = {}
s_to_n = 100
# Don't know what the apparent mag should be?
exposures.update({Constants.r_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.r_prime]))})
exposures.update({Constants.i_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.i_prime]))})
exposures.update({Constants.B_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.B_band]))})
exposures.update({Constants.V_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.V_band]))})
# Finally, don't go less than 10s for Nickel std, don't go more than 600s on Nickel
for key, value in exposures.items():
if exposures[key] < 10:
exposures[key] = 10
elif exposures[key] > 600:
exposures[key] = 600
std.exposures = exposures
def compute_template_exposure(self, tmp):
exposures = {}
exposures.update({Constants.B_band: 1800})
exposures.update({Constants.V_band: 1200})
exposures.update({Constants.r_prime: 1200})
exposures.update({Constants.i_prime: 1200})
tmp.exposures = exposures
def compute_exposures(self):
for tgt in self.targets:
total_possible_time = np.sum(np.where(tgt.raw_airmass_array <= Constants.airmass_threshold)[0])
if total_possible_time > 0:
tgt.total_observable_min = total_possible_time
self.exp_funcs[tgt.type](tgt) # Sets exposures for each target by target type
# per observatory - estimatation for Lick Nickel
fudge_factor = 200 if len(tgt.exposures) > 2 else 100 # Build in a fudge factor based on # of exps
tgt.total_minutes = round((sum(tgt.exposures.values()) + fudge_factor)/60) # Sum total minutes
good_airmass = tgt.raw_airmass_array[np.asarray(np.where(tgt.raw_airmass_array <= Constants.airmass_threshold))]
integrated_good_am = np.sum(good_airmass)
if integrated_good_am > 0:
tgt.total_good_air_mass = integrated_good_am
if tgt.total_observable_min > 0:
tgt.fraction_time_obs = float(tgt.total_minutes)/float(tgt.total_observable_min)
def nickel_filter_row(self, exp_name, exp_time):
filter_row = []
filter_row.append(None)
filter_row.append(None)
filter_row.append(None)
filter_row.append(None)
filter_row.append(exp_name)
filter_row.append(exp_time)
return filter_row
def write_schedule(self, observatory_name, obs_date, targets):
file_to_write = "%s_%s_%s_GoodSchedule.csv" % (observatory_name, self.name, obs_date.strftime('%Y%m%d'))
with open(file_to_write,"w") as csvoutput:
writer = csv.writer(csvoutput, lineterminator="\n")
output_rows = []
header_row = []
header_row.append("Object Name")
header_row.append("Right Ascension")
header_row.append("Declination")
header_row.append("Estimated Magnitude")
header_row.append("Filter")
header_row.append("Exposure Time")
output_rows.append(header_row)
last_filter = Constants.r_prime
for t in targets:
ra = t.coord.ra.hms
dec = t.coord.dec.dms
tgt_row = []
tgt_row.append(t.name)
tgt_row.append("=\"%02d:%02d:%0.1f\"" % (ra[0],ra[1],ra[2]))
dec_field = ("=\"%02d:%02d:%0.1f\"" % (dec[0],np.abs(dec[1]),np.abs(dec[2])))
# Python has a -0.0 object. If the deg is this (because object lies < 60 min south), the string formatter will drop the negative sign
if t.coord.dec < 0.0 and dec[0] == 0.0:
dec_field = ("=\"-0:%02d:%0.1f\"" % (np.abs(dec[1]),np.abs(dec[2])))
tgt_row.append(dec_field)
tgt_row.append(None)
# Last criterion: if previous obj had full 4 filters, but this target only has 2
if (last_filter == Constants.r_prime) or \
(last_filter == Constants.i_prime) or \
(last_filter == Constants.B_band and len(t.exposures) < 4):
tgt_row.append(Constants.r_prime)
tgt_row.append(10) # Acquisition in r'
output_rows.append(tgt_row)
# Start in r'i'VB order
output_rows.append(self.nickel_filter_row(Constants.r_prime, t.exposures[Constants.r_prime]))
output_rows.append(self.nickel_filter_row(Constants.i_prime, t.exposures[Constants.i_prime]))
last_filter = Constants.i_prime
if len(t.exposures) > 2:
output_rows.append(self.nickel_filter_row(Constants.V_band, t.exposures[Constants.V_band]))
output_rows.append(self.nickel_filter_row(Constants.B_band, t.exposures[Constants.B_band]))
last_filter = Constants.B_band
# Flip order: BVi'r'
else:
tgt_row.append(Constants.B_band)
tgt_row.append(20) # Acquisition in B
output_rows.append(tgt_row)
output_rows.append(self.nickel_filter_row(Constants.B_band, t.exposures[Constants.B_band]))
output_rows.append(self.nickel_filter_row(Constants.V_band, t.exposures[Constants.V_band]))
output_rows.append(self.nickel_filter_row(Constants.i_prime, t.exposures[Constants.i_prime]))
output_rows.append(self.nickel_filter_row(Constants.r_prime, t.exposures[Constants.r_prime]))
last_filter = Constants.r_prime
writer.writerows(output_rows)
# Used with CTIO observatory
class SMARTS(Telescope):
def __init__(self):
self.targets = None
self.name = "SMARTS"
# Filter name: Zero-point
self.filters = {
Constants.B_band:22.58,
Constants.V_band:22.88,
Constants.r_prime:22.81,
Constants.i_prime:22.65
}
self.exp_funcs = {
TargetType.Supernova: self.compute_sn_exposure,
TargetType.Template: self.compute_template_exposure,
TargetType.Standard: self.compute_standard_exposure
}
def set_targets(self, targets):
self.targets = targets
def get_targets(self):
return self.targets
def compute_sn_exposure(self, sn):
exposures = {}
# Compute the current guess at apparent magnitude
days_from_disc = (sn.obs_date - sn.disc_date).days
mag_reduction = days_from_disc*0.03
adj_app_mag = sn.apparent_mag + mag_reduction
# Change S/N depending on phase...
s_to_n = 10 # base signal to noise
if days_from_disc <= 10:
s_to_n = 30
elif days_from_disc > 10 and days_from_disc <= 60:
s_to_n = 20
exposures.update({Constants.r_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.r_prime]))})
exposures.update({Constants.i_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.i_prime]))})
# Only include these exposures if a relatively new SN
if days_from_disc < 60:
exposures.update({Constants.B_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.B_band]))})
exposures.update({Constants.V_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, adj_app_mag, self.filters[Constants.V_band]))})
# Finally, don't go less than 45s (~ readout time), don't go more than 600s on Swope
for key, value in exposures.items():
if exposures[key] < 45:
exposures[key] = 45
elif exposures[key] > 600:
exposures[key] = 600
sn.exposures = exposures
def compute_standard_exposure(self, std):
exposures = {}
s_to_n = 100
# Don't know what the apparent mag should be?
exposures.update({Constants.r_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.r_prime]))})
exposures.update({Constants.i_prime: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.i_prime]))})
exposures.update({Constants.B_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.B_band]))})
exposures.update({Constants.V_band: self.round_to_num(Constants.round_to, self.time_to_S_N(s_to_n, std.ApparentMag, self.filters[Constants.V_band]))})
# Finally, don't go less than 10s for Nickel std, don't go more than 600s on Nickel
for key, value in exposures.items():
if exposures[key] < 10:
exposures[key] = 10
elif exposures[key] > 600:
exposures[key] = 600
std.exposures = exposures
def compute_template_exposure(self, tmp):
exposures = {}
exposures.update({Constants.B_band: 1800})
exposures.update({Constants.V_band: 1200})
exposures.update({Constants.r_prime: 1200})
exposures.update({Constants.i_prime: 1200})
tmp.exposures = exposures
def compute_exposures(self):
for tgt in self.targets:
total_possible_time = np.sum(np.where(tgt.raw_airmass_array <= Constants.airmass_threshold)[0])
if total_possible_time > 0:
tgt.total_observable_min = total_possible_time
self.exp_funcs[tgt.type](tgt) # Sets exposures for each target by target type
# per observatory - estimatation for Lick Nickel
fudge_factor = 200 if len(tgt.exposures) > 2 else 100 # Build in a fudge factor based on # of exps
tgt.total_minutes = round((sum(tgt.exposures.values()) + fudge_factor)/60) # Sum total minutes
good_airmass = tgt.raw_airmass_array[np.asarray(np.where(tgt.raw_airmass_array <= Constants.airmass_threshold))]
integrated_good_am = np.sum(good_airmass)
if integrated_good_am > 0:
tgt.total_good_air_mass = integrated_good_am
if tgt.total_observable_min > 0:
tgt.fraction_time_obs = float(tgt.total_minutes)/float(tgt.total_observable_min)
def nickel_filter_row(self, exp_name, exp_time):
filter_row = []
filter_row.append(None)
filter_row.append(None)
filter_row.append(None)
filter_row.append(None)
filter_row.append(exp_name)
filter_row.append(exp_time)
return filter_row
def write_schedule(self, observatory_name, obs_date, targets):
file_to_write = "%s_%s_%s_GoodSchedule.csv" % (observatory_name, self.name, obs_date.strftime('%Y%m%d'))
with open(file_to_write,"w") as csvoutput:
writer = csv.writer(csvoutput, lineterminator="\n")
output_rows = []
header_row = []
header_row.append("Object Name")
header_row.append("Right Ascension")
header_row.append("Declination")
header_row.append("Estimated Magnitude")
header_row.append("Filter")
header_row.append("Exposure Time")
output_rows.append(header_row)
last_filter = Constants.r_prime
for t in targets:
ra = t.coord.ra.hms
dec = t.coord.dec.dms
tgt_row = []
tgt_row.append(t.name)
tgt_row.append("=\"%02d:%02d:%0.1f\"" % (ra[0],ra[1],ra[2]))
dec_field = ("=\"%02d:%02d:%0.1f\"" % (dec[0],np.abs(dec[1]),np.abs(dec[2])))
# Python has a -0.0 object. If the deg is this (because object lies < 60 min south), the string formatter will drop the negative sign
if t.coord.dec < 0.0 and dec[0] == 0.0:
dec_field = ("=\"-0:%02d:%0.1f\"" % (np.abs(dec[1]),np.abs(dec[2])))
tgt_row.append(dec_field)
tgt_row.append(None)
# Last criterion: if previous obj had full 4 filters, but this target only has 2
if (last_filter == Constants.r_prime) or \
(last_filter == Constants.i_prime) or \
(last_filter == Constants.B_band and len(t.exposures) < 4):
tgt_row.append(Constants.r_prime)
tgt_row.append(10) # Acquisition in r'
output_rows.append(tgt_row)
# Start in r'i'VB order
output_rows.append(self.nickel_filter_row(Constants.r_prime, t.exposures[Constants.r_prime]))
output_rows.append(self.nickel_filter_row(Constants.i_prime, t.exposures[Constants.i_prime]))
last_filter = Constants.i_prime
if len(t.exposures) > 2:
output_rows.append(self.nickel_filter_row(Constants.V_band, t.exposures[Constants.V_band]))
output_rows.append(self.nickel_filter_row(Constants.B_band, t.exposures[Constants.B_band]))
last_filter = Constants.B_band
# Flip order: BVi'r'
else:
tgt_row.append(Constants.B_band)
tgt_row.append(20) # Acquisition in B
output_rows.append(tgt_row)
output_rows.append(self.nickel_filter_row(Constants.B_band, t.exposures[Constants.B_band]))
output_rows.append(self.nickel_filter_row(Constants.V_band, t.exposures[Constants.V_band]))
output_rows.append(self.nickel_filter_row(Constants.i_prime, t.exposures[Constants.i_prime]))
output_rows.append(self.nickel_filter_row(Constants.r_prime, t.exposures[Constants.r_prime]))
last_filter = Constants.r_prime
writer.writerows(output_rows)