-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b854bd
commit 7f7d0a3
Showing
4 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
common pytest fixtures for tests in dl1-data-handler. | ||
Credits to ctapipe for the original code. | ||
""" | ||
|
||
import pytest | ||
|
||
from ctapipe.core import run_tool | ||
from ctapipe.utils import get_dataset_path | ||
from ctapipe.utils.filelock import FileLock | ||
|
||
@pytest.fixture(scope="session") | ||
def prod5_gamma_simtel_path(): | ||
return get_dataset_path("gamma_prod5.simtel.zst") | ||
|
||
@pytest.fixture(scope="session") | ||
def dl1_tmp_path(tmp_path_factory): | ||
"""Temporary directory for global dl1 test data""" | ||
return tmp_path_factory.mktemp("dl1_") | ||
|
||
@pytest.fixture(scope="session") | ||
def dl1_gamma_file(dl1_tmp_path, prod5_gamma_simtel_path): | ||
""" | ||
DL1 file containing both images and parameters from a gamma simulation set. | ||
""" | ||
from ctapipe.tools.process import ProcessorTool | ||
|
||
output = dl1_tmp_path / "gamma.dl1.h5" | ||
|
||
# prevent running process multiple times in case of parallel tests | ||
with FileLock(output.with_suffix(output.suffix + ".lock")): | ||
if output.is_file(): | ||
return output | ||
|
||
argv = [ | ||
f"--input={prod5_gamma_simtel_path}", | ||
f"--output={output}", | ||
"--write-images", | ||
"--DataWriter.Contact.name=αℓℓ the äüöß", | ||
] | ||
assert run_tool(ProcessorTool(), argv=argv, cwd=dl1_tmp_path) == 0 | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from traitlets.config.loader import Config | ||
|
||
from dl1_data_handler.reader import DLImageReader | ||
|
||
def test_dl1_image_reading(dl1_tmp_path, dl1_gamma_file): | ||
"""check reading from pixel-wise image data files""" | ||
# Create a configuration suitable for the test | ||
config = Config( | ||
{ | ||
"DLImageReader": { | ||
"allowed_tels": [4], | ||
}, | ||
} | ||
) | ||
# Create an image reader and test basic properties | ||
dl1_reader = DLImageReader(input_url_signal=[dl1_gamma_file], config=config) | ||
assert dl1_reader._get_n_events() == 1 | ||
assert dl1_reader.tel_type == "LST_LST_LSTCam" | ||
# Test the generation of a mono batch | ||
mono_batch = dl1_reader.generate_mono_batch([0]) | ||
assert mono_batch["tel_id"] == 4 | ||
assert mono_batch["features"].shape == (1, 110, 110, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
[tool:pytest] | ||
pep8ignore = | ||
[tool:pytest] |