Esempio n. 1
0
def make_mrf(modf_file_path, irf_name):
    """Write the XIPE modulation factor response function.
    """
    logger.info('Creating XIPE effective area fits file...')
    output_file_name = '%s.mrf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Loading modulation factor from %s...' % modf_file_path)
    _x, _y = numpy.loadtxt(modf_file_path, unpack=True)
    modf = xInterpolatedUnivariateSplineLinear(_x, _y)
    logger.info('Filling in arrays...')
    modfresp = modf(ENERGY_CENTER)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', XIPE_KEYWORDS, XIPE_COMMENTS)
    print(repr(primary_hdu.header))
    logger.info('Creating MODFRESP HDU...')
    data = [ENERGY_LO, ENERGY_HI, modfresp]
    modfresp_hdu = xBinTableHDUMODFRESP(data, XIPE_KEYWORDS, XIPE_COMMENTS)
    print(repr(modfresp_hdu.header))
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, modfresp_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 2
0
def make_mrf(modf_file_path, irf_name):
    """Write the XIPE modulation factor response function.
    """
    logger.info('Creating XIPE effective area fits file...')
    output_file_name = '%s.mrf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Loading modulation factor from %s...' % modf_file_path)
    _x, _y = numpy.loadtxt(modf_file_path, unpack=True)
    modf = xInterpolatedUnivariateSplineLinear(_x, _y)
    logger.info('Filling in arrays...')
    modfresp = modf(ENERGY_CENTER)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', INSTR_KEYWORDS, INSTR_COMMENTS)
    print(repr(primary_hdu.header))
    logger.info('Creating MODFRESP HDU...')
    data = [ENERGY_LO, ENERGY_HI, modfresp]
    modfresp_hdu = xBinTableHDUMODFRESP(data, INSTR_KEYWORDS, INSTR_COMMENTS)
    print(repr(modfresp_hdu.header))
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, modfresp_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 3
0
def distsrc():
    """ Create a plain source distribution.
    """
    tag, buildDate = version_info()
    logger.info('Creating plain source distribution...')
    distDir = os.path.join(XIMPOL_DIST, 'src')
    srcLogFilePath = 'src.log'
    # Create the distribution.
    cmd('python setup.py sdist --dist-dir=%s --prune' % distDir,
        verbose=False, logFilePath=srcLogFilePath)
    # Cleanup.
    rm(srcLogFilePath)
    rm(os.path.join(XIMPOL_ROOT, 'MANIFEST'))
    logger.info('Done.')
Esempio n. 4
0
def run(repeat=3):
    #First simulate the events
    file_list = []
    for i in range(repeat):
        output_file_path = EVT_FILE_PATH.replace('.fits', '_%d.fits' % i)
        file_list.append(output_file_path)
        PIPELINE.xpobssim(configfile=CFG_FILE, duration=SIM_DURATION,
                          outfile=output_file_path, seed=i)
    file_list = str(file_list).strip('[]').replace('\'', '').replace(' ', '')
    if PIPELINE.clobber:
        rm(EVT_FILE_PATH)
    cmd('ftmerge %s %s' % (file_list, EVT_FILE_PATH))

    PIPELINE.xpbin(EVT_FILE_PATH, algorithm='MCUBE', ebinalg='LIST',
                       ebinning=E_BINNING)
def generate(count=100):
    """Generate the events.
    """
    #First simulate the events
    file_list = []
    for i in range(count):
        output_file_path = EVT_FILE_PATH.replace('.fits', '_%d.fits' % i)
        file_list.append(output_file_path)
        PIPELINE.xpobssim(configfile=CFG_FILE_PATH,
                          duration=SIM_DURATION/count,
                          outfile=output_file_path, seed=i)
    file_list = str(file_list).strip('[]').replace('\'', '').replace(' ', '')
    if PIPELINE.clobber:
        rm(EVT_FILE_PATH)
    cmd('ftmerge %s %s' % (file_list, EVT_FILE_PATH))
Esempio n. 6
0
def distsrc():
    """ Create a plain source distribution.
    """
    tag, buildDate = version_info()
    logger.info('Creating plain source distribution...')
    distDir = os.path.join(XIMPOL_DIST, 'src')
    srcLogFilePath = 'src.log'
    # Create the distribution.
    cmd('python setup.py sdist --dist-dir=%s --prune' % distDir,
        verbose=False,
        logFilePath=srcLogFilePath)
    # Cleanup.
    rm(srcLogFilePath)
    rm(os.path.join(XIMPOL_ROOT, 'MANIFEST'))
    logger.info('Done.')
