Ejemplo n.º 1
0
def test_lightcurve_estimator_spectrum_datasets_withmaskfit():
    # Doing a LC on one hour bin
    datasets = get_spectrum_datasets()
    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T01:00:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]

    e_min_fit = 1 * u.TeV
    e_max_fit = 3 * u.TeV
    for dataset in datasets:
        mask_fit = dataset.counts.energy_mask(emin=e_min_fit, emax=e_max_fit)
        dataset.mask_fit = mask_fit

    steps = ["err", "counts", "ts", "norm-scan"]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    lightcurve = estimator.run(
        e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps
    )
    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["stat"], [6.60304, 0.421047], rtol=1e-5)
    assert_allclose(lightcurve.table["norm"], [0.885082, 0.967022], rtol=1e-5)
Ejemplo n.º 2
0
def test_lightcurve_estimator_map_datasets():
    datasets = get_map_datasets()

    estimator = LightCurveEstimator(datasets, source="source")
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(e_ref=10 * u.TeV,
                               e_min=1 * u.TeV,
                               e_max=100 * u.TeV,
                               steps=steps)

    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10, 10])
    assert_allclose(lightcurve.table["e_min"], [1, 1])
    assert_allclose(lightcurve.table["e_max"], [100, 100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-13, 1e-13])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-12, 9.9e-12])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-11, 4.60517e-11])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-11, 1e-11])
    assert_allclose(lightcurve.table["loglike"],
                    [-86541.447142, -89740.436161])
    assert_allclose(lightcurve.table["norm_err"], [0.042729, 0.042469],
                    rtol=1e-4)
    assert_allclose(lightcurve.table["counts"], [46648, 47321])
    assert_allclose(lightcurve.table["sqrt_ts"], [54.034112, 53.920883],
                    rtol=1e-5)
    assert_allclose(lightcurve.table["ts"], [2919.685309, 2907.461611],
                    rtol=1e-5)
Ejemplo n.º 3
0
def test_lightcurve_estimator_spectrum_datasets():
    # Doing a LC on one hour bin
    datasets = get_spectrum_datasets()
    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T01:00:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    lightcurve = estimator.run(e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV)
    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10, 10])
    assert_allclose(lightcurve.table["e_min"], [1, 1])
    assert_allclose(lightcurve.table["e_max"], [100, 100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-14, 1e-14])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-13, 9.9e-13])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-12, 4.60517e-12])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-12, 1e-12])
    assert_allclose(lightcurve.table["stat"], [23.302288, 22.457766], rtol=1e-5)
    assert_allclose(lightcurve.table["norm"], [0.988127, 0.948108], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_err"], [0.043985, 0.043498], rtol=1e-4)
    assert_allclose(lightcurve.table["counts"], [2281, 2222])
    assert_allclose(lightcurve.table["norm_errp"], [0.044231, 0.04377], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_errn"], [0.04374, 0.043226], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_ul"], [1.077213, 1.036237], rtol=1e-5)
    assert_allclose(lightcurve.table["sqrt_ts"], [26.773925, 25.796426], rtol=1e-4)
    assert_allclose(lightcurve.table["ts"], [716.843084, 665.455601], rtol=1e-4)
    assert_allclose(lightcurve.table[0]["norm_scan"], [0.2, 1.0, 5.0])
    assert_allclose(
        lightcurve.table[0]["stat_scan"],
        [444.426957, 23.375417, 3945.382802],
        rtol=1e-5,
    )
Ejemplo n.º 4
0
def test_lightcurve_estimator_spectrum_datasets():
    datasets = get_spectrum_datasets()

    estimator = LightCurveEstimator(datasets, norm_n_values=3)
    lightcurve = estimator.run(e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV)

    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10, 10])
    assert_allclose(lightcurve.table["e_min"], [1, 1])
    assert_allclose(lightcurve.table["e_max"], [100, 100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-14, 1e-14])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-13, 9.9e-13])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-12, 4.60517e-12])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-12, 1e-12])
    assert_allclose(lightcurve.table["loglike"], [23.302288, 22.457766], rtol=1e-5)
    assert_allclose(lightcurve.table["norm"], [0.988127, 0.948108], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_err"], [0.043985, 0.043498], rtol=1e-4)
    assert_allclose(lightcurve.table["counts"], [2281, 2222])
    assert_allclose(lightcurve.table["norm_errp"], [0.044231, 0.04377], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_errn"], [0.04374, 0.043226], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_ul"], [1.077213, 1.036237], rtol=1e-5)
    assert_allclose(lightcurve.table["sqrt_ts"], [37.16802, 37.168033], rtol=1e-5)
    assert_allclose(lightcurve.table["ts"], [1381.461738, 1381.462675], rtol=1e-5)
    assert_allclose(lightcurve.table[0]["norm_scan"], [0.2, 1.0, 5.0])
    assert_allclose(
        lightcurve.table[0]["dloglike_scan"],
        [444.426957, 23.375417, 3945.382802],
        rtol=1e-5,
    )
