Skip to content

Commit

Permalink
Reiterated on get_time/cable_delay functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fschlueter committed Dec 20, 2023
1 parent 4c07621 commit a1cca48
Showing 1 changed file with 25 additions and 39 deletions.
64 changes: 25 additions & 39 deletions NuRadioReco/detector/RNO_G/rnog_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,42 +1000,16 @@ def is_channel_noiseless(self, station_id, channel_id):
"This information is not (yet) implemented in the DB.")
return is_noiseless

def get_time_delay_stored(self, station_id, channel_id):
""" Return the sum of the time delay of all components in the signal chain stored in the DB

Parameters
----------
station_id: int
The station id
channel_id: int
The channel id
Returns
-------
time_delay: float
Sum of the time delays of all components in the signal chain for one channel
def get_cable_delay(self, station_id, channel_id, use_stored=True):
"""
Return the cable delay of a signal chain as stored in the detector description.
This interface is required by simulation.py. See get_time_delay for description of
arguments.
"""
return self.get_time_delay(station_id, channel_id, cable_only=True, use_stored=use_stored)

signal_chain_dict = self.get_channel_signal_chain(
station_id, channel_id)

time_delay = 0
for key, value in signal_chain_dict["response_chain"].items():
if not "time_delay" in value:
self.logger.warning(f"The signal chain component \"{key}\" of station.channel {station_id}.{channel_id} has not time delay stored...")
continue
time_delay += value["time_delay"]

return time_delay

def get_cable_delay(self, station_id, channel_id):
""" Return the cable delay of a signal chain. This interface is required by simulation.py """
return self.get_time_delay(station_id, channel_id, cable_only=True)

def get_time_delay(self, station_id, channel_id, cable_only=False):
def get_time_delay(self, station_id, channel_id, cable_only=False, use_stored=False):
""" Return the sum of the time delay of all components in the signal chain calculated from the phase
Parameters
Expand All @@ -1050,6 +1024,9 @@ def get_time_delay(self, station_id, channel_id, cable_only=False):
cable_only: bool
If True: Consider only cables to calculate delay. (Default: False)
use_stored: bool
If True, take time delay as stored in DB rather than calculated from response. (Default: False)
Returns
-------
Expand All @@ -1060,18 +1037,27 @@ def get_time_delay(self, station_id, channel_id, cable_only=False):
signal_chain_dict = self.get_channel_signal_chain(
station_id, channel_id)

measurement_components_dic = signal_chain_dict["response_chain"]

time_delay = 0
for key, value in measurement_components_dic.items():
for key, value in signal_chain_dict["response_chain"].items():

if re.search("cable", key) is None and cable_only:
continue

ydata = [value["mag"], value["phase"]]
response = Response(value["frequencies"], ydata, value["y-axis_units"], name=key)
if use_stored:
if "time_delay" not in value or "cable_delay" not in value:
self.logger.warning(f"The signal chain component \"{key}\" of station.channel {station_id}.{channel_id} has no cable/time delay stored... Skip it")
continue

try:
time_delay += value["time_delay"]
except KeyError:
time_delay += value["cable_delay"]

else:
ydata = [value["mag"], value["phase"]]
response = Response(value["frequencies"], ydata, value["y-axis_units"], name=key)

time_delay += response.get_time_delay()
time_delay += response.get_time_delay()

return time_delay

Expand Down

0 comments on commit a1cca48

Please sign in to comment.