Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sanity check to subtract_time_delay_from_response #638

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions NuRadioReco/detector/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -393,6 +406,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 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))

return resp