From 6af18eff98cd5609d7bfafc60ac527ed19310ed0 Mon Sep 17 00:00:00 2001 From: Julian Sitarek Date: Wed, 27 Nov 2024 15:54:40 +0900 Subject: [PATCH 1/3] Fixed DL3 creation complaining about mismatch in binning. It sometimes happened that the IRF files have different bin ranges saved despite using the same input card. The difference is very small, comparable to the numerical accuracy of double precision. I saw it in the files processed in CNAF and my suspicion is that it comes from inhomogenuity of machines over which the code was run. Now if different binning is detected, it checks also if the relative difference exceeds somewhere 10^-15 and only then raises an error. --- magicctapipe/io/io.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/magicctapipe/io/io.py b/magicctapipe/io/io.py index 11ea135a..4823bf75 100644 --- a/magicctapipe/io/io.py +++ b/magicctapipe/io/io.py @@ -1325,7 +1325,11 @@ def load_irf_files(input_dir_irf): unique_bins = np.unique(irf_data[key], axis=0) if len(unique_bins) > 1: - raise RuntimeError(f"The binning of '{key}' do not match.") + if not np.all(np.abs(unique_bins - unique_bins[0]) < unique_bins[0]*1.e-15): + raise RuntimeError(f"The binning of '{key}' do not match.") + else: + logger.warning(f"The bins of '{key}' do not match, but the difference is within numerical precision, ignoring") + irf_data[key] = unique_bins[0] else: # Set the unique bins From 34e3688f4689ef6d0f3afaebb0bc848f05de744f Mon Sep 17 00:00:00 2001 From: Julian Sitarek Date: Wed, 27 Nov 2024 16:20:25 +0900 Subject: [PATCH 2/3] fixed formating issue. also set the default language version of python because otherwise pre-commit complained trying to find python 3.1 (??) --- .pre-commit-config.yaml | 5 ++++- magicctapipe/io/io.py | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa272f02..db9ff5ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,4 +27,7 @@ repos: magicctapipe/version.py| .*__init__.py| .*/tests/.* - )$ \ No newline at end of file + )$ + +default_language_version: + python: python3.11 \ No newline at end of file diff --git a/magicctapipe/io/io.py b/magicctapipe/io/io.py index 4823bf75..6009a12a 100644 --- a/magicctapipe/io/io.py +++ b/magicctapipe/io/io.py @@ -1325,10 +1325,14 @@ def load_irf_files(input_dir_irf): unique_bins = np.unique(irf_data[key], axis=0) if len(unique_bins) > 1: - if not np.all(np.abs(unique_bins - unique_bins[0]) < unique_bins[0]*1.e-15): + if not np.all( + np.abs(unique_bins - unique_bins[0]) < unique_bins[0] * 1.0e-15 + ): raise RuntimeError(f"The binning of '{key}' do not match.") - else: - logger.warning(f"The bins of '{key}' do not match, but the difference is within numerical precision, ignoring") + else: + logger.warning( + f"The bins of '{key}' do not match, but the difference is within numerical precision, ignoring" + ) irf_data[key] = unique_bins[0] else: From fa58c146a48485983b646a1d1ee23f820f880bcb Mon Sep 17 00:00:00 2001 From: Julian Sitarek Date: Wed, 27 Nov 2024 16:25:31 +0900 Subject: [PATCH 3/3] another trial with precommit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db9ff5ed..5d51d7b2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,4 +30,4 @@ repos: )$ default_language_version: - python: python3.11 \ No newline at end of file + python: python3 \ No newline at end of file