generated from nipreps/Cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from smeisler/pydra-synthstrip
[ENH] Pydra version of synthstrip
- Loading branch information
Showing
3 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | ||
# vi: set ft=python sts=4 ts=4 sw=4 et: | ||
# | ||
# Copyright 2022 The NiPreps Developers <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We support and encourage derived works from this project, please read | ||
# about our expectations at | ||
# | ||
# https://www.nipreps.org/community/licensing/ | ||
# | ||
"""SynthStrip interface.""" | ||
|
||
import os | ||
import attr | ||
from pathlib import Path | ||
import pydra | ||
|
||
_fs_home = os.getenv("FREESURFER_HOME", None) | ||
_default_model_path = Path(_fs_home) / "models" / "synthstrip.1.pt" if _fs_home else None | ||
|
||
if _fs_home and not _default_model_path.exists(): | ||
_default_model_path = None | ||
|
||
SynthStripInputSpec = pydra.specs.SpecInfo( | ||
name='SynthStripInputSpec', | ||
fields=[ | ||
( | ||
'in_file', | ||
attr.ib( | ||
type=str, | ||
metadata={ | ||
'argstr': "-i", | ||
'help_string': 'Input image to skullstrip', | ||
'mandatory': True, | ||
}, | ||
), | ||
), | ||
( | ||
'out_file', | ||
str, | ||
{ | ||
'argstr': "-o", | ||
"help_string": "Save stripped image to path", | ||
"output_file_template": "{in_file}_desc-brain.nii.gz", | ||
}, | ||
), | ||
( | ||
'out_mask', | ||
str, | ||
{ | ||
'argstr': "-m", | ||
"help_string": "Save binary brain mask to path", | ||
"output_file_template": "{in_file}_desc-brain_mask.nii.gz", | ||
}, | ||
), | ||
( | ||
'use_gpu', | ||
bool, | ||
False, | ||
{ | ||
'argstr': "-g", | ||
'help_string': 'Use the GPU', | ||
}, | ||
), | ||
( | ||
'border_mm', | ||
int, | ||
1, | ||
{ | ||
'argstr': "-b", | ||
"help_string": "Mask border threshold in mm", | ||
}, | ||
), | ||
( | ||
'no_csf', | ||
bool, | ||
False, | ||
{ | ||
'argstr': "--no-csf", | ||
'help_string': 'Exclude CSF from brain border', | ||
}, | ||
), | ||
( | ||
'model', | ||
pydra.specs.File, | ||
str(_default_model_path), | ||
{ | ||
'argstr': "--model", | ||
"help_string": "File containing model's weights", | ||
}, | ||
), | ||
( | ||
'num_threads', | ||
int, | ||
{ | ||
'argstr': "-n", | ||
"help_string": "Number of threads", | ||
}, | ||
), | ||
], | ||
bases=(pydra.specs.ShellSpec,), | ||
) | ||
|
||
SynthStrip = pydra.ShellCommandTask( | ||
executable="nipreps-synthstrip", | ||
input_spec = SynthStripInputSpec | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters