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