Skip to content

Commit

Permalink
Merge pull request #74 from Enzo-Kerkhof/88-numpy-version-nan
Browse files Browse the repository at this point in the history
Issue #88: fixed np.NaN deprecation
  • Loading branch information
thompson318 committed Jul 9, 2024
2 parents 2dcc8e4 + 180afca commit 0a1f2a8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sksurgerycore/algorithms/tracking_smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _rvec_to_quaternion(rvec):
rvec_rs = np.reshape(rvec, (1, 3))

if np.isnan(rvec_rs).any():
return np.full(4, np.NaN)
return np.full(4, np.nan)

angle = np.linalg.norm(rvec_rs)
assert angle >= 0.0
Expand All @@ -31,7 +31,7 @@ def _rvec_to_quaternion(rvec):

rvec_norm = rvec_rs / angle

quaternion = np.full(4, np.NaN)
quaternion = np.full(4, np.nan)
quaternion[0] = math.cos(angle/2)
quaternion[1] = rvec_norm[0][0] * math.sin(angle/2)
quaternion[2] = rvec_norm[0][1] * math.sin(angle/2)
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self, vector_size=3, buffer_size=1, datatype = float):

self._buffer = np.empty((buffer_size, vector_size), dtype=datatype)
if datatype in [float, np.float32, np.float64]:
self._buffer[:] = np.NaN
self._buffer[:] = np.nan
else:
self._buffer[:] = -1

Expand All @@ -97,7 +97,7 @@ def pop(self, vector):

def getmean(self):
"""
Returns the mean vector across the buffer, ignoring NaNs
Returns the mean vector across the buffer, ignoring nans
"""
with warnings.catch_warnings():
#nanmean raises a warning if all values are nan,
Expand Down Expand Up @@ -135,7 +135,7 @@ def pop(self, vector, is_quaternion = False):

def getmean(self):
"""
Returns the mean quaternion across the buffer, ignoring NaNs
Returns the mean quaternion across the buffer, ignoring nans
"""
no_nan_buffer = self._buffer[~np.isnan(self._buffer)]
samples = int(no_nan_buffer.shape[0]/4)
Expand All @@ -146,4 +146,4 @@ def getmean(self):
if no_nan_buffer.shape[0] > 0:
return average_quaternions(np.reshape(no_nan_buffer, (samples, 4)))

return [np.NaN, np.NaN, np.NaN, np.NaN]
return [np.nan, np.nan, np.nan, np.nan]

0 comments on commit 0a1f2a8

Please sign in to comment.