Skip to content

Commit

Permalink
FIX numpy 1.20 compatibility: np.int --> int
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed Aug 2, 2023
1 parent 5d8dba3 commit 051a635
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions surfer/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def test_huge_cross():
def test_create_color_lut():
"""Test various ways of making a colormap."""
# Test valid lut
cmap_in = (np.random.rand(256, 4) * 255).astype(np.int)
cmap_in = (np.random.rand(256, 4) * 255).astype(int)
cmap_out = utils.create_color_lut(cmap_in)
assert_array_equal(cmap_in, cmap_out)

# Test mostly valid lut
cmap_in = cmap_in[:, :3]
cmap_out = utils.create_color_lut(cmap_in)
assert_array_equal(cmap_in, cmap_out[:, :3])
assert_array_equal(cmap_out[:, 3], np.ones(256, np.int) * 255)
assert_array_equal(cmap_out[:, 3], np.ones(256, int) * 255)

# Test named matplotlib lut
cmap_out = utils.create_color_lut("BuGn_r")
Expand Down
10 changes: 5 additions & 5 deletions surfer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def load_curvature(self):
"""Load in curvature values from the ?h.curv file."""
curv_path = op.join(self.data_path, "surf", "%s.curv" % self.hemi)
self.curv = nib.freesurfer.read_morph_data(curv_path)
self.bin_curv = np.array(self.curv > 0, np.int)
self.bin_curv = np.array(self.curv > 0, int)

def load_label(self, name):
"""Load in a Freesurfer .label file.
Expand All @@ -163,7 +163,7 @@ def load_label(self, name):
"""
label = nib.freesurfer.read_label(op.join(self.data_path, 'label',
'%s.%s.label' % (self.hemi, name)))
label_array = np.zeros(len(self.x), np.int)
label_array = np.zeros(len(self.x), int)
label_array[label] = 1
try:
self.labels[name] = label_array
Expand Down Expand Up @@ -513,10 +513,10 @@ def create_color_lut(cmap, n_colors=256, center=None):
if np.ndim(cmap) == 2:
if cmap.shape[1] == 4:
# This looks likes a LUT that's ready to go
lut = cmap.astype(np.int)
lut = cmap.astype(int)
elif cmap.shape[1] == 3:
# This looks like a LUT, but it's missing the alpha channel
alpha = np.ones(len(cmap), np.int) * 255
alpha = np.ones(len(cmap), int) * 255
lut = np.c_[cmap, alpha]

return lut
Expand Down Expand Up @@ -548,7 +548,7 @@ def create_color_lut(cmap, n_colors=256, center=None):
raise ValueError("Input %r was not valid for making a lut" % cmap)

# Convert from a matplotlib colormap to a lut array
lut = (cmap(np.linspace(0, 1, n_colors)) * 255).astype(np.int)
lut = (cmap(np.linspace(0, 1, n_colors)) * 255).astype(int)

return lut

Expand Down
2 changes: 1 addition & 1 deletion surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ def _to_borders(self, label, hemi, borders, restrict_idx=None):
n_vertices = label.size
edges = utils.mesh_edges(self.geo[hemi].faces)
border_edges = label[edges.row] != label[edges.col]
show = np.zeros(n_vertices, dtype=np.int)
show = np.zeros(n_vertices, dtype=int)
keep_idx = np.unique(edges.row[border_edges])
if isinstance(borders, int):
for _ in range(borders):
Expand Down

0 comments on commit 051a635

Please sign in to comment.