From 51419f214fd4d59c2810c4a999ed17a29a923046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Schl=C3=BCter?= Date: Thu, 22 Feb 2024 21:48:11 +0100 Subject: [PATCH 1/2] Add sanity check to subtract_time_delay_from_response --- NuRadioReco/detector/response.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NuRadioReco/detector/response.py b/NuRadioReco/detector/response.py index 06c648dc9..a04c50ac4 100644 --- a/NuRadioReco/detector/response.py +++ b/NuRadioReco/detector/response.py @@ -393,6 +393,11 @@ def subtract_time_delay_from_response(frequencies, resp, phase=None, time_delay= if time_delay is None: raise ValueError("You have to specify a time delay") + if np.any(np.abs(2 * time_delay * np.diff(frequencies)) > 1): + raise ValueError("The frequency binning (resolution) of the response " + "is to large/corse to correctly remove the time delay. " + "You need to upsample the response function.") + resp = gain * np.exp(1j * (phase + 2 * np.pi * time_delay * frequencies)) return resp \ No newline at end of file From 120fa3a2446e7065de9cf906e95c5690108f9eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Schl=C3=BCter?= Date: Fri, 23 Feb 2024 15:26:13 +0100 Subject: [PATCH 2/2] Automatically upsample response function if frequency binnging is to coarse --- NuRadioReco/detector/response.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/NuRadioReco/detector/response.py b/NuRadioReco/detector/response.py index a04c50ac4..3b7e1c85c 100644 --- a/NuRadioReco/detector/response.py +++ b/NuRadioReco/detector/response.py @@ -111,9 +111,22 @@ def __init__(self, frequency, y, y_unit, time_delay=0, weight=1, else: raise KeyError - # Remove the average group delay from response + y_phase_orig = np.copy(y_phase) + if remove_time_delay: - y_phase_orig = np.copy(np.unwrap(y_phase)) + if np.any(np.abs(2 * time_delay * np.diff(self.__frequency)) > 1): + df_max = 1 / np.abs(2 * time_delay) * 0.8 # the factor of 0.8 is to be lower + self.logger.warning( + f"The frequency binning (resolution) of {np.diff(self.__frequency)[0] * 1e3:.2f} MHz " + f"of the response function is to large/corse to correctly remove the time delay of {time_delay} ns. " + f"The response function is now upsampled to {df_max * 1e3:.2f} MHz.") + new_frequencies = np.arange(self.__frequency[0], self.__frequency[-1], df_max) + gain = np.interp(new_frequencies, self.__frequency, gain) + y_phase = np.interp(new_frequencies, self.__frequency, y_phase) + self.__frequency = new_frequencies + + # Remove the average group delay from response + if remove_time_delay and time_delay: _response = subtract_time_delay_from_response(self.__frequency, gain, y_phase, time_delay) y_phase = np.angle(_response) else: @@ -394,8 +407,8 @@ def subtract_time_delay_from_response(frequencies, resp, phase=None, time_delay= raise ValueError("You have to specify a time delay") if np.any(np.abs(2 * time_delay * np.diff(frequencies)) > 1): - raise ValueError("The frequency binning (resolution) of the response " - "is to large/corse to correctly remove the time delay. " + raise ValueError("The frequency binning (resolution) of the response function " + f"is to large/corse to correctly remove the time delay of {time_delay} ns. " "You need to upsample the response function.") resp = gain * np.exp(1j * (phase + 2 * np.pi * time_delay * frequencies))