|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
from asgardpy.config import AsgardpyConfig |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
def test_input_dl3(caplog): |
|
7
|
|
|
"""Testing basic fail safes for DL3Files class.""" |
|
8
|
|
|
|
|
9
|
|
|
from asgardpy.io.input_dl3 import DL3Files |
|
10
|
|
|
|
|
11
|
|
|
config = AsgardpyConfig() |
|
12
|
|
|
dl3_dict = config.dataset3d.instruments[0].input_dl3[0] |
|
13
|
|
|
|
|
14
|
|
|
dl3_files = DL3Files(dir_dict=dl3_dict, log=None) |
|
15
|
|
|
|
|
16
|
|
|
assert dl3_files.log.name == "asgardpy.io.input_dl3" |
|
17
|
|
|
assert dl3_files.log.level == 20 |
|
18
|
|
|
assert caplog.record_tuples[0][2] == "type is not in the expected range for DL3 files" |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
def test_io_dl4(caplog): |
|
22
|
|
|
"""Testing basic fail safes for DL4Files class.""" |
|
23
|
|
|
|
|
24
|
|
|
from asgardpy.io.io_dl4 import DL4Files |
|
25
|
|
|
|
|
26
|
|
|
config = AsgardpyConfig() |
|
27
|
|
|
dl4_info = config.dataset1d.instruments[0].dl4_dataset_info |
|
28
|
|
|
dl4_info.dl4_dataset.glob_pattern["dl4_files"] = "dl4*" |
|
29
|
|
|
obs_config = config.dataset1d.instruments[0].dataset_info.observation |
|
30
|
|
|
|
|
31
|
|
|
dl4_files = DL4Files(dl4_dataset_info=dl4_info, log=None) |
|
32
|
|
|
|
|
33
|
|
|
d_list, _ = dl4_files.get_dl4_files(obs_config) |
|
34
|
|
|
|
|
35
|
|
|
assert dl4_files.log.name == "asgardpy.io.io_dl4" |
|
36
|
|
|
assert dl4_files.log.level == 20 |
|
37
|
|
|
assert caplog.record_tuples[0][2] == "No datasets found in ." |
|
38
|
|
|
with pytest.raises(ZeroDivisionError): |
|
39
|
|
|
1 / len(d_list) |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def test_io_dl4_w_models(gammapy_data_path): |
|
43
|
|
|
"""Testing some more IO options when DL4 have associated models.""" |
|
44
|
|
|
|
|
45
|
|
|
from asgardpy.io.io_dl4 import DL4Files |
|
46
|
|
|
|
|
47
|
|
|
config = AsgardpyConfig() |
|
48
|
|
|
dl4_info = config.dataset1d.instruments[0].dl4_dataset_info |
|
49
|
|
|
obs_config = config.dataset1d.instruments[0].dataset_info.observation |
|
50
|
|
|
|
|
51
|
|
|
dl4_info.dl4_dataset.input_dir = f"{gammapy_data_path}fermi-3fhl-crab/" |
|
52
|
|
|
dl4_info.dl4_dataset.glob_pattern["dl4_files"] = "Fermi*data*fits" |
|
53
|
|
|
dl4_info.dl4_dataset.glob_pattern["dl4_model_files"] = "Fermi*models.yaml" |
|
54
|
|
|
|
|
55
|
|
|
dl4_files = DL4Files(dl4_dataset_info=dl4_info, log=None) |
|
56
|
|
|
d_list = dl4_files.get_dl4_dataset(obs_config) |
|
57
|
|
|
|
|
58
|
|
|
assert len(d_list) == 1 |
|
59
|
|
|
|
|
60
|
|
|
dl4_info.dl4_dataset.glob_pattern["dl4_files"] = "Fermi*data*yaml" |
|
61
|
|
|
dl4_files = DL4Files(dl4_dataset_info=dl4_info, log=None) |
|
62
|
|
|
d_list = dl4_files.get_dl4_dataset(obs_config) |
|
63
|
|
|
|
|
64
|
|
|
assert d_list[0].tag == "MapDataset" |
|
65
|
|
|
|
|
66
|
|
|
assert dl4_files.read_dl4_file("random.txt") is None |
|
67
|
|
|
|