Example #1
0
def test_model_plot_sed_type():
    pwl = PowerLawSpectralModel(
        amplitude=1e-12 * u.Unit("TeV-1 cm-2 s-1"), reference=1 * u.Unit("TeV"), index=2
    )
    pwl.amplitude.error = 0.1e-12 * u.Unit("TeV-1 cm-2 s-1")

    with mpl_plot_check():
        ax1 = pwl.plot((1 * u.TeV, 100 * u.TeV), sed_type="dnde")
        ax2 = pwl.plot_error((1 * u.TeV, 100 * u.TeV), sed_type="dnde")
        assert ax1.axes.axes.get_ylabel() == "dnde [1 / (cm2 s TeV)]"
        assert ax2.axes.axes.get_ylabel() == "dnde [1 / (cm2 s TeV)]"

    with mpl_plot_check():
        ax1 = pwl.plot((1 * u.TeV, 100 * u.TeV), sed_type="e2dnde")
        ax2 = pwl.plot_error((1 * u.TeV, 100 * u.TeV), sed_type="e2dnde")
        assert ax1.axes.axes.get_ylabel() == "e2dnde [erg / (cm2 s)]"
        assert ax2.axes.axes.get_ylabel() == "e2dnde [erg / (cm2 s)]"

    with mpl_plot_check():
        ax1 = pwl.plot((1 * u.TeV, 100 * u.TeV), sed_type="flux")
        ax2 = pwl.plot_error((1 * u.TeV, 100 * u.TeV), sed_type="flux")
        assert ax1.axes.axes.get_ylabel() == "flux [1 / (cm2 s)]"
        assert ax2.axes.axes.get_ylabel() == "flux [1 / (cm2 s)]"

    with mpl_plot_check():
        ax1 = pwl.plot((1 * u.TeV, 100 * u.TeV), sed_type="eflux")
        ax2 = pwl.plot_error((1 * u.TeV, 100 * u.TeV), sed_type="eflux")
        assert ax1.axes.axes.get_ylabel() == "eflux [erg / (cm2 s)]"
        assert ax2.axes.axes.get_ylabel() == "eflux [erg / (cm2 s)]"
Example #2
0
def test_model_plot():
    pwl = PowerLawSpectralModel(amplitude=1e-12 * u.Unit("TeV-1 cm-2 s-1"),
                                reference=1 * u.Unit("TeV"),
                                index=2)
    pwl.parameters.set_error(amplitude=0.1e-12 * u.Unit("TeV-1 cm-2 s-1"))
    with mpl_plot_check():
        pwl.plot((1 * u.TeV, 10 * u.TeV))

    with mpl_plot_check():
        pwl.plot_error((1 * u.TeV, 10 * u.TeV))
Example #3
0
def test_model_plot():
    pars, errs = {}, {}
    pars["amplitude"] = 1e-12 * u.Unit("TeV-1 cm-2 s-1")
    pars["reference"] = 1 * u.Unit("TeV")
    pars["index"] = 2 * u.Unit("")
    errs["amplitude"] = 0.1e-12 * u.Unit("TeV-1 cm-2 s-1")

    pwl = PowerLawSpectralModel(**pars)
    pwl.parameters.set_parameter_errors(errs)
    with mpl_plot_check():
        pwl.plot((1 * u.TeV, 10 * u.TeV))

    with mpl_plot_check():
        pwl.plot_error((1 * u.TeV, 10 * u.TeV))
Example #4
0
# In[ ]:

print(pwl)

# Finally we plot the data points and the best fit model:

# In[ ]:

ax = flux_points.plot(energy_power=2)
pwl.plot(energy_range=[1e-4, 1e2] * u.TeV, ax=ax, energy_power=2)

# assign covariance for plotting
pwl.parameters.covariance = result_pwl.parameters.covariance

pwl.plot_error(energy_range=[1e-4, 1e2] * u.TeV, ax=ax, energy_power=2)
ax.set_ylim(1e-13, 1e-11)

# ## Exponential Cut-Off Powerlaw Fit
#
# Next we fit an `~gammapy.modeling.models.ExpCutoffPowerLawSpectralModel` law to the data.

# In[ ]:

ecpl = ExpCutoffPowerLawSpectralModel(
    index=1.8,
    amplitude="2e-12 cm-2 s-1 TeV-1",
    reference="1 TeV",
    lambda_="0.1 TeV-1",
)
model = SkyModel(spectral_model=ecpl)