Ejemplo n.º 5
0
def test_lightcurve_estimator_spectrum_datasets_largerbin():
    # Test all dataset in a single LC bin, here two hours
    datasets = get_spectrum_datasets()
    time_intervals = [Time(["2010-01-01T00:00:00", "2010-01-01T02:00:00"])]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(
        e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps
    )

    assert_allclose(lightcurve.table["time_min"], [55197.0])
    assert_allclose(lightcurve.table["time_max"], [55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10])
    assert_allclose(lightcurve.table["e_min"], [1])
    assert_allclose(lightcurve.table["e_max"], [100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-14])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-13])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-12])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-12])
    assert_allclose(lightcurve.table["stat"], [46.177981], rtol=1e-5)
    assert_allclose(lightcurve.table["norm"], [0.968049], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_err"], [0.030929], rtol=1e-4)
    assert_allclose(lightcurve.table["ts"], [1381.880757], rtol=1e-4)
def data_fit(datasets):
    lc_maker_1d = LightCurveEstimator(datasets,
                                      source="crab",
                                      reoptimize=False)
    lc_1d = lc_maker_1d.run(e_ref=1 * u.TeV,
                            e_min=1.0 * u.TeV,
                            e_max=10.0 * u.TeV)
Ejemplo n.º 7
0
def test_lightcurve_estimator_map_datasets():
    datasets = get_map_datasets()

    estimator = LightCurveEstimator(datasets, source="source")
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(
        e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps
    )

    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10, 10])
    assert_allclose(lightcurve.table["e_min"], [1, 1])
    assert_allclose(lightcurve.table["e_max"], [100, 100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-13, 1e-13])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-12, 9.9e-12])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-11, 4.60517e-11])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-11, 1e-11])
    assert_allclose(
        lightcurve.table["loglike"], [-86845.74348, -90386.086642], rtol=1e-5
    )
    assert_allclose(lightcurve.table["norm_err"], [0.041529, 0.041785], rtol=1e-3)
    assert_allclose(lightcurve.table["counts"], [46702, 47508])
    assert_allclose(lightcurve.table["sqrt_ts"], [54.503321, 54.296488], atol=0.01)
    assert_allclose(lightcurve.table["ts"], [2970.61202, 2948.108572], atol=0.01)
Ejemplo n.º 8
0
def test_lightcurve_estimator_map_datasets():
    datasets = get_map_datasets()

    estimator = LightCurveEstimator(datasets, source="source")
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(e_ref=10 * u.TeV,
                               e_min=1 * u.TeV,
                               e_max=100 * u.TeV,
                               steps=steps)

    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10, 10])
    assert_allclose(lightcurve.table["e_min"], [1, 1])
    assert_allclose(lightcurve.table["e_max"], [100, 100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-13, 1e-13])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-12, 9.9e-12])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-11, 4.60517e-11])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-11, 1e-11])
    assert_allclose(lightcurve.table["loglike"],
                    [-87130.477068, -89848.520203],
                    rtol=1e-5)
    assert_allclose(lightcurve.table["norm_err"], [0.042941, 0.040918],
                    rtol=1e-3)
    assert_allclose(lightcurve.table["counts"], [46804, 47417])
    assert_allclose(lightcurve.table["sqrt_ts"], [55.505477, 55.342541],
                    atol=0.01)
    assert_allclose(lightcurve.table["ts"], [3080.857998, 3062.796807],
                    atol=0.01)
