Пример #1
0
 def estimate_flux(dnde,energy,emin,emax, e_weight):
     """ estimate the emin to emax flux for a source with prefactor
         dnde at the given energy. assuming the source has a
         spectral index of 2. 
         
         Note, for our situation dnde has units [ph/cm^2/s/TeV]
         and energy has units [TeV], but the ouptut of the
         i_flux function is correct. If e_weight=0,
         the return has units [ph/cm^2/s]. If e_weight=1,
         the return has units [TeV/cm^2/s]. """
     model = PowerLaw(index=2, norm=dnde, e0=energy)
     return model.i_flux(emin=emin, emax=emax, e_weight=e_weight)
Пример #2
0
 def estimate_flux(dnde, energy, emin, emax, e_weight):
     """ estimate the emin to emax flux for a source with prefactor
         dnde at the given energy. assuming the source has a
         spectral index of 2. 
         
         Note, for our situation dnde has units [ph/cm^2/s/TeV]
         and energy has units [TeV], but the ouptut of the
         i_flux function is correct. If e_weight=0,
         the return has units [ph/cm^2/s]. If e_weight=1,
         the return has units [TeV/cm^2/s]. """
     model = PowerLaw(index=2, norm=dnde, e0=energy)
     return model.i_flux(emin=emin, emax=emax, e_weight=e_weight)
Пример #3
0
    def test_ff(self):
        """ Simulate from a filefunction object and test that the best
        fit flux
            is consistent with the simulated flux. """
        name = 'ff'

        model = PowerLaw(index=2)
        model.set_flux(1e-6)
        simdir = path.expand('$SIMDIR/%s' % name)
        if not os.path.exists(simdir):
            os.makedirs(simdir)

        filename = abspath(join(simdir, 'file_function.txt'))
        model.save_profile(filename, 10, 1e6)
        ff = FileFunction(file=filename)

        center = SkyDir(0, 0)
        ps = PointSource(name='source', skydir=center, model=ff)
        point_sources = [ps]
        diffuse_sources = None
        roi = PointlikeTest.get_roi(name,
                                    center,
                                    point_sources,
                                    diffuse_sources,
                                    emin=1e2,
                                    emax=1e5,
                                    binsperdec=4)

        if PointlikeTest.VERBOSE:
            roi.print_summary()
            print roi

        roi.fit(use_gradient=PointlikeTest.USE_GRADIENT)

        if PointlikeTest.VERBOSE:
            roi.print_summary()
            print roi

        fit, error = ff.i_flux(1e2, 1e5, error=True)
        true = model.i_flux(1e2, 1e5, error=False)
        self.assertPull(fit, true, error, 'flux')