Exemplo n.º 1
0
    def add(self, others, output, binfile, ltcube):
        """Combine this DataSpec instance with another and return the result

        The two instances must have consistent definitions (DSS, binning,
        and livetime), and must have non-overlapping Gtis. The binfiles and
        ltcubes will be combined and written to the provided destinations;
        perhaps in the future, I will come up with sensible defaults.
        """
        if not hasattr(others, '__iter__'):
            others = [others]
        for other in others:
            exc = self.check_consistency(other)
            if exc is not None:
                raise (exc)
        binfile = os.path.expandvars(binfile)
        ltcube = os.path.expandvars(ltcube)
        gti = skymaps.Gti(self.gti)
        ft1 = self.ft1files
        ft2 = self.ft2files
        bpd = skymaps.BinnedPhotonData(self.binfile)
        for other in others:
            gti.intersection(other.gti)
            ft1 += other.ft1files
            ft2 += other.ft2files
            bpd.add(skymaps.BinnedPhotonData(other.binfile))
        if gti.computeOntime() > 0:
            raise DataError("DataSpec instances have overlapping GTIs")
        ft2 = sorted(list(set(ft2)))
        bpd.write(binfile)
        fitstools.merge_lt([self.ltcube] + [other.ltcube for other in others],
                           outfile=ltcube,
                           weighted=self.use_weighted_livetime)
        dssman.DSSEntries(self.binfile, header_key=0).write(binfile,
                                                            header_key=0)
        dssman.DSSEntries(self.ltcube, header_key=0).write(ltcube,
                                                           header_key=0)
        #TODO: move the copying of DSS entries into the merge_bpd and merge_lt functions
        gti_mask = skymaps.Gti(self.gti_mask)
        for other in others:
            gti_mask.combine(other.gti_mask)
        kwargs = dict(ft1=ft1,
                      ft2=ft2,
                      binfile=binfile,
                      ltcube=ltcube,
                      gti_mask=gti_mask,
                      binsperdec=self.binsperdec,
                      mc_src_id=self.mc_src_id,
                      mc_energy=self.mc_energy,
                      use_weighted_livetime=self.use_weighted_livetime,
                      livetime_buffer=self.livetime_buffer,
                      livetime_pixelsize=self.livetime_pixelsize,
                      clobber=False)
        return DataSpec(output, **kwargs)
Exemplo n.º 2
0
 def _load_binfile(self):
     if not self.quiet: print 'loading binfile %s ...' % self.binfile,
     try:
         self.dmap = skymaps.BinnedPhotonData(self.binfile)
         if not self.quiet:                print 'found %d photons in %d bands, energies %.0f-%.0f MeV'\
  % (self.dmap.photonCount(),len(self.dmap), self.dmap[1].emin(), self.dmap[len(self.dmap)-1].emax())
     except RuntimeError:
         self.dmap = binned_data.BinFile(self.binfile)
         if not self.quiet: print self.dmap
     if self.verbose:
         self.dmap.info()
         print '---------------------'
Exemplo n.º 3
0
 def __init__(self, ds):
     """Initialize a DataManager instance.
     
         ds: a DataSpec instance
     """
     self.dataspec = ds
     self.bpd = skymaps.BinnedPhotonData(ds.binfile)
     self.lt = skymaps.LivetimeCube(ds.ltcube, weighted=False)
     if ds.use_weighted_livetime:
         self.weighted_lt = skymaps.LivetimeCube(ds.ltcube, weighted=True)
     else:
         self.weighted_lt = None
     self.gti = self.lt.gti()  #Just to provide a reference.
Exemplo n.º 4
0
    def get_data(self):

        #if no binned object present, create; apply cuts
        if self.binfile is None or not os.path.exists(self.binfile):
            my_bins = 10**N.arange(N.log10(self.emin),
                                   N.log10(self.emax * 1.01),
                                   1. / self.binsperdec)

            self._Data_setup(my_bins)

            if not self.quiet:
                print 'loading %d FT1 file(s) %s...%s' % (len(
                    self.ft1files), self.ft1files[0], self.ft1files[-1])
                if self.event_class > -1:
                    print 'selecting event_class %d' % self.event_class
            src_id = -1 if 'mc_src_id' not in self.__dict__ else self.mc_src_id
            data = pointlike.Data(self.ft1files, self.conv_type, self.tstart,
                                  self.tstop, src_id, '')

            self.dmap = data.map()
            self.fill_empty_bands(self.dmap, my_bins)  # fill any empty bins

            if self.verbose: print 'done'
            if self.binfile is not None:
                if not self.quiet:
                    print '.....saving binfile %s for subsequent use' % self.binfile
                data.write(self.binfile)
        if self.binfile is not None:
            if not self.quiet:
                print '.....loading binfile %s ...' % self.binfile,
            self.dmap = skymaps.BinnedPhotonData(self.binfile)
        if not self.quiet:            print 'found %d bands, energies %.0f-%.0f MeV'\
 % (len(self.dmap), self.dmap[1].emin(), self.dmap[len(self.dmap)-1].emax())

        if self.verbose:
            self.dmap.info()
            print '---------------------'