Skip to content

Commit

Permalink
Merge pull request #320 from christianbrodbeck/py310
Browse files Browse the repository at this point in the history
Compatibility updates
  • Loading branch information
christianbrodbeck authored Aug 2, 2023
2 parents a5a019e + c26eb3b commit 1554026
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion surfer/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import gzip
import numpy as np
import nibabel as nib
from nibabel.spatialimages import ImageFileError
try:
from nibabel.spatialimages import ImageFileError # removed in nibabel 5.1
except ImportError:
from nibabel.filebasedimages import ImageFileError

from .utils import verbose

Expand Down
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
15 changes: 9 additions & 6 deletions surfer/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from collections import Sequence
try:
from collections.abc import Sequence
except ImportError: # Py 2.7
from collections import Sequence
from distutils.version import LooseVersion
import logging
import warnings
Expand Down Expand Up @@ -150,7 +153,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 +166,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 +516,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 +551,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 1554026

Please sign in to comment.