Exemple #1
0
    def __init__(self,  burst: int = None,
                        datatype: str = None,
                        times = None,
                        bgs: bool = False,
                        light_GRB: bool = True):

        self.colours   = ['red', 'orange', 'green', 'blue']
        self.clabels   = ['1', '2', '3', '4']
        self.labels    = ['  20 - 50   keV', '  50 - 100 keV',
                          ' 100 - 300  keV', '300 +      keV']
        self.datatypes = {'discsc':'discsc', 'tte':'tte'}
        try:
            self.burst = int(burst)
        except:
            raise ValueError(
                'Input variable `burst` should be an integer. '
                'Is {} when it should be int.'.format(type(burst)))
        try:
            self.datatype = self.datatypes[datatype]
        except:
            raise AssertionError(
                'Input variable `datatype` is {} when it '
                'should be `discsc` or `tte`.'.format(datatype))

        self.kwargs    = {  'colours'   : self.colours,
                            'clabels'   : self.clabels,
                            'labels'    : self.labels,
                            'datatype'  : self.datatype,
                            'burst'     : self.burst,
                            'satellite' : 'BATSE'}

        self.times     = times
        self.light_GRB = light_GRB
        # GetBATSEBurst downdloads file if it does not exist
        fetch = GetBATSEBurst(trigger = self.burst, datatype = self.datatype)
        # with closes the file automatically after finished.
        with fits.open(fetch.path) as hdu_list:
            self.data = hdu_list[-1].data
            ### initialise data arrays from fits file, over entire data set
            self.bin_left  = np.array(self.data['TIMES'][:, 0])
            self.bin_right = np.array(self.data['TIMES'][:, 1])
            self.rates     = np.array(self.data['RATES'][:, :])
            # errors in BATSE rates are calculated by scaling the counts
            # count errors are calculated with as Poisson errors = sqrt(counts)
            self.errors = np.array(self.data['ERRORS'][:, :])
            self.counts = np.array([np.multiply(self.rates[:, i],
                    self.bin_right - self.bin_left) for i in range(4)]).T
            self.count_err = np.sqrt(self.counts)
            self.t90_st, self.end = self.bin_left[0], self.bin_right[-1]
            try:
                (self.t90_st, self.end) = times
            except:
                if times == 'T90':
                    self._read_T90_table()
                elif times == 'T100':
                    self._read_T90_table()
                    self.t90_st = min(-2, self.t90_st)
                    self.end += max(5, 0.25 * self.t90)

            super().__init__(times, bgs)
Exemple #2
0
    def __init__(self, live_detectors = None):
        super(BATSETTEList, self).__init__()
        if self.verbose:
            print('Analysing BATSE TTE list data')

        fetch = GetBATSEBurst(trigger = self.trigger, datatype = self.datatype)
        with fits.open(fetch.path) as hdu_list:
            self._get_energy_bin_edges(hdu_list[1].data)
            count_data  = hdu_list[2].data

        self.detectors    = np.arange(8)
        self.det_count    = np.zeros( 8)
        self.photon_list  = []
        self.channel_list = []
        for i in range(8):
            det, num_phots, a1, a2, photons, channels = count_data[i]
            self.det_count[i] = num_phots
            self.photon_list.append(photons)
            self.channel_list.append(channels)

        if live_detectors is not None:
            self.live_detectors = live_detectors
        else:
            self.live_detectors = np.arange(8)
            print('Analysis running over all 8 detectors.')
            print('Would you rather analyse only the triggered detectors?')

        self.channel_1_times = self._sum_detectors(1)
        self.channel_2_times = self._sum_detectors(2)
        self.channel_3_times = self._sum_detectors(3)
        self.channel_4_times = self._sum_detectors(4)
        self.channels = [   self.channel_1_times, self.channel_2_times,
                            self.channel_3_times, self.channel_4_times]
        # channel x times are the photon arrival times in ANY channel.
        self.channel_x_times = self._sum_channels([1,2,3,4])
        self.sampling_rate = self._get_sampling_rate()
        if self.verbose:
            self._plot_arrival_histogram()
        times, ch1_rts = self._interpolate_bins(1)
        times, ch2_rts = self._interpolate_bins(2)
        times, ch3_rts = self._interpolate_bins(3)
        times, ch4_rts = self._interpolate_bins(4)
        if self.verbose:
            print(times.shape)
            print(ch1_rts.shape)
            print(ch2_rts.shape)
            print(ch3_rts.shape)
            print(ch4_rts.shape)

        self.bin_left  = times
        self.bin_right = times + self.sampling_rate
        self.counts    = np.zeros((len(self.bin_left),4))
        self.counts[:,0] = ch1_rts
        self.counts[:,1] = ch2_rts
        self.counts[:,2] = ch3_rts
        self.counts[:,3] = ch4_rts
Exemple #3
0
 def test_trigger_found(self):
     path = 'data/BATSE/discsc/discsc_bfits_105.fits.gz'
     try:
         os.remove(path)
         delete = False
     except:
         delete = True
     GetBATSEBurst(trigger=self.trigger, datatype=self.datatype)
     assert (os.path.exists(path))
     if delete:
         os.remove(path)
Exemple #4
0
 def test_trigger_not_found(self):
     trigger = 101
     with self.assertRaises(FileNotFoundError):
         GetBATSEBurst(trigger=trigger, datatype=self.datatype)
Exemple #5
0
 def test_datatype(self):
     datatype = "banana"
     with self.assertRaises(AssertionError):
         GetBATSEBurst(trigger=self.trigger, datatype=datatype)