Skip to content

Commit

Permalink
Use ruff and manual coding to adapt to numpy 2 (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfmoraes committed Sep 16, 2024
1 parent 875e0b6 commit 3d73c09
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion invesalius/data/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions invesalius/data/imagedata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion invesalius/data/tractography.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions invesalius/data/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion invesalius/gui/deep_learning_seg_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion invesalius/gui/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions invesalius/segmentation/deep_learning/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 3d73c09

Please sign in to comment.