Passed
Pull Request — main (#155)
by Chaitanya
01:35
created

test_xml_only_source_models()   A

Complexity

Conditions 1

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 25
nop 1
dl 0
loc 33
rs 9.28
c 0
b 0
f 0
1
from pathlib import Path
2
3
import pytest
4
from gammapy.modeling.models import Models
5
6
from asgardpy.gammapy.read_models import read_fermi_xml_models_list
7
8
9
@pytest.mark.test_data
10
def test_xml_only_source_models(gammapy_data_path):
11
    """Test reading various different Fermi-XML source models."""
12
    from asgardpy.config import AsgardpyConfig
13
14
    config = AsgardpyConfig()
15
    list_source_models = []
16
17
    dl3_aux_path = Path(f"{gammapy_data_path}fermipy-crab/")
18
19
    diffuse_models = {}
20
21
    xml_file = dl3_aux_path / "test_fermi_xml_models.xml"
22
    config.target.source_name = "4FGL J0534.5+2201i"
23
    config.target.from_3d = True
24
25
    list_source_models, _ = read_fermi_xml_models_list(
26
        list_source_models, dl3_aux_path, xml_file, diffuse_models, config.target
27
    )
28
    list_source_models = Models(list_source_models)
29
30
    assert list_source_models[0].spatial_model.tag[0] == "GaussianSpatialModel"
31
    assert list_source_models[0].spectral_model.tag[1] == "lp"
32
    assert list_source_models[1].spatial_model.tag[0] == "TemplateSpatialModel"
33
    assert list_source_models[2].spatial_model.tag[0] == "PointSpatialModel"
34
    assert list_source_models[2].spectral_model.tag[1] == "ecpl"
35
    assert list_source_models[3].spectral_model.tag[1] == "pl"
36
    assert list_source_models[4].spectral_model.tag[1] == "ecpl"
37
    assert list_source_models[5].spectral_model.tag[1] == "secpl-4fgl-dr3"
38
    assert list_source_models[6].spectral_model.tag[1] == "bpl"
39
    assert list_source_models[7].spectral_model.tag[1] == "sbpl"
40
    assert list_source_models[8].spectral_model.tag[1] == "pl"
41
    assert list_source_models[8].spatial_model.tag[0] == "GaussianSpatialModel"
42
43
44
@pytest.mark.test_data
45
def test_xml_with_diffuse_models(gammapy_data_path):
46
    """Test reading Fermi-XML models with diffuse models included."""
47
48
    list_source_models = []
49
    diffuse_models = {}
50
51
    dl3_aux_path = Path(f"{gammapy_data_path}fermipy-crab/")
52
53
    xml_file = dl3_aux_path / "srcmdl_00.xml"
54
    diffuse_models["gal_diffuse"] = dl3_aux_path / "gll_iem_v07_cutout.fits"
55
    diffuse_models["iso_diffuse"] = dl3_aux_path / "iso_P8R3_SOURCE_V3_FRONT_v1.txt"
56
    diffuse_models["key_name"] = None
57
58
    list_source_models, diffuse_models = read_fermi_xml_models_list(
59
        list_source_models, dl3_aux_path, xml_file, diffuse_models
60
    )
61
    list_source_models = Models(list_source_models)
62
63
    assert list_source_models[1].name == "4FGL J0534.5+2201s"
64
    assert list_source_models[-1].name == "diffuse-iem"
65
    assert list_source_models[-2].name == "fermi-diffuse-iso"
66