nebius/SWE-bench-extra huggingface dataset:
Repository: nion-software/niondata

Issue:
Should register_template return offset relative to center pixel?
```
quality, offset = xd.register_template(img, tmpl_img)
offset = Geometry.FloatPoint(y=img.data_shape[0] * 0.5 - offset[0], x=img.data_shape[1] * 0.5 - offset[1])
```


Comments:

Patch:
diff --git a/nion/data/Core.py b/nion/data/Core.py
index ca5f2c4..43e17b0 100755
--- a/nion/data/Core.py
+++ b/nion/data/Core.py
@@ -386,7 +386,7 @@ def function_register_template(image_xdata: DataAndMetadata.DataAndMetadata, tem
     ccorr_xdata = function_match_template(image_xdata, template_xdata)
     error, ccoeff, max_pos = TemplateMatching.find_ccorr_max(ccorr_xdata.data)
     if not error:
-        return ccoeff, max_pos
+        return ccoeff, tuple(max_pos[i] - image_xdata.data_shape[i] * 0.5 for i in range(len(image_xdata.data_shape)))
 
 
 def function_shift(src: DataAndMetadata.DataAndMetadata, shift: typing.Tuple[float, ...], *, order: int = 1) -> DataAndMetadata.DataAndMetadata:


Test patch:
diff --git a/nion/data/test/Core_test.py b/nion/data/test/Core_test.py
index 54ef2a1..054d822 100755
--- a/nion/data/test/Core_test.py
+++ b/nion/data/test/Core_test.py
@@ -932,7 +932,7 @@ class TestCore(unittest.TestCase):
         template_xdata = DataAndMetadata.new_data_and_metadata(data[40:60])
         ccoeff, max_pos = Core.function_register_template(image_xdata, template_xdata)
         self.assertEqual(len(max_pos), 1)
-        self.assertAlmostEqual(max_pos[0], 50, places=1)
+        self.assertAlmostEqual(max_pos[0], 0, places=1)
         self.assertAlmostEqual(ccoeff, 1.0, places=1)
 
     def test_register_template_for_2d_data(self):
@@ -941,7 +941,7 @@ class TestCore(unittest.TestCase):
         template_xdata = DataAndMetadata.new_data_and_metadata(data[40:60, 15:20])
         ccoeff, max_pos = Core.function_register_template(image_xdata, template_xdata)
         self.assertEqual(len(max_pos), 2)
-        self.assertTrue(numpy.allclose(max_pos, (50, 17), atol=0.1))
+        self.assertTrue(numpy.allclose(max_pos, (0, -33), atol=0.1))
         self.assertAlmostEqual(ccoeff, 1.0, places=1)
 
     def test_sequence_join(self):
Repository: nion-software/nionutils

Issue:
Regex in IntegerToStringConverter not handling negative numbers
https://github.com/nion-software/nionutils/blob/c4b09457ab9433dde6f224279fe8f35265c6c041/nion/utils/Converter.py#L46

This regex is not sufficient to properly handle negative numbers. It will also fail to convert floating point numbers. See the following examples:

```
from nion.utils import Converter
conv = Converter.IntegerToStringConverter()
conv.convert_back("-1")
>>> 1
conv.convert_back("1.243")
>>> 1243


Comments:

Patch:
diff --git a/nion/utils/Converter.py b/nion/utils/Converter.py
index 8bfacb2..178a127 100644
--- a/nion/utils/Converter.py
+++ b/nion/utils/Converter.py
@@ -43,7 +43,7 @@ class IntegerToStringConverter(ConverterLike[int, str]):
 
     def convert_back(self, formatted_value: typing.Optional[str]) -> typing.Optional[int]:
         """ Convert string to value using standard int conversion """
-        formatted_value = re.sub("[^0-9]", "", formatted_value) if self.__fuzzy and formatted_value else None
+        formatted_value = re.sub("[+-](?!\d)|(?<=\.)\w*|[^-+0-9]", "", formatted_value) if self.__fuzzy and formatted_value else None
         if formatted_value:
             return int(formatted_value)
         else:


Test patch:
diff --git a/nion/utils/test/Converter_test.py b/nion/utils/test/Converter_test.py
index 2fcbf1b..65b8717 100644
--- a/nion/utils/test/Converter_test.py
+++ b/nion/utils/test/Converter_test.py
@@ -23,6 +23,12 @@ class TestConverter(unittest.TestCase):
         self.assertAlmostEqual(converter.convert_back(converter.convert(-100)) or 0.0, -100)
         self.assertAlmostEqual(converter.convert_back(converter.convert(100)) or 0.0, 100)
 
+    def test_integer_to_string_converter(self) -> None:
+        converter = Converter.IntegerToStringConverter()
+        self.assertEqual(converter.convert_back("-1"), -1)
+        self.assertEqual(converter.convert_back("2.45653"), 2)
+        self.assertEqual(converter.convert_back("-adcv-2.15sa56aas"), -2)
+        self.assertEqual(converter.convert_back("xx4."), 4)
 
 
 if __name__ == '__main__':
Repository: nipy/nipype

Issue:
FreeSurferSource doesn't check subjects_dir
### Summary
`FreeSurferSource` doesn't check `subjects_dir` is an existing path.

### How to replicate the behavior

```
from nipype.interfaces.io import FreeSurferSource
fs = FreeSurferSource()
fs.inputs.subjects_dir = 'path/to/no/existing/directory'
fs.inputs.subject_id = 'sub-01'
res = fs.run()
```

### Actual behavior
Doesn't give an error.

### Expected behavior
Should check if directory exists (and possibly if there are files for `subject_id` ?).



Comments:

Patch:
diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py
index fc3617036..6bb9a943f 100644
--- a/nipype/interfaces/io.py
+++ b/nipype/interfaces/io.py
@@ -1555,16 +1555,12 @@ class DataFinder(IOBase):
 
 
 class FSSourceInputSpec(BaseInterfaceInputSpec):
-    subjects_dir = Directory(
-        mandatory=True, desc='Freesurfer subjects directory.')
-    subject_id = Str(
-        mandatory=True, desc='Subject name for whom to retrieve data')
-    hemi = traits.Enum(
-        'both',
-        'lh',
-        'rh',
-        usedefault=True,
-        desc='Selects hemisphere specific outputs')
+    subjects_dir = Directory(exists=True, mandatory=True,
+                             desc='Freesurfer subjects directory.')
+    subject_id = Str(mandatory=True,
+                     desc='Subject name for whom to retrieve data')
+    hemi = traits.Enum('both', 'lh', 'rh', usedefault=True,
+                       desc='Selects hemisphere specific outputs')
 
 
 class FSSourceOutputSpec(TraitedSpec):


Test patch:
diff --git a/nipype/interfaces/tests/test_io.py b/nipype/interfaces/tests/test_io.py
index a2103eadf..76fc9e257 100644
--- a/nipype/interfaces/tests/test_io.py
+++ b/nipype/interfaces/tests/test_io.py
@@ -16,7 +16,7 @@ from collections import namedtuple
 import pytest
 import nipype
 import nipype.interfaces.io as nio
-from nipype.interfaces.base import Undefined
+from nipype.interfaces.base import Undefined, TraitError
 
 # Check for boto
 noboto = False
@@ -498,6 +498,12 @@ def test_freesurfersource():
     assert fss.inputs.subjects_dir == Undefined
 
 
+def test_freesurfersource_incorrectdir():
+    fss = nio.FreeSurferSource()
+    with pytest.raises(TraitError) as err:
+        fss.inputs.subjects_dir = 'path/to/no/existing/directory'
+
+
 def test_jsonsink_input():
 
     ds = nio.JSONFileSink()
Repository: nipy/nipype

Issue:
NiftyReg's RegTools is missing interpolation order argument

Comments:

Patch:
diff --git a/.zenodo.json b/.zenodo.json
index 1058e3b15..29e7f047a 100644
--- a/.zenodo.json
+++ b/.zenodo.json
@@ -558,7 +558,7 @@
       "name": "Flandin, Guillaume"
     },
     {
-      "affiliation": "Stereotaxy Core, Brain & Spine Institute",
+      "affiliation": "University College London",
       "name": "P\u00e9rez-Garc\u00eda, Fernando",
       "orcid": "0000-0001-9090-3024"
     },
diff --git a/nipype/interfaces/niftyreg/regutils.py b/nipype/interfaces/niftyreg/regutils.py
index 7c3ed28ea..0910b7d65 100644
--- a/nipype/interfaces/niftyreg/regutils.py
+++ b/nipype/interfaces/niftyreg/regutils.py
@@ -122,7 +122,7 @@ warpfield.nii -res im2_res.nii.gz'
     # Need this overload to properly constraint the interpolation type input
     def _format_arg(self, name, spec, value):
         if name == 'inter_val':
-            inter_val = {'NN': 0, 'LIN': 1, 'CUB': 3, 'SINC': 5}
+            inter_val = {'NN': 0, 'LIN': 1, 'CUB': 3, 'SINC': 4}
             return spec.argstr % inter_val[value]
         else:
             return super(RegResample, self)._format_arg(name, spec, value)
@@ -295,6 +295,15 @@ class RegToolsInputSpec(NiftyRegCommandInputSpec):
         desc=desc,
         argstr='-smoG %f %f %f')
 
+    # Interpolation type
+    inter_val = traits.Enum(
+        'NN',
+        'LIN',
+        'CUB',
+        'SINC',
+        desc='Interpolation order to use to warp the floating image',
+        argstr='-interp %d')
+
 
 class RegToolsOutputSpec(TraitedSpec):
     """ Output Spec for RegTools. """
@@ -326,6 +335,14 @@ class RegTools(NiftyRegCommand):
     output_spec = RegToolsOutputSpec
     _suffix = '_tools'
 
+    # Need this overload to properly constraint the interpolation type input
+    def _format_arg(self, name, spec, value):
+        if name == 'inter_val':
+            inter_val = {'NN': 0, 'LIN': 1, 'CUB': 3, 'SINC': 4}
+            return spec.argstr % inter_val[value]
+        else:
+            return super(RegTools, self)._format_arg(name, spec, value)
+
 
 class RegAverageInputSpec(NiftyRegCommandInputSpec):
     """ Input Spec for RegAverage. """


Test patch:
diff --git a/nipype/interfaces/niftyreg/tests/test_auto_RegTools.py b/nipype/interfaces/niftyreg/tests/test_auto_RegTools.py
index 97ea5e6c9..f0f66083c 100644
--- a/nipype/interfaces/niftyreg/tests/test_auto_RegTools.py
+++ b/nipype/interfaces/niftyreg/tests/test_auto_RegTools.py
@@ -24,6 +24,7 @@ def test_RegTools_inputs():
             argstr='-in %s',
             mandatory=True,
         ),
+        inter_val=dict(argstr='-interp %d', ),
         iso_flag=dict(argstr='-iso', ),
         mask_file=dict(argstr='-nan %s', ),
         mul_val=dict(argstr='-mul %s', ),
Repository: nipy/nipype

Issue:
Wrong argstr for fsl:bedpostx
### Summary

File fsl/dti.py, Line 174:
An argument "burninnoard" for bedpostx is set. This argument does not exist, bedpostx crashes.
The correct argument is "burnin_noard".

### Solution
Please change 
argstr='--burninnoard=%d',
to
argstr='--burnin_noard=%d',

Comments:

Patch:
diff --git a/nipype/interfaces/fsl/dti.py b/nipype/interfaces/fsl/dti.py
index f318b5cb1..d8812cec6 100644
--- a/nipype/interfaces/fsl/dti.py
+++ b/nipype/interfaces/fsl/dti.py
@@ -171,7 +171,7 @@ class FSLXCommandInputSpec(FSLCommandInputSpec):
         low=0,
         value=0,
         usedefault=True,
-        argstr='--burninnoard=%d',
+        argstr='--burnin_noard=%d',
         desc=('num of burnin jumps before the ard is'
               ' imposed'))
     sample_every = traits.Range(
@@ -424,7 +424,7 @@ class BEDPOSTX5(FSLXCommand):
     >>> bedp = fsl.BEDPOSTX5(bvecs='bvecs', bvals='bvals', dwi='diffusion.nii',
     ...                     mask='mask.nii', n_fibres=1)
     >>> bedp.cmdline
-    'bedpostx bedpostx -b 0 --burninnoard=0 --forcedir -n 1 -j 5000 \
+    'bedpostx bedpostx -b 0 --burnin_noard=0 --forcedir -n 1 -j 5000 \
 -s 1 --updateproposalevery=40'
 
     """


Test patch:
diff --git a/nipype/interfaces/fsl/tests/test_auto_BEDPOSTX5.py b/nipype/interfaces/fsl/tests/test_auto_BEDPOSTX5.py
index b105405c7..1ac5db111 100644
--- a/nipype/interfaces/fsl/tests/test_auto_BEDPOSTX5.py
+++ b/nipype/interfaces/fsl/tests/test_auto_BEDPOSTX5.py
@@ -15,7 +15,7 @@ def test_BEDPOSTX5_inputs():
             usedefault=True,
         ),
         burn_in_no_ard=dict(
-            argstr='--burninnoard=%d',
+            argstr='--burnin_noard=%d',
             usedefault=True,
         ),
         bvals=dict(mandatory=True, ),
diff --git a/nipype/interfaces/fsl/tests/test_auto_FSLXCommand.py b/nipype/interfaces/fsl/tests/test_auto_FSLXCommand.py
index b215f70bc..fd85eee3b 100644
--- a/nipype/interfaces/fsl/tests/test_auto_FSLXCommand.py
+++ b/nipype/interfaces/fsl/tests/test_auto_FSLXCommand.py
@@ -15,7 +15,7 @@ def test_FSLXCommand_inputs():
             usedefault=True,
         ),
         burn_in_no_ard=dict(
-            argstr='--burninnoard=%d',
+            argstr='--burnin_noard=%d',
             usedefault=True,
         ),
         bvals=dict(
diff --git a/nipype/interfaces/fsl/tests/test_auto_XFibres5.py b/nipype/interfaces/fsl/tests/test_auto_XFibres5.py
index 25da78450..d72bb3bb4 100644
--- a/nipype/interfaces/fsl/tests/test_auto_XFibres5.py
+++ b/nipype/interfaces/fsl/tests/test_auto_XFibres5.py
@@ -15,7 +15,7 @@ def test_XFibres5_inputs():
             usedefault=True,
         ),
         burn_in_no_ard=dict(
-            argstr='--burninnoard=%d',
+            argstr='--burnin_noard=%d',
             usedefault=True,
         ),
         bvals=dict(
Repository: nipy/nipype

Issue:
fsl randomise f_only flag contains typo, can't work
### Summary
when calling randomise with f_only=True, nipypes interfaces appends --f_only instead of --fonly. This is incorrect and prevents the call from working.

The offending line is [here](https://github.com/nipy/nipype/blob/master/nipype/interfaces/fsl/model.py#L2250), where the last bit should be `argstr="--fonly"`
### Actual behavior
appending --fonly to the randomise call.

### Expected behavior

--f_only is appended, breaking the call.

### Script/Workflow details

```
    fsl_randomise = mem.cache(fsl.Randomise)
    randomise_results = fsl_randomise(
        in_file=`fourdimage.nii`,
        mask=`mask.nii`,
        num_perm=10000,
        f_only=True,
        **kwargs
        )
```

### Platform details:

```
{'commit_hash': 'c5ce0e2c9',
 'commit_source': 'installation',
 'networkx_version': '2.5',
 'nibabel_version': '3.2.1',
 'nipype_version': '1.4.2',
 'numpy_version': '1.20.1',
 'pkg_path': '/usr/local/miniconda/lib/python3.7/site-packages/nipype',
 'scipy_version': '1.6.1',
 'sys_executable': '/usr/local/miniconda/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.7.4 (default, Aug 13 2019, 20:35:49) \n[GCC 7.3.0]',
 'traits_version': '6.2.0'}
```

Comments:

Patch:
diff --git a/nipype/interfaces/fsl/model.py b/nipype/interfaces/fsl/model.py
index 8c269caac..15fb36f6c 100644
--- a/nipype/interfaces/fsl/model.py
+++ b/nipype/interfaces/fsl/model.py
@@ -2245,7 +2245,7 @@ class RandomiseInputSpec(FSLCommandInputSpec):
         desc=("carry out Threshold-Free Cluster Enhancement with 2D " "optimisation"),
         argstr="--T2",
     )
-    f_only = traits.Bool(desc="calculate f-statistics only", argstr="--f_only")
+    f_only = traits.Bool(desc="calculate f-statistics only", argstr="--fonly")
     raw_stats_imgs = traits.Bool(
         desc="output raw ( unpermuted ) statistic images", argstr="-R"
     )


Test patch:
diff --git a/nipype/interfaces/fsl/tests/test_auto_Randomise.py b/nipype/interfaces/fsl/tests/test_auto_Randomise.py
index cf816c56d..9b0b74bf2 100644
--- a/nipype/interfaces/fsl/tests/test_auto_Randomise.py
+++ b/nipype/interfaces/fsl/tests/test_auto_Randomise.py
@@ -37,7 +37,7 @@ def test_Randomise_inputs():
             argstr="-S %.2f",
         ),
         f_only=dict(
-            argstr="--f_only",
+            argstr="--fonly",
         ),
         fcon=dict(
             argstr="-f %s",