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

Added tolerance to parallel channels #634

Open
wants to merge 3 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
85 changes: 49 additions & 36 deletions NuRadioReco/detector/detector_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,42 +607,55 @@ def get_channel_ids(self, station_id):
channel_ids.append(channel['channel_id'])
return sorted(channel_ids)

def get_parallel_channels(self, station_id):
"""
get a list of parallel antennas

Parameters
----------
station_id: int
the station id

Returns list of list of ints
"""
res = self.__get_channels(station_id)
orientations = np.zeros((len(res), 4))
antenna_types = []
channel_ids = []
for iCh, ch in enumerate(res.values()):
channel_id = ch['channel_id']
channel_ids.append(channel_id)
antenna_types.append(self.get_antenna_type(station_id, channel_id))
orientations[iCh] = self.get_antenna_orientation(station_id, channel_id)
orientations[iCh][3] = hp.get_normalized_angle(orientations[iCh][3], interval=np.deg2rad([0, 180]))
channel_ids = np.array(channel_ids)
antenna_types = np.array(antenna_types)
orientations = np.round(np.rad2deg(orientations)) # round to one degree to overcome rounding errors
parallel_antennas = []
for antenna_type in np.unique(antenna_types):
for u_zen_ori in np.unique(orientations[:, 0]):
for u_az_ori in np.unique(orientations[:, 1]):
for u_zen_rot in np.unique(orientations[:, 2]):
for u_az_rot in np.unique(orientations[:, 3]):
mask = (antenna_types == antenna_type) \
& (orientations[:, 0] == u_zen_ori) & (orientations[:, 1] == u_az_ori) \
& (orientations[:, 2] == u_zen_rot) & (orientations[:, 3] == u_az_rot)
if np.sum(mask):
parallel_antennas.append(channel_ids[mask])
return np.array(parallel_antennas)
def get_parallel_channels(self, station_id, tol=1*units.deg, anti_parallel=False):
"""
get a list of parallel antennas

Parameters
----------
station_id: int
the station id
tol: float
tolerance to difference in angles between parallel channels
atni-parallel: bool
if True, also returns anti-parallel channels

Returns list of list of ints
"""
def angle_diff(a, b, anti_parallel=False):
if anti_parallel:
return np.abs(hp.get_normalized_angle(a - b, interval=np.deg2rad([0, 90])))
return np.abs(hp.get_normalized_angle(a - b, interval=np.deg2rad([0, 180])))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intervals need to be [-90, 90] and [-180,180].


res = self.__get_channels(station_id)
orientations = np.zeros((len(res), 4))
antenna_types = []
channel_ids = []
for iCh, ch in enumerate(res.values()):
channel_id = ch['channel_id']
channel_ids.append(channel_id)
antenna_types.append(self.get_antenna_type(station_id, channel_id))
orientations[iCh] = self.get_antenna_orientation(station_id, channel_id)
orientations[iCh][3] = hp.get_normalized_angle(orientations[iCh][3], interval=np.deg2rad([0, 180]))
channel_ids = np.array(channel_ids)
antenna_types = np.array(antenna_types)
parallel_antennas = []
for antenna_type in np.unique(antenna_types):
for u_zen_ori in np.unique(orientations[:, 0]):
for u_az_ori in np.unique(orientations[:, 1]):
for u_zen_rot in np.unique(orientations[:, 2]):
for u_az_rot in np.unique(orientations[:, 3]):
mask = (antenna_types == antenna_type) \
& (angle_diff(orientations[:, 0], u_zen_ori, anti_parallel) <= tol) & (angle_diff(orientations[:, 1], u_az_ori, anti_parallel) <= tol) \
& (angle_diff(orientations[:, 2], u_zen_rot, anti_parallel) <= tol) & (angle_diff(orientations[:, 3], u_az_rot, anti_parallel) <= tol)
if np.sum(mask):
match = False
for pair in parallel_antennas:
if np.array_equal(pair, channel_ids[mask] or np.all(np.isin(channel_ids[mask], pair)):
match = True
if not match:
parallel_antennas.append(channel_ids[mask])
return parallel_antennas



Expand Down