Skip to content

Commit

Permalink
FIX stop using expired deprecation for numpy 1.24 (#479)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TomDLT authored Jan 25, 2023
1 parent 2a51886 commit 56f6307
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cortex/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get_anat(self, subject, type='raw', xfmname=None, recache=False, order=1, **
return anatnib

from . import volume
return volume.anat2epispace(anatnib.get_data().T.astype(np.float), subject, xfmname, order=order)
return volume.anat2epispace(anatnib.get_data().T.astype(float), subject, xfmname, order=order)

def get_surfinfo(self, subject, type="curvature", recache=False, **kwargs):
"""Return auxillary surface information from the filestore. Surface info is defined as
Expand Down
2 changes: 1 addition & 1 deletion cortex/freesurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def get_label(cx_subject, label, fs_subject=None, fs_dir=None, src_subject='fsav
print("Transforming label file to subject's freesurfer directory...")
_move_labels(fs_subject, label, hemisphere=hemisphere, fs_dir=fs_dir, src_subject=src_subject)
verts, values = _parse_labels(label_files, cx_subject)
idx = verts.astype(np.int)
idx = verts.astype(int)
return idx, values


Expand Down
4 changes: 2 additions & 2 deletions cortex/polyutils/subsurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_subsurface(self, vertex_mask=None, polygon_mask=None):

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

# reindex vertices and polygons
Expand All @@ -92,7 +92,7 @@ def get_connected_vertices(self, vertex, mask, old_version=False):
- helper method for other methods
Parameters
-----------
----------
- vertex : one of [scalar int index | list of int indices | numpy array of int indices]
vertex or set of vertices to use as seed
- mask : boolean array
Expand Down
4 changes: 2 additions & 2 deletions cortex/quickflat/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add_curvature(fig, dataview, extents=None, height=None, threshold=True, cont
if default_smoothing.lower()=='none':
default_smoothing = None
else:
default_smoothing = np.float(default_smoothing)
default_smoothing = np.float_(default_smoothing)
if smooth is None:
# (Might still be None!)
smooth = default_smoothing
Expand Down Expand Up @@ -98,7 +98,7 @@ def add_curvature(fig, dataview, extents=None, height=None, threshold=True, cont
if not legacy_mode:
if use_threshold_curvature:
# Assumes symmetrical curvature_lims
curv_im = (np.nan_to_num(curv_im) > 0.5).astype(np.float)
curv_im = (np.nan_to_num(curv_im) > 0.5).astype(float)
curv_im[np.isnan(curv)] = np.nan
# Get defaults for brightness, contrast
if brightness is None:
Expand Down
4 changes: 3 additions & 1 deletion cortex/surfinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def tissots_indicatrix(outfile, sub, radius=10, spacing=50):

tissots.append(tissot_array)
allcenters.append(np.array(centers))


# make an array of objects to allow different lengths for each hemisphere
allcenters = np.array(allcenters, dtype="object")
np.savez(outfile, left=tissots[0], right=tissots[1], centers=allcenters)

def flat_border(outfile, subject):
Expand Down
10 changes: 9 additions & 1 deletion cortex/svgoverlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def get_texture(self, layer_name, height, name=None, background=None, labels=Tru
self.svg.getroot().insert(0, img)
if height is None:
height = self.svgshape[1]
height = int(height)
#label_defaults = _parse_defaults(layer+'_labels')

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

if name is None:
png.seek(0)
im = plt.imread(png)
try:
im = plt.imread(png)
except SyntaxError as e:
raise RuntimeError(f"Error reading image from {pngfile}: {e}"
f" (inkscape version: {INKSCAPE_VERSION})"
f" (inkscape command: {inkscape_cmd})"
f" (stdout: {stdout})"
f" (stderr: {stderr})")
return im

class Overlay(object):
Expand Down
4 changes: 2 additions & 2 deletions cortex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def get_roi_mask(subject, xfmname, roi=None, projection='nearest'):
# This is broken; unclear when/if backward mappers ever worked this way.
#left, right = mapper.backwards(vert_mask)
#output[name] = left + right
output[name] = mapper.backwards(verts.astype(np.float))
output[name] = mapper.backwards(verts.astype(float))
# Threshold?
return output

Expand Down Expand Up @@ -613,7 +613,7 @@ def get_roi_masks(subject, xfmname, roi_list=None, gm_sampler='cortical', split_
print("ROI {} not found...".format(roi))
continue
if use_mapper:
roi_voxels[roi] = mapper.backwards(roi_verts[roi].astype(np.float))
roi_voxels[roi] = mapper.backwards(roi_verts[roi].astype(float))
# Optionally threshold probablistic values returned by mapper
if threshold is not None:
roi_voxels[roi] = roi_voxels[roi] > threshold
Expand Down
4 changes: 2 additions & 2 deletions cortex/webgl/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def make_base64(imgfile):
class NPEncode(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
if obj.dtype == np.float:
if obj.dtype == float:
obj = obj.astype(np.float32)
elif obj.dtype == np.int:
elif obj.dtype == int:
obj = obj.astype(np.int32)

return dict(
Expand Down
2 changes: 1 addition & 1 deletion cortex/webgl/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def _get_anim_seq(self, keyframes, fps=30, interpolation='linear'):
tdif = float(t1-t0)
# Check whether to continue frame sequence to endpoint
use_endpoint = keyframes[-1]==end
nvalues = np.round(tdif/fs).astype(np.int)
nvalues = np.round(tdif/fs).astype(int)
if use_endpoint:
nvalues += 1
fr_time = np.linspace(0, 1, nvalues, endpoint=use_endpoint)
Expand Down
8 changes: 4 additions & 4 deletions cortex/xfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def from_fsl(cls, xfm, func_nii, anat_nii):
if isinstance(xfm, string_types):
with open(xfm, 'r') as fid:
L = fid.readlines()
xfm = np.array([[np.float(s) for s in ll.split() if s] for ll in L])
xfm = np.array([[np.float_(s) for s in ll.split() if s] for ll in L])

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

Expand All @@ -263,7 +263,7 @@ def from_freesurfer(cls, fs_register, func_nii, subject, freesurfer_subject_dir=
try:
cmd = ('mri_info', '--vox2ras', anat_mgz)
L = decode(subprocess.check_output(cmd)).splitlines()
anat_vox2ras = np.array([[np.float(s) for s in ll.split() if s] for ll in L])
anat_vox2ras = np.array([[np.float_(s) for s in ll.split() if s] for ll in L])
except OSError:
print ("Error occured while executing:\n{}".format(' '.join(cmd)))
raise
Expand Down Expand Up @@ -381,7 +381,7 @@ def _vox2ras_tkr(image):
# unpredictable.
L = L[-4:]
tkrvox2ras = np.array(
[[np.float(s) for s in ll.split() if s] for ll in L])
[[np.float_(s) for s in ll.split() if s] for ll in L])
except OSError as e:
print("Error occured while executing:\n{}".format(' '.join(cmd)))
raise e
Expand Down

0 comments on commit 56f6307

Please sign in to comment.