From 3d73c09a6ab4f9169f27b622f4f46a4361d0e6a7 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Mon, 16 Sep 2024 15:28:40 -0300 Subject: [PATCH] Use ruff and manual coding to adapt to numpy 2 (#845) --- invesalius/data/coordinates.py | 2 +- invesalius/data/imagedata_utils.py | 4 ++-- invesalius/data/tractography.py | 2 +- invesalius/data/transformations.py | 4 ++-- invesalius/gui/deep_learning_seg_dialog.py | 2 +- invesalius/gui/dialogs.py | 2 +- invesalius/segmentation/deep_learning/segment.py | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/invesalius/data/coordinates.py b/invesalius/data/coordinates.py index fbdfdba3e..68222da11 100644 --- a/invesalius/data/coordinates.py +++ b/invesalius/data/coordinates.py @@ -621,7 +621,7 @@ def dynamic_reference(probe, reference): # a: rotation of plane (X, Y) around Z axis (azimuth) # b: rotation of plane (X', Z) around Y' axis (elevation) # a: rotation of plane (Y', Z') around X'' axis (roll) - m_rot = np.mat( + m_rot = np.asmatrix( [ [ cos(a) * cos(b), diff --git a/invesalius/data/imagedata_utils.py b/invesalius/data/imagedata_utils.py index cb79c6657..f2fbd5aec 100644 --- a/invesalius/data/imagedata_utils.py +++ b/invesalius/data/imagedata_utils.py @@ -701,10 +701,10 @@ def create_spherical_grid(radius=10, subdivision=1): def random_sample_sphere(radius=3, size=100): - uvw = np.random.normal(0, 1, (size, 3)) + uvw = np.random.default_rng().normal(0, 1, (size, 3)) norm = np.linalg.norm(uvw, axis=1, keepdims=True) # Change/remove **(1./3) to make samples more concentrated around the center - r = np.random.uniform(0, 1, (size, 1)) ** 1.5 + r = np.random.default_rng().uniform(0, 1, (size, 1)) ** 1.5 scale = radius * np.divide(r, norm) xyz = scale * uvw return xyz diff --git a/invesalius/data/tractography.py b/invesalius/data/tractography.py index b8fe4e5b8..cb3c8d5d9 100644 --- a/invesalius/data/tractography.py +++ b/invesalius/data/tractography.py @@ -465,7 +465,7 @@ def run(self): # Spherical sampling of seed coordinates --- # compute the samples of a sphere centered on seed coordinate offset by the grid # given in the invesalius-vtk space - samples = np.random.choice(coord_list_sphere.shape[1], size=100) + samples = np.random.default_rng().choice(coord_list_sphere.shape[1], size=100) m_seed[:-1, -1] = coord_offset.copy() # translate the spherical grid samples to the coil location in invesalius-vtk space seed_trk_r_inv = m_seed @ coord_list_sphere[:, samples] diff --git a/invesalius/data/transformations.py b/invesalius/data/transformations.py index 24d5aecea..4562a9db5 100644 --- a/invesalius/data/transformations.py +++ b/invesalius/data/transformations.py @@ -1499,7 +1499,7 @@ def random_quaternion(rand=None): """ if rand is None: - rand = numpy.random.rand(3) + rand = numpy.random.default_rng().random(3) else: assert len(rand) == 3 r1 = numpy.sqrt(1.0 - rand[0]) @@ -1813,7 +1813,7 @@ def random_vector(size): False """ - return numpy.random.random(size) + return numpy.random.default_rng().random(size) def vector_product(v0, v1, axis=0): diff --git a/invesalius/gui/deep_learning_seg_dialog.py b/invesalius/gui/deep_learning_seg_dialog.py index 91d1bc812..4527aa3e6 100644 --- a/invesalius/gui/deep_learning_seg_dialog.py +++ b/invesalius/gui/deep_learning_seg_dialog.py @@ -358,7 +358,7 @@ def OnTickTimer(self, evt): return progress = self.ps.get_completion() - if progress == np.Inf: + if progress == np.inf: progress = 1 self.AfterSegment() progress = max(0, min(progress, 1)) diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index d78c554cc..04ede8caa 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -6735,7 +6735,7 @@ def LoadRegistration(self, evt: wx.CommandEvent) -> None: reader = csv.reader(file, delimiter="\t") content = [row for row in reader] - self.matrix_tracker_to_robot = np.vstack(list(np.float_(content))) + self.matrix_tracker_to_robot = np.vstack(list(np.float64(content))) # Send registration to robot. Publisher.sendMessage( diff --git a/invesalius/segmentation/deep_learning/segment.py b/invesalius/segmentation/deep_learning/segment.py index 9d319977f..76a5e6d4d 100644 --- a/invesalius/segmentation/deep_learning/segment.py +++ b/invesalius/segmentation/deep_learning/segment.py @@ -88,7 +88,7 @@ def segment_keras(image, weights_file, overlap, probability_array, comm_array, p sums[iz:ez, iy:ey, ix:ex] += 1 probability_array /= sums - comm_array[0] = np.Inf + comm_array[0] = np.inf def download_callback(comm_array): @@ -127,7 +127,7 @@ def segment_torch( sums[iz:ez, iy:ey, ix:ex] += 1 probability_array /= sums - comm_array[0] = np.Inf + comm_array[0] = np.inf def segment_torch_jit( @@ -190,7 +190,7 @@ def segment_torch_jit( probability_array, output_shape=old_shape, preserve_range=True ) - comm_array[0] = np.Inf + comm_array[0] = np.inf ctx = multiprocessing.get_context("spawn")