Exemplo n.º 1
0
 def __read_map(self, filename):
     """Load the FITS hdulist using astropy.io.fits.
     """
     w = wcs.WCS(filename)
     hdu = fits.open(filename)
     data = hdu[0].data
     nbinsx, nbinsy = data.shape
     x = range(nbinsx)
     y = range(nbinsy)
     spline = xInterpolatedBivariateSplineLinear(x, y, data)
     return w, spline
Exemplo n.º 2
0
 def __read_map(self, filename):
     """Load the FITS hdulist using astropy.io.fits.
     """
     w = wcs.WCS(filename)
     hdu = fits.open(filename)
     data = hdu[0].data
     nbinsx, nbinsy = data.shape
     x = range(nbinsx)
     y = range(nbinsy)
     spline = xInterpolatedBivariateSplineLinear(x, y, data)
     return w, data, spline
Exemplo n.º 3
0
def _make_aeff_ratio(aeff, c_aeff, c_vign, emin=0.3, emax=10.0):
    """Make the ratio between ximpol and Chandra effective area taking in
    account the vignetting.
    """
    _x = aeff.x[(aeff.x >= emin) * (aeff.x <= emax)]
    _aeff_ratio = aeff(_x) / c_aeff(_x)
    _y = aeff.vignetting.y
    _x_mesh, _y_mesh = numpy.meshgrid(_x, _y)
    _vign_ratio = (aeff.vignetting(_x_mesh, _y_mesh) / c_vign(_x_mesh, _y_mesh)).T
    _z = (_vign_ratio.T * _aeff_ratio).T
    fmt = dict(xname="Energy", xunits="keV", yname="Off-axis angle", yunits="arcmin", zname="Effective area ratio")
    return xInterpolatedBivariateSplineLinear(_x, _y, _z, **fmt)
Exemplo n.º 4
0
def _load_chandra_vign(vign_file):
    """Load the Chandra vignetting data from file.
    """
    hdu_list = fits.open(vign_file)
    tbdata = hdu_list[1].data
    _x = 0.5 * (tbdata.field("ENERG_LO") + tbdata.field("ENERG_HI"))[0, :]
    _y = tbdata.field("THETA")[0, :]
    _vignet = tbdata.field("VIGNET")
    _z = numpy.mean(_vignet[0, :, :, :], axis=0)
    _mask = _y <= 10  # arcmin
    _y = _y[_mask]
    _z = _z[_mask, :]
    fmt = dict(xname="Energy", xunits="keV", yname="Off-axis angle", yunits="arcmin", zname="Vignetting")
    return xInterpolatedBivariateSplineLinear(_x, _y, _z.T, **fmt)
Exemplo n.º 5
0
Arquivo: rmf.py Projeto: pabell/ximpol
 def __init__(self, hdu, num_aux_points=200):
     """Constructor.
     """
     # First build a bivariate spline with the full data grid.
     _matrix = hdu.data
     _x = 0.5*(_matrix['ENERG_LO'] + _matrix['ENERG_HI'])
     _y = numpy.arange(0, len(_matrix['MATRIX'][0]), 1) - 0.5
     _z = _matrix['MATRIX']
     _pdf = xInterpolatedBivariateSplineLinear(_y, _x, _z.transpose())
     # Then initialize the actual xUnivariateAuxGenerator object
     # with a down-sampled aux axis.
     _aux = numpy.linspace(_pdf.ymin(), _pdf.ymax(), num_aux_points)
     _rv = _y
     fmt = dict(auxname='Energy', auxunits='keV', rvname='Channel',
                pdfname='Probability density')
     xUnivariateAuxGenerator.__init__(self, _aux, _rv, _pdf, **fmt)
Exemplo n.º 6
0
 def __init__(self, arf_file_path):
     """Constructor.
     """
     logger.info('Reading effective area data from %s...' % arf_file_path)
     self.hdu_list = fits.open(arf_file_path)
     self.hdu_list.info()
     _data = self.hdu_list['SPECRESP'].data
     _x = 0.5*(_data.field('ENERG_LO') + _data.field('ENERG_HI'))
     _y = _data.field('SPECRESP')
     fmt = dict(xname='Energy', xunits='keV', yname='Effective area',
                yunits='cm$^2$')
     xInterpolatedUnivariateSplineLinear.__init__(self, _x, _y, **fmt)
     _x = self.hdu_list['VIGNETTING'].data['ENERGY'][0]
     _y = self.hdu_list['VIGNETTING'].data['THETA'][0]
     _z = self.hdu_list['VIGNETTING'].data['VIGNETTING'][0]
     fmt = dict(xname='Energy', xunits='keV', yname='Off-axis angle',
                yunits='arcmin', zname='Vignetting')
     self.vignetting = xInterpolatedBivariateSplineLinear(_x, _y, _z, **fmt)
