From 0afbb81b98b38dba4d0a54501ba05acf730b54f8 Mon Sep 17 00:00:00 2001 From: Himanshu Aggarwal Date: Tue, 11 Feb 2025 16:32:03 +0100 Subject: [PATCH 1/2] [FIX] Set length to 1 when np.squeeze returns a 0D array --- nipype/algorithms/misc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nipype/algorithms/misc.py b/nipype/algorithms/misc.py index e1a67f0b08..a29b629703 100644 --- a/nipype/algorithms/misc.py +++ b/nipype/algorithms/misc.py @@ -1495,7 +1495,11 @@ def merge_rois(in_files, in_idxs, in_ref, dtype=None, out_file=None): for d, fname in enumerate(nii): data = np.asanyarray(nb.load(fname).dataobj).reshape(-1) cdata = nb.load(cname).dataobj[..., d].reshape(-1) - nels = len(idxs) + try: + nels = len(idxs) + except TypeError: + nels = 1 + idata = (idxs,) data[idata] = cdata[0:nels] nb.Nifti1Image(data.reshape(rsh[:3]), aff, hdr).to_filename(fname) From 2c8017df7e2c16ae76f55ce5939d73f4784f6d17 Mon Sep 17 00:00:00 2001 From: Himanshu Aggarwal Date: Tue, 11 Feb 2025 17:38:39 +0100 Subject: [PATCH 2/2] apply code review suggestion --- nipype/algorithms/misc.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nipype/algorithms/misc.py b/nipype/algorithms/misc.py index a29b629703..fe27b877a2 100644 --- a/nipype/algorithms/misc.py +++ b/nipype/algorithms/misc.py @@ -1490,18 +1490,13 @@ def merge_rois(in_files, in_idxs, in_ref, dtype=None, out_file=None): for cname, iname in zip(in_files, in_idxs): f = np.load(iname) - idxs = np.squeeze(f["arr_0"]) + idxs = np.atleast_1d(np.squeeze(f["arr_0"])) + nels = len(idxs) for d, fname in enumerate(nii): data = np.asanyarray(nb.load(fname).dataobj).reshape(-1) cdata = nb.load(cname).dataobj[..., d].reshape(-1) - try: - nels = len(idxs) - except TypeError: - nels = 1 - - idata = (idxs,) - data[idata] = cdata[0:nels] + data[idxs] = cdata[:nels] nb.Nifti1Image(data.reshape(rsh[:3]), aff, hdr).to_filename(fname) imgs = [nb.load(im) for im in nii]