コード例 #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.')
コード例 #2
0
ファイル: xipe.py プロジェクト: petarmimica/ximpol
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.')
コード例 #3
0
ファイル: grb_swift_mdp.py プロジェクト: lucabaldini/ximpol
def build_grb_fits_file(data,outfile):
    primary_hdu = xPrimaryHDU()
    grb_info_hdu = xBinTableGRBmain(data)
    hdu_list = fits.HDUList([primary_hdu, grb_info_hdu])
    hdu_list.info()
    logger.info('Writing GRB main infos table to %s...' % outfile)
    hdu_list.writeto(outfile, clobber=True)
    logger.info('Done.')
コード例 #4
0
ファイル: binning.py プロジェクト: pabell/ximpol
 def build_primary_hdu(self):
     """Build the primary HDU for the output file.
     """
     primary_hdu = xPrimaryHDU()
     primary_hdu.setup_header(self.event_file.primary_keywords())
     primary_hdu.add_keyword('BINALG', self.get('algorithm'),
                             'the binning algorithm used')
     primary_hdu.add_comment('%s run with kwargs %s' %\
                             (self.__class__.__name__, self.kwargs))
     return primary_hdu
コード例 #5
0
ファイル: binning.py プロジェクト: pabell/ximpol
 def build_primary_hdu(self):
     """Build the primary HDU for the output file.
     """
     primary_hdu = xPrimaryHDU()
     primary_hdu.setup_header(self.event_file.primary_keywords())
     primary_hdu.add_keyword('BINALG', self.get('algorithm'),
                             'the binning algorithm used')
     primary_hdu.add_comment('%s run with kwargs %s' %\
                             (self.__class__.__name__, self.kwargs))
     return primary_hdu
コード例 #6
0
ファイル: event.py プロジェクト: lucabaldini/ximpol
    def write_fits(self, file_path, simulation_info):
        """Write the event list and associated ancillary information to file.

        Arguments
        ---------
        file_path : str
            The path to the output file.

        simulation_info :
            A generic container with all the relevant information about the
            simulation.

        Warning
        -------
        The information about the detector and telescope should be in the
        primary header of the IRF tables, and that's where we should be
        retrieving it from. (See issue #49.)
        """
        primary_hdu = xPrimaryHDU()
        roi_model = simulation_info.roi_model
        irf_name = simulation_info.irf_name
        ebounds_header = simulation_info.edisp.hdu_list['EBOUNDS'].header
        gti_list = simulation_info.gti_list
        keywords = [
            ('ROIRA'   , roi_model.ra , 'right ascension of the ROI center'),
            ('ROIDEC'  , roi_model.dec, 'declination of the ROI center'),
            ('EQUINOX' , 2000.        , 'equinox for RA and DEC'),
            ('IRFNAME' , irf_name     , 'name of the IRFs used for the MC'),
            ('TELESCOP', ebounds_header['TELESCOP']),
            ('INSTRUME', ebounds_header['INSTRUME']),
            ('DETNAM'  , ebounds_header['DETNAM']),
            ('DETCHANS', ebounds_header['DETCHANS'])
        ]
        primary_hdu.setup_header(keywords)
        data = [self[name] for name in\
                xBinTableHDUMonteCarloEvents.spec_names()]
        event_hdu = xBinTableHDUMonteCarloEvents(data)
        _start = numpy.array([gti[0] for gti in gti_list])
        _stop = numpy.array([gti[1] for gti in gti_list])
        gti_hdu = xBinTableHDUGTI([_start, _stop])
        _src_id = numpy.array([src.identifier for src in roi_model.values()])
        _src_name = numpy.array([src.name for src in roi_model.values()])
        roi_hdu = xBinTableHDURoiTable([_src_id, _src_name])
        hdu_list = fits.HDUList([primary_hdu, event_hdu, gti_hdu, roi_hdu])
        hdu_list.info()
        hdu_list.writeto(file_path, clobber=True)
        logger.info('Event list written to %s...' % file_path)
コード例 #7
0
ファイル: xipe.py プロジェクト: petarmimica/ximpol
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.')
コード例 #8
0
ファイル: event.py プロジェクト: pabell/ximpol
    def write_fits(self, file_path, simulation_info):
        """Write the event list and associated ancillary information to file.

        Arguments
        ---------
        file_path : str
            The path to the output file.

        simulation_info :
            A generic container with all the relevant information about the
            simulation.

        Warning
        -------
        The information about the detector and telescope should be in the
        primary header of the IRF tables, and that's where we should be
        retrieving it from. (See issue #49.)
        """
        primary_hdu = xPrimaryHDU()
        roi_model = simulation_info.roi_model
        irf_name = simulation_info.irf_name
        ebounds_header = simulation_info.edisp.hdu_list['EBOUNDS'].header
        gti_list = simulation_info.gti_list
        keywords = [('ROIRA', roi_model.ra,
                     'right ascension of the ROI center'),
                    ('ROIDEC', roi_model.dec, 'declination of the ROI center'),
                    ('EQUINOX', 2000., 'equinox for RA and DEC'),
                    ('IRFNAME', irf_name, 'name of the IRFs used for the MC'),
                    ('TELESCOP', ebounds_header['TELESCOP']),
                    ('INSTRUME', ebounds_header['INSTRUME']),
                    ('DETNAM', ebounds_header['DETNAM']),
                    ('DETCHANS', ebounds_header['DETCHANS'])]
        primary_hdu.setup_header(keywords)
        data = [self[name] for name in\
                xBinTableHDUMonteCarloEvents.spec_names()]
        event_hdu = xBinTableHDUMonteCarloEvents(data)
        _start = numpy.array([gti[0] for gti in gti_list])
        _stop = numpy.array([gti[1] for gti in gti_list])
        gti_hdu = xBinTableHDUGTI([_start, _stop])
        _src_id = numpy.array([src.identifier for src in roi_model.values()])
        _src_name = numpy.array([src.name for src in roi_model.values()])
        roi_hdu = xBinTableHDURoiTable([_src_id, _src_name])
        hdu_list = fits.HDUList([primary_hdu, event_hdu, gti_hdu, roi_hdu])
        hdu_list.info()
        hdu_list.writeto(file_path, clobber=True)
        logger.info('Event list written to %s...' % file_path)
コード例 #9
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.')
コード例 #10
0
ファイル: xipe.py プロジェクト: petarmimica/ximpol
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.')
コード例 #11
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.')
コード例 #12
0
ファイル: xipe.py プロジェクト: petarmimica/ximpol
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.')
コード例 #13
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.')