Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
AI(
fixed_image=str(bold_template),
fixed_image_mask=str(brain_mask),
metric=("Mattes", 32, "Regular", 0.2),
transform=("Affine", 0.1),
search_factor=(20, 0.12),
principal_axes=False,
convergence=(10, 1e-6, 10),
verbose=True,
),
name="init_aff",
n_procs=omp_nthreads,
)
# Registration().version may be None
if parseversion(Registration().version or "0.0.0") > Version("2.2.0"):
init_aff.inputs.search_grid = (40, (0, 40, 40))
# Set up spatial normalization
norm = pe.Node(
Registration(
from_file=pkgr_fn("niworkflows.data", "epi_atlasbased_brainmask.json")
),
name="norm",
n_procs=omp_nthreads,
)
norm.inputs.fixed_image = str(bold_template)
map_brainmask = pe.Node(
ApplyTransforms(
interpolation="MultiLabel", input_image=str(brain_mask)
),
name="map_brainmask",
# Save outputs (if available)
init_out = _write_outputs(init_result.runtime, ".nipype-init")
if init_out:
NIWORKFLOWS_LOG.info(
"Terminal outputs of initialization saved (%s).",
", ".join(init_out),
)
ants_args["initial_moving_transform"] = init_result.outputs.out_file
# For each settings file...
for ants_settings in settings_files:
NIWORKFLOWS_LOG.info("Loading settings from file %s.", ants_settings)
# Configure an ANTs run based on these settings.
self.norm = Registration(from_file=ants_settings, **ants_args)
self.norm.resource_monitor = False
self.norm.terminal_output = self.terminal_output
cmd = self.norm.cmdline
# Print the retry number and command line call to the log.
NIWORKFLOWS_LOG.info("Retry #%d, commandline: \n%s", self.retry, cmd)
self.norm.ignore_exception = True
with open("command.txt", "w") as cmdfile:
print(cmd + "\n", file=cmdfile)
# Try running registration.
interface_result = self.norm.run()
if interface_result.runtime.returncode != 0:
NIWORKFLOWS_LOG.warning("Retry #%d failed.", self.retry)
# Save outputs (if available)
# Initialize transforms with antsAI
init_aff = pe.Node(
AI(
metric=("Mattes", 32, "Regular", 0.25),
transform=("Affine", 0.1),
search_factor=(15, 0.1),
principal_axes=False,
convergence=(10, 1e-6, 10),
verbose=True,
),
name="init_aff",
n_procs=omp_nthreads,
)
# Tolerate missing ANTs at construction time
_ants_version = Registration().version
if _ants_version and parseversion(_ants_version) >= Version("2.3.0"):
init_aff.inputs.search_grid = (40, (0, 40, 40))
# Set up spatial normalization
settings_file = (
"antsBrainExtraction_%s.json"
if use_laplacian
else "antsBrainExtractionNoLaplacian_%s.json"
)
norm = pe.Node(
Registration(
from_file=pkgr_fn("niworkflows.data", settings_file % normalization_quality)
),
name="norm",
n_procs=omp_nthreads,
mem_gb=mem_gb,
def _run_interface(self, runtime, correct_return_codes=(0,)):
# Run normally
runtime = super(FixHeaderRegistration, self)._run_interface(
runtime, correct_return_codes
)
# Forward transform
out_file = self._get_outputfilenames(inverse=False)
if out_file is not None and out_file:
_copyxform(
self.inputs.fixed_image[0],
os.path.abspath(out_file),
message="%s (niworkflows v%s)" % (self.__class__.__name__, __version__),
)
# Inverse transform
out_file = self._get_outputfilenames(inverse=True)
if out_file is not None and out_file:
_copyxform(
search_factor=(20, 0.12),
principal_axes=False,
convergence=(10, 1e-6, 10),
verbose=True,
),
name="init_aff",
n_procs=omp_nthreads,
)
# Registration().version may be None
if parseversion(Registration().version or "0.0.0") > Version("2.2.0"):
init_aff.inputs.search_grid = (40, (0, 40, 40))
# Set up spatial normalization
norm = pe.Node(
Registration(
from_file=pkgr_fn("niworkflows.data", "epi_atlasbased_brainmask.json")
),
name="norm",
n_procs=omp_nthreads,
)
norm.inputs.fixed_image = str(bold_template)
map_brainmask = pe.Node(
ApplyTransforms(
interpolation="MultiLabel", input_image=str(brain_mask)
),
name="map_brainmask",
)
# fmt: off
workflow.connect([
(inputnode, init_aff, [("in_file", "moving_image")]),
(inputnode, map_brainmask, [("in_file", "reference_image")]),
n_procs=omp_nthreads,
)
# Tolerate missing ANTs at construction time
_ants_version = Registration().version
if _ants_version and parseversion(_ants_version) >= Version("2.3.0"):
init_aff.inputs.search_grid = (40, (0, 40, 40))
# Set up spatial normalization
settings_file = (
"antsBrainExtraction_%s.json"
if use_laplacian
else "antsBrainExtractionNoLaplacian_%s.json"
)
norm = pe.Node(
Registration(
from_file=pkgr_fn("niworkflows.data", settings_file % normalization_quality)
),
name="norm",
n_procs=omp_nthreads,
mem_gb=mem_gb,
)
norm.inputs.float = use_float
fixed_mask_trait = "fixed_image_mask"
if _ants_version and parseversion(_ants_version) >= Version("2.2.0"):
fixed_mask_trait += "s"
map_brainmask = pe.Node(
ApplyTransforms(interpolation="Gaussian", float=True),
name="map_brainmask",
mem_gb=1,
)