From 2e75d3284e6d4bd9c6af8523c2d1dff2a7b656d5 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 12 Oct 2022 11:26:43 +0200 Subject: [PATCH] explicitly perform NaN check to avoid RuntimeWarning in EFAP --- scripts/pyaudio3dtools/EFAP.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/pyaudio3dtools/EFAP.py b/scripts/pyaudio3dtools/EFAP.py index 73b8df6ee0..e5b4219cc0 100644 --- a/scripts/pyaudio3dtools/EFAP.py +++ b/scripts/pyaudio3dtools/EFAP.py @@ -496,9 +496,12 @@ class EFAP: ) if mod: - A[0] %= mod - B[0] %= mod - C[0] %= mod + if not np.isnan(A[0]): + A[0] %= mod + if not np.isnan(B[0]): + B[0] %= mod + if not np.isnan(C[0]): + C[0] %= mod if self._in_triangle(P, A, B, C): N = np.transpose([B[1] - C[1], C[0] - B[0]]) @@ -560,15 +563,17 @@ class EFAP: return True, None # if the azimuth difference is large, perform the 2D check again with azimuths wrapped to (-360, 0] and [0, 360) - # RuntimeWarning due to NaNs can be safely ignored, _in_triangle() accounts for them if np.nanmax(azi) - np.nanmin(azi) > 180: for tri in combinations(poly, 3): A = np.array(self._get_azi_ele(tri[0])) B = np.array(self._get_azi_ele(tri[1])) C = np.array(self._get_azi_ele(tri[2])) - A[0] %= 360 - B[0] %= 360 - C[0] %= 360 + if not np.isnan(A[0]): + A[0] %= 360 + if not np.isnan(B[0]): + B[0] %= 360 + if not np.isnan(C[0]): + C[0] %= 360 if self._in_triangle(P, A, B, C): return True, 360 @@ -576,9 +581,12 @@ class EFAP: A = np.array(self._get_azi_ele(tri[0])) B = np.array(self._get_azi_ele(tri[1])) C = np.array(self._get_azi_ele(tri[2])) - A[0] %= -360 - B[0] %= -360 - C[0] %= -360 + if not np.isnan(A[0]): + A[0] %= -360 + if not np.isnan(B[0]): + B[0] %= -360 + if not np.isnan(C[0]): + C[0] %= -360 if self._in_triangle(P, A, B, C): return True, -360 -- GitLab