From 823c0582d015a771b7664599191045bfdf2d255e Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Mon, 12 May 2025 17:14:26 -1000 Subject: [PATCH 1/3] fix: the commandline is set ``--model `` --- nipreps/synthstrip/wrappers/nipype.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nipreps/synthstrip/wrappers/nipype.py b/nipreps/synthstrip/wrappers/nipype.py index 2362916..81dfe9e 100644 --- a/nipreps/synthstrip/wrappers/nipype.py +++ b/nipreps/synthstrip/wrappers/nipype.py @@ -37,8 +37,12 @@ _fs_home = os.getenv('FREESURFER_HOME', None) _default_model_path = Path(_fs_home) / 'models' / 'synthstrip.1.pt' if _fs_home else Undefined +use_defaultmodel = False if _fs_home and not _default_model_path.exists(): _default_model_path = Undefined +else: + use_defaultmodel = True + _default_model_path = str(_default_model_path) class _SynthStripInputSpec(CommandLineInputSpec): @@ -50,8 +54,8 @@ class _SynthStripInputSpec(CommandLineInputSpec): ) use_gpu = traits.Bool(False, usedefault=True, argstr='-g', desc='Use GPU', nohash=True) model = File( - str(_default_model_path), - usedefault=True, + _default_model_path, + usedefault=use_defaultmodel, exists=True, argstr='--model %s', desc="file containing model's weights", From 905fa86ab5a3e446000a882571a005f9327335fe Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Mon, 12 May 2025 17:19:36 -1000 Subject: [PATCH 2/3] sty: use f-strings --- nipreps/synthstrip/model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipreps/synthstrip/model.py b/nipreps/synthstrip/model.py index 3081d2d..74eba9c 100644 --- a/nipreps/synthstrip/model.py +++ b/nipreps/synthstrip/model.py @@ -89,7 +89,7 @@ def __init__( max_pool = [max_pool] * self.nb_levels # cache downsampling / upsampling operations - MaxPooling = getattr(nn, 'MaxPool%dd' % ndims) + MaxPooling = getattr(nn, f'MaxPool{ndims}d') self.pooling = [MaxPooling(s) for s in max_pool] self.upsampling = [nn.Upsample(scale_factor=s, mode='nearest') for s in max_pool] @@ -164,7 +164,7 @@ class ConvBlock(nn.Module): def __init__(self, ndims, in_channels, out_channels, stride=1, activation='leaky'): super().__init__() - Conv = getattr(nn, 'Conv%dd' % ndims) + Conv = getattr(nn, f'Conv{ndims}d') self.conv = Conv(in_channels, out_channels, 3, stride, 1) if activation == 'leaky': self.activation = nn.LeakyReLU(0.2) From d821517276b16b5a0292e98da7c83a5f8e8ce79a Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Thu, 15 May 2025 05:36:52 +0200 Subject: [PATCH 3/3] fix: improve logic --- nipreps/synthstrip/wrappers/nipype.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nipreps/synthstrip/wrappers/nipype.py b/nipreps/synthstrip/wrappers/nipype.py index 81dfe9e..6fe2d85 100644 --- a/nipreps/synthstrip/wrappers/nipype.py +++ b/nipreps/synthstrip/wrappers/nipype.py @@ -23,6 +23,7 @@ """SynthStrip interface.""" import os +from contextlib import suppress from pathlib import Path from nipype.interfaces.base import ( @@ -38,10 +39,8 @@ _default_model_path = Path(_fs_home) / 'models' / 'synthstrip.1.pt' if _fs_home else Undefined use_defaultmodel = False -if _fs_home and not _default_model_path.exists(): - _default_model_path = Undefined -else: - use_defaultmodel = True +with suppress(AttributeError): + use_defaultmodel = _default_model_path.exists() _default_model_path = str(_default_model_path)