def _create_timeseries(self): """ create all the time series for each detector :return: None """ self._time_series = collections.OrderedDict() for det_num in range(14): # detectors are arranged [time,det,channel] # for now just keep the normal exposure # we will create binned spectra for each time slice drm_gen = DRMGenTrig( self._qauts, self._sc_pos, det_num, # det number tstart=self._tstart, tstop=self._tstop, mat_type=2, time=0, occult=True ) # we will use a single response for each detector tmp_drm = BALROG_DRM(drm_gen, 0, 0) # extract the counts counts = self._rates[:, det_num, :] * self._time_intervals.widths.reshape( (len(self._time_intervals), 1) ) # now create a binned spectrum for each interval binned_spectrum_list = [] for c, start, stop in zip(counts, self._tstart, self._tstop): binned_spectrum_list.append( BinnedSpectrumWithDispersion( counts=c, exposure=stop - start, response=tmp_drm, tstart=start, tstop=stop, ) ) # make a binned spectrum set bss = BinnedSpectrumSet( binned_spectrum_list, reference_time=0.0, time_intervals=self._time_intervals, ) # convert that set to a series bss2 = BinnedSpectrumSeries(bss, first_channel=0) # now we need to get the name of the detector name = lu[det_num] if self._restore_poly_fit is not None: bkg_fit_file = self._restore_poly_fit.get(name, None) else: bkg_fit_file = None # create a time series builder which can produce plugins tsb = TimeSeriesBuilder( name, bss2, response=tmp_drm, verbose=self._verbose, poly_order=self._poly_order, restore_poly_fit=bkg_fit_file, ) # attach that to the full list self._time_series[name] = tsb
def from_gbm_cspec_or_ctime(cls, name, cspec_or_ctime_file, rsp_file, restore_background=None, trigger_time=None, poly_order=-1, verbose=True): """ A plugin to natively bin, view, and handle Fermi GBM TTE data. A TTE event file are required as well as the associated response Background selections are specified as a comma separated string e.g. "-10-0,10-20" Initial source selection is input as a string e.g. "0-5" One can choose a background polynomial order by hand (up to 4th order) or leave it as the default polyorder=-1 to decide by LRT test :param name: name for your choosing :param tte_file: GBM tte event file :param rsp_file: Associated TTE CSPEC response file :param trigger_time: trigger time if needed :param poly_order: 0-4 or -1 for auto :param unbinned: unbinned likelihood fit (bool) :param verbose: verbose (bool) """ # self._default_unbinned = unbinned # Load the relevant information from the TTE file cdata = GBMCdata(cspec_or_ctime_file, rsp_file) # Set a trigger time if one has not been set if trigger_time is not None: cdata.trigger_time = trigger_time # Create the the event list event_list = BinnedSpectrumSeries(cdata.spectrum_set, first_channel=0, mission='Fermi', instrument=cdata.det_name, verbose=verbose) # we need to see if this is an RSP2 if isinstance(rsp_file, str) or isinstance(rsp_file, unicode): test = re.match('^.*\.rsp2$', rsp_file) # some GBM RSPs that are not marked RSP2 are in fact RSP2s # we need to check if test is None: with fits.open(rsp_file) as f: # there should only be a header, ebounds and one spec rsp extension if len(f) > 3: # make test a dummy value to trigger the nest loop test = -1 custom_warnings.warn( 'The RSP file is marked as a single response but in fact has multiple matrices. We will treat it as an RSP2' ) if test is not None: rsp = InstrumentResponseSet.from_rsp2_file( rsp2_file=rsp_file, counts_getter=event_list.counts_over_interval, exposure_getter=event_list.exposure_over_interval, reference_time=cdata.trigger_time) else: rsp = OGIPResponse(rsp_file) else: assert isinstance( rsp_file, InstrumentResponse ), 'The provided response is not a 3ML InstrumentResponse' rsp = rsp_file # pass to the super class return cls(name, event_list, response=rsp, poly_order=poly_order, unbinned=False, verbose=verbose, restore_poly_fit=restore_background, container_type=BinnedSpectrumWithDispersion)