コード例 #1
0
def extract_aeff(exposure, target_position, energy):
    energy_log_ctr = np.sqrt(energy[1:] * energy[:-1])
    lon = target_position.galactic.l
    lat = target_position.galactic.b
    expo_values = exposure.get_by_coord((lon.value, lat.value, energy_log_ctr.value))

    table = Table(
        [energy[:-1], energy[1:], expo_values],
        names=("ENERG_LO", "ENERG_HI", "SPECRESP"),
        dtype=("float64", "float64", "float64"),
        meta={"name": "Fermi-LAT exposure"},
    )

    table["ENERG_LO"].unit = str(energy.unit)
    table["ENERG_HI"].unit = str(energy.unit)
    table["SPECRESP"].unit = "cm2"

    table.meta["EXTNAME"] = "SPECRESP"
    table.meta["TELESCOP"] = "Fermi"
    table.meta["INSTRUME"] = "LAT"
    table.meta["EXPOSURE"] = "1"
    table.meta["FILTER"] = ""
    table.meta["HDUCLASS"] = "OGIP"
    table.meta["HDUCLAS1"] = "RESPONSE"
    table.meta["HDUCLAS2"] = "SPECRESP"
    table.meta["HDUVERS"] = "1.1.0"

    return EffectiveAreaTable.from_table(table)
コード例 #2
0
def extract_aeff(exposure, target_position, energy):
    """Function to extract the effective area of Fermi-LAT starting from a
    file containing the exposure.

    We rely on the following assumption:

    1) the exposure is flat in the ROI we are considering, so we assume the
    value at the source position is valid all over the ROI

    2) since the exposure is the convolution of the effective area and time
    what we do is simply to store the exposure as it is [cm2 s] and then
    put a mock livetime of 1 s in the PHACountsSpectrum definition later on

    Parameters
    ----------
    exposure : `~gammapy.maps.HpxMapND`
        Fermi-LAT exposure
    target_position : `~astropy.coordinates.SkyCoord`
        position of the source of interest
    energy : `~astropy.units.Quantity`
        energy binning to calculate the effective area

    Returns
    -------
    `~gammapy.irf.EffectiveAreaTable`
    table containing the effective area
    """
    energy_log_ctr = np.sqrt(energy[1:] * energy[:-1])
    # the exposure is defined pixel-wise, fetch the value at source position
    lon = target_position.galactic.l
    lat = target_position.galactic.b
    expo_values = exposure.get_by_coord((lon.value, lat.value, energy_log_ctr.value))
    # generate an ARF table for the effective area
    # according to the format defined in
    # https://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.html#Sec:ARF-format
    # we will create an astropy table that can be read by EffectiveAreaTable
    # via from_table method

    # we need low and high bin edges
    table = Table(
        [energy[:-1], energy[1:], expo_values],
        names=("ENERG_LO", "ENERG_HI", "SPECRESP"),
        dtype=("float64", "float64", "float64"),
        meta={"name": "Fermi-LAT exposure"},
    )

    # declare units
    table["ENERG_LO"].unit = str(energy.unit)
    table["ENERG_HI"].unit = str(energy.unit)
    table["SPECRESP"].unit = "cm2"

    # add mandatory keywords in header
    table.meta["EXTNAME"] = "SPECRESP"
    table.meta["TELESCOP"] = "Fermi"
    table.meta["INSTRUME"] = "LAT"
    table.meta["EXPOSURE"] = "1"
    table.meta["FILTER"] = ""
    table.meta["HDUCLASS"] = "OGIP"
    table.meta["HDUCLAS1"] = "RESPONSE"
    table.meta["HDUCLAS2"] = "SPECRESP"
    table.meta["HDUVERS"] = "1.1.0"

    return EffectiveAreaTable.from_table(table)