Skip to content

Commit 56f6307

Browse files
authored
FIX stop using expired deprecation for numpy 1.24 (#479)
* MNT stop using np.int and np.float * FIX use array of objects to allow different lengths for each hemisphere * WIP debug SyntaxError: not a PNG file * WIP * WIP * WIP * FIX use integer height parameter for Inkscape
1 parent 2a51886 commit 56f6307

File tree

10 files changed

+27
-17
lines changed

10 files changed

+27
-17
lines changed

cortex/database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_anat(self, subject, type='raw', xfmname=None, recache=False, order=1, **
222222
return anatnib
223223

224224
from . import volume
225-
return volume.anat2epispace(anatnib.get_data().T.astype(np.float), subject, xfmname, order=order)
225+
return volume.anat2epispace(anatnib.get_data().T.astype(float), subject, xfmname, order=order)
226226

227227
def get_surfinfo(self, subject, type="curvature", recache=False, **kwargs):
228228
"""Return auxillary surface information from the filestore. Surface info is defined as

cortex/freesurfer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def get_label(cx_subject, label, fs_subject=None, fs_dir=None, src_subject='fsav
555555
print("Transforming label file to subject's freesurfer directory...")
556556
_move_labels(fs_subject, label, hemisphere=hemisphere, fs_dir=fs_dir, src_subject=src_subject)
557557
verts, values = _parse_labels(label_files, cx_subject)
558-
idx = verts.astype(np.int)
558+
idx = verts.astype(int)
559559
return idx, values
560560

561561

cortex/polyutils/subsurface.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def create_subsurface(self, vertex_mask=None, polygon_mask=None):
6666

6767
# build map from old index to new index
6868
# vertices not in the subsurface are represented with large numbers
69-
vertex_map = np.ones(self.pts.shape[0], dtype=np.int) * np.iinfo(np.int32).max
69+
vertex_map = np.ones(self.pts.shape[0], dtype=int) * np.iinfo(np.int32).max
7070
vertex_map[vertex_mask] = range(vertex_mask.sum())
7171

7272
# reindex vertices and polygons
@@ -92,7 +92,7 @@ def get_connected_vertices(self, vertex, mask, old_version=False):
9292
- helper method for other methods
9393
9494
Parameters
95-
-----------
95+
----------
9696
- vertex : one of [scalar int index | list of int indices | numpy array of int indices]
9797
vertex or set of vertices to use as seed
9898
- mask : boolean array

cortex/quickflat/composite.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def add_curvature(fig, dataview, extents=None, height=None, threshold=True, cont
6666
if default_smoothing.lower()=='none':
6767
default_smoothing = None
6868
else:
69-
default_smoothing = np.float(default_smoothing)
69+
default_smoothing = np.float_(default_smoothing)
7070
if smooth is None:
7171
# (Might still be None!)
7272
smooth = default_smoothing
@@ -98,7 +98,7 @@ def add_curvature(fig, dataview, extents=None, height=None, threshold=True, cont
9898
if not legacy_mode:
9999
if use_threshold_curvature:
100100
# Assumes symmetrical curvature_lims
101-
curv_im = (np.nan_to_num(curv_im) > 0.5).astype(np.float)
101+
curv_im = (np.nan_to_num(curv_im) > 0.5).astype(float)
102102
curv_im[np.isnan(curv)] = np.nan
103103
# Get defaults for brightness, contrast
104104
if brightness is None:

cortex/surfinfo.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def tissots_indicatrix(outfile, sub, radius=10, spacing=50):
147147

148148
tissots.append(tissot_array)
149149
allcenters.append(np.array(centers))
150-
150+
151+
# make an array of objects to allow different lengths for each hemisphere
152+
allcenters = np.array(allcenters, dtype="object")
151153
np.savez(outfile, left=tissots[0], right=tissots[1], centers=allcenters)
152154

153155
def flat_border(outfile, subject):

cortex/svgoverlay.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def get_texture(self, layer_name, height, name=None, background=None, labels=Tru
244244
self.svg.getroot().insert(0, img)
245245
if height is None:
246246
height = self.svgshape[1]
247+
height = int(height)
247248
#label_defaults = _parse_defaults(layer+'_labels')
248249

249250
# separate kwargs starting with "label-"
@@ -298,7 +299,14 @@ def get_texture(self, layer_name, height, name=None, background=None, labels=Tru
298299

299300
if name is None:
300301
png.seek(0)
301-
im = plt.imread(png)
302+
try:
303+
im = plt.imread(png)
304+
except SyntaxError as e:
305+
raise RuntimeError(f"Error reading image from {pngfile}: {e}"
306+
f" (inkscape version: {INKSCAPE_VERSION})"
307+
f" (inkscape command: {inkscape_cmd})"
308+
f" (stdout: {stdout})"
309+
f" (stderr: {stderr})")
302310
return im
303311

304312
class Overlay(object):

cortex/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def get_roi_mask(subject, xfmname, roi=None, projection='nearest'):
407407
# This is broken; unclear when/if backward mappers ever worked this way.
408408
#left, right = mapper.backwards(vert_mask)
409409
#output[name] = left + right
410-
output[name] = mapper.backwards(verts.astype(np.float))
410+
output[name] = mapper.backwards(verts.astype(float))
411411
# Threshold?
412412
return output
413413

@@ -613,7 +613,7 @@ def get_roi_masks(subject, xfmname, roi_list=None, gm_sampler='cortical', split_
613613
print("ROI {} not found...".format(roi))
614614
continue
615615
if use_mapper:
616-
roi_voxels[roi] = mapper.backwards(roi_verts[roi].astype(np.float))
616+
roi_voxels[roi] = mapper.backwards(roi_verts[roi].astype(float))
617617
# Optionally threshold probablistic values returned by mapper
618618
if threshold is not None:
619619
roi_voxels[roi] = roi_voxels[roi] > threshold

cortex/webgl/serve.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def make_base64(imgfile):
3838
class NPEncode(json.JSONEncoder):
3939
def default(self, obj):
4040
if isinstance(obj, np.ndarray):
41-
if obj.dtype == np.float:
41+
if obj.dtype == float:
4242
obj = obj.astype(np.float32)
43-
elif obj.dtype == np.int:
43+
elif obj.dtype == int:
4444
obj = obj.astype(np.int32)
4545

4646
return dict(

cortex/webgl/view.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def _get_anim_seq(self, keyframes, fps=30, interpolation='linear'):
709709
tdif = float(t1-t0)
710710
# Check whether to continue frame sequence to endpoint
711711
use_endpoint = keyframes[-1]==end
712-
nvalues = np.round(tdif/fs).astype(np.int)
712+
nvalues = np.round(tdif/fs).astype(int)
713713
if use_endpoint:
714714
nvalues += 1
715715
fr_time = np.linspace(0, 1, nvalues, endpoint=use_endpoint)

cortex/xfm.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def from_fsl(cls, xfm, func_nii, anat_nii):
109109
if isinstance(xfm, string_types):
110110
with open(xfm, 'r') as fid:
111111
L = fid.readlines()
112-
xfm = np.array([[np.float(s) for s in ll.split() if s] for ll in L])
112+
xfm = np.array([[np.float_(s) for s in ll.split() if s] for ll in L])
113113

114114
# Internally, pycortex computes the OPPOSITE transform: from anatomical volume to functional volume.
115115
# Thus, assign anat to "infile" (starting point for transform)
@@ -248,7 +248,7 @@ def from_freesurfer(cls, fs_register, func_nii, subject, freesurfer_subject_dir=
248248
if isinstance(fs_register, string_types):
249249
with open(fs_register, 'r') as fid:
250250
L = fid.readlines()
251-
anat2func = np.array([[np.float(s) for s in ll.split() if s] for ll in L[4:8]])
251+
anat2func = np.array([[np.float_(s) for s in ll.split() if s] for ll in L[4:8]])
252252
else:
253253
anat2func = fs_register
254254

@@ -263,7 +263,7 @@ def from_freesurfer(cls, fs_register, func_nii, subject, freesurfer_subject_dir=
263263
try:
264264
cmd = ('mri_info', '--vox2ras', anat_mgz)
265265
L = decode(subprocess.check_output(cmd)).splitlines()
266-
anat_vox2ras = np.array([[np.float(s) for s in ll.split() if s] for ll in L])
266+
anat_vox2ras = np.array([[np.float_(s) for s in ll.split() if s] for ll in L])
267267
except OSError:
268268
print ("Error occured while executing:\n{}".format(' '.join(cmd)))
269269
raise
@@ -381,7 +381,7 @@ def _vox2ras_tkr(image):
381381
# unpredictable.
382382
L = L[-4:]
383383
tkrvox2ras = np.array(
384-
[[np.float(s) for s in ll.split() if s] for ll in L])
384+
[[np.float_(s) for s in ll.split() if s] for ll in L])
385385
except OSError as e:
386386
print("Error occured while executing:\n{}".format(' '.join(cmd)))
387387
raise e

0 commit comments

Comments
 (0)