From 6c319e085687fbbf4fda3c74f811968e2e56fd0e Mon Sep 17 00:00:00 2001 From: morcuended Date: Mon, 27 Nov 2023 08:12:54 +0000 Subject: [PATCH 1/5] require pyirf 0.10 --- environment.yml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index b1ad558f88..d055b62103 100644 --- a/environment.yml +++ b/environment.yml @@ -33,5 +33,5 @@ dependencies: - seaborn - ctapipe_io_lst=0.22 - pytest - - pyirf=0.8 + - pyirf~=0.10.0 diff --git a/setup.py b/setup.py index e5d3ca4928..ed93bb2e19 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ def find_scripts(script_dir, prefix): 'numpy', 'pandas', 'protobuf~=3.20.0', - 'pyirf~=0.8.0', + 'pyirf~=0.10.0', 'scipy>=1.8', 'seaborn', 'scikit-learn~=1.2', From a6840f5cadc35c7348e96654ded3006953f58334 Mon Sep 17 00:00:00 2001 From: morcuended Date: Mon, 27 Nov 2023 08:14:02 +0000 Subject: [PATCH 2/5] add required viewcone min argument --- lstchain/io/io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lstchain/io/io.py b/lstchain/io/io.py index 3ebd9a0db4..8f0f06a1a0 100644 --- a/lstchain/io/io.py +++ b/lstchain/io/io.py @@ -977,7 +977,8 @@ def read_mc_dl2_to_QTable(filename): energy_max=simu_info.energy_range_max, max_impact=simu_info.max_scatter_range, spectral_index=simu_info.spectral_index, - viewcone=simu_info.max_viewcone_radius + viewcone_min=simu_info.min_viewcone_radius, + viewcone_max=simu_info.max_viewcone_radius ) events = pd.read_hdf(filename, key=dl2_params_lstcam_key) From ef306be8893d6c9440a24d7968faed0f0894fcc6 Mon Sep 17 00:00:00 2001 From: morcuended Date: Mon, 27 Nov 2023 08:14:59 +0000 Subject: [PATCH 3/5] adapt interpolators to pyirf 0.10 api --- lstchain/high_level/interpolate.py | 40 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lstchain/high_level/interpolate.py b/lstchain/high_level/interpolate.py index c098cd453f..60579bcdd5 100644 --- a/lstchain/high_level/interpolate.py +++ b/lstchain/high_level/interpolate.py @@ -14,10 +14,10 @@ ) from pyirf.interpolation import ( GridDataInterpolator, - interpolate_effective_area_per_energy_and_fov, - interpolate_energy_dispersion, - interpolate_psf_table, - interpolate_rad_max, + EnergyDispersionEstimator, + EffectiveAreaEstimator, + PSFTableEstimator, + RadMaxEstimator, ) from scipy.spatial import Delaunay, distance, QhullError @@ -361,8 +361,8 @@ def interpolate_gh_cuts( ---------- .. [1] https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html """ - interp = GridDataInterpolator(grid_points=grid_points, params=gh_cuts) - gh_cuts_interp = interp(target_point, method=method) + interp = GridDataInterpolator(grid_points=grid_points, params=gh_cuts, method=method) + gh_cuts_interp = interp(target_point) return gh_cuts_interp @@ -402,8 +402,8 @@ def interpolate_al_cuts( ---------- .. [1] https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html """ - interp = GridDataInterpolator(grid_points=grid_points, params=al_cuts) - al_cuts_interp = interp(target_point, method=method) + interp = GridDataInterpolator(grid_points=grid_points, params=al_cuts, method=method) + al_cuts_interp = interp(target_point) return al_cuts_interp @@ -507,12 +507,11 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): e_true = np.append(temp_irf["ENERG_LO"][0], temp_irf["ENERG_HI"][0][-1]) fov_off = np.append(temp_irf["THETA_LO"][0], temp_irf["THETA_HI"][0][-1]) - aeff_interp = interpolate_effective_area_per_energy_and_fov( + aeff_estimator = EffectiveAreaEstimator( + grid_points=irf_pars_sel, effective_area=effarea_list, - grid_points=irf_pars_sel, - target_point=interp_pars_sel, - method=interp_method ) + aeff_interp = aeff_estimator(interp_pars_sel) aeff_hdu_interp = create_aeff2d_hdu( effective_area=aeff_interp.T[0], @@ -540,13 +539,12 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): e_migra = np.append(temp_irf["MIGRA_LO"][0], temp_irf["MIGRA_HI"][0][-1]) fov_off = np.append(temp_irf["THETA_LO"][0], temp_irf["THETA_HI"][0][-1]) - edisp_interp = interpolate_energy_dispersion( - migra_bins=e_migra, - edisps=edisp_list, + edisp_estimator = EnergyDispersionEstimator( grid_points=irf_pars_sel, - target_point=interp_pars_sel, - quantile_resolution=1e-3 + migra_bins=e_migra, + energy_dispersion=edisp_list, ) + edisp_interp = edisp_estimator(interp_pars_sel) edisp_hdu_interp = create_energy_dispersion_hdu( energy_dispersion=edisp_interp[0], @@ -599,12 +597,12 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): radmax_list = load_irf_grid(irfs, extname="RAD_MAX", interp_col="RAD_MAX") temp_irf = QTable.read(irfs[0], hdu="RAD_MAX") - rad_max_interp = interpolate_rad_max( - rad_max=radmax_list, + rad_max_estimator = RadMaxEstimator( grid_points=irf_pars_sel, - target_point=interp_pars_sel, - method=interp_method + rad_max=radmax_list, ) + rad_max_interp = rad_max_estimator(interp_pars_sel) + temp_irf["RAD_MAX"] = rad_max_interp[0].T[np.newaxis, ...] * u.deg From bf57dc314dad47721caa6aa0c4f82b646498d148 Mon Sep 17 00:00:00 2001 From: morcuended Date: Mon, 27 Nov 2023 10:05:26 +0000 Subject: [PATCH 4/5] use PSF estimator and interpolator for pyirf 0.10 API --- lstchain/high_level/interpolate.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lstchain/high_level/interpolate.py b/lstchain/high_level/interpolate.py index 60579bcdd5..827fe04216 100644 --- a/lstchain/high_level/interpolate.py +++ b/lstchain/high_level/interpolate.py @@ -34,6 +34,7 @@ log = logging.getLogger(__name__) + def interp_params(params_list, data): """ From a given list of angular parameters, to be used for interpolation, @@ -361,7 +362,9 @@ def interpolate_gh_cuts( ---------- .. [1] https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html """ - interp = GridDataInterpolator(grid_points=grid_points, params=gh_cuts, method=method) + interp = GridDataInterpolator( + grid_points=grid_points, params=gh_cuts, method=method + ) gh_cuts_interp = interp(target_point) return gh_cuts_interp @@ -402,7 +405,9 @@ def interpolate_al_cuts( ---------- .. [1] https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html """ - interp = GridDataInterpolator(grid_points=grid_points, params=al_cuts, method=method) + interp = GridDataInterpolator( + grid_points=grid_points, params=al_cuts, method=method + ) al_cuts_interp = interp(target_point) return al_cuts_interp @@ -508,7 +513,7 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): fov_off = np.append(temp_irf["THETA_LO"][0], temp_irf["THETA_HI"][0][-1]) aeff_estimator = EffectiveAreaEstimator( - grid_points=irf_pars_sel, + grid_points=irf_pars_sel, effective_area=effarea_list, ) aeff_interp = aeff_estimator(interp_pars_sel) @@ -573,7 +578,7 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): gh_cuts=gh_cuts_list, grid_points=irf_pars_sel, target_point=interp_pars_sel, - method=interp_method + method=interp_method, ) gh_header = fits.Header() @@ -603,7 +608,6 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): ) rad_max_interp = rad_max_estimator(interp_pars_sel) - temp_irf["RAD_MAX"] = rad_max_interp[0].T[np.newaxis, ...] * u.deg radmax_header = fits.Header() @@ -659,13 +663,13 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): src_bins = np.append(temp_irf["RAD_LO"][0], temp_irf["RAD_HI"][0][-1]) fov_off = np.append(temp_irf["THETA_LO"][0], temp_irf["THETA_HI"][0][-1]) - psf_interp = interpolate_psf_table( - source_offset_bins=src_bins, - psfs=psf_list, + psf_estimator = PSFTableEstimator( grid_points=irf_pars_sel, - target_point=interp_pars_sel, - quantile_resolution=1e-3, + source_offset_bins=src_bins, + psf=psf_list, ) + psf_interp = psf_estimator(interp_pars_sel) + psf_hdu_interp = create_psf_table_hdu( psf=psf_interp[0], true_energy=e_true, From 674501f0da3c8c683b672b9e7fd5f2ba2d8d8c5f Mon Sep 17 00:00:00 2001 From: morcuended Date: Mon, 27 Nov 2023 15:14:05 +0000 Subject: [PATCH 5/5] allow passing interpolation method to estimators --- lstchain/high_level/interpolate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lstchain/high_level/interpolate.py b/lstchain/high_level/interpolate.py index 827fe04216..fe84c1babc 100644 --- a/lstchain/high_level/interpolate.py +++ b/lstchain/high_level/interpolate.py @@ -334,8 +334,7 @@ def interpolate_gh_cuts( method="linear", ): """ - Interpolates a grid of GH_CUTS tables to a target-point. Same as pyirf's - interpolate_rad_max function. + Interpolates a grid of GH_CUTS tables to a target-point. Wrapper around scipy.interpolate.griddata [1]. @@ -377,8 +376,7 @@ def interpolate_al_cuts( method="linear", ): """ - Interpolates a grid of AL_CUTS tables to a target-point. Same as pyirf's - interpolate_rad_max function. + Interpolates a grid of AL_CUTS tables to a target-point. Wrapper around scipy.interpolate.griddata [1]. @@ -515,6 +513,7 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): aeff_estimator = EffectiveAreaEstimator( grid_points=irf_pars_sel, effective_area=effarea_list, + interpolator_kwargs={"method": interp_method}, ) aeff_interp = aeff_estimator(interp_pars_sel) @@ -605,6 +604,7 @@ def interpolate_irf(irfs, data_pars, interp_method="linear"): rad_max_estimator = RadMaxEstimator( grid_points=irf_pars_sel, rad_max=radmax_list, + interpolator_kwargs={"method": interp_method}, ) rad_max_interp = rad_max_estimator(interp_pars_sel)