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

Use ruff and manual coding to adapt to numpy 2 #845

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -713,10 +713,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 @@ -467,7 +467,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 @@ -1502,7 +1502,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 @@ -1816,7 +1816,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 @@ -363,7 +363,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 @@ -6731,7 +6731,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 @@ -92,7 +92,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 @@ -131,7 +131,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 @@ -194,7 +194,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
Loading