<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 GBM Geometry Demo
J. Michael Burgess
gbmeometry is a module with routines for handling GBM geometry. It performs a few tasks
Step1:  Making an interpolation from TRIGDAT
Getting the data
We can use GetGBMData to download the data
Step2:  By default, GetGBMData will grad data from all detectors. However, one can set a subset to retrieve different data types
Step3:  Interpolating
First let's create an interpolating object for a given TRIGDAT file (POSHIST files are also readable)
Step4:  Single detector
One can look at a single detector which knows about it's orientation in the Fermi SC coordinates
Step5:  We can also go back into the GBMFrame
Step6:  Earth Centered Coordinates
The sc_pos are Earth centered coordinates (in km for trigdat and m for poshist) and can also be passed. It is a good idea to specify the units!
Step7:  Working with the GBM class
Ideally, we want to know about many detectors. The GBM class performs operations on all detectors for ease of use. It also has plotting capabilities
Step8:  Plotting
We can look at the NaI view on the sky for a given FOV
Step9:  In Fermi GBM coodinates
We can also plot in Fermi GBM spacecraft coordinates
Step10:  Capturing points on the sky
We can even see which detector's FOVs contain a point on the sky. We create a mock GRB SKycoord first.
Step11:  Looking at Earth occulted points on the sky
We can plot the points occulted by the Earth (assuming points 68.5 degrees form the Earth anti-zenith are hidden)
Step12:  Source/Detector Separation
We can even look at the separation angles for the detectors and the source
Step13:  Examining Legal Detector Pairs
To see which detectors are valid, can look at the legal pairs map
<ASSISTANT_TASK:>
Python Code:
%pylab inline
from astropy.coordinates import SkyCoord
import astropy.coordinates as coord
import astropy.units as u
from gbmgeometry import *
Explanation: GBM Geometry Demo
J. Michael Burgess
gbmeometry is a module with routines for handling GBM geometry. It performs a few tasks:
* creates and astropy coordinate frame for Fermi GBM given a quarternion
* allows for coordinate transforms from Fermi frame to in astropy frame (J2000, etc.)
* plots the GBM NaI detectors at a given time for a given FOV
* determines if a astropy SkyCoord location is within an NaI's FOV
* creates interpolations over GBM quarternions and SC coordinates
End of explanation
data = GetGBMData("080916009")
data.set_destination("") # You can enter a folder here. If you want the CWD, you do not have to set
data.get_trigdat()
Explanation: Making an interpolation from TRIGDAT
Getting the data
We can use GetGBMData to download the data
End of explanation
data.select_detectors('n1','n2','b0')
data.get_rsp_cspec()
Explanation: By default, GetGBMData will grad data from all detectors. However, one can set a subset to retrieve different data types
End of explanation
interp = PositionInterpolator(trigdat="glg_trigdat_all_bn080916009_v02.fit")
# In trigger times
print "Quaternions"
print interp.quaternion(0)
print interp.quaternion(10)
print
print "SC XYZ"
print interp.sc_pos(0)
print interp.sc_pos(10)
Explanation: Interpolating
First let's create an interpolating object for a given TRIGDAT file (POSHIST files are also readable)
End of explanation
na = NaIA(interp.quaternion(0))
print na.get_center()
print na.get_center().icrs #J2000
print na.get_center().galactic # Galactic
print 
print "Changing in time"
na.set_quaternion(interp.quaternion(100))
print na.get_center()
print na.get_center().icrs #J2000
print na.get_center().galactic # Galactic
Explanation: Single detector
One can look at a single detector which knows about it's orientation in the Fermi SC coordinates
End of explanation
center_j2000 = na.get_center().icrs
center_j2000
center_j2000.transform_to(GBMFrame(quaternion=interp.quaternion(100.)))
Explanation: We can also go back into the GBMFrame
End of explanation
na = NaIA(interp.quaternion(0),interp.sc_pos(0)*u.km)
na.get_center()
Explanation: Earth Centered Coordinates
The sc_pos are Earth centered coordinates (in km for trigdat and m for poshist) and can also be passed. It is a good idea to specify the units!
End of explanation
myGBM = GBM(interp.quaternion(0),sc_pos=interp.sc_pos(0)*u.km)
myGBM.get_centers()
[x.icrs for x in myGBM.get_centers()]
Explanation: Working with the GBM class
Ideally, we want to know about many detectors. The GBM class performs operations on all detectors for ease of use. It also has plotting capabilities
End of explanation
myGBM.detector_plot(radius=60)
myGBM.detector_plot(radius=10,projection='ortho',lon_0=40)
myGBM.detector_plot(radius=10,projection='ortho',lon_0=0,lat_0=40,fignum=2)
Explanation: Plotting
We can look at the NaI view on the sky for a given FOV
End of explanation
myGBM.detector_plot(radius=60,fermi_frame=True)
myGBM.detector_plot(radius=10,projection='ortho',lon_0=20,fermi_frame=True)
myGBM.detector_plot(radius=10,projection='ortho',lon_0=200,fermi_frame=True,fignum=3)
myGBM.detector_plot(radius=10,projection='ortho',lon_0=0,lat_0=40,fignum=2,fermi_frame=True)
Explanation: In Fermi GBM coodinates
We can also plot in Fermi GBM spacecraft coordinates
End of explanation
grb = SkyCoord(ra=130.,dec=-45 ,frame='icrs', unit='deg')
myGBM.detector_plot(radius=60,
                    projection='moll',
                    good=True, # only plot NaIs that see the GRB
                    point=grb,
                    lon_0=110,lat_0=-0)
myGBM.detector_plot(radius=60,
                    projection='ortho',
                    good=True, # only plot NaIs that see the GRB
                    point=grb,
                    lon_0=180,lat_0=-40,fignum=2)
Explanation: Capturing points on the sky
We can even see which detector's FOVs contain a point on the sky. We create a mock GRB SKycoord first.
End of explanation
myGBM.detector_plot(radius=10,show_earth=True,lon_0=90)
myGBM.detector_plot(radius=10,lon_0=100,show_earth=True,projection='ortho')
myGBM.detector_plot(radius=10,show_earth=True,lon_0=120,lat_0=-30,fermi_frame=True,projection='ortho')
Explanation: Looking at Earth occulted points on the sky
We can plot the points occulted by the Earth (assuming points 68.5 degrees form the Earth anti-zenith are hidden)
End of explanation
seps = myGBM.get_separation(grb)
seps.sort("Separation")
seps
Explanation: Source/Detector Separation
We can even look at the separation angles for the detectors and the source
End of explanation
get_legal_pairs()
Explanation: Examining Legal Detector Pairs
To see which detectors are valid, can look at the legal pairs map
End of explanation
<END_TASK>