Exemplo n.º 7
0
Arquivo: rmf.py Projeto: pabell/ximpol
 def __init__(self, hdu, num_aux_points=200):
     """Constructor.
     """
     # First build a bivariate spline with the full data grid.
     _matrix = hdu.data
     _x = 0.5 * (_matrix['ENERG_LO'] + _matrix['ENERG_HI'])
     _y = numpy.arange(0, len(_matrix['MATRIX'][0]), 1) - 0.5
     _z = _matrix['MATRIX']
     _pdf = xInterpolatedBivariateSplineLinear(_y, _x, _z.transpose())
     # Then initialize the actual xUnivariateAuxGenerator object
     # with a down-sampled aux axis.
     _aux = numpy.linspace(_pdf.ymin(), _pdf.ymax(), num_aux_points)
     _rv = _y
     fmt = dict(auxname='Energy',
                auxunits='keV',
                rvname='Channel',
                pdfname='Probability density')
     xUnivariateAuxGenerator.__init__(self, _aux, _rv, _pdf, **fmt)
Exemplo n.º 8
0
 def __init__(self, arf_file_path):
     """Constructor.
     """
     logger.info('Reading effective area data from %s...' % arf_file_path)
     self.hdu_list = fits.open(arf_file_path)
     self.hdu_list.info()
     _data = self.hdu_list['SPECRESP'].data
     _x = 0.5 * (_data.field('ENERG_LO') + _data.field('ENERG_HI'))
     _y = _data.field('SPECRESP')
     fmt = dict(xname='Energy',
                xunits='keV',
                yname='Effective area',
                yunits='cm$^2$')
     xInterpolatedUnivariateSplineLinear.__init__(self, _x, _y, **fmt)
     _x = self.hdu_list['VIGNETTING'].data['ENERGY'][0]
     _y = self.hdu_list['VIGNETTING'].data['THETA'][0]
     _z = self.hdu_list['VIGNETTING'].data['VIGNETTING'][0]
     fmt = dict(xname='Energy',
                xunits='keV',
                yname='Off-axis angle',
                yunits='arcmin',
                zname='Vignetting')
     self.vignetting = xInterpolatedBivariateSplineLinear(_x, _y, _z, **fmt)
Exemplo n.º 9
0
aeff, psf, modf, edisp = load_irfs(IRF_NAME)

def C(t):
    return 1. - 0.9*t/(T_MAX - T_MIN)

def Gamma(t):
    return 1.5 + t/(T_MAX - T_MIN)

spectrum = power_law(C, Gamma)

plt.figure('Source spectrum')
_t = numpy.linspace(T_MIN, T_MAX, 100)
_e = aeff.x
fmt = dict(xname='Time', xunits='s', yname='Energy', yunits='keV',
           zname='dN/dE', zunits='cm$^{-2}$ s$^{-1}$ keV$^{-1}$')
spectrum_spline = xInterpolatedBivariateSplineLinear(_t, _e, spectrum, **fmt)
spectrum_spline.plot(show=False, logz=True)
save_current_figure('source_spectrum.png', OUTPUT_FOLDER, clear=False)

plt.figure('Source spectrum slices')
for t in [T_MIN, 0.5*(T_MIN + T_MAX), T_MAX]:
    spectrum_spline.vslice(t).plot(show=False, logx=True, logy=True,
                                   label='t = %d s' % t)
plt.legend(bbox_to_anchor=(0.75, 0.95))
plt.axis([1, 10, None, None])
save_current_figure('source_spectrum_slices.png', OUTPUT_FOLDER, clear=False)

plt.figure('Count spectrum')
count_spectrum = xCountSpectrum(spectrum, aeff, _t)
count_spectrum.plot(show=False, logz=True)
save_current_figure('count_spectrum.png', OUTPUT_FOLDER, clear=False)