Ejemplo n.º 9
0
def test_lightcurve_estimator_spectrum_datasets_default():
    # Test default time interval: each time interval is equal to the gti of each dataset, here one hour
    datasets = get_spectrum_datasets()
    estimator = LightCurveEstimator(datasets, norm_n_values=3)
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(
        e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps
    )
    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["norm"], [0.988127, 0.948108], rtol=1e-5)
Ejemplo n.º 10
0
def test_group_datasets_in_time_interval_outflows():
    datasets = get_spectrum_datasets()
    # Check Overflow
    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T00:55:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    steps = ["err", "counts", "ts", "norm-scan"]
    estimator.run(e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps)
    assert estimator.group_table_info["Bin_type"][0] == "Overflow"

    # Check underflow
    time_intervals = [
        Time(["2010-01-01T00:05:00", "2010-01-01T01:00:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    steps = ["err", "counts", "ts", "norm-scan"]
    estimator.run(e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps)
    assert estimator.group_table_info["Bin_type"][0] == "Underflow"
Ejemplo n.º 11
0
def test_lightcurve_estimator_spectrum_datasets_gti_not_include_in_time_intervals():
    # Check that it returns a ValueError if the time intervals are smaller than the dataset GTI.
    datasets = get_spectrum_datasets()
    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T00:05:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T01:05:00"]),
    ]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    with pytest.raises(ValueError) as excinfo:
        steps = ["err", "counts", "ts", "norm-scan"]
        estimator.run(e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps)
    msg = "LightCurveEstimator: No datasets in time intervals"
    assert str(excinfo.value) == msg
Ejemplo n.º 12
0
def test_lightcurve_estimator_spectrum_datasets_notordered():
    # Test that if the time intervals given are not ordered in time, it is first ordered correctly and then
    # compute as expected
    datasets = get_spectrum_datasets()
    time_intervals = [
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
        Time(["2010-01-01T00:00:00", "2010-01-01T01:00:00"]),
    ]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(
        e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps
    )
    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["norm"], [0.988127, 0.948108], rtol=1e-5)
Ejemplo n.º 13
0
def test_lightcurve_estimator_spectrum_datasets_timeoverlaped():
    # Check that it returns a ValueError if the time intervals overlapped
    datasets = get_spectrum_datasets()
    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T01:30:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]
    with pytest.raises(ValueError) as excinfo:
        LightCurveEstimator(datasets, norm_n_values=3, time_intervals=time_intervals)
    msg = "LightCurveEstimator requires non-overlapping time bins."
    assert str(excinfo.value) == msg
Ejemplo n.º 14
0
def test_group_datasets_in_time_interval():
    # Doing a LC on one hour bin
    datasets = get_spectrum_datasets()
    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T01:00:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]
    estimator = LightCurveEstimator(
        datasets, norm_n_values=3, time_intervals=time_intervals
    )
    steps = ["err", "counts", "ts", "norm-scan"]
    estimator.run(e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps)

    assert len(estimator.group_table_info) == 2
    assert estimator.group_table_info["Name"][0] == "dataset_1"
    assert_allclose(estimator.group_table_info["Tstart"], [55197.0, 55197.04166666667])
    assert_allclose(
        estimator.group_table_info["Tstop"], [55197.04166666667, 55197.083333333336]
    )
    assert_allclose(estimator.group_table_info["Group_ID"], [0, 1])
Ejemplo n.º 15
0
def test_lightcurve_estimator_map_datasets():
    datasets = get_map_datasets()

    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T01:00:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]
    estimator = LightCurveEstimator(datasets,
                                    source="source",
                                    time_intervals=time_intervals)
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(e_ref=10 * u.TeV,
                               e_min=1 * u.TeV,
                               e_max=100 * u.TeV,
                               steps=steps)
    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10, 10])
    assert_allclose(lightcurve.table["e_min"], [1, 1])
    assert_allclose(lightcurve.table["e_max"], [100, 100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-13, 1e-13])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-12, 9.9e-12])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-11, 4.60517e-11])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-11, 1e-11])
    assert_allclose(lightcurve.table["stat"], [-86845.74348, -90386.086642],
                    rtol=1e-5)
    assert_allclose(lightcurve.table["norm_err"], [0.041529, 0.041785],
                    rtol=1e-3)
    assert_allclose(lightcurve.table["sqrt_ts"], [39.016115, 37.766553],
                    atol=0.01)
    assert_allclose(lightcurve.table["ts"], [1522.257266, 1426.31252],
                    atol=0.01)

    datasets = get_map_datasets()
    time_intervals2 = [Time(["2010-01-01T00:00:00", "2010-01-01T02:00:00"])]
    estimator2 = LightCurveEstimator(datasets,
                                     source="source",
                                     time_intervals=time_intervals2)
    lightcurve2 = estimator2.run(e_ref=10 * u.TeV,
                                 e_min=1 * u.TeV,
                                 e_max=100 * u.TeV)

    assert_allclose(lightcurve2.table["time_min"], [55197.0])
    assert_allclose(lightcurve2.table["time_max"], [55197.083333])
    assert_allclose(lightcurve2.table["e_ref"], [10])
    assert_allclose(lightcurve2.table["e_min"], [1])
    assert_allclose(lightcurve2.table["e_max"], [100])
    assert_allclose(lightcurve2.table["ref_dnde"], [1e-13])
    assert_allclose(lightcurve2.table["ref_flux"], [9.9e-12])
    assert_allclose(lightcurve2.table["ref_eflux"], [4.60517e-11])
    assert_allclose(lightcurve2.table["ref_e2dnde"], [1e-11])
    assert_allclose(lightcurve2.table["stat"], [-177231.653683], rtol=1e-5)
    assert_allclose(lightcurve2.table["norm_err"], [0.029441], rtol=1e-3)
    assert_allclose(lightcurve.table["counts"], [46702, 47508])
    assert_allclose(lightcurve2.table["ts"], [2948.403853], atol=0.01)
Ejemplo n.º 16
0
def test_lightcurve_estimator_map_datasets():
    datasets = get_map_datasets()

    time_intervals = [
        Time(["2010-01-01T00:00:00", "2010-01-01T01:00:00"]),
        Time(["2010-01-01T01:00:00", "2010-01-01T02:00:00"]),
    ]
    estimator = LightCurveEstimator(
        datasets, source="source", time_intervals=time_intervals
    )
    steps = ["err", "counts", "ts", "norm-scan"]
    lightcurve = estimator.run(
        e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV, steps=steps
    )
    assert_allclose(lightcurve.table["time_min"], [55197.0, 55197.041667])
    assert_allclose(lightcurve.table["time_max"], [55197.041667, 55197.083333])
    assert_allclose(lightcurve.table["e_ref"], [10, 10])
    assert_allclose(lightcurve.table["e_min"], [1, 1])
    assert_allclose(lightcurve.table["e_max"], [100, 100])
    assert_allclose(lightcurve.table["ref_dnde"], [1e-13, 1e-13])
    assert_allclose(lightcurve.table["ref_flux"], [9.9e-12, 9.9e-12])
    assert_allclose(lightcurve.table["ref_eflux"], [4.60517e-11, 4.60517e-11])
    assert_allclose(lightcurve.table["ref_e2dnde"], [1e-11, 1e-11])
    assert_allclose(lightcurve.table["stat"], [-87412.393367, -89856.129206], rtol=1e-5)
    assert_allclose(lightcurve.table["norm_err"], [0.042259, 0.043614], rtol=1e-3)
    assert_allclose(lightcurve.table["sqrt_ts"], [38.527512, 39.489968], rtol=1e-4)
    assert_allclose(lightcurve.table["ts"], [1484.369159, 1559.457547], rtol=1e-4)

    datasets = get_map_datasets()
    time_intervals2 = [Time(["2010-01-01T00:00:00", "2010-01-01T02:00:00"])]
    estimator2 = LightCurveEstimator(
        datasets, source="source", time_intervals=time_intervals2
    )
    lightcurve2 = estimator2.run(e_ref=10 * u.TeV, e_min=1 * u.TeV, e_max=100 * u.TeV)

    assert_allclose(lightcurve2.table["time_min"], [55197.0])
    assert_allclose(lightcurve2.table["time_max"], [55197.083333])
    assert_allclose(lightcurve2.table["e_ref"], [10])
    assert_allclose(lightcurve2.table["e_min"], [1])
    assert_allclose(lightcurve2.table["e_max"], [100])
    assert_allclose(lightcurve2.table["ref_dnde"], [1e-13])
    assert_allclose(lightcurve2.table["ref_flux"], [9.9e-12])
    assert_allclose(lightcurve2.table["ref_eflux"], [4.60517e-11])
    assert_allclose(lightcurve2.table["ref_e2dnde"], [1e-11])
    assert_allclose(lightcurve2.table["stat"], [-177267.775615], rtol=1e-5)
    assert_allclose(lightcurve2.table["norm_err"], [0.030358], rtol=1e-3)
    assert_allclose(lightcurve.table["counts"], [46794, 47388])
    assert_allclose(lightcurve2.table["ts"], [3042.893291], rtol=1e-4)
Ejemplo n.º 17
0
    reference=1 * u.TeV,
)
spectral_model.parameters["index"].frozen = False

sky_model = SkyModel(spatial_model=None,
                     spectral_model=spectral_model,
                     name="crab")

# We affect to each dataset it spectral model

# In[ ]:

for dataset in datasets:
    dataset.models = sky_model

# In[ ]:

lc_maker_1d = LightCurveEstimator(datasets, source="crab")

# In[ ]:

lc_1d = lc_maker_1d.run(e_ref=1 * u.TeV, e_min=1.0 * u.TeV, e_max=10.0 * u.TeV)

# Finally we plot the result for the 1D lightcurve:

# In[ ]:

lc_1d.plot(marker="o")

# In[ ]:
Ejemplo n.º 18
0
#
# Now that we have created the datasets we assign them the model to be fitted:

# In[ ]:

for dataset in datasets:
    # Copy the source model
    model = sky_model.copy(name="crab")
    dataset.model = model

# We can now create the light curve estimator by passing it the list of datasets.
# We can optionally ask for parameters reoptimization during fit, e.g. to fit background normalization in each time bin.

# In[ ]:

lc_maker = LightCurveEstimator(datasets, source="crab", reoptimize=True)

# We now run the estimator once we pass it the energy interval on which to compute the integral flux of the source.

# In[ ]:

get_ipython().run_cell_magic(
    'time', '',
    'lc = lc_maker.run(e_ref=1 * u.TeV, e_min=1.0 * u.TeV, e_max=10.0 * u.TeV)'
)

# The LightCurve object contains a table which we can explore.

# In[ ]:

lc.table["time_min", "time_max", "flux", "flux_err"]
Ejemplo n.º 19
0
for obs in extraction.obs_list:
    intervals.append([obs.events.time[0], obs.events.time[-1]])

# In[8]:

# Model to compute the expected counts (generally, parameters come from the fit)
model = PowerLaw(
    index=2. * u.Unit(''),
    amplitude=2.e-11 * u.Unit('1 / (cm2 s TeV)'),
    reference=1 * u.TeV,
)

# In[9]:

# Estimation of the light curve
lc_estimator = LightCurveEstimator(extraction)
lc = lc_estimator.light_curve(
    time_intervals=intervals,
    spectral_model=model,
    energy_range=[0.7, 100] * u.TeV,
)

# ## Results
#
# The light curve measurement result is stored in a table. Let's have a look at the results:

# In[10]:

print(lc.table.colnames)

# In[11]:
Ejemplo n.º 20
0
analysis_3d.set_models(models)

# ## Light Curve estimation: by observation
#
# We can now create the light curve estimator.
#
# We pass it the list of datasets and the name of the model component for which we want to build the light curve.
# We can optionally ask for parameters reoptimization during fit, that is most of the time to fit background normalization in each time bin.
#
# If we don't set any time interval, the `~gammapy.time.LightCurveEstimator` is determines the flux of each dataset and places it at the corresponding time in the light curve.
# Here one dataset equals to one observing run.

# In[ ]:

lc_maker_3d = LightCurveEstimator(analysis_3d.datasets,
                                  source="crab",
                                  reoptimize=False)
lc_3d = lc_maker_3d.run(e_ref=1 * u.TeV, e_min=1.0 * u.TeV, e_max=10.0 * u.TeV)

# The LightCurve object contains a table which we can explore.

# In[ ]:

lc_3d.table["time_min", "time_max", "e_min", "e_max", "flux", "flux_err"]

# ## Running the light curve extraction in 1D

# ### Building the 1D analysis configuration
#

# In[ ]: