예제 #1
0
파일: fermi.py 프로젝트: fjhzwl/gammapy
    def spectral_model(self):
        """Best fit spectral model (`~gammapy.modeling.models.SpectralModel`)."""
        spec_type = self.data["SpectrumType"].strip()

        pars, errs = {}, {}
        pars["reference"] = self.data["Pivot_Energy"]

        if spec_type == "PowerLaw":
            pars["amplitude"] = self.data["PL_Flux_Density"]
            pars["index"] = self.data["PL_Index"]
            errs["amplitude"] = self.data["Unc_PL_Flux_Density"]
            errs["index"] = self.data["Unc_PL_Index"]
            model = PowerLawSpectralModel(**pars)
        elif spec_type == "LogParabola":
            pars["amplitude"] = self.data["LP_Flux_Density"]
            pars["alpha"] = self.data["LP_Index"]
            pars["beta"] = self.data["LP_beta"]
            errs["amplitude"] = self.data["Unc_LP_Flux_Density"]
            errs["alpha"] = self.data["Unc_LP_Index"]
            errs["beta"] = self.data["Unc_LP_beta"]
            model = LogParabolaSpectralModel(**pars)
        elif spec_type == "PLSuperExpCutoff":
            pars["amplitude"] = self.data["PLEC_Flux_Density"]
            pars["index_1"] = self.data["PLEC_Index"]
            pars["index_2"] = self.data["PLEC_Exp_Index"]
            pars["expfactor"] = self.data["PLEC_Expfactor"]
            errs["amplitude"] = self.data["Unc_PLEC_Flux_Density"]
            errs["index_1"] = self.data["Unc_PLEC_Index"]
            errs["index_2"] = np.nan_to_num(self.data["Unc_PLEC_Exp_Index"])
            errs["expfactor"] = self.data["Unc_PLEC_Expfactor"]
            model = SuperExpCutoffPowerLaw4FGLSpectralModel(**pars)
        else:
            raise ValueError(f"Invalid spec_type: {spec_type!r}")

        model.parameters.set_parameter_errors(errs)
        return model
예제 #2
0
     model=ExpCutoffPowerLaw3FGLSpectralModel(
         index=2.3 * u.Unit(""),
         amplitude=4 / u.cm ** 2 / u.s / u.TeV,
         reference=1 * u.TeV,
         ecut=10 * u.TeV,
     ),
     val_at_2TeV=u.Quantity(0.7349563611124971, "cm-2 s-1 TeV-1"),
     integral_1_10TeV=u.Quantity(2.6034046173089, "cm-2 s-1"),
     eflux_1_10TeV=u.Quantity(5.340285560055799, "TeV cm-2 s-1"),
 ),
 dict(
     name="plsec_4fgl",
     model=SuperExpCutoffPowerLaw4FGLSpectralModel(
         index_1=1.5,
         index_2=2,
         amplitude=1 / u.cm ** 2 / u.s / u.TeV,
         reference=1 * u.TeV,
         expfactor=1e-2,
     ),
     val_at_2TeV=u.Quantity(0.3431043087721737, "cm-2 s-1 TeV-1"),
     integral_1_10TeV=u.Quantity(1.2125247, "cm-2 s-1"),
     eflux_1_10TeV=u.Quantity(3.38072082, "TeV cm-2 s-1"),
 ),
 dict(
     name="logpar",
     model=LogParabolaSpectralModel(
         alpha=2.3 * u.Unit(""),
         amplitude=4 / u.cm ** 2 / u.s / u.TeV,
         reference=1 * u.TeV,
         beta=0.5 * u.Unit(""),
     ),
예제 #3
0
# ------------
# Here is an example plot of the model:

from astropy import units as u
import matplotlib.pyplot as plt
from gammapy.modeling.models import (
    Models,
    SkyModel,
    SuperExpCutoffPowerLaw4FGLSpectralModel,
)

energy_range = [0.1, 100] * u.TeV
model = SuperExpCutoffPowerLaw4FGLSpectralModel(
    index_1=1,
    index_2=2,
    amplitude="1e-12 TeV-1 cm-2 s-1",
    reference="1 TeV",
    expfactor=1e-2,
)
model.plot(energy_range)
plt.grid(which="both")
plt.ylim(1e-24, 1e-10)

# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

model = SkyModel(spectral_model=model, name="super-exp-cutoff-power-law-4fgl-model")
models = Models([model])