From 421810b23a0e4de27d7d18c6b63fe369b3ff1881 Mon Sep 17 00:00:00 2001 From: Michele Peresano Date: Mon, 29 Mar 2021 15:10:12 +0200 Subject: [PATCH 1/2] use energy model output in training of gamma2 and proton1 --- protopipe/scripts/tests/test_pipeline.py | 70 ++++++++++++++---------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/protopipe/scripts/tests/test_pipeline.py b/protopipe/scripts/tests/test_pipeline.py index 562cc73c..baeb7b73 100644 --- a/protopipe/scripts/tests/test_pipeline.py +++ b/protopipe/scripts/tests/test_pipeline.py @@ -90,11 +90,38 @@ def test_GET_GAMMAS_FOR_ENERGY_MODEL(test_case, pipeline_testdir): @pytest.mark.parametrize("test_case", [ - pytest.param("PROD3B_CTA_NORTH", marks=pytest.mark.dependency(name="g2N")), - pytest.param("PROD3B_CTA_SOUTH", marks=pytest.mark.dependency(name="g2S")), + pytest.param("PROD3B_CTA_NORTH", marks=pytest.mark.dependency(name="EN", + depends=["g1N"])), + pytest.param("PROD3B_CTA_SOUTH", marks=pytest.mark.dependency(name="ES", + depends=["g1S"])), +]) +def test_BUILD_ENERGY_MODEL_AdaBoost_DecisionTreeRegressor(test_case, pipeline_testdir): + """Launch protopipe.scripts.build_model for a AdaBoost DecisionTreeRegressor.""" + + infile = pipeline_testdir / f"test_gamma1_noImages_{test_case}.h5" + outdir = pipeline_testdir / f"energy_model_{test_case}" + + config = resource_filename("protopipe", "scripts/tests/test_regressor.yaml") + + exit_status = system( + f"python {build_model.__file__}\ + --config_file {config}\ + --infile_signal {infile}\ + --outdir {outdir}\ + --cameras_from_file" + ) + assert exit_status == 0 + + +@pytest.mark.parametrize("test_case", [ + pytest.param("PROD3B_CTA_NORTH", marks=pytest.mark.dependency(name="g2N", + depends=["EN"])), + pytest.param("PROD3B_CTA_SOUTH", marks=pytest.mark.dependency(name="g2S", + depends=["ES"])), ]) def test_GET_GAMMAS_FOR_CLASSIFICATION_MODEL(test_case, pipeline_testdir): + modelpath = pipeline_testdir / f"energy_model_{test_case}" outpath = pipeline_testdir / f"test_gamma2_noImages_{test_case}.h5" exit_status = system( @@ -102,7 +129,9 @@ def test_GET_GAMMAS_FOR_CLASSIFICATION_MODEL(test_case, pipeline_testdir): --config_file {input_data[test_case]['config']}\ -o {outpath}\ -i {input_data[test_case]['gamma2'].parent}\ - -f {input_data[test_case]['gamma2'].name}" + -f {input_data[test_case]['gamma2'].name}\ + --estimate_energy True\ + --regressor_dir {modelpath}" ) # check that the script ends without crashing @@ -114,11 +143,14 @@ def test_GET_GAMMAS_FOR_CLASSIFICATION_MODEL(test_case, pipeline_testdir): @pytest.mark.parametrize("test_case", [ - pytest.param("PROD3B_CTA_NORTH", marks=pytest.mark.dependency(name="p1N")), - pytest.param("PROD3B_CTA_SOUTH", marks=pytest.mark.dependency(name="p1S")), + pytest.param("PROD3B_CTA_NORTH", marks=pytest.mark.dependency(name="p1N", + depends=["EN"])), + pytest.param("PROD3B_CTA_SOUTH", marks=pytest.mark.dependency(name="p1S", + depends=["ES"])), ]) def test_GET_PROTONS_FOR_CLASSIFICATION_MODEL(test_case, pipeline_testdir): + modelpath = pipeline_testdir / f"energy_model_{test_case}" outpath = pipeline_testdir / f"test_proton1_noImages_{test_case}.h5" exit_status = system( @@ -127,7 +159,9 @@ def test_GET_PROTONS_FOR_CLASSIFICATION_MODEL(test_case, pipeline_testdir): -o {outpath}\ -m 10\ -i {input_data[test_case]['proton1'].parent}\ - -f {input_data[test_case]['proton1'].name}" + -f {input_data[test_case]['proton1'].name}\ + --estimate_energy True\ + --regressor_dir {modelpath}" ) # check that the script ends without crashing @@ -138,30 +172,6 @@ def test_GET_PROTONS_FOR_CLASSIFICATION_MODEL(test_case, pipeline_testdir): assert file.get_filesize() > 0 -@pytest.mark.parametrize("test_case", [ - pytest.param("PROD3B_CTA_NORTH", marks=pytest.mark.dependency(name="EN", - depends=["g1N"])), - pytest.param("PROD3B_CTA_SOUTH", marks=pytest.mark.dependency(name="ES", - depends=["g1S"])), -]) -def test_BUILD_ENERGY_MODEL_AdaBoost_DecisionTreeRegressor(test_case, pipeline_testdir): - """Launch protopipe.scripts.build_model for a AdaBoost DecisionTreeRegressor.""" - - infile = pipeline_testdir / f"test_gamma1_noImages_{test_case}.h5" - outdir = pipeline_testdir / f"energy_model_{test_case}" - - config = resource_filename("protopipe", "scripts/tests/test_regressor.yaml") - - exit_status = system( - f"python {build_model.__file__}\ - --config_file {config}\ - --infile_signal {infile}\ - --outdir {outdir}\ - --cameras_from_file" - ) - assert exit_status == 0 - - @pytest.mark.parametrize("test_case", [ pytest.param("PROD3B_CTA_NORTH", marks=pytest.mark.dependency(name="C1", depends=["g2N", "p1N"])), From 01b3aa224aa9364d766f8214cfed2c35fed5a57d Mon Sep 17 00:00:00 2001 From: Michele Peresano Date: Mon, 29 Mar 2021 15:15:45 +0200 Subject: [PATCH 2/2] make test analysis config name relevant for tests --- protopipe/scripts/tests/test_config_analysis_north.yaml | 2 +- protopipe/scripts/tests/test_config_analysis_south.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/protopipe/scripts/tests/test_config_analysis_north.yaml b/protopipe/scripts/tests/test_config_analysis_north.yaml index fedebd55..2391676b 100644 --- a/protopipe/scripts/tests/test_config_analysis_north.yaml +++ b/protopipe/scripts/tests/test_config_analysis_north.yaml @@ -1,7 +1,7 @@ # General informations # NOTE: only Prod3b simulations are currently supported. General: - config_name: 'v0.4.0_dev1' + config_name: 'test_CTA_North' site: 'north' # 'north' or 'south' # array can be either # - 'subarray_LSTs', 'subarray_MSTs', 'subarray_SSTs' or 'full_array' diff --git a/protopipe/scripts/tests/test_config_analysis_south.yaml b/protopipe/scripts/tests/test_config_analysis_south.yaml index 448d6899..36e8e288 100644 --- a/protopipe/scripts/tests/test_config_analysis_south.yaml +++ b/protopipe/scripts/tests/test_config_analysis_south.yaml @@ -1,7 +1,7 @@ # General informations # NOTE: only Prod3b simulations are currently supported. General: - config_name: 'v0.4.0_dev1' + config_name: 'test_CTA_South' site: 'south' # 'north' or 'south' # array can be either # - 'subarray_LSTs', 'subarray_MSTs', 'subarray_SSTs' or 'full_array'