From 551ba6e587e1f36db9c1672217e2a809105b149c Mon Sep 17 00:00:00 2001 From: candytaco Date: Mon, 18 May 2026 14:35:49 -0700 Subject: [PATCH 1/2] replace np.in1d with np.isin --- cortex/rois.py | 4 ++-- cortex/segment.py | 2 +- cortex/surfinfo.py | 2 +- cortex/utils.py | 4 ++-- pyproject.toml | 2 +- requirements.txt | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cortex/rois.py b/cortex/rois.py index d5d9bbace..8ceeb9ba0 100644 --- a/cortex/rois.py +++ b/cortex/rois.py @@ -117,8 +117,8 @@ def to_svg(self, open_inkscape=False, filename=None): # Find polys allbpolys = np.unique(surf.connected[inbound+exbound].indices) selbpolys = surf.polys[allbpolys] - inpolys = np.in1d(selbpolys, inbound).reshape(selbpolys.shape) - expolys = np.in1d(selbpolys, exbound).reshape(selbpolys.shape) + inpolys = np.isin(selbpolys, inbound).reshape(selbpolys.shape) + expolys = np.isin(selbpolys, exbound).reshape(selbpolys.shape) badpolys = np.logical_or(inpolys.all(1), expolys.all(1)) boundpolys = np.logical_and(np.logical_or(inpolys, expolys).all(1), ~badpolys) diff --git a/cortex/segment.py b/cortex/segment.py index f274b6ab6..3d5c24808 100644 --- a/cortex/segment.py +++ b/cortex/segment.py @@ -384,7 +384,7 @@ def flatten_slim( ) # Cull pts that are not in manifold pi = np.arange(len(pts)) - pii = np.in1d(pi, polys.flatten()) + pii = np.isin(pi, polys.flatten()) idx = np.nonzero(pii)[0] pts_new = pts[idx] # Match indices in polys to new index for pts diff --git a/cortex/surfinfo.py b/cortex/surfinfo.py index 798403335..f59525648 100644 --- a/cortex/surfinfo.py +++ b/cortex/surfinfo.py @@ -186,7 +186,7 @@ def make_surface_graph(tris): mwallset = set.union(*(set(g[v]) for v in fog.nodes())) & set(allbounds) #cutset = (set(g.nodes()) - mwallset) & set(allbounds) - mwallbounds = [np.in1d(b, mwallset) for b in bounds] + mwallbounds = [np.isin(b, mwallset) for b in bounds] changes = [np.nonzero(np.diff(b.astype(float))!=0)[0]+1 for b in mwallbounds] #splitbounds = [np.split(b, c) for b,c in zip(bounds, changes)] diff --git a/cortex/utils.py b/cortex/utils.py index 8cfaf201d..b813aef0d 100644 --- a/cortex/utils.py +++ b/cortex/utils.py @@ -811,12 +811,12 @@ def get_roi_masks(subject, xfmname, roi_list=None, gm_sampler='cortical', split_ vert_in_scan = np.hstack([np.array((m>0).sum(1)).flatten() for m in mapper.masks]) vert_in_scan = vert_in_scan[roi_verts[roi]] elif use_cortex_mask: - vox_in_roi = np.in1d(vox_idx.flatten(), roi_verts[roi]).reshape(vox_idx.shape) + vox_in_roi = np.isin(vox_idx.flatten(), roi_verts[roi]).reshape(vox_idx.shape) roi_voxels[roi] = vox_in_roi & cortex_mask # This is not accurate... because vox_idx only contains the indices of the *nearest* # vertex to each voxel, it excludes many vertices. I can't think of a way to compute # this accurately for non-mapper gm_samplers for now... ML 2017.07.14 - vert_in_scan = np.in1d(roi_verts[roi], vox_idx[cortex_mask]) + vert_in_scan = np.isin(roi_verts[roi], vox_idx[cortex_mask]) # Compute ROI coverage pct_coverage[roi] = vert_in_scan.mean() * 100 if use_mapper: diff --git a/pyproject.toml b/pyproject.toml index af55bc7b0..6acd93aad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] # Minimum requirements for the build system to execute, according to PEP518 # specification. -requires = ["setuptools>=64", "setuptools-scm>=8", "build", "numpy", "cython", "wheel"] +requires = ["setuptools>=64", "setuptools-scm>=8", "build", "numpy>=1.13.0", "cython", "wheel"] build-backend = "setuptools.build_meta" [project] diff --git a/requirements.txt b/requirements.txt index b05b6dd0b..56fa497c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ setuptools future -numpy +numpy>=1.13.0 scipy tornado>=4.3 shapely From ef74ff091beb08ea1cb7d8386ccd381c18594546 Mon Sep 17 00:00:00 2001 From: candytaco Date: Tue, 19 May 2026 09:14:50 -0700 Subject: [PATCH 2/2] remove redundant `reshape` calls `isin` preserves shapes of original array Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- cortex/rois.py | 4 ++-- cortex/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cortex/rois.py b/cortex/rois.py index 8ceeb9ba0..e9553c90b 100644 --- a/cortex/rois.py +++ b/cortex/rois.py @@ -117,8 +117,8 @@ def to_svg(self, open_inkscape=False, filename=None): # Find polys allbpolys = np.unique(surf.connected[inbound+exbound].indices) selbpolys = surf.polys[allbpolys] - inpolys = np.isin(selbpolys, inbound).reshape(selbpolys.shape) - expolys = np.isin(selbpolys, exbound).reshape(selbpolys.shape) + inpolys = np.isin(selbpolys, inbound) + expolys = np.isin(selbpolys, exbound) badpolys = np.logical_or(inpolys.all(1), expolys.all(1)) boundpolys = np.logical_and(np.logical_or(inpolys, expolys).all(1), ~badpolys) diff --git a/cortex/utils.py b/cortex/utils.py index b813aef0d..6ed7ab520 100644 --- a/cortex/utils.py +++ b/cortex/utils.py @@ -811,7 +811,7 @@ def get_roi_masks(subject, xfmname, roi_list=None, gm_sampler='cortical', split_ vert_in_scan = np.hstack([np.array((m>0).sum(1)).flatten() for m in mapper.masks]) vert_in_scan = vert_in_scan[roi_verts[roi]] elif use_cortex_mask: - vox_in_roi = np.isin(vox_idx.flatten(), roi_verts[roi]).reshape(vox_idx.shape) + vox_in_roi = np.isin(vox_idx, roi_verts[roi]) roi_voxels[roi] = vox_in_roi & cortex_mask # This is not accurate... because vox_idx only contains the indices of the *nearest* # vertex to each voxel, it excludes many vertices. I can't think of a way to compute