From b85e5384bc082a3d0c89649238d90d15828c4cf1 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Mon, 27 May 2024 12:27:57 +0200 Subject: [PATCH 01/34] Update event_selection.py --- lstchain/io/event_selection.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lstchain/io/event_selection.py b/lstchain/io/event_selection.py index 533e45e1e2..c5c7941a49 100644 --- a/lstchain/io/event_selection.py +++ b/lstchain/io/event_selection.py @@ -364,6 +364,11 @@ class DataBinning(Component): default_value=25, ).tag(config=True) + scale_true_energy= Float( + help="Scaling value for True energy", + default_value=1,0, + ).tag(config=True) + reco_energy_min = Float( help="Minimum value for Reco Energy bins in TeV units", default_value=0.005, From 14d53d14ab19cdc0eecb4cac0c5e4601d24cefe1 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Mon, 27 May 2024 12:30:26 +0200 Subject: [PATCH 02/34] Update lstchain_create_irf_files.py --- lstchain/tools/lstchain_create_irf_files.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 1186570289..d5ccf0b76c 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -317,6 +317,10 @@ def start(self): p["geomag_params"], ) = read_mc_dl2_to_QTable(p["file"]) + p["events"]["true_energy"] *= self.data_bin.scale_true_energy + p["simulation_info"].energy_min *= self.data_bin.scale_true_energy + p["simulation_info"].energy_max *= self.data_bin.scale_true_energy + p["mc_type"] = check_mc_type(p["file"]) self.log.debug( From ee2ff272f84f15c23c2c7b0b78dddf711e9a0fb4 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Mon, 27 May 2024 12:32:19 +0200 Subject: [PATCH 03/34] Update irf_dl3_tool_config.json --- docs/examples/irf_dl3_tool_config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/examples/irf_dl3_tool_config.json b/docs/examples/irf_dl3_tool_config.json index 61de3ef1d6..0a69e7e822 100644 --- a/docs/examples/irf_dl3_tool_config.json +++ b/docs/examples/irf_dl3_tool_config.json @@ -32,6 +32,7 @@ "true_energy_min": 0.005, "true_energy_max": 500, "true_energy_n_bins": 25, + "scale_true_energy": 1.15, "reco_energy_min": 0.005, "reco_energy_max": 500, "reco_energy_n_bins": 25, From 0ac1de3ee4e4ee5cfd95eaaabf81a9b7a5ed0df0 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Mon, 27 May 2024 15:53:16 +0200 Subject: [PATCH 04/34] Update event_selection.py --- lstchain/io/event_selection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/io/event_selection.py b/lstchain/io/event_selection.py index c5c7941a49..c13f87c69c 100644 --- a/lstchain/io/event_selection.py +++ b/lstchain/io/event_selection.py @@ -366,7 +366,7 @@ class DataBinning(Component): scale_true_energy= Float( help="Scaling value for True energy", - default_value=1,0, + default_value=1.0, ).tag(config=True) reco_energy_min = Float( From e0b8f9a3e036c2a382fb75862b7b81f63f470fcb Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Mon, 27 May 2024 16:18:55 +0200 Subject: [PATCH 05/34] Update lstchain_create_irf_files.py --- lstchain/tools/lstchain_create_irf_files.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index d5ccf0b76c..1b2dc63eda 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -317,9 +317,10 @@ def start(self): p["geomag_params"], ) = read_mc_dl2_to_QTable(p["file"]) - p["events"]["true_energy"] *= self.data_bin.scale_true_energy - p["simulation_info"].energy_min *= self.data_bin.scale_true_energy - p["simulation_info"].energy_max *= self.data_bin.scale_true_energy + if self.data_bin.scale_true_energy != 1.0: + p["events"]["true_energy"] *= self.data_bin.scale_true_energy + p["simulation_info"].energy_min *= self.data_bin.scale_true_energy + p["simulation_info"].energy_max *= self.data_bin.scale_true_energy p["mc_type"] = check_mc_type(p["file"]) From 00dbe27e9ee2e535856288c6a7b7fc4b1d12fd64 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:19:36 +0200 Subject: [PATCH 06/34] Update irf_dl3_tool_config.json --- docs/examples/irf_dl3_tool_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/irf_dl3_tool_config.json b/docs/examples/irf_dl3_tool_config.json index 0a69e7e822..a9c75a9e39 100644 --- a/docs/examples/irf_dl3_tool_config.json +++ b/docs/examples/irf_dl3_tool_config.json @@ -32,7 +32,7 @@ "true_energy_min": 0.005, "true_energy_max": 500, "true_energy_n_bins": 25, - "scale_true_energy": 1.15, + "scale_true_energy": 1.0, "reco_energy_min": 0.005, "reco_energy_max": 500, "reco_energy_n_bins": 25, From de4b7518b4eba3a8a45cfe0cb667e82fc6c16974 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:44:31 +0200 Subject: [PATCH 07/34] Update lstchain_create_irf_files.py --- lstchain/tools/lstchain_create_irf_files.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 1b2dc63eda..7f3cacd663 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -28,6 +28,9 @@ If you want to generate source-dependent IRFs, source-dep flag should be activated. The global alpha cut used to generate IRFs is stored as AL_CUT in the HDU header. +Modified IRFs can be created in case of considering systematics in the +light efficiency. This can be done by setting a value different to one for the +"scale_true_energy" argument present in the DataBinning Component of the configuration file. """ from astropy import table @@ -317,7 +320,10 @@ def start(self): p["geomag_params"], ) = read_mc_dl2_to_QTable(p["file"]) + if self.data_bin.scale_true_energy != 1.0: + # This will scale the true energy of the MC events just before filling the IRFs histograms when pyirf commands are used. + # Effects expected: non-diagonal energy dispersion matrix and a different spectrum. p["events"]["true_energy"] *= self.data_bin.scale_true_energy p["simulation_info"].energy_min *= self.data_bin.scale_true_energy p["simulation_info"].energy_max *= self.data_bin.scale_true_energy From e06e0ac4d6c1076b7ca52ac6ef044690d08cf050 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:33:37 +0200 Subject: [PATCH 08/34] Update lstchain_create_irf_files.py Upload of the modifications suggested. --- lstchain/tools/lstchain_create_irf_files.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 7f3cacd663..49c72d3afe 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -28,9 +28,15 @@ If you want to generate source-dependent IRFs, source-dep flag should be activated. The global alpha cut used to generate IRFs is stored as AL_CUT in the HDU header. -Modified IRFs can be created in case of considering systematics in the -light efficiency. This can be done by setting a value different to one for the -"scale_true_energy" argument present in the DataBinning Component of the configuration file. +Modified IRFs with true energy scaled by a given factor can be created to evaluate +the systematic uncertainty in the light collection efficiency. This can be done by +setting a value different from one for the "scale_true_energy" argument present in +the DataBinning Component of the configuration file of the IRF creation Tool. +(The true energy of the MC events will be scaled before filling the IRFs histograms +when pyirf commands are used. The effects expected are a non-diagonal energy dispersion +matrix and a different spectrum). + + """ from astropy import table @@ -322,8 +328,6 @@ def start(self): if self.data_bin.scale_true_energy != 1.0: - # This will scale the true energy of the MC events just before filling the IRFs histograms when pyirf commands are used. - # Effects expected: non-diagonal energy dispersion matrix and a different spectrum. p["events"]["true_energy"] *= self.data_bin.scale_true_energy p["simulation_info"].energy_min *= self.data_bin.scale_true_energy p["simulation_info"].energy_max *= self.data_bin.scale_true_energy From eb1c4ab946e1952d2442d266a466be0afffb9aee Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:57:10 +0200 Subject: [PATCH 09/34] Update lstchain_create_irf_files.py Add alias and header for 'scale_true_energy' component. --- lstchain/tools/lstchain_create_irf_files.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 49c72d3afe..3ea408eb55 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -230,6 +230,7 @@ class IRFFITSWriter(Tool): "global-alpha-cut": "DL3Cuts.global_alpha_cut", "allowed-tels": "DL3Cuts.allowed_tels", "overwrite": "IRFFITSWriter.overwrite", + "scale_true_energy": "DataBinning.scale_true_energy" } flags = { @@ -542,7 +543,10 @@ def start(self): geomag_params["GEOMAG_DELTA"].to_value(u.deg), "deg", ) - + extra_headers["ETRUE SCALE"]= ( + self.data_bin.scale_true_energy + ) + if self.point_like: self.log.info("Generating point_like IRF HDUs") else: From eac6f10509acff8852215b07662d8784a55ce67c Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:38:41 +0200 Subject: [PATCH 10/34] Update lstchain_create_irf_files.py --- lstchain/tools/lstchain_create_irf_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 3ea408eb55..35bd0bf5c7 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -543,7 +543,7 @@ def start(self): geomag_params["GEOMAG_DELTA"].to_value(u.deg), "deg", ) - extra_headers["ETRUE SCALE"]= ( + extra_headers["ETRUE_SCALE"]= ( self.data_bin.scale_true_energy ) From 319258a3b678cfce22a1a4c3f6b4252436ce293c Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:26:01 +0200 Subject: [PATCH 11/34] Update lstchain_create_irf_files.py Example code in the IRF tool. --- lstchain/tools/lstchain_create_irf_files.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 35bd0bf5c7..50c2a05ac0 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -145,7 +145,13 @@ class IRFFITSWriter(Tool): --global-alpha-cut 10 --source-dep - """ + To build modified IRFs by specifying a scaling factor applying to the true energy (without using a config file): + > lstchain_create_irf_files + -g /path/to/DL2_MC_gamma_file.h5 + -o /path/to/irf.fits.gz + --point-like (Only for point_like IRFs) + --scaling_true_energy 1.15 + """ input_gamma_dl2 = traits.Path( help="Input MC gamma DL2 file", From f28019d9e7ec6e3778ed989e0546af027e3eae1b Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:03:49 +0200 Subject: [PATCH 12/34] Update test_tools.py Add a test for verification of the validation of modified IRFs Need to be refined because only few events. --- lstchain/tools/tests/test_tools.py | 320 ++++++++++++++++++++++++++++- 1 file changed, 319 insertions(+), 1 deletion(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 0cdc683fea..0a8b15a39d 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -3,7 +3,8 @@ import os from astropy.io import fits import numpy as np - +from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D +import astropy.units as u def test_create_irf_full_enclosure(temp_dir_observed_files, simulated_dl2_file): """ @@ -379,3 +380,320 @@ def test_index_dl3_files(temp_dir_observed_files): data = DataStore.from_dir(temp_dir_observed_files) assert 2008 in data.obs_table["OBS_ID"] + + +def test_create_irf_point_like_srcdep_energy_dependent_cuts( + temp_dir_observed_srcdep_files, simulated_srcdep_dl2_file +): + """ + Generating point-like source-dependent IRF file from a test DL2 files, + using energy-dependent cuts + """ + from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter + from astropy.table import QTable + + irf_file = temp_dir_observed_srcdep_files / "irf_edep.fits.gz" + + assert ( + run_tool( + IRFFITSWriter(), + argv=[ + f"--input-gamma-dl2={simulated_srcdep_dl2_file}", + f"--output-irf-file={irf_file}", + "--point-like", + "--source-dep", + "--energy-dependent-gh", + "--energy-dependent-alpha", + "--DL3Cuts.min_event_p_en_bin=2", + "--overwrite", + ], + cwd=temp_dir_observed_srcdep_files, + ) + == 0 + ) + + gh_cuts = QTable.read(irf_file, hdu="GH_CUTS") + assert isinstance(gh_cuts.meta["GH_EFF"], float) + + al_cuts = QTable.read(irf_file, hdu="AL_CUTS") + assert isinstance(al_cuts.meta["AL_CONT"], float) + + +@pytest.mark.private_data +def test_create_dl3_energy_dependent_cuts(temp_dir_observed_files, observed_dl2_file): + """ + Generating an DL3 file from a test DL2 files and test IRF file, using + energy dependent cuts. Here the previously created IRF is used. + """ + from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter + from gammapy.data import Observation + + irf_file = temp_dir_observed_files / "pnt_irf.fits.gz" + + dl2_name = observed_dl2_file.name + observed_dl3_file = temp_dir_observed_files / dl2_name.replace("dl2", "dl3") + observed_dl3_file = observed_dl3_file.with_suffix(".fits") + + assert ( + run_tool( + DataReductionFITSWriter(), + argv=[ + f"--input-dl2={observed_dl2_file}", + f"--output-dl3-path={temp_dir_observed_files}", + f"--input-irf-path={temp_dir_observed_files}", + "--irf-file-pattern=pnt_irf.fits.gz", + "--source-name=Crab", + "--source-ra=83.633deg", + "--source-dec=22.01deg", + "--overwrite", + ], + cwd=temp_dir_observed_files, + ) + == 0 + ) + + assert ( + Observation.read(event_file=observed_dl3_file, irf_file=irf_file).obs_id == 2008 + ) + + +@pytest.mark.private_data +def test_create_dl3(temp_dir_observed_files, observed_dl2_file, simulated_irf_file): + """ + Generating an DL3 file from a test DL2 files and test IRF file + """ + from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter + + assert ( + run_tool( + DataReductionFITSWriter(), + argv=[ + f"--input-dl2={observed_dl2_file}", + f"--output-dl3-path={temp_dir_observed_files}", + f"--input-irf-path={simulated_irf_file.parent}", + f"--irf-file-pattern={simulated_irf_file.name}", + "--source-name=Crab", + "--source-ra=83.633deg", + "--source-dec=22.01deg", + "--overwrite", + ], + cwd=temp_dir_observed_files, + ) + == 0 + ) + + +@pytest.mark.private_data +def test_create_dl3_with_config(temp_dir_observed_files, observed_dl2_file): + """ + Generating an DL3 file from a test DL2 files and test IRF file, using + a config file + """ + from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter + + config_file = os.path.join(os.getcwd(), "docs/examples/irf_dl3_tool_config.json") + + assert ( + run_tool( + DataReductionFITSWriter(), + argv=[ + f"--input-dl2={observed_dl2_file}", + f"--output-dl3-path={temp_dir_observed_files}", + f"--input-irf-path={temp_dir_observed_files}", + "--irf-file-pattern=fe_irf.fits.gz", + "--source-name=Crab", + "--source-ra=83.633deg", + "--source-dec=22.01deg", + f"--config={config_file}", + "--overwrite", + ], + cwd=temp_dir_observed_files, + ) + == 0 + ) + + +@pytest.mark.private_data +def test_create_srcdep_dl3( + temp_dir_observed_srcdep_files, observed_srcdep_dl2_file, simulated_srcdep_irf_file +): + """ + Generating a source-dependent DL3 file from a test DL2 files and test IRF file + """ + from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter + from lstchain.paths import dl2_to_dl3_filename + + assert ( + run_tool( + DataReductionFITSWriter(), + argv=[ + f"--input-dl2={observed_srcdep_dl2_file}", + f"--output-dl3-path={temp_dir_observed_srcdep_files}", + f"--input-irf-path={simulated_srcdep_irf_file.parent}", + f"--irf-file-pattern={simulated_srcdep_irf_file.name}", + "--source-name=Crab", + "--source-ra=83.633deg", + "--source-dec=22.01deg", + "--source-dep", + "--overwrite", + ], + cwd=temp_dir_observed_srcdep_files, + ) + == 0 + ) + + hdulist = fits.open( + temp_dir_observed_srcdep_files / dl2_to_dl3_filename(observed_srcdep_dl2_file) + ) + ra = hdulist[1].data["RA"] + dec = hdulist[1].data["DEC"] + + np.testing.assert_allclose(ra, 83.63, atol=1e-2) + np.testing.assert_allclose(dec, 22.01, atol=1e-2) + + +@pytest.mark.private_data +def test_create_srcdep_dl3_energy_dependent_cuts( + temp_dir_observed_srcdep_files, observed_srcdep_dl2_file +): + """ + Generating a source-dependent DL3 file from a test DL2 files and test IRF file, + using energy-dependent cuts + """ + from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter + + irf_file = temp_dir_observed_srcdep_files / "irf_edep.fits.gz" + + assert ( + run_tool( + DataReductionFITSWriter(), + argv=[ + f"--input-dl2={observed_srcdep_dl2_file}", + f"--output-dl3-path={temp_dir_observed_srcdep_files}", + f"--input-irf-path={irf_file.parent}", + f"--irf-file-pattern={irf_file.name}", + "--source-name=Crab", + "--source-ra=83.633deg", + "--source-dec=22.01deg", + "--source-dep", + "--overwrite", + ], + cwd=temp_dir_observed_srcdep_files, + ) + == 0 + ) + + +@pytest.mark.private_data +def test_index_dl3_files(temp_dir_observed_files): + """ + Generating Index files from a given path and glob pattern for DL3 files + """ + from lstchain.tools.lstchain_create_dl3_index_files import FITSIndexWriter + from gammapy.data import DataStore + + assert ( + run_tool( + FITSIndexWriter(), + argv=[ + f"--input-dl3-dir={temp_dir_observed_files}", + "--overwrite", + ], + cwd=temp_dir_observed_files, + ) + == 0 + ) + data = DataStore.from_dir(temp_dir_observed_files) + + assert 2008 in data.obs_table["OBS_ID"] + + + +def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_file): + """ + Checking the validy of modified IRFs after scaling the True Energy by a factor. + """ + + from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter + + irf_file=temp_dir_observed_files / "fe_irf.fits.gz" + irf_file_mod = temp_dir_observed_files / "mod_irf.fits.gz" + config_file = os.path.join(os.getcwd(), "/home/deborahd/cta-lstchain/docs/examples/irf_dl3_tool_config.json") + config_file_mod = os.path.join(os.getcwd(), "/home/deborahd/cta-lstchain/docs/examples/irf_dl3_tool_config_mod.json") + + assert ( + run_tool( + IRFFITSWriter(), + argv=[ + f"--input-gamma-dl2={simulated_dl2_file}", + f"--input-proton-dl2={simulated_dl2_file}", + f"--input-electron-dl2={simulated_dl2_file}", + f"--output-irf-file={irf_file}", + f"--config={config_file}", + "--overwrite", + "--DataBinning.true_energy_n_bins=10", + "--DataBinning.reco_energy_n_bins=10", + "--DL3Cuts.min_event_p_en_bin=2", + "--DataBinning.energy_migration_n_bins=15", + ], + cwd=temp_dir_observed_files, + ) + == 0 + ) + assert ( + run_tool( + IRFFITSWriter(), + argv=[ + f"--input-gamma-dl2={simulated_dl2_file}", + f"--input-proton-dl2={simulated_dl2_file}", + f"--input-electron-dl2={simulated_dl2_file}", + f"--output-irf-file={irf_file_mod}", + f"--config={config_file_mod}", + "--overwrite", + "--DataBinning.true_energy_n_bins=10", + "--DataBinning.reco_energy_n_bins=10", + "--DL3Cuts.min_event_p_en_bin=2", + "--DataBinning.energy_migration_n_bins=15", + ], + cwd=temp_dir_observed_files, + ) + == 0 + ) + + aeff_hdu=EffectiveAreaTable2D.read(irf_file, hdu='EFFECTIVE AREA') + aeff_mod_hdu=EffectiveAreaTable2D.read(irf_file_mod, hdu='EFFECTIVE AREA') + + edisp_hdu=EnergyDispersion2D.read(irf_file, hdu='ENERGY DISPERSION') + edisp_mod_hdu=EnergyDispersion2D.read(irf_file_mod, hdu='ENERGY DISPERSION') + + + #assert (aeff_mod.data.shape==(25,1)) + #assert (edisp_mod.data.shape==(25,30,1))#(E,migra,offset) + assert(aeff_mod_hdu.data.shape==aeff_hdu.data.shape) + assert(edisp_mod_hdu.data.shape==edisp_hdu.data.shape) + + #test with scaling factor=1.15 + edisp=EnergyDispersion2D.read(irf_file) + edisp_mod=EnergyDispersion2D.read(irf_file_mod) + + e_migra = edisp.axes["migra"].center + e_migra_mod=edisp_mod.axes["migra"].center + + e_true_list=[0.2,2,20] + + for i in e_true_list: + e_true = i* u.TeV + e_migra_prob = edisp.evaluate( + offset=0.4*u.deg, + energy_true=e_true, + migra=e_migra + ) + e_migra_prob_mod = edisp_mod.evaluate( + offset=0.4*u.deg, + energy_true=e_true, + migra=e_migra_mod + ) + + #for Ereco/Etrue near 1 (test for 0.94 and 1.05) + assert (e_migra_prob_mod[14]>e_migra_prob[14]) + assert (e_migra_prob_mod[15]>e_migra_prob[15]) From d9673e1d92c26df80b00a83c1f447d412a491ec0 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:11:58 +0200 Subject: [PATCH 13/34] Update test_tools.py Change the directories for config files. --- lstchain/tools/tests/test_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 0a8b15a39d..bd55c845ec 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -618,8 +618,8 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi irf_file=temp_dir_observed_files / "fe_irf.fits.gz" irf_file_mod = temp_dir_observed_files / "mod_irf.fits.gz" - config_file = os.path.join(os.getcwd(), "/home/deborahd/cta-lstchain/docs/examples/irf_dl3_tool_config.json") - config_file_mod = os.path.join(os.getcwd(), "/home/deborahd/cta-lstchain/docs/examples/irf_dl3_tool_config_mod.json") + config_file = os.path.join(os.getcwd(), "docs/examples/irf_dl3_tool_config.json") + config_file_mod = os.path.join(os.getcwd(), "docs/examples/irf_dl3_tool_config_mod.json") assert ( run_tool( From c239f72fca2715b4b62a2e9ef6c472ea25f9b869 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:14:12 +0200 Subject: [PATCH 14/34] Create irf_dl3_tool_config_mod.json --- docs/examples/irf_dl3_tool_config_mod.json | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 docs/examples/irf_dl3_tool_config_mod.json diff --git a/docs/examples/irf_dl3_tool_config_mod.json b/docs/examples/irf_dl3_tool_config_mod.json new file mode 100644 index 0000000000..0a69e7e822 --- /dev/null +++ b/docs/examples/irf_dl3_tool_config_mod.json @@ -0,0 +1,52 @@ +{ + "EventSelector": { + "filters": { + "intensity": [50, Infinity], + "width": [0, Infinity], + "length": [0, Infinity], + "r": [0, 1], + "wl": [0.01, 1], + "leakage_intensity_width_2": [0, 1], + "event_type": [32, 32] + } + }, + "DL3Cuts": { + "min_event_p_en_bin": 100, + "global_gh_cut": 0.7, + "gh_efficiency": 0.7, + "min_gh_cut": 0.1, + "max_gh_cut": 0.98, + "global_alpha_cut": 10, + "global_theta_cut": 0.2, + "theta_containment": 0.7, + "alpha_containment": 0.7, + "min_theta_cut": 0.1, + "max_theta_cut": 0.32, + "fill_theta_cut": 0.32, + "min_alpha_cut": 1, + "max_alpha_cut": 20, + "fill_alpha_cut": 20, + "allowed_tels": [1] + }, + "DataBinning": { + "true_energy_min": 0.005, + "true_energy_max": 500, + "true_energy_n_bins": 25, + "scale_true_energy": 1.15, + "reco_energy_min": 0.005, + "reco_energy_max": 500, + "reco_energy_n_bins": 25, + "energy_migration_min": 0.2, + "energy_migration_max": 5, + "energy_migration_n_bins": 30, + "fov_offset_min": 0.1, + "fov_offset_max": 1.1, + "fov_offset_n_edges": 9, + "bkg_fov_offset_min": 0, + "bkg_fov_offset_max": 10, + "bkg_fov_offset_n_edges": 21, + "source_offset_min": 0, + "source_offset_max": 1, + "source_offset_n_edges": 101 + } +} From 3d0a15391184e7f24417bd85c3571cd7c4dd0246 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:05:48 +0200 Subject: [PATCH 15/34] Update test_tools.py Update new test for energy sclaing in IRFs which has been verified and adapted. --- lstchain/tools/tests/test_tools.py | 253 ++++------------------------- 1 file changed, 34 insertions(+), 219 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index bd55c845ec..29c8ea2cea 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -3,8 +3,6 @@ import os from astropy.io import fits import numpy as np -from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D -import astropy.units as u def test_create_irf_full_enclosure(temp_dir_observed_files, simulated_dl2_file): """ @@ -381,213 +379,17 @@ def test_index_dl3_files(temp_dir_observed_files): assert 2008 in data.obs_table["OBS_ID"] - -def test_create_irf_point_like_srcdep_energy_dependent_cuts( - temp_dir_observed_srcdep_files, simulated_srcdep_dl2_file -): - """ - Generating point-like source-dependent IRF file from a test DL2 files, - using energy-dependent cuts - """ - from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter - from astropy.table import QTable - - irf_file = temp_dir_observed_srcdep_files / "irf_edep.fits.gz" - - assert ( - run_tool( - IRFFITSWriter(), - argv=[ - f"--input-gamma-dl2={simulated_srcdep_dl2_file}", - f"--output-irf-file={irf_file}", - "--point-like", - "--source-dep", - "--energy-dependent-gh", - "--energy-dependent-alpha", - "--DL3Cuts.min_event_p_en_bin=2", - "--overwrite", - ], - cwd=temp_dir_observed_srcdep_files, - ) - == 0 - ) - - gh_cuts = QTable.read(irf_file, hdu="GH_CUTS") - assert isinstance(gh_cuts.meta["GH_EFF"], float) - - al_cuts = QTable.read(irf_file, hdu="AL_CUTS") - assert isinstance(al_cuts.meta["AL_CONT"], float) - - -@pytest.mark.private_data -def test_create_dl3_energy_dependent_cuts(temp_dir_observed_files, observed_dl2_file): - """ - Generating an DL3 file from a test DL2 files and test IRF file, using - energy dependent cuts. Here the previously created IRF is used. - """ - from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter - from gammapy.data import Observation - - irf_file = temp_dir_observed_files / "pnt_irf.fits.gz" - - dl2_name = observed_dl2_file.name - observed_dl3_file = temp_dir_observed_files / dl2_name.replace("dl2", "dl3") - observed_dl3_file = observed_dl3_file.with_suffix(".fits") - - assert ( - run_tool( - DataReductionFITSWriter(), - argv=[ - f"--input-dl2={observed_dl2_file}", - f"--output-dl3-path={temp_dir_observed_files}", - f"--input-irf-path={temp_dir_observed_files}", - "--irf-file-pattern=pnt_irf.fits.gz", - "--source-name=Crab", - "--source-ra=83.633deg", - "--source-dec=22.01deg", - "--overwrite", - ], - cwd=temp_dir_observed_files, - ) - == 0 - ) - - assert ( - Observation.read(event_file=observed_dl3_file, irf_file=irf_file).obs_id == 2008 - ) - - -@pytest.mark.private_data -def test_create_dl3(temp_dir_observed_files, observed_dl2_file, simulated_irf_file): - """ - Generating an DL3 file from a test DL2 files and test IRF file - """ - from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter - - assert ( - run_tool( - DataReductionFITSWriter(), - argv=[ - f"--input-dl2={observed_dl2_file}", - f"--output-dl3-path={temp_dir_observed_files}", - f"--input-irf-path={simulated_irf_file.parent}", - f"--irf-file-pattern={simulated_irf_file.name}", - "--source-name=Crab", - "--source-ra=83.633deg", - "--source-dec=22.01deg", - "--overwrite", - ], - cwd=temp_dir_observed_files, - ) - == 0 - ) - - -@pytest.mark.private_data -def test_create_dl3_with_config(temp_dir_observed_files, observed_dl2_file): - """ - Generating an DL3 file from a test DL2 files and test IRF file, using - a config file - """ - from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter - - config_file = os.path.join(os.getcwd(), "docs/examples/irf_dl3_tool_config.json") - - assert ( - run_tool( - DataReductionFITSWriter(), - argv=[ - f"--input-dl2={observed_dl2_file}", - f"--output-dl3-path={temp_dir_observed_files}", - f"--input-irf-path={temp_dir_observed_files}", - "--irf-file-pattern=fe_irf.fits.gz", - "--source-name=Crab", - "--source-ra=83.633deg", - "--source-dec=22.01deg", - f"--config={config_file}", - "--overwrite", - ], - cwd=temp_dir_observed_files, - ) - == 0 - ) - + for hdu_name in [ + 'EVENTS', 'GTI', 'POINTING', + 'EFFECTIVE AREA', 'ENERGY DISPERSION', + 'BACKGROUND', 'PSF' + ]: + assert hdu_name in data.hdu_table['HDU_NAME'] @pytest.mark.private_data -def test_create_srcdep_dl3( - temp_dir_observed_srcdep_files, observed_srcdep_dl2_file, simulated_srcdep_irf_file -): +def test_index_srcdep_dl3_files(temp_dir_observed_srcdep_files): """ - Generating a source-dependent DL3 file from a test DL2 files and test IRF file - """ - from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter - from lstchain.paths import dl2_to_dl3_filename - - assert ( - run_tool( - DataReductionFITSWriter(), - argv=[ - f"--input-dl2={observed_srcdep_dl2_file}", - f"--output-dl3-path={temp_dir_observed_srcdep_files}", - f"--input-irf-path={simulated_srcdep_irf_file.parent}", - f"--irf-file-pattern={simulated_srcdep_irf_file.name}", - "--source-name=Crab", - "--source-ra=83.633deg", - "--source-dec=22.01deg", - "--source-dep", - "--overwrite", - ], - cwd=temp_dir_observed_srcdep_files, - ) - == 0 - ) - - hdulist = fits.open( - temp_dir_observed_srcdep_files / dl2_to_dl3_filename(observed_srcdep_dl2_file) - ) - ra = hdulist[1].data["RA"] - dec = hdulist[1].data["DEC"] - - np.testing.assert_allclose(ra, 83.63, atol=1e-2) - np.testing.assert_allclose(dec, 22.01, atol=1e-2) - - -@pytest.mark.private_data -def test_create_srcdep_dl3_energy_dependent_cuts( - temp_dir_observed_srcdep_files, observed_srcdep_dl2_file -): - """ - Generating a source-dependent DL3 file from a test DL2 files and test IRF file, - using energy-dependent cuts - """ - from lstchain.tools.lstchain_create_dl3_file import DataReductionFITSWriter - - irf_file = temp_dir_observed_srcdep_files / "irf_edep.fits.gz" - - assert ( - run_tool( - DataReductionFITSWriter(), - argv=[ - f"--input-dl2={observed_srcdep_dl2_file}", - f"--output-dl3-path={temp_dir_observed_srcdep_files}", - f"--input-irf-path={irf_file.parent}", - f"--irf-file-pattern={irf_file.name}", - "--source-name=Crab", - "--source-ra=83.633deg", - "--source-dec=22.01deg", - "--source-dep", - "--overwrite", - ], - cwd=temp_dir_observed_srcdep_files, - ) - == 0 - ) - - -@pytest.mark.private_data -def test_index_dl3_files(temp_dir_observed_files): - """ - Generating Index files from a given path and glob pattern for DL3 files + Generating Index files from a given path and glob pattern for srcdep DL3 files """ from lstchain.tools.lstchain_create_dl3_index_files import FITSIndexWriter from gammapy.data import DataStore @@ -596,18 +398,22 @@ def test_index_dl3_files(temp_dir_observed_files): run_tool( FITSIndexWriter(), argv=[ - f"--input-dl3-dir={temp_dir_observed_files}", + f"--input-dl3-dir={temp_dir_observed_srcdep_files}", "--overwrite", ], - cwd=temp_dir_observed_files, + cwd=temp_dir_observed_srcdep_files, ) == 0 ) - data = DataStore.from_dir(temp_dir_observed_files) + data = DataStore.from_dir(temp_dir_observed_srcdep_files) assert 2008 in data.obs_table["OBS_ID"] - + for hdu_name in [ + 'EVENTS', 'GTI', 'POINTING', + 'EFFECTIVE AREA', 'ENERGY DISPERSION' + ]: + assert hdu_name in data.hdu_table['HDU_NAME'] def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_file): """ @@ -615,6 +421,8 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi """ from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter + from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D + import astropy.units as u irf_file=temp_dir_observed_files / "fe_irf.fits.gz" irf_file_mod = temp_dir_observed_files / "mod_irf.fits.gz" @@ -631,10 +439,11 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi f"--output-irf-file={irf_file}", f"--config={config_file}", "--overwrite", - "--DataBinning.true_energy_n_bins=10", - "--DataBinning.reco_energy_n_bins=10", + "--DataBinning.true_energy_n_bins=2", + "--DataBinning.reco_energy_n_bins=2", + "--DataBinning.true_energy_min: 0.2", + "--DataBinning.true_energy_max: 0.3", "--DL3Cuts.min_event_p_en_bin=2", - "--DataBinning.energy_migration_n_bins=15", ], cwd=temp_dir_observed_files, ) @@ -650,10 +459,11 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi f"--output-irf-file={irf_file_mod}", f"--config={config_file_mod}", "--overwrite", - "--DataBinning.true_energy_n_bins=10", - "--DataBinning.reco_energy_n_bins=10", + "--DataBinning.true_energy_n_bins=2", + "--DataBinning.reco_energy_n_bins=2", + "--DataBinning.true_energy_min: 0.2", + "--DataBinning.true_energy_max: 0.3", "--DL3Cuts.min_event_p_en_bin=2", - "--DataBinning.energy_migration_n_bins=15", ], cwd=temp_dir_observed_files, ) @@ -694,6 +504,11 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi migra=e_migra_mod ) - #for Ereco/Etrue near 1 (test for 0.94 and 1.05) - assert (e_migra_prob_mod[14]>e_migra_prob[14]) - assert (e_migra_prob_mod[15]>e_migra_prob[15]) + #check that the maximum of the density probability of the migration has shifted + for i in range(len(e_migra)): + if e_migra_prob[i]>e_migra_prob[i-1]: + order_max=i + if e_migra_prob_mod[i]>e_migra_prob_mod[i-1]: + order_max_mod=i + + assert (order_max!=order_max_mod) From b8fb8c5f7d57d0bc148bf763a5d420970bbe726e Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:29:38 +0200 Subject: [PATCH 16/34] Update test_tools.py Use only one config_file for the test for energy scaling in irfs --- lstchain/tools/tests/test_tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 29c8ea2cea..b069de0fd6 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -427,8 +427,7 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi irf_file=temp_dir_observed_files / "fe_irf.fits.gz" irf_file_mod = temp_dir_observed_files / "mod_irf.fits.gz" config_file = os.path.join(os.getcwd(), "docs/examples/irf_dl3_tool_config.json") - config_file_mod = os.path.join(os.getcwd(), "docs/examples/irf_dl3_tool_config_mod.json") - + assert ( run_tool( IRFFITSWriter(), @@ -457,13 +456,14 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi f"--input-proton-dl2={simulated_dl2_file}", f"--input-electron-dl2={simulated_dl2_file}", f"--output-irf-file={irf_file_mod}", - f"--config={config_file_mod}", + f"--config={config_file}", "--overwrite", "--DataBinning.true_energy_n_bins=2", "--DataBinning.reco_energy_n_bins=2", "--DataBinning.true_energy_min: 0.2", "--DataBinning.true_energy_max: 0.3", "--DL3Cuts.min_event_p_en_bin=2", + "--DataBinning.scale_true_energy=1.15", ], cwd=temp_dir_observed_files, ) From 7a924090bd0624e430bbbe6233e3ec55e6d393ed Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:35:26 +0200 Subject: [PATCH 17/34] Delete docs/examples/irf_dl3_tool_config_mod.json --- docs/examples/irf_dl3_tool_config_mod.json | 52 ---------------------- 1 file changed, 52 deletions(-) delete mode 100644 docs/examples/irf_dl3_tool_config_mod.json diff --git a/docs/examples/irf_dl3_tool_config_mod.json b/docs/examples/irf_dl3_tool_config_mod.json deleted file mode 100644 index 0a69e7e822..0000000000 --- a/docs/examples/irf_dl3_tool_config_mod.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "EventSelector": { - "filters": { - "intensity": [50, Infinity], - "width": [0, Infinity], - "length": [0, Infinity], - "r": [0, 1], - "wl": [0.01, 1], - "leakage_intensity_width_2": [0, 1], - "event_type": [32, 32] - } - }, - "DL3Cuts": { - "min_event_p_en_bin": 100, - "global_gh_cut": 0.7, - "gh_efficiency": 0.7, - "min_gh_cut": 0.1, - "max_gh_cut": 0.98, - "global_alpha_cut": 10, - "global_theta_cut": 0.2, - "theta_containment": 0.7, - "alpha_containment": 0.7, - "min_theta_cut": 0.1, - "max_theta_cut": 0.32, - "fill_theta_cut": 0.32, - "min_alpha_cut": 1, - "max_alpha_cut": 20, - "fill_alpha_cut": 20, - "allowed_tels": [1] - }, - "DataBinning": { - "true_energy_min": 0.005, - "true_energy_max": 500, - "true_energy_n_bins": 25, - "scale_true_energy": 1.15, - "reco_energy_min": 0.005, - "reco_energy_max": 500, - "reco_energy_n_bins": 25, - "energy_migration_min": 0.2, - "energy_migration_max": 5, - "energy_migration_n_bins": 30, - "fov_offset_min": 0.1, - "fov_offset_max": 1.1, - "fov_offset_n_edges": 9, - "bkg_fov_offset_min": 0, - "bkg_fov_offset_max": 10, - "bkg_fov_offset_n_edges": 21, - "source_offset_min": 0, - "source_offset_max": 1, - "source_offset_n_edges": 101 - } -} From be83a587431fafb361c2ef7dec27dbd7b01c1cfd Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:56:55 +0200 Subject: [PATCH 18/34] Update lstchain_create_irf_files.py Remove --point-like argument --- lstchain/tools/lstchain_create_irf_files.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 50c2a05ac0..65cb2537c7 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -149,7 +149,6 @@ class IRFFITSWriter(Tool): > lstchain_create_irf_files -g /path/to/DL2_MC_gamma_file.h5 -o /path/to/irf.fits.gz - --point-like (Only for point_like IRFs) --scaling_true_energy 1.15 """ From f8614a28c2a2ad07197fc0135197921ccda7cc7a Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Thu, 4 Jul 2024 08:08:58 +0200 Subject: [PATCH 19/34] Update test_tools.py Modifications to test for the different energies. --- lstchain/tools/tests/test_tools.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index b069de0fd6..0377551f50 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -482,7 +482,6 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi assert(aeff_mod_hdu.data.shape==aeff_hdu.data.shape) assert(edisp_mod_hdu.data.shape==edisp_hdu.data.shape) - #test with scaling factor=1.15 edisp=EnergyDispersion2D.read(irf_file) edisp_mod=EnergyDispersion2D.read(irf_file_mod) @@ -490,25 +489,31 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi e_migra_mod=edisp_mod.axes["migra"].center e_true_list=[0.2,2,20] + e_migra_prob=[] + e_migra_prob_mod=[] for i in e_true_list: e_true = i* u.TeV - e_migra_prob = edisp.evaluate( + e_migra_prob.append(edisp.evaluate( offset=0.4*u.deg, energy_true=e_true, migra=e_migra - ) - e_migra_prob_mod = edisp_mod.evaluate( + )) + e_migra_prob_mod.append(edisp_mod.evaluate( offset=0.4*u.deg, energy_true=e_true, migra=e_migra_mod - ) + )) #check that the maximum of the density probability of the migration has shifted - for i in range(len(e_migra)): - if e_migra_prob[i]>e_migra_prob[i-1]: - order_max=i - if e_migra_prob_mod[i]>e_migra_prob_mod[i-1]: - order_max_mod=i - - assert (order_max!=order_max_mod) + order_max = [] + order_max_mod = [] + for idx, _ in enumerate(e_true_list): + for j in range(len(e_migra)): + if e_migra_prob[idx][j] > e_migra_prob[idx][j-1]: + order_max.append(j) + if e_migra_prob_mod[idx][j] > e_migra_prob_mod[idx][j-1]: + order_max_mod.append(j) + + for i in range(len(order_max)): + assert (order_max[i]!=order_max_mod[i]) From a41fa4f2c6ccba0da2581400daead150e44c3323 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Thu, 4 Jul 2024 08:21:52 +0200 Subject: [PATCH 20/34] Update lstchain_create_irf_files.py Redefine the argument scaling-true-energy --- lstchain/tools/lstchain_create_irf_files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 65cb2537c7..0e631f4357 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -149,7 +149,7 @@ class IRFFITSWriter(Tool): > lstchain_create_irf_files -g /path/to/DL2_MC_gamma_file.h5 -o /path/to/irf.fits.gz - --scaling_true_energy 1.15 + --scaling-true-energy 1.15 """ input_gamma_dl2 = traits.Path( @@ -235,7 +235,7 @@ class IRFFITSWriter(Tool): "global-alpha-cut": "DL3Cuts.global_alpha_cut", "allowed-tels": "DL3Cuts.allowed_tels", "overwrite": "IRFFITSWriter.overwrite", - "scale_true_energy": "DataBinning.scale_true_energy" + "scale-true-energy": "DataBinning.scale_true_energy" } flags = { From dc361ce86995b00d97eb2a73cd07ecda979efba1 Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Thu, 4 Jul 2024 08:30:03 +0200 Subject: [PATCH 21/34] Update lstchain_create_irf_files.py Rename the argument correctly --- lstchain/tools/lstchain_create_irf_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/tools/lstchain_create_irf_files.py b/lstchain/tools/lstchain_create_irf_files.py index 0e631f4357..d3c2e464b3 100644 --- a/lstchain/tools/lstchain_create_irf_files.py +++ b/lstchain/tools/lstchain_create_irf_files.py @@ -149,7 +149,7 @@ class IRFFITSWriter(Tool): > lstchain_create_irf_files -g /path/to/DL2_MC_gamma_file.h5 -o /path/to/irf.fits.gz - --scaling-true-energy 1.15 + --scale-true-energy 1.15 """ input_gamma_dl2 = traits.Path( From 9a0605a27012be469f9eab874477cfa3ee39c17e Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Thu, 4 Jul 2024 08:59:55 +0200 Subject: [PATCH 22/34] Update test_tools.py Remove additional comments. --- lstchain/tools/tests/test_tools.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 0377551f50..09b976083b 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -476,9 +476,6 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi edisp_hdu=EnergyDispersion2D.read(irf_file, hdu='ENERGY DISPERSION') edisp_mod_hdu=EnergyDispersion2D.read(irf_file_mod, hdu='ENERGY DISPERSION') - - #assert (aeff_mod.data.shape==(25,1)) - #assert (edisp_mod.data.shape==(25,30,1))#(E,migra,offset) assert(aeff_mod_hdu.data.shape==aeff_hdu.data.shape) assert(edisp_mod_hdu.data.shape==edisp_hdu.data.shape) From 221aaf71c1a9d06ac1545b434781eb1d5992c80c Mon Sep 17 00:00:00 2001 From: deborahDOR <129405198+deborahDOR@users.noreply.github.com> Date: Thu, 4 Jul 2024 09:50:38 +0200 Subject: [PATCH 23/34] Update test_tools.py Cleaning of code for assert lines --- lstchain/tools/tests/test_tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 09b976083b..d90d485647 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -476,8 +476,8 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi edisp_hdu=EnergyDispersion2D.read(irf_file, hdu='ENERGY DISPERSION') edisp_mod_hdu=EnergyDispersion2D.read(irf_file_mod, hdu='ENERGY DISPERSION') - assert(aeff_mod_hdu.data.shape==aeff_hdu.data.shape) - assert(edisp_mod_hdu.data.shape==edisp_hdu.data.shape) + assert aeff_mod_hdu.data.shape==aeff_hdu.data.shape + assert edisp_mod_hdu.data.shape==edisp_hdu.data.shape edisp=EnergyDispersion2D.read(irf_file) edisp_mod=EnergyDispersion2D.read(irf_file_mod) @@ -513,4 +513,4 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi order_max_mod.append(j) for i in range(len(order_max)): - assert (order_max[i]!=order_max_mod[i]) + assert order_max[i]!=order_max_mod[i] From 264f39c2023fa9b43705ffa794102450df57e8a5 Mon Sep 17 00:00:00 2001 From: Daniel Morcuende Date: Thu, 4 Jul 2024 11:36:30 +0200 Subject: [PATCH 24/34] [skip ci] typo --- lstchain/tools/tests/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index d90d485647..8c5bd37d98 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -417,7 +417,7 @@ def test_index_srcdep_dl3_files(temp_dir_observed_srcdep_files): def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_file): """ - Checking the validy of modified IRFs after scaling the True Energy by a factor. + Checking the validity of modified IRFs after scaling the True Energy by a factor. """ from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter From ce611f55e559221c856760ec78981bed6b2e4852 Mon Sep 17 00:00:00 2001 From: Gabriel Emery Date: Wed, 3 Jul 2024 16:17:34 +0200 Subject: [PATCH 25/34] Improve the exploration of Simtel config history to handle more LST MC productions. --- lstchain/io/io.py | 56 ++++++++++++++++---------------------- lstchain/reco/r0_to_dl1.py | 4 +-- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/lstchain/io/io.py b/lstchain/io/io.py index 04cd0c9ffe..fcefb9ead2 100644 --- a/lstchain/io/io.py +++ b/lstchain/io/io.py @@ -1,6 +1,5 @@ import logging import os -import re import warnings from multiprocessing import Pool from contextlib import ExitStack @@ -22,9 +21,8 @@ from ctapipe.instrument import SubarrayDescription from ctapipe.io import HDF5TableReader, HDF5TableWriter -from eventio import Histograms, EventIOFile -from eventio.search_utils import yield_toplevel_of_type, yield_all_subobjects -from eventio.simtel.objects import History, HistoryConfig +from eventio import Histograms, SimTelFile +from eventio.search_utils import yield_toplevel_of_type from pyirf.simulations import SimulatedEventsInfo @@ -59,7 +57,6 @@ 'global_metadata', 'merge_dl2_runs', 'merging_check', - 'parse_cfg_bytestring', 'read_data_dl2_to_QTable', 'read_dl2_params', 'read_mc_dl2_to_QTable', @@ -1264,37 +1261,32 @@ def remove_duplicated_events(data): data.remove_rows(remove_row_list) -def parse_cfg_bytestring(bytestring): - """ - Parse configuration as read by eventio - :param bytes bytestring: A ``Bytes`` object with configuration data for one parameter - :return: Tuple in form ``('parameter_name', 'value')`` - """ - line_decoded = bytestring.decode('utf-8').rstrip() - if 'ECHO' in line_decoded or '#' in line_decoded: - return None - line_list = line_decoded.split('%', 1)[0] # drop comment - res = re.sub(' +', ' ', line_list).strip().split(' ', 1) # remove extra whitespaces and split - return res[0].upper(), res[1] - - def extract_simulation_nsb(filename): """ Get current run NSB from configuration in simtel file :param str filename: Input file name - :return array of `float` by tel_id: NSB rate - """ - nsb = [] - with EventIOFile(filename) as f: - for o in yield_all_subobjects(f, [History, HistoryConfig]): - if hasattr(o, 'parse'): - try: - cfg_element = parse_cfg_bytestring(o.parse()[1]) - if cfg_element is not None: - if cfg_element[0] == 'NIGHTSKY_BACKGROUND': - nsb.append(float(cfg_element[1].strip('all:'))) - except Exception as e: - print('Unexpected end of %s,\n caught exception %s', filename, e) + :return dict of `float` by tel_id: NSB rate + """ + nsb = {} + # In current MC, correct NSB are logged after 'STORE_PHOTOELECTRONS' entries + # TODO In any new production, behaviour needs to be verified. + # New version of simtel will allow to use better metadata + next_nsb = False + tel_id = 1 + with SimTelFile(filename) as f: + try: + for _, line in f.history: + line = line.decode('utf-8').strip().split(' ') + if next_nsb and line[0] == 'NIGHTSKY_BACKGROUND': + nsb[tel_id] = line[1].strip('all:') + tel_id = tel_id+1 + if line[0] == 'STORE_PHOTOELECTRONS': + next_nsb = True + else: + next_nsb = False + except Exception as e: + log.error('Unexpected end of %s,\n caught exception %s', filename, e) + raise e return nsb diff --git a/lstchain/reco/r0_to_dl1.py b/lstchain/reco/r0_to_dl1.py index 1dbe3be1aa..3f2db65a45 100644 --- a/lstchain/reco/r0_to_dl1.py +++ b/lstchain/reco/r0_to_dl1.py @@ -433,10 +433,8 @@ def r0_to_dl1( charge_spe_cumulative_pdf = interp1d(spe_integral, spe[0], kind='cubic', bounds_error=False, fill_value=0., assume_sorted=True) - allowed_tel = np.zeros(len(nsb_original), dtype=bool) - allowed_tel[np.array(config['source_config']['LSTEventSource']['allowed_tels'])] = True logger.info('Tuning NSB on MC waveform from ' - + str(np.asarray(nsb_original)[allowed_tel]) + + str(np.asarray(nsb_original)) + 'GHz to {0:d}%'.format(int(nsb_tuning_ratio * 100 + 100.5)) + ' for telescopes ids ' + str(config['source_config']['LSTEventSource']['allowed_tels'])) nsb_tuning_args = [nsb_tuning_ratio, nsb_original, pulse_template, charge_spe_cumulative_pdf] From 8b7d8f6244f125011f0c10e17327d1b6189ff57a Mon Sep 17 00:00:00 2001 From: Gabriel Emery Date: Wed, 3 Jul 2024 16:44:16 +0200 Subject: [PATCH 26/34] Fix test --- lstchain/io/tests/test_io.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lstchain/io/tests/test_io.py b/lstchain/io/tests/test_io.py index 8f65bd674f..6442eff66e 100644 --- a/lstchain/io/tests/test_io.py +++ b/lstchain/io/tests/test_io.py @@ -156,8 +156,7 @@ def test_extract_simulation_nsb(mc_gamma_testfile): from lstchain.io.io import extract_simulation_nsb nsb = extract_simulation_nsb(mc_gamma_testfile) - assert np.isclose(nsb[0], 0.246, rtol=0.1) - assert np.isclose(nsb[1], 0.217, rtol=0.1) + assert np.isclose(nsb[1], 0.246, rtol=0.1) def test_remove_duplicated_events(): From b28556c0f3950cf74a824db4502b2a9d3cadd774 Mon Sep 17 00:00:00 2001 From: Gabriel Emery Date: Wed, 3 Jul 2024 17:09:00 +0200 Subject: [PATCH 27/34] Convert to float --- lstchain/io/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/io/io.py b/lstchain/io/io.py index fcefb9ead2..d5921cd922 100644 --- a/lstchain/io/io.py +++ b/lstchain/io/io.py @@ -1278,7 +1278,7 @@ def extract_simulation_nsb(filename): for _, line in f.history: line = line.decode('utf-8').strip().split(' ') if next_nsb and line[0] == 'NIGHTSKY_BACKGROUND': - nsb[tel_id] = line[1].strip('all:') + nsb[tel_id] = float(line[1].strip('all:')) tel_id = tel_id+1 if line[0] == 'STORE_PHOTOELECTRONS': next_nsb = True From edfaf3985d0a906cba2394ffef47bfe1365a9b3a Mon Sep 17 00:00:00 2001 From: Gabriel Emery Date: Thu, 4 Jul 2024 15:16:13 +0200 Subject: [PATCH 28/34] Remove try block without handled exception. --- lstchain/io/io.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lstchain/io/io.py b/lstchain/io/io.py index d5921cd922..1d6962447c 100644 --- a/lstchain/io/io.py +++ b/lstchain/io/io.py @@ -1274,19 +1274,15 @@ def extract_simulation_nsb(filename): next_nsb = False tel_id = 1 with SimTelFile(filename) as f: - try: - for _, line in f.history: - line = line.decode('utf-8').strip().split(' ') - if next_nsb and line[0] == 'NIGHTSKY_BACKGROUND': - nsb[tel_id] = float(line[1].strip('all:')) - tel_id = tel_id+1 - if line[0] == 'STORE_PHOTOELECTRONS': - next_nsb = True - else: - next_nsb = False - except Exception as e: - log.error('Unexpected end of %s,\n caught exception %s', filename, e) - raise e + for _, line in f.history: + line = line.decode('utf-8').strip().split(' ') + if next_nsb and line[0] == 'NIGHTSKY_BACKGROUND': + nsb[tel_id] = float(line[1].strip('all:')) + tel_id = tel_id+1 + if line[0] == 'STORE_PHOTOELECTRONS': + next_nsb = True + else: + next_nsb = False return nsb From b0820e616edf4fd6ab327bc0d78c12f257d3827f Mon Sep 17 00:00:00 2001 From: Gabriel Emery Date: Thu, 4 Jul 2024 15:26:08 +0200 Subject: [PATCH 29/34] Add warning log message --- lstchain/io/io.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lstchain/io/io.py b/lstchain/io/io.py index 1d6962447c..bfcf686ef5 100644 --- a/lstchain/io/io.py +++ b/lstchain/io/io.py @@ -1283,6 +1283,10 @@ def extract_simulation_nsb(filename): next_nsb = True else: next_nsb = False + log.warning('Original MC night sky background extracted from the config history in the simtel file.\n' + 'This is done for existing LST MC such as the one created using: ' + 'https://github.com/cta-observatory/lst-sim-config/tree/sim-tel_LSTProd2_MAGICST0316' + '\nExtracted values are: ' + str(np.asarray(nsb)) + 'GHz. Check that it corresponds to expectations.') return nsb From c137ade6b5741604a2d9256726fffd7a2a48580f Mon Sep 17 00:00:00 2001 From: Gabriel Emery Date: Fri, 5 Jul 2024 09:12:23 +0200 Subject: [PATCH 30/34] Move comment about NSB extraction from simtel file to the function docstring. --- lstchain/io/io.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lstchain/io/io.py b/lstchain/io/io.py index bfcf686ef5..79a82ad556 100644 --- a/lstchain/io/io.py +++ b/lstchain/io/io.py @@ -1263,14 +1263,16 @@ def remove_duplicated_events(data): def extract_simulation_nsb(filename): """ - Get current run NSB from configuration in simtel file + Get current run NSB from configuration in simtel file. + + WARNING : In current MC, correct NSB are logged after 'STORE_PHOTOELECTRONS' entries + In any new production, behaviour needs to be verified. + New version of simtel will allow to use better metadata. + :param str filename: Input file name :return dict of `float` by tel_id: NSB rate """ nsb = {} - # In current MC, correct NSB are logged after 'STORE_PHOTOELECTRONS' entries - # TODO In any new production, behaviour needs to be verified. - # New version of simtel will allow to use better metadata next_nsb = False tel_id = 1 with SimTelFile(filename) as f: From 037f9005d3100bed533e984a6020098498ff9521 Mon Sep 17 00:00:00 2001 From: Chaitanya Priyadarshi Date: Mon, 8 Jul 2024 10:55:49 +0200 Subject: [PATCH 31/34] Run black and add the missing pytest marker --- lstchain/tools/tests/test_tools.py | 93 +++++++++++++++++------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 8c5bd37d98..3e5b96b900 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -4,6 +4,7 @@ from astropy.io import fits import numpy as np + def test_create_irf_full_enclosure(temp_dir_observed_files, simulated_dl2_file): """ Generating full enclosure IRF file from a test DL2 files @@ -380,11 +381,16 @@ def test_index_dl3_files(temp_dir_observed_files): assert 2008 in data.obs_table["OBS_ID"] for hdu_name in [ - 'EVENTS', 'GTI', 'POINTING', - 'EFFECTIVE AREA', 'ENERGY DISPERSION', - 'BACKGROUND', 'PSF' + "EVENTS", + "GTI", + "POINTING", + "EFFECTIVE AREA", + "ENERGY DISPERSION", + "BACKGROUND", + "PSF", ]: - assert hdu_name in data.hdu_table['HDU_NAME'] + assert hdu_name in data.hdu_table["HDU_NAME"] + @pytest.mark.private_data def test_index_srcdep_dl3_files(temp_dir_observed_srcdep_files): @@ -410,24 +416,29 @@ def test_index_srcdep_dl3_files(temp_dir_observed_srcdep_files): assert 2008 in data.obs_table["OBS_ID"] for hdu_name in [ - 'EVENTS', 'GTI', 'POINTING', - 'EFFECTIVE AREA', 'ENERGY DISPERSION' + "EVENTS", + "GTI", + "POINTING", + "EFFECTIVE AREA", + "ENERGY DISPERSION", ]: - assert hdu_name in data.hdu_table['HDU_NAME'] + assert hdu_name in data.hdu_table["HDU_NAME"] + +@pytest.mark.private_data def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_file): """ Checking the validity of modified IRFs after scaling the True Energy by a factor. """ - from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter - from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D import astropy.units as u + from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D + from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter - irf_file=temp_dir_observed_files / "fe_irf.fits.gz" + irf_file = temp_dir_observed_files / "fe_irf.fits.gz" irf_file_mod = temp_dir_observed_files / "mod_irf.fits.gz" config_file = os.path.join(os.getcwd(), "docs/examples/irf_dl3_tool_config.json") - + assert ( run_tool( IRFFITSWriter(), @@ -470,47 +481,51 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi == 0 ) - aeff_hdu=EffectiveAreaTable2D.read(irf_file, hdu='EFFECTIVE AREA') - aeff_mod_hdu=EffectiveAreaTable2D.read(irf_file_mod, hdu='EFFECTIVE AREA') + aeff_hdu = EffectiveAreaTable2D.read(irf_file, hdu="EFFECTIVE AREA") + aeff_mod_hdu = EffectiveAreaTable2D.read(irf_file_mod, hdu="EFFECTIVE AREA") - edisp_hdu=EnergyDispersion2D.read(irf_file, hdu='ENERGY DISPERSION') - edisp_mod_hdu=EnergyDispersion2D.read(irf_file_mod, hdu='ENERGY DISPERSION') + edisp_hdu = EnergyDispersion2D.read(irf_file, hdu="ENERGY DISPERSION") + edisp_mod_hdu = EnergyDispersion2D.read(irf_file_mod, hdu="ENERGY DISPERSION") - assert aeff_mod_hdu.data.shape==aeff_hdu.data.shape - assert edisp_mod_hdu.data.shape==edisp_hdu.data.shape + assert aeff_mod_hdu.data.shape == aeff_hdu.data.shape + assert edisp_mod_hdu.data.shape == edisp_hdu.data.shape - edisp=EnergyDispersion2D.read(irf_file) - edisp_mod=EnergyDispersion2D.read(irf_file_mod) + edisp = EnergyDispersion2D.read(irf_file) + edisp_mod = EnergyDispersion2D.read(irf_file_mod) e_migra = edisp.axes["migra"].center - e_migra_mod=edisp_mod.axes["migra"].center + e_migra_mod = edisp_mod.axes["migra"].center - e_true_list=[0.2,2,20] - e_migra_prob=[] - e_migra_prob_mod=[] + e_true_list = [0.2, 2, 20] + e_migra_prob = [] + e_migra_prob_mod = [] for i in e_true_list: - e_true = i* u.TeV - e_migra_prob.append(edisp.evaluate( - offset=0.4*u.deg, - energy_true=e_true, - migra=e_migra - )) - e_migra_prob_mod.append(edisp_mod.evaluate( - offset=0.4*u.deg, - energy_true=e_true, - migra=e_migra_mod - )) - - #check that the maximum of the density probability of the migration has shifted + e_true = i * u.TeV + e_migra_prob.append( + edisp.evaluate( + offset=0.4 * u.deg, + energy_true=e_true, + migra=e_migra, + ) + ) + e_migra_prob_mod.append( + edisp_mod.evaluate( + offset=0.4 * u.deg, + energy_true=e_true, + migra=e_migra_mod, + ) + ) + + # Check that the maximum of the density probability of the migration has shifted order_max = [] order_max_mod = [] for idx, _ in enumerate(e_true_list): for j in range(len(e_migra)): - if e_migra_prob[idx][j] > e_migra_prob[idx][j-1]: + if e_migra_prob[idx][j] > e_migra_prob[idx][j - 1]: order_max.append(j) - if e_migra_prob_mod[idx][j] > e_migra_prob_mod[idx][j-1]: + if e_migra_prob_mod[idx][j] > e_migra_prob_mod[idx][j - 1]: order_max_mod.append(j) for i in range(len(order_max)): - assert order_max[i]!=order_max_mod[i] + assert order_max[i] != order_max_mod[i] From 66a99d741df2a232a2d7d980a969bb6ae4fae815 Mon Sep 17 00:00:00 2001 From: Chaitanya Priyadarshi Date: Mon, 8 Jul 2024 10:48:41 +0200 Subject: [PATCH 32/34] Update test_tools.py by running black and adding a missing pytest marker --- lstchain/tools/tests/test_tools.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 3e5b96b900..5f6837c8b5 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -3,7 +3,10 @@ import os from astropy.io import fits import numpy as np +<<<<<<< HEAD +======= +>>>>>>> 3d0a1539 (Update test_tools.py) def test_create_irf_full_enclosure(temp_dir_observed_files, simulated_dl2_file): """ @@ -434,6 +437,8 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi import astropy.units as u from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter + from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D + import astropy.units as u irf_file = temp_dir_observed_files / "fe_irf.fits.gz" irf_file_mod = temp_dir_observed_files / "mod_irf.fits.gz" From 980aabe81ea303fb85ff169c9b96feb34f6230a7 Mon Sep 17 00:00:00 2001 From: Chaitanya Priyadarshi Date: Mon, 8 Jul 2024 10:51:19 +0200 Subject: [PATCH 33/34] Update test_tools.py Use only one config_file for the test for energy scaling in irfs --- lstchain/tools/tests/test_tools.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 5f6837c8b5..0d52ffaba5 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -3,10 +3,7 @@ import os from astropy.io import fits import numpy as np -<<<<<<< HEAD -======= ->>>>>>> 3d0a1539 (Update test_tools.py) def test_create_irf_full_enclosure(temp_dir_observed_files, simulated_dl2_file): """ From e9990020da874566b13aff9f865e036b34577633 Mon Sep 17 00:00:00 2001 From: Chaitanya Priyadarshi Date: Mon, 8 Jul 2024 11:02:10 +0200 Subject: [PATCH 34/34] Run pyflakes to clean up rebase issues --- lstchain/tools/tests/test_tools.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lstchain/tools/tests/test_tools.py b/lstchain/tools/tests/test_tools.py index 0d52ffaba5..3e5b96b900 100644 --- a/lstchain/tools/tests/test_tools.py +++ b/lstchain/tools/tests/test_tools.py @@ -434,8 +434,6 @@ def test_add_scale_true_energy_in_irfs(temp_dir_observed_files, simulated_dl2_fi import astropy.units as u from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D from lstchain.tools.lstchain_create_irf_files import IRFFITSWriter - from gammapy.irf import EffectiveAreaTable2D, EnergyDispersion2D - import astropy.units as u irf_file = temp_dir_observed_files / "fe_irf.fits.gz" irf_file_mod = temp_dir_observed_files / "mod_irf.fits.gz"