Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ctlearn/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ def mock_lst1_dl1_file(tmp_path_factory):
return _create_mock_lst1_dl1_file(output)


@pytest.fixture(scope="session")
def dl1_real_data_file(dl1_tmp_path, converted_lst1_dl0):
"""
DL1 file containing both images and parameters from a DL0 real test data.
"""
output = dl1_tmp_path / "real_data.dl1.h5"
argv = [
f"--input={converted_lst1_dl0}",
f"--output={output}",
"--write-images",
]
assert run_tool(ProcessorTool(), argv=argv, cwd=dl1_tmp_path) == 0
return output


@pytest.fixture(scope="session")
def dl1_gamma_file(dl1_tmp_path, gamma_simtel_path):
"""
Expand Down Expand Up @@ -165,6 +180,19 @@ def dl1_proton_file(dl1_tmp_path, proton_simtel_path):
assert run_tool(ProcessorTool(), argv=argv, cwd=dl1_tmp_path) == 0
return output

@pytest.fixture(scope="session")
def r1_real_data_file(r1_tmp_path, converted_lst1_dl0):
"""
R1 file containing both waveforms and parameters from a DL0 real test data.
"""
output = r1_tmp_path / "real_data.r1.h5"
argv = [
f"--input={converted_lst1_dl0}",
f"--output={output}",
f"--DataWriter.write_r1_waveforms=True",
]
assert run_tool(ProcessorTool(), argv=argv, cwd=r1_tmp_path) == 0
return output

@pytest.fixture(scope="session")
def r1_gamma_file(r1_tmp_path, gamma_simtel_path):
Expand Down
20 changes: 16 additions & 4 deletions ctlearn/tools/tests/test_predict_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@
"tels_with_trigger",
]

@pytest.fixture
def h5_file(request):
"""Dynamically resolves fixture names passed via indirect parameterization."""
return request.getfixturevalue(request.param)

@pytest.mark.verifies_usecase("DPPS-UC-130-1.2")
@pytest.mark.parametrize("framework", ["Keras", "PyTorch"])
@pytest.mark.parametrize(
"h5_file, file_type",
[
("r1_gamma_file", "gamma"),
("r1_real_data_file", "real_data"),
],
indirect=["h5_file"],
)
def test_predict_mono_model_with_r1_waveforms(
tmp_path, ctlearn_trained_r1_mono_models, r1_gamma_file, framework
tmp_path, ctlearn_trained_r1_mono_models, h5_file, file_type, framework
):
"""
Test training CTLearn mono model using the R1 gamma and proton files for all reconstruction tasks
Expand All @@ -51,7 +63,7 @@ def test_predict_mono_model_with_r1_waveforms(
dl2_dir.mkdir(parents=True, exist_ok=True)
# Define telescope types and their available telescopes
telescope_type = "LST"
available_tels = [1, 2]
available_tels = [1]
# Hardcopy the trained models to the model directory
for reco_task in ["type", "energy", "cameradirection"]:
key = f"{framework}_{telescope_type}_{reco_task}"
Expand All @@ -63,15 +75,15 @@ def test_predict_mono_model_with_r1_waveforms(
assert model_file.exists(), f"Trained mono model file not found for {key}"
# Build command-line arguments
argv = [
f"--input_url={r1_gamma_file}",
f"--input_url={h5_file}",
"--PredictCTLearnModel.batch_size=2",
"--PredictCTLearnModel.dl1dh_reader_type=DLWaveformReader",
"--DLWaveformReader.sequence_length=5",
"--DLWaveformReader.focal_length_choice=EQUIVALENT",
"--no-r1-waveforms",
"--dl2-telescope",
]
output_file = dl2_dir / f"gamma_{framework}_{telescope_type}_mono_from_waveforms.dl2.h5"
output_file = dl2_dir / f"{file_type}_{framework}_{telescope_type}_mono_from_waveforms.dl2.h5"
# Run Prediction tool
assert (
run_tool(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ tests = [
"pytest-cov",
"pytest-xdist",
"pytest_astropy_header",
"ctao-pytest-dpps @ git+https://gitlab.cta-observatory.org/cta-computing/dpps/pytest-dpps@main",
]

docs = [
Expand Down
Loading