Exemplo n.º 1
0
    def _ebounds_hdu(self, use_sherpa):
        energy = self.counts.energy.edges

        if use_sherpa:
            energy = energy.to("keV")

        return energy_axis_to_ebounds(energy)
Exemplo n.º 2
0
    def to_hdulist(self, use_sherpa=False, **kwargs):
        """Convert RMF to FITS HDU list format.

        Parameters
        ----------
        header : `~astropy.io.fits.Header`
            Header to be written in the fits file.
        energy_unit : str
            Unit in which the energy is written in the HDU list

        Returns
        -------
        hdulist : `~astropy.io.fits.HDUList`
            RMF in HDU list format.

        Notes
        -----
        For more info on the RMF FITS file format see:
        https://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal_gen_92_002_summary.html
        """
        # Cannot use table_to_fits here due to variable length array
        # http://docs.astropy.org/en/v1.0.4/io/fits/usage/unfamiliar.html

        table = self.to_table()
        name = table.meta.pop("name")

        header = fits.Header()
        header.update(table.meta)

        if use_sherpa:
            table["ENERG_HI"] = table["ENERG_HI"].quantity.to("keV")
            table["ENERG_LO"] = table["ENERG_LO"].quantity.to("keV")

        cols = table.columns
        c0 = fits.Column(name=cols[0].name,
                         format="E",
                         array=cols[0],
                         unit=str(cols[0].unit))
        c1 = fits.Column(name=cols[1].name,
                         format="E",
                         array=cols[1],
                         unit=str(cols[1].unit))
        c2 = fits.Column(name=cols[2].name, format="I", array=cols[2])
        c3 = fits.Column(name=cols[3].name, format="PI()", array=cols[3])
        c4 = fits.Column(name=cols[4].name, format="PI()", array=cols[4])
        c5 = fits.Column(name=cols[5].name, format="PE()", array=cols[5])

        hdu = fits.BinTableHDU.from_columns([c0, c1, c2, c3, c4, c5],
                                            header=header,
                                            name=name)

        energy = self.e_reco.edges

        if use_sherpa:
            energy = energy.to("keV")

        ebounds = energy_axis_to_ebounds(energy)
        prim_hdu = fits.PrimaryHDU()

        return fits.HDUList([prim_hdu, hdu, ebounds])
Exemplo n.º 3
0
    def to_hdulist(self, use_sherpa=False):
        """Convert to `~astropy.io.fits.HDUList`.

        This adds an ``EBOUNDS`` extension to the ``BinTableHDU`` produced by
        ``to_table``, in order to store the energy axis
        """
        table = self.to_table()
        name = table.meta["name"]
        hdu = fits.BinTableHDU(table, name=name)

        energy = self.energy.edges

        if use_sherpa:
            energy = energy.to("keV")

        ebounds = energy_axis_to_ebounds(energy)
        return fits.HDUList([fits.PrimaryHDU(), hdu, ebounds])
Exemplo n.º 4
0
def make_images_several_energyband(image_size,
                                   energy_bins,
                                   offset_band,
                                   source_name,
                                   center,
                                   data_store,
                                   obs_table_subset,
                                   exclusion_mask,
                                   outdir,
                                   make_background_image=True,
                                   spectral_index=2.3,
                                   for_integral_flux=False,
                                   radius=10.,
                                   save_bkg_norm=True):
    """
    MAke the counts, bkg, mask, exposure, significance and ecxees images for different energy bands

    Parameters
    ----------
    energy_bins: array of energy bands on which you want to compute the map
    offset_band: offset band on which you want to compute the map
    center: SkyCoord of the source
    data_store: DataStore object containing the data used to coompute the image
    obs_table_subset: obs_table of the data_store containing the observations you want to use to compute the image. Could
    be smaller than the one of the datastore
    exclusion_mask: SkyMask used for the escluded regions
    outdir: directory where the fits image will go
    make_background_image: if you want to compute the bkg for the images. Most of the case yes otherwise there is only the counts image
    spectral_index: assumed spectral index to compute the exposure
    for_integral_flux: True if you want to get the inegrak flux with the exposure
    radius: Disk radius in pixels for the significance

    Returns
    -------
    """
    list_mosaicimages = list()
    for i, E in enumerate(energy_bins[0:-1]):
        energy_band = Energy([energy_bins[i].value, energy_bins[i + 1].value],
                             energy_bins.unit)
        print energy_band
        mosaicimages = make_images(image_size, energy_band, offset_band,
                                   center, data_store, obs_table_subset,
                                   exclusion_mask, outdir,
                                   make_background_image, spectral_index,
                                   for_integral_flux, radius, save_bkg_norm)
        list_mosaicimages.append(mosaicimages)
    if save_bkg_norm:
        table = Table()
        for i, mosaic_images in enumerate(list_mosaicimages):
            table_bkg = mosaic_images.table_bkg_scale
            if i == 0:
                array_bkg_scale = np.zeros(
                    (len(obs_table_subset), len(energy_bins[0:-1])))
                array_counts = np.zeros(
                    (len(obs_table_subset), len(energy_bins[0:-1])))
            itot = 0
            for irun, run in enumerate(table_bkg["OBS_ID"]):
                while run != obs_table_subset["OBS_ID"][itot]:
                    itot += 1
                array_bkg_scale[itot, i] = table_bkg["bkg_scale"][irun]
                array_counts[itot, i] = table_bkg["N_counts"][irun]
                itot += 1
        c0 = fits.Column(name="OBS_ID",
                         format='E',
                         array=table_bkg["OBS_ID"].data)
        c1 = fits.Column(name="bkg_norm", format='PE()', array=array_bkg_scale)
        c2 = fits.Column(name="counts", format='PE()', array=array_counts)
        hdu = fits.BinTableHDU.from_columns([c0, c1, c2])
        ebounds = energy_axis_to_ebounds(energy_bins)
        #ebounds = energy_axis_to_ebounds(BinnedDataAxis(energy_bins[0:-1],energy_bins[1:]))
        prim_hdu = fits.PrimaryHDU()
        hdu_list = fits.HDUList([prim_hdu, hdu, ebounds])
        hdu_list.writeto(outdir + "/table_bkg_norm_.fits")