Esempio n. 7
0
def make_rmf(eres_file_path, irf_name):
    """Write the XIPE edisp response function.

    The specifications are describes at page ~15 of the following document:
    ftp://legacy.gsfc.nasa.gov/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.ps
    """
    output_file_name = '%s.rmf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Loading energy dispersion from %s...' % eres_file_path)
    _x, _y = numpy.loadtxt(eres_file_path, unpack=True)
    edisp_fwhm = xInterpolatedUnivariateSplineLinear(_x, _y)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', INSTR_KEYWORDS, INSTR_COMMENTS)
    print(repr(primary_hdu.header))
    keyword = ('DETCHANS', NUM_CHANNELS, 'Total number of detector channels')
    rmf_header_keywords = INSTR_KEYWORDS + [keyword]
    logger.info('Creating MATRIX HDU...')
    nrows = len(ENERGY_LO)
    ngrp = numpy.ones(nrows)
    fchan = numpy.zeros(nrows)
    nchan = numpy.array([NUM_CHANNELS]*nrows, 'i')
    matrix = numpy.zeros((0, NUM_CHANNELS))
    ch = numpy.arange(NUM_CHANNELS)
    for energy, rms in zip(ENERGY_CENTER, edisp_fwhm(ENERGY_CENTER)/2.358):
        mean_chan = int((energy - E_CHAN_OFFSET)/E_CHAN_SLOPE)
        rms_chan = rms/E_CHAN_SLOPE
        rv = stats.norm(loc=mean_chan, scale=rms_chan)
        matrix = numpy.vstack([matrix, rv.pdf(ch)])
    data = [ENERGY_LO, ENERGY_HI, ngrp, fchan, nchan, matrix]
    matrix_hdu = xBinTableHDUMATRIX(NUM_CHANNELS, data, rmf_header_keywords,
                                    INSTR_COMMENTS)
    print(repr(matrix_hdu.header))
    logger.info('Creating EBOUNDS HDU...')
    ch = numpy.arange(NUM_CHANNELS)
    emin = ch*E_CHAN_SLOPE + E_CHAN_OFFSET
    emax = (ch + 1)*E_CHAN_SLOPE + E_CHAN_OFFSET
    data = [ch, emin, emax]
    ebounds_hdu = xBinTableHDUEBOUNDS(data, rmf_header_keywords, INSTR_COMMENTS)
    print(repr(ebounds_hdu.header))
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, matrix_hdu, ebounds_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 8
0
def make_rmf(eres_file_path, irf_name):
    """Write the XIPE edisp response function.

    The specifications are describes at page ~15 of the following document:
    ftp://legacy.gsfc.nasa.gov/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.ps
    """
    output_file_name = '%s.rmf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Loading energy dispersion from %s...' % eres_file_path)
    _x, _y = numpy.loadtxt(eres_file_path, unpack=True)
    edisp_fwhm = xInterpolatedUnivariateSplineLinear(_x, _y)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', XIPE_KEYWORDS, XIPE_COMMENTS)
    print(repr(primary_hdu.header))
    keyword = ('DETCHANS', NUM_CHANNELS, 'Total number of detector channels')
    rmf_header_keywords = XIPE_KEYWORDS + [keyword]
    logger.info('Creating MATRIX HDU...')
    nrows = len(ENERGY_LO)
    ngrp = numpy.ones(nrows)
    fchan = numpy.zeros(nrows)
    nchan = numpy.array([NUM_CHANNELS] * nrows, 'i')
    matrix = numpy.zeros((0, NUM_CHANNELS))
    ch = numpy.arange(NUM_CHANNELS)
    for energy, rms in zip(ENERGY_CENTER, edisp_fwhm(ENERGY_CENTER) / 2.358):
        mean_chan = int((energy - E_CHAN_OFFSET) / E_CHAN_SLOPE)
        rms_chan = rms / E_CHAN_SLOPE
        rv = stats.norm(loc=mean_chan, scale=rms_chan)
        matrix = numpy.vstack([matrix, rv.pdf(ch)])
    data = [ENERGY_LO, ENERGY_HI, ngrp, fchan, nchan, matrix]
    matrix_hdu = xBinTableHDUMATRIX(NUM_CHANNELS, data, rmf_header_keywords,
                                    XIPE_COMMENTS)
    print(repr(matrix_hdu.header))
    logger.info('Creating EBOUNDS HDU...')
    ch = numpy.arange(NUM_CHANNELS)
    emin = ch * E_CHAN_SLOPE + E_CHAN_OFFSET
    emax = (ch + 1) * E_CHAN_SLOPE + E_CHAN_OFFSET
    data = [ch, emin, emax]
    ebounds_hdu = xBinTableHDUEBOUNDS(data, rmf_header_keywords, XIPE_COMMENTS)
    print(repr(ebounds_hdu.header))
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, matrix_hdu, ebounds_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 9
0
def make_arf(aeff_file_path, qeff_file_path, irf_name, off_axis_data=[]):
    """Write the XIPE effective area response function.
    """
    logger.info('Creating XIPE effective area fits file...')
    output_file_name = '%s.arf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Loading mirror effective area from %s...' % aeff_file_path)
    _x, _y = numpy.loadtxt(aeff_file_path, unpack=True)
    opt_aeff = xInterpolatedUnivariateSplineLinear(_x, _y)
    logger.info('Loading quantum efficiency from %s...' % qeff_file_path)
    _x, _y = numpy.loadtxt(qeff_file_path, unpack=True)
    gpd_eff = xInterpolatedUnivariateSplineLinear(_x, _y)
    aeff = opt_aeff*gpd_eff
    specresp = aeff(ENERGY_CENTER)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', INSTR_KEYWORDS, INSTR_COMMENTS)
    print(repr(primary_hdu.header))
    logger.info('Creating SPECRESP HDU...')
    data = [ENERGY_LO, ENERGY_HI, specresp]
    specresp_hdu = xBinTableHDUSPECRESP(data, INSTR_KEYWORDS, INSTR_COMMENTS)
    print(repr(specresp_hdu.header))
    logger.info('Processing off-axis data...')
    energy = numpy.linspace(ENERGY_MIN, ENERGY_MAX, 100)
    theta = [0]
    vignetting = [[1.]*len(energy)]
    for r, file_path in off_axis_data:
        logger.info('Reading %s (at %.2f arcsec)...' % (file_path, r))
        theta.append(r)
        _x, _y = numpy.loadtxt(file_path, unpack=True)
        _aeff = xInterpolatedUnivariateSplineLinear(_x, _y)
        ratio = _aeff/opt_aeff
        vignetting.append(ratio(energy))
    theta = numpy.array(theta)
    vignetting = numpy.array(vignetting).transpose()
    data = [energy, theta, vignetting]
    vignetting_hdu = xBinTableHDUVIGNETTING(data)
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, specresp_hdu, vignetting_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 10
0
def make_arf(aeff_file_path, qeff_file_path, irf_name, off_axis_data=None):
    """Write the XIPE effective area response function.
    """
    logger.info('Creating XIPE effective area fits file...')
    output_file_name = '%s.arf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Loading mirror effective area from %s...' % aeff_file_path)
    _x, _y = numpy.loadtxt(aeff_file_path, unpack=True)
    opt_aeff = xInterpolatedUnivariateSplineLinear(_x, _y)
    logger.info('Loading quantum efficiency from %s...' % qeff_file_path)
    _x, _y = numpy.loadtxt(qeff_file_path, unpack=True)
    gpd_eff = xInterpolatedUnivariateSplineLinear(_x, _y)
    aeff = opt_aeff * gpd_eff
    specresp = aeff(ENERGY_CENTER)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', XIPE_KEYWORDS, XIPE_COMMENTS)
    print(repr(primary_hdu.header))
    logger.info('Creating SPECRESP HDU...')
    data = [ENERGY_LO, ENERGY_HI, specresp]
    specresp_hdu = xBinTableHDUSPECRESP(data, XIPE_KEYWORDS, XIPE_COMMENTS)
    print(repr(specresp_hdu.header))
    logger.info('Processing off-axis data...')
    energy = numpy.linspace(ENERGY_MIN, ENERGY_MAX, 100)
    theta = [0]
    vignetting = [[1.] * len(energy)]
    for r, file_path in off_axis_data:
        logger.info('Reading %s (at %.2f arcsec)...' % (file_path, r))
        theta.append(r)
        _x, _y = numpy.loadtxt(file_path, unpack=True)
        _aeff = xInterpolatedUnivariateSplineLinear(_x, _y)
        ratio = _aeff / opt_aeff
        vignetting.append(ratio(energy))
    theta = numpy.array(theta)
    vignetting = numpy.array(vignetting).transpose()
    data = [energy, theta, vignetting]
    vignetting_hdu = xBinTableHDUVIGNETTING(data)
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, specresp_hdu, vignetting_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 11
0
def make_psf(irf_name):
    """Write the XIPE PSF parameters.
    """
    logger.info('Creating XIPE effective area fits file...')
    output_file_name = '%s.psf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', INSTR_KEYWORDS, INSTR_COMMENTS)
    print(repr(primary_hdu.header))
    logger.info('Creating PSF HDU...')
    data = PSF_PARAMETERS
    psf_hdu = xBinTableHDUPSF(data, [], INSTR_COMMENTS)
    print(repr(psf_hdu.header))
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, psf_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 12
0
def make_psf(irf_name):
    """Write the XIPE PSF parameters.
    """
    logger.info('Creating XIPE effective area fits file...')
    output_file_name = '%s.psf' % irf_name
    output_file_path = os.path.join(XIMPOL_IRF, 'fits', output_file_name)
    if os.path.exists(output_file_path):
        rm(output_file_path)
    logger.info('Creating PRIMARY HDU...')
    primary_hdu = xPrimaryHDU('ximpol', XIPE_KEYWORDS, XIPE_COMMENTS)
    print(repr(primary_hdu.header))
    logger.info('Creating PSF HDU...')
    data = PSF_PARAMETERS
    psf_hdu = xBinTableHDUPSF(data, [], XIPE_COMMENTS)
    print(repr(psf_hdu.header))
    logger.info('Writing output file %s...' % output_file_path)
    hdulist = fits.HDUList([primary_hdu, psf_hdu])
    hdulist.info()
    hdulist.writeto(output_file_path)
    logger.info('Done.')
Esempio n. 13
0
 def delete_event_files(self):
     """Remove all the event files generated by the pipeline.
     """
     for file_path in self.event_files:
         rm(file_path)
Esempio n. 14
0
 def delete_event_files(self):
     """Remove all the event files generated by the pipeline.
     """
     for file_path in self.event_files:
         rm(file_path)