示例#1
0
 def test_plots(self):
     """
     """
     model = xpeInterstellarAbsorptionModel()
     plt.figure()
     model.xsection.plot(logx=True, logy=True, show=False)
     save_current_figure('gabs_xsection.png', clear=False)
     plt.figure()
     model.xsection_ecube().plot(logx=True, show=False)
     save_current_figure('gabs_xsection_ecube.png', clear=False)
     plt.figure()
     ra, dec = 10.684, 41.269
     column_density = mapped_column_density_HI(ra, dec, 'LAB')
     trans = model.transmission_factor(column_density)
     trans.plot(logx=True, show=False, label='$n_H = $%.3e' % column_density)
     plt.legend(loc='upper left')
     save_current_figure('gabs_trans_lab.png', clear=False)
     plt.figure()
     for column_density in [1.e20, 1.e21, 1.e22, 1.e23]:
         trans = model.transmission_factor(column_density)
         trans.plot(logx=True, show=False, label='$n_H = $%.1e' %\
                    column_density)
     plt.legend(loc='upper left')
     save_current_figure('gabs_trans_samples.png', clear=False)
     if sys.flags.interactive:
         plt.show()
示例#2
0
def scale_flux(energy, flux, emin=2., emax=8.):
    ism_model = xpeInterstellarAbsorptionModel()
    ism_trans = ism_model.transmission_factor(GAL_NH)
    flux *= ism_trans(energy)
    norm = xInterpolatedUnivariateSplineLinear(energy,energy*flux).integral(
                                                                emin, emax)
    norm = keV2erg(norm)
    scale_factor =  FLUX/norm
    return flux*scale_factor
 def setUpClass(cls):
     """Setup.
     """
     cls.irf_name = "xipe_baseline"
     cls.aeff = load_arf(cls.irf_name)
     cls.modf = load_mrf(cls.irf_name)
     cls.emin = 2.0
     cls.emax = 8.0
     cls.ebinning = numpy.linspace(cls.emin, cls.emax, 4)
     cls.ism_model = xpeInterstellarAbsorptionModel()
示例#4
0
 def test_transmission(self):
     """
     """
     model = xpeInterstellarAbsorptionModel()
     for nh, label in [(1e21, '1e21'), (1e22, '1e22'), (1e23, '1e23')]:
         trans = model.transmission_factor(nh)
         file_name = 'xspec_wabs_%s.txt' % label        
         file_path = os.path.join(XIMPOL_SRCMODEL, 'ascii', file_name)
         elo, ehi, txspec = numpy.loadtxt(file_path, unpack=True)
         energy = numpy.sqrt(elo*ehi)
         _mask = (txspec > 1.e-2)
         energy = energy[_mask]
         txspec = txspec[_mask]
         tximpol = trans(energy)
         delta = abs(txspec - tximpol)/txspec
         delta_ave = numpy.average(delta)
         self.assertTrue(delta_ave < 0.01, 'average difference %s' %\
                         delta_ave)
示例#5
0
        def _pdf(E, t):
            """Return the convolution between the effective area and
            the input photon spectrum.

            Note that, due the way this callable is used within the constructor
            of xUnivariateAuxGenerator at this point E and t are two numpy
            arrays whose shape is `(num_time_samples, num_energy_samples)`.
            Particularly, `E[0]` is the array of energy values that we use for
            sampling the spectrum (nominally the same sampling that we use
            for the effective area).

            We start from all the stuff that is energy-independent, e.g., the
            effective area and the interstellar absorption and do the proper
            convolutions in energy space. Then we tile the values horizontally
            for as many times as the length of the array sampling the time,
            and at the end we multiply the resulting bidimensional array by
            an equal-size array containing the value of the differential
            energy spectrum on the time-energy grid.
            """
            # Grab the one-dimensional array used to sample the energy.
            _energy = E[0]
            # Calculate the effective area on the array.
            _vals = aeff(_energy)
            # Multiply by the scale factor.
            _vals *= scale_factor
            # If needed, fold in the transmission factor for the interstellar
            # absorption.
            if column_density > 0.:
                logger.info('Applying interstellar absorption (nH = %.3e)' %\
                            column_density)
                ism_model = xpeInterstellarAbsorptionModel()
                ism_trans = ism_model.transmission_factor(column_density)
                _vals *= ism_trans(_energy)
            # Tile the one dimensional vector horizontally.
            _vals = numpy.tile(_vals, (t.shape[0], 1))
            # And multiply by the source spectrum---we're done.
            _vals *= source_spectrum(E*(1 + redshift), t)
            return _vals