In [1]:
%matplotlib inline
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
from threeML import *
from threeML.io.package_data import get_path_of_data_file
Many times we encounter event lists or sets of spectral histograms from which we would like to derive a single or set of plugins. For this purpose, we provide the TimeSeriesBuilder which provides a unified interface to time series data. Here we will demonstrate how to construct plugins from an different of data types.
The TimeSeriesBuilder currently supports reading of the following data type:
If you would like to build a time series from your own custom data, consider creating a TimeSeriesBuilder.from_your_data() class method.
Building plugins from GBM is achieved in the following fashion
In [2]:
cspec_file = get_path_of_data_file('datasets/glg_cspec_n3_bn080916009_v01.pha')
tte_file = get_path_of_data_file('datasets/glg_tte_n3_bn080916009_v01.fit.gz')
gbm_rsp = get_path_of_data_file('datasets/glg_cspec_n3_bn080916009_v00.rsp2')
gbm_cspec = TimeSeriesBuilder.from_gbm_cspec_or_ctime('nai3_cspec',
cspec_or_ctime_file=cspec_file,
rsp_file=gbm_rsp)
gbm_tte = TimeSeriesBuilder.from_gbm_tte('nai3_tte',
tte_file=tte_file,
rsp_file=gbm_rsp)
In [3]:
lle_file = get_path_of_data_file('datasets/gll_lle_bn080916009_v10.fit')
ft2_file = get_path_of_data_file('datasets/gll_pt_bn080916009_v10.fit')
lle_rsp = get_path_of_data_file('datasets/gll_cspec_bn080916009_v10.rsp')
lat_lle = TimeSeriesBuilder.from_lat_lle('lat_lle',
lle_file=lle_file,
ft2_file=ft2_file,
rsp_file=lle_rsp)
In [7]:
gbm_tte.view_lightcurve(start=-20,stop=200)
Perhaps we want to fit the time interval from 0-10 seconds. We make a selection like this:
In [9]:
gbm_tte.set_active_time_interval('0-10')
gbm_tte.view_lightcurve(start=-20,stop=200)
For event list style data like time tagged events, the selection is exact. However, pre-binned data in the form of e.g. PHAII files will have the selection automatically adjusted to the underlying temporal bins.
Several discontinuous time selections can be made.
In order to get to a plugin, we need to model and create an estimated the background for our interval of interest. The process that we have implemented is to fit temporal off-source regions to polynomials in time. First, a polynomial is fit to the total count rate. From this fit we determine the best polynomial order via a likelihood ratio test, unless the user supplies a polynomial order in the constructor or directly via the polynomial_order attribute. Then, this order of polynomial is fit to every channel in the data.
From the polynomial fit, the polynomial is integrated in time over the active source interval to estimate the count rate in each channel. The estimated background and background errors then stored for each channel.
In [13]:
gbm_tte.set_background_interval('-24--5','100-200')
gbm_tte.view_lightcurve(start=-20,stop=200)
For event list data, binned or unbinned background fits are possible. For pre-binned data, only a binned fit is possible.
In [19]:
gbm_tte.set_background_interval('-24--5','100-200',unbinned=False)
In [21]:
gbm_plugin = gbm_tte.to_spectrumlike()
In [22]:
gbm_plugin.display()
In [29]:
gbm_tte.create_time_bins(start=0, stop=70, method='bayesblocks', p0=.1)
gbm_tte.view_lightcurve(use_binner=True)
_=plt.ylim(top=3000)
gbm_tte.create_time_bins(start=0, stop=70, method='bayesblocks', use_background=True, p0=.1)
gbm_tte.view_lightcurve(use_binner=True)
_=plt.ylim(top=3000)
In [31]:
gbm_tte.create_time_bins(start=0, stop=70, method='significance', sigma=30)
gbm_tte.view_lightcurve(use_binner=True)
In [32]:
gbm_tte.create_time_bins(start=0, stop=70, method='constant', dt=10)
gbm_tte.view_lightcurve(use_binner=True)
In [4]:
gbm_tte.create_time_bins(start=[0,1.4,2], stop=[1.4,2,3.8], method='custom')
gbm_tte.view_lightcurve(use_binner=True)
In [39]:
gbm_plugins = gbm_tte.to_spectrumlike(from_bins=True)
gbm_tte.write_pha_from_binner('my_selections',overwrite=True)
We can also export list from pre-binned data, but it is important to specifiy the time range we wish to use.
In [4]:
gbm_cspec.set_background_interval('-200--10','200-400')
gbm_cspec.view_lightcurve(start=-100,stop=300)
gbm_plugins = gbm_cspec.to_spectrumlike(from_bins=True, start=1,stop=10)
In [5]:
gbm_cspec.save_background('my_cspec_background')
This even allows us to read the background of the CSPEC data (with a much longer time baseline) in to the TTE file.
In [7]:
gbm_tte = TimeSeriesBuilder.from_gbm_tte('nai3_tte',
tte_file=tte_file,
rsp_file=gbm_rsp,
restore_background='my_cspec_background.h5')
In [9]:
gbm_tte.view_lightcurve(start=-20,stop=200)
In [ ]: