|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
from asgardpy.analysis import AsgardpyAnalysis |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
@pytest.mark.test_data |
|
7
|
|
|
def test_joint_3d_1d(base_config): |
|
8
|
|
|
""" |
|
9
|
|
|
Test to run a major Fermi (3D) + HESS (1D) + MAGIC (1D) joint analysis. |
|
10
|
|
|
""" |
|
11
|
|
|
|
|
12
|
|
|
analysis = AsgardpyAnalysis(base_config) |
|
13
|
|
|
|
|
14
|
|
|
extra_config = base_config.copy() |
|
15
|
|
|
extra_config.general.n_jobs = 33 |
|
16
|
|
|
analysis.update_config(extra_config) |
|
17
|
|
|
|
|
18
|
|
|
analysis.run(["datasets-3d"]) |
|
19
|
|
|
analysis.run(["datasets-1d"]) |
|
20
|
|
|
analysis.run_fit() |
|
21
|
|
|
|
|
22
|
|
|
assert analysis.config.general.n_jobs == 33 |
|
23
|
|
|
assert len(analysis.datasets) == 4 |
|
24
|
|
|
assert len(analysis.models) == 11 |
|
25
|
|
|
assert analysis.fit_result.success is True |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
@pytest.mark.test_data |
|
29
|
|
|
def test_analysis_basics(gammapy_data_path, base_config): |
|
30
|
|
|
"""Testing some basic analysis functions.""" |
|
31
|
|
|
|
|
32
|
|
|
other_config_path_1 = f"{gammapy_data_path}fermi-3fhl-crab/Fermi-LAT-3FHL_models.yaml" |
|
33
|
|
|
|
|
34
|
|
|
base_config.target.models_file = other_config_path_1 |
|
35
|
|
|
|
|
36
|
|
|
analysis_1 = AsgardpyAnalysis(base_config) |
|
37
|
|
|
|
|
38
|
|
|
with pytest.raises(RuntimeError): |
|
39
|
|
|
print(analysis_1.models) |
|
40
|
|
|
|
|
41
|
|
|
spec_model_name = analysis_1.config.target.components[0].spectral.type |
|
42
|
|
|
|
|
43
|
|
|
assert spec_model_name == "LogParabolaSpectralModel" |
|
44
|
|
|
|
|
45
|
|
|
other_config_path_2 = f"{gammapy_data_path}fermi-3fhl-crab/Fermi-LAT-3FHL_datasets.yaml" |
|
46
|
|
|
|
|
47
|
|
|
base_config.target.models_file = other_config_path_2 |
|
48
|
|
|
|
|
49
|
|
|
with pytest.raises(TypeError): |
|
50
|
|
|
AsgardpyAnalysis(base_config) |
|
51
|
|
|
|
|
52
|
|
|
config_dict = {"general": {"n_jobs": 111}} |
|
53
|
|
|
analysis_1.config = config_dict |
|
54
|
|
|
|
|
55
|
|
|
assert analysis_1.config.general.n_jobs == 111 |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
@pytest.mark.test_data |
|
59
|
|
|
def test_ebl_deabsorbed(gammapy_data_path, ebl_hess_pks): |
|
60
|
|
|
"""Testing generation of EBL-deabsorbed Flux points.""" |
|
61
|
|
|
|
|
62
|
|
|
analysis = AsgardpyAnalysis(ebl_hess_pks) |
|
63
|
|
|
|
|
64
|
|
|
analysis.run() |
|
65
|
|
|
|
|
66
|
|
|
analysis.get_correct_ebl_deabs_flux_points() |
|
67
|
|
|
|
|
68
|
|
|
assert len(analysis.model_deabs.parameters) == 3 |
|
69
|
|
|
assert analysis.flux_points_deabs |
|
70
|
|
|
|