Skip to content

Commit 1554026

Browse files
Merge pull request #320 from christianbrodbeck/py310
Compatibility updates
2 parents a5a019e + c26eb3b commit 1554026

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

surfer/io.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import gzip
88
import numpy as np
99
import nibabel as nib
10-
from nibabel.spatialimages import ImageFileError
10+
try:
11+
from nibabel.spatialimages import ImageFileError # removed in nibabel 5.1
12+
except ImportError:
13+
from nibabel.filebasedimages import ImageFileError
1114

1215
from .utils import verbose
1316

surfer/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ def test_huge_cross():
7373
def test_create_color_lut():
7474
"""Test various ways of making a colormap."""
7575
# Test valid lut
76-
cmap_in = (np.random.rand(256, 4) * 255).astype(np.int)
76+
cmap_in = (np.random.rand(256, 4) * 255).astype(int)
7777
cmap_out = utils.create_color_lut(cmap_in)
7878
assert_array_equal(cmap_in, cmap_out)
7979

8080
# Test mostly valid lut
8181
cmap_in = cmap_in[:, :3]
8282
cmap_out = utils.create_color_lut(cmap_in)
8383
assert_array_equal(cmap_in, cmap_out[:, :3])
84-
assert_array_equal(cmap_out[:, 3], np.ones(256, np.int) * 255)
84+
assert_array_equal(cmap_out[:, 3], np.ones(256, int) * 255)
8585

8686
# Test named matplotlib lut
8787
cmap_out = utils.create_color_lut("BuGn_r")

surfer/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from collections import Sequence
1+
try:
2+
from collections.abc import Sequence
3+
except ImportError: # Py 2.7
4+
from collections import Sequence
25
from distutils.version import LooseVersion
36
import logging
47
import warnings
@@ -150,7 +153,7 @@ def load_curvature(self):
150153
"""Load in curvature values from the ?h.curv file."""
151154
curv_path = op.join(self.data_path, "surf", "%s.curv" % self.hemi)
152155
self.curv = nib.freesurfer.read_morph_data(curv_path)
153-
self.bin_curv = np.array(self.curv > 0, np.int)
156+
self.bin_curv = np.array(self.curv > 0, int)
154157

155158
def load_label(self, name):
156159
"""Load in a Freesurfer .label file.
@@ -163,7 +166,7 @@ def load_label(self, name):
163166
"""
164167
label = nib.freesurfer.read_label(op.join(self.data_path, 'label',
165168
'%s.%s.label' % (self.hemi, name)))
166-
label_array = np.zeros(len(self.x), np.int)
169+
label_array = np.zeros(len(self.x), int)
167170
label_array[label] = 1
168171
try:
169172
self.labels[name] = label_array
@@ -513,10 +516,10 @@ def create_color_lut(cmap, n_colors=256, center=None):
513516
if np.ndim(cmap) == 2:
514517
if cmap.shape[1] == 4:
515518
# This looks likes a LUT that's ready to go
516-
lut = cmap.astype(np.int)
519+
lut = cmap.astype(int)
517520
elif cmap.shape[1] == 3:
518521
# This looks like a LUT, but it's missing the alpha channel
519-
alpha = np.ones(len(cmap), np.int) * 255
522+
alpha = np.ones(len(cmap), int) * 255
520523
lut = np.c_[cmap, alpha]
521524

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

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

553556
return lut
554557

surfer/viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ def _to_borders(self, label, hemi, borders, restrict_idx=None):
14571457
n_vertices = label.size
14581458
edges = utils.mesh_edges(self.geo[hemi].faces)
14591459
border_edges = label[edges.row] != label[edges.col]
1460-
show = np.zeros(n_vertices, dtype=np.int)
1460+
show = np.zeros(n_vertices, dtype=int)
14611461
keep_idx = np.unique(edges.row[border_edges])
14621462
if isinstance(borders, int):
14631463
for _ in range(borders):

0 commit comments

Comments
 (0)