Example #1
0
def test_integral_error_power_law():
    energy = np.linspace(1 * u.TeV, 10 * u.TeV, 10)
    energy_min = energy[:-1]
    energy_max = energy[1:]

    powerlaw = PowerLawSpectralModel()
    powerlaw.parameters["index"].error = 0.4
    powerlaw.parameters["amplitude"].error = 1e-13

    flux, flux_error = powerlaw.integral_error(energy_min, energy_max)

    assert_allclose(flux.value[0] / 1e-13, 5.0, rtol=1e-3)
    assert_allclose(flux_error.value[0] / 1e-14, 7.915984, rtol=1e-3)
Example #2
0
def test_integral_error_PowerLaw():
    energy = np.linspace(1 * u.TeV, 10 * u.TeV, 10)
    emin = energy[:-1]
    emax = energy[1:]

    powerlaw = PowerLawSpectralModel()
    powerlaw.parameters['index'].error = 0.4
    powerlaw.parameters['amplitude'].error = 1e-13

    flux, flux_error = powerlaw.integral_error(emin, emax)

    assert_allclose(flux.value[0] / 1e-13, 5.0, rtol=0.1)
    assert_allclose(flux_error.value[0] / 1e-14, 8.546615432273905, rtol=0.01)
Example #3
0
def test_pwl_index_2_error():
    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=1e-13 * u.Unit("TeV-1 cm-2 s-1"))

    val, val_err = pwl.evaluate_error(1 * u.TeV)
    assert_quantity_allclose(val, 1e-12 * u.Unit("TeV-1 cm-2 s-1"))
    assert_quantity_allclose(val_err, 0.1e-12 * u.Unit("TeV-1 cm-2 s-1"))

    flux, flux_err = pwl.integral_error(1 * u.TeV, 10 * u.TeV)
    assert_quantity_allclose(flux, 9e-13 * u.Unit("cm-2 s-1"))
    assert_quantity_allclose(flux_err, 9e-14 * u.Unit("cm-2 s-1"))

    eflux, eflux_err = pwl.energy_flux_error(1 * u.TeV, 10 * u.TeV)
    assert_quantity_allclose(eflux, 2.302585e-12 * u.Unit("TeV cm-2 s-1"))
    assert_quantity_allclose(eflux_err, 0.2302585e-12 * u.Unit("TeV cm-2 s-1"))
Example #4
0
def test_pwl_index_2_error():
    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)

    val, val_err = pwl.evaluate_error(1 * u.TeV)
    assert_quantity_allclose(val, 1e-12 * u.Unit("TeV-1 cm-2 s-1"))
    assert_quantity_allclose(val_err, 0.1e-12 * u.Unit("TeV-1 cm-2 s-1"))

    flux, flux_err = pwl.integral_error(1 * u.TeV, 10 * u.TeV)
    assert_quantity_allclose(flux, 9e-13 * u.Unit("cm-2 s-1"))
    assert_quantity_allclose(flux_err, 9e-14 * u.Unit("cm-2 s-1"))

    eflux, eflux_err = pwl.energy_flux_error(1 * u.TeV, 10 * u.TeV)
    assert_quantity_allclose(eflux, 2.302585e-12 * u.Unit("TeV cm-2 s-1"))
    assert_quantity_allclose(eflux_err, 0.2302585e-12 * u.Unit("TeV cm-2 s-1"))