Skip to content

Commit 1527855

Browse files
committed
Seeting omp to 1 if not set and removing PositiveInt to use traits.Range
1 parent f12762a commit 1527855

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

nipype/interfaces/niftyreg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Top-level namespace for niftyreg.
1010
"""
1111

12-
from .base import no_niftyreg, get_custom_path, PositiveInt
12+
from .base import no_niftyreg, get_custom_path
1313
from .reg import RegAladin, RegF3D
1414
from .regutils import (RegResample, RegJacobian, RegAverage, RegTools,
1515
RegTransform, RegMeasure)

nipype/interfaces/niftyreg/base.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import subprocess
2626
from warnings import warn
2727

28-
from ..base import CommandLine, isdefined, traits
28+
from ..base import CommandLine, isdefined
2929
from ...utils.filemanip import split_filename
3030

3131

@@ -46,25 +46,12 @@ def no_niftyreg(cmd='reg_f3d'):
4646
return True
4747

4848

49-
class PositiveInt(traits.BaseInt):
50-
# Define the default value
51-
default_value = 0
52-
# Describe the trait type
53-
info_text = 'A positive integer'
54-
55-
def validate(self, obj, name, value):
56-
value = super(PositiveInt, self).validate(obj, name, value)
57-
if (value >= 0) == 1:
58-
return value
59-
self.error(obj, name, value)
60-
61-
6249
class NiftyRegCommand(CommandLine):
6350
"""
6451
Base support interface for NiftyReg commands.
6552
"""
6653
_suffix = '_nr'
67-
_min_version = '1.5.10'
54+
_min_version = '1.5.30'
6855

6956
def __init__(self, required_version=None, **inputs):
7057
super(NiftyRegCommand, self).__init__(**inputs)
@@ -111,6 +98,13 @@ def exists(self):
11198
return False
11299
return True
113100

101+
def _run_interface(self, runtime):
102+
# Update num threads estimate from OMP_NUM_THREADS env var
103+
# Default to 1 if not set
104+
if not isdefined(self.inputs.environ['OMP_NUM_THREADS']):
105+
self.inputs.environ['OMP_NUM_THREADS'] = self.num_threads
106+
return super(NiftyRegCommand, self)._run_interface(runtime)
107+
114108
def _gen_fname(self, basename, out_dir=None, suffix=None, ext=None):
115109
if basename == '':
116110
msg = 'Unable to generate filename for command %s. ' % self.cmd

nipype/interfaces/niftyreg/reg.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import warnings
2323

2424
from ..base import TraitedSpec, File, traits, isdefined, CommandLineInputSpec
25-
from .base import get_custom_path, NiftyRegCommand, PositiveInt
25+
from .base import get_custom_path, NiftyRegCommand
2626
from ...utils.filemanip import split_filename
2727

2828

@@ -65,14 +65,14 @@ class RegAladinInputSpec(CommandLineInputSpec):
6565
desc='The input floating mask',
6666
argstr='-fmask %s')
6767
# Maximum number of iterations
68-
maxit_val = PositiveInt(desc='Maximum number of iterations',
69-
argstr='-maxit %d')
68+
maxit_val = traits.Range(desc='Maximum number of iterations',
69+
argstr='-maxit %d', low=0)
7070
# Multiresolution levels
71-
ln_val = PositiveInt(desc='Number of resolution levels to create',
72-
argstr='-ln %d')
71+
ln_val = traits.Range(desc='Number of resolution levels to create',
72+
argstr='-ln %d', low=0)
7373
# Number of resolution levels to process
74-
lp_val = PositiveInt(desc='Number of resolution levels to perform',
75-
argstr='-lp %d')
74+
lp_val = traits.Range(desc='Number of resolution levels to perform',
75+
argstr='-lp %d', low=0)
7676
# Smoothing to apply on reference image
7777
desc = 'Amount of smoothing to apply to reference image'
7878
smoo_r_val = traits.Float(desc=desc,
@@ -90,10 +90,11 @@ class RegAladinInputSpec(CommandLineInputSpec):
9090
cog_flag = traits.Bool(desc=desc,
9191
argstr='-cog')
9292
# Percent of blocks that are considered active.
93-
v_val = PositiveInt(desc='Percent of blocks that are active',
94-
argstr='-pv %d')
93+
v_val = traits.Range(desc='Percent of blocks that are active',
94+
argstr='-pv %d', low=0)
9595
# Percent of inlier blocks
96-
i_val = PositiveInt(desc='Percent of inlier blocks', argstr='-pi %d')
96+
i_val = traits.Range(desc='Percent of inlier blocks', argstr='-pi %d',
97+
low=0)
9798
# Lower threshold on reference image
9899
ref_low_val = traits.Float(desc='Lower threshold value on reference image',
99100
argstr='-refLowThr %f')
@@ -226,19 +227,19 @@ class RegF3DInputSpec(CommandLineInputSpec):
226227

227228
# Lower threshold for reference image
228229
desc = 'Lower threshold for reference image at the specified time point'
229-
rlwth2_thr_val = traits.Tuple(PositiveInt, traits.Float,
230+
rlwth2_thr_val = traits.Tuple(traits.Range(low=0), traits.Float,
230231
desc=desc, argstr='-rLwTh %d %f')
231232
# Upper threshold for reference image
232233
desc = 'Upper threshold for reference image at the specified time point'
233-
rupth2_thr_val = traits.Tuple(PositiveInt, traits.Float,
234+
rupth2_thr_val = traits.Tuple(traits.Range(low=0), traits.Float,
234235
desc=desc, argstr='-rUpTh %d %f')
235236
# Lower threshold for reference image
236237
desc = 'Lower threshold for floating image at the specified time point'
237-
flwth2_thr_val = traits.Tuple(PositiveInt, traits.Float,
238+
flwth2_thr_val = traits.Tuple(traits.Range(low=0), traits.Float,
238239
desc=desc, argstr='-fLwTh %d %f')
239240
# Upper threshold for reference image
240241
desc = 'Upper threshold for floating image at the specified time point'
241-
fupth2_thr_val = traits.Tuple(PositiveInt, traits.Float,
242+
fupth2_thr_val = traits.Tuple(traits.Range(low=0), traits.Float,
242243
desc=desc, argstr='-fUpTh %d %f')
243244

244245
# Final grid spacing along the 3 axes
@@ -263,33 +264,33 @@ class RegF3DInputSpec(CommandLineInputSpec):
263264
desc = 'use NMI even when other options are specified'
264265
nmi_flag = traits.Bool(argstr='--nmi', desc=desc)
265266
desc = 'Number of bins in the histogram for reference image'
266-
rbn_val = PositiveInt(desc=desc, argstr='--rbn %d')
267+
rbn_val = traits.Range(low=0, desc=desc, argstr='--rbn %d')
267268
desc = 'Number of bins in the histogram for reference image'
268-
fbn_val = PositiveInt(desc=desc, argstr='--fbn %d')
269+
fbn_val = traits.Range(low=0, desc=desc, argstr='--fbn %d')
269270
desc = 'Number of bins in the histogram for reference image for given \
270271
time point'
271-
rbn2_val = traits.Tuple(PositiveInt, PositiveInt,
272+
rbn2_val = traits.Tuple(traits.Range(low=0), traits.Range(low=0),
272273
desc=desc, argstr='-rbn %d %d')
273274

274275
desc = 'Number of bins in the histogram for reference image for given \
275276
time point'
276-
fbn2_val = traits.Tuple(PositiveInt, PositiveInt,
277+
fbn2_val = traits.Tuple(traits.Range(low=0), traits.Range(low=0),
277278
desc=desc, argstr='-fbn %d %d')
278279

279280
lncc_val = traits.Float(desc='SD of the Gaussian for computing LNCC',
280281
argstr='--lncc %f')
281282
desc = 'SD of the Gaussian for computing LNCC for a given time point'
282-
lncc2_val = traits.Tuple(PositiveInt, traits.Float,
283+
lncc2_val = traits.Tuple(traits.Range(low=0), traits.Float,
283284
desc=desc, argstr='-lncc %d %f')
284285

285286
ssd_flag = traits.Bool(desc='Use SSD as the similarity measure',
286287
argstr='--ssd')
287288
desc = 'Use SSD as the similarity measure for a given time point'
288-
ssd2_flag = PositiveInt(desc=desc, argstr='-ssd %d')
289+
ssd2_flag = traits.Range(low=0, desc=desc, argstr='-ssd %d')
289290
kld_flag = traits.Bool(desc='Use KL divergence as the similarity measure',
290291
argstr='--kld')
291292
desc = 'Use KL divergence as the similarity measure for a given time point'
292-
kld2_flag = PositiveInt(desc=desc, argstr='-kld %d')
293+
kld2_flag = traits.Range(low=0, desc=desc, argstr='-kld %d')
293294
amc_flag = traits.Bool(desc='Use additive NMI', argstr='-amc')
294295

295296
nox_flag = traits.Bool(desc="Don't optimise in x direction",
@@ -300,18 +301,18 @@ class RegF3DInputSpec(CommandLineInputSpec):
300301
argstr='-noz')
301302

302303
# Optimization options
303-
maxit_val = PositiveInt(desc='Maximum number of iterations per level',
304-
argstr='-maxit %d')
305-
ln_val = PositiveInt(desc='Number of resolution levels to create',
306-
argstr='-ln %d')
307-
lp_val = PositiveInt(desc='Number of resolution levels to perform',
308-
argstr='-lp %d')
304+
maxit_val = traits.Range(low=0, argstr='-maxit %d',
305+
desc='Maximum number of iterations per level')
306+
ln_val = traits.Range(low=0, argstr='-ln %d',
307+
desc='Number of resolution levels to create')
308+
lp_val = traits.Range(low=0, argstr='-lp %d',
309+
desc='Number of resolution levels to perform')
309310
nopy_flag = traits.Bool(desc='Do not use the multiresolution approach',
310311
argstr='-nopy')
311312
noconj_flag = traits.Bool(desc='Use simple GD optimization',
312313
argstr='-noConj')
313314
desc = 'Add perturbation steps after each optimization step'
314-
pert_val = PositiveInt(desc=desc, argstr='-pert %d')
315+
pert_val = traits.Range(low=0, desc=desc, argstr='-pert %d')
315316

316317
# F3d2 options
317318
vel_flag = traits.Bool(desc='Use velocity field integration',

0 commit comments

Comments
 (0)