forked from annayqho/HE_Burst_Search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_pointing_history.py
80 lines (69 loc) · 2.45 KB
/
search_pointing_history.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
"""
This script takes in an RA, Dec, and Time.
It searches the GBM history to see whether the detector was pointing that way
at the time.
"""
import numpy as np
import sys
import glob
from subprocess import call
import re
from astropy.time import Time
from gbm import GBMgeo
from gbm.clock import *
from swiftbat_python.swiftbat import swinfo
def search_gbm_pointing(ra, dec, t):
""" Search the GBM history to see whether the detector was
sensitive to a given position at a given time
Parameters
----------
ra: right ascension in degrees
dec: declination in degrees
t: time in astropy isot format
"""
print("Searching GBM")
# The GBM package uses MET: Mission Elapsed Time
cMET = utc2fermi(t.datetime)
# Download the relevant poshist file
yymmdd = re.sub('-', '', t.iso[2:10])
root = "https://heasarc.gsfc.nasa.gov/FTP/fermi/data/gbm/daily/"
date = "20" + yymmdd[0:2] + "/" + yymmdd[2:4] + "/" + yymmdd[4:6]
fname = "glg_poshist_all_%s_v00.fit" %yymmdd
if glob.glob(fname):
print("File already downloaded")
else:
get = root + date + "/current/glg_poshist_all_%s_v00.fit" %yymmdd
print("Downloading the relevant poshist file")
print(get)
call(["curl", "-LO", get])
# Check for the time
gtiflag = GBMgeo.checkGTI(cMET)
print(gtiflag)
if not gtiflag:
print('Occurred during a bad time interval (likely SAA)')
else:
print('Occurred during a good time interval')
Era, Edec = GBMgeo.getEarthCenter(cMET)
angularoffset = GBMgeo.getAngOff(Era, Edec, ra, dec)
if angularoffset > 68.0:
print('The source was visible to GBM at this time')
elif angularoffset > 66.0:
print('The source was possibly visible to GBM at this time (between 66 and 68 deg offset)')
else:
print('The source was occulted at this time')
def search_bat_pointing(ra, dec, t):
""" Search the BAT history to see whether the detector was
sensitive to a given position at a given time """
print("Searching BAT")
swinfo.main(
["swinfo.py", t.isot,
"-p %s %s" %(ra,dec)])
if __name__=="__main__":
ra = 123.813909
dec = -5.867007
jd_steps = np.linspace(2459230.7774, 2459230.7915, 5)
times = Time(jd_steps, format='jd')
for t0 in times:
print(t0)
#search_gbm_pointing(ra, dec, t0)
search_bat_pointing(ra, dec, t0)