Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
wf = init_single_subject_wf(
anat_only=False,
debug=False,
force_syn=True,
freesurfer=True,
hires=True,
ignore=[],
layout=BIDSLayout('.'),
longitudinal=False,
low_mem=False,
name='single_subject_wf',
omp_nthreads=1,
output_dir='.',
reportlets_dir='.',
skull_strip_fixed_seed=False,
skull_strip_template=Reference('OASIS30ANTs'),
spaces=SpatialReferences(
spaces=['MNI152Lin',
('fsaverage', {'density': '10k'}),
'T1w',
'fsnative'],
checkpoint=True),
subject_id='test',
use_syn=True,
)
"""
dataset_folder = dataset_name if not dataset_prefix \
else '%s%s' % (dataset_prefix, dataset_name)
default_paths = default_paths or ''
paths = [p / dataset_folder for p in _get_data_path(data_dir)]
all_paths = [Path(p) / dataset_folder
for p in default_paths.split(os.pathsep)] + paths
# Check if the dataset folder exists somewhere and is not empty
for path in all_paths:
if path.is_dir() and list(path.iterdir()):
if verbose > 1:
NIWORKFLOWS_LOG.info(
'Dataset "%s" already cached in %s', dataset_name, path)
return path, True
for path in paths:
if verbose > 0:
NIWORKFLOWS_LOG.info(
'Dataset "%s" not cached, downloading to %s', dataset_name, path)
path.mkdir(parents=True, exist_ok=True)
return path, False
default_paths = default_paths or ''
paths = [p / dataset_folder for p in _get_data_path(data_dir)]
all_paths = [Path(p) / dataset_folder
for p in default_paths.split(os.pathsep)] + paths
# Check if the dataset folder exists somewhere and is not empty
for path in all_paths:
if path.is_dir() and list(path.iterdir()):
if verbose > 1:
NIWORKFLOWS_LOG.info(
'Dataset "%s" already cached in %s', dataset_name, path)
return path, True
for path in paths:
if verbose > 0:
NIWORKFLOWS_LOG.info(
'Dataset "%s" not cached, downloading to %s', dataset_name, path)
path.mkdir(parents=True, exist_ok=True)
return path, False
def init_spaces(checkpoint=True):
"""Initialize the :attr:`~workflow.spaces` setting."""
from niworkflows.utils.spaces import Reference, SpatialReferences
spaces = execution.output_spaces or SpatialReferences()
if not isinstance(spaces, SpatialReferences):
spaces = SpatialReferences(
[ref for s in spaces.split(" ") for ref in Reference.from_string(s)]
)
if checkpoint and not spaces.is_cached():
spaces.checkpoint()
# Make the SpatialReferences object available
workflow.spaces = spaces
def parse_args(args=None, namespace=None):
"""Parse args and run further checks on the command line."""
import logging
from niworkflows.utils.spaces import Reference, SpatialReferences
parser = _build_parser()
opts = parser.parse_args(args, namespace)
config.execution.log_level = int(max(25 - 5 * opts.verbose_count, logging.DEBUG))
config.from_dict(vars(opts))
config.loggers.init()
# Initialize --output-spaces if not defined
if config.execution.output_spaces is None:
config.execution.output_spaces = SpatialReferences([Reference("run")])
# Retrieve logging level
build_log = config.loggers.cli
if config.execution.fs_license_file is None:
raise RuntimeError(
"""\
ERROR: a valid license file is required for FreeSurfer to run. dMRIPrep looked for an existing \
license file at several paths, in this order: 1) command line argument ``--fs-license-file``; \
2) ``$FS_LICENSE`` environment variable; and 3) the ``$FREESURFER_HOME/license.txt`` path. Get it \
(for free) by registering at https://surfer.nmr.mgh.harvard.edu/registration.html"""
)
os.environ["FS_LICENSE"] = str(config.execution.fs_license_file)
# Load base plugin_settings from file if --use-plugin
if opts.use_plugin is not None:
current_palette = sns.color_palette()
in_nii = nb.load(in_file)
if not tr:
tr = in_nii.header.get_zooms()[3]
units = in_nii.header.get_xyzt_units()
if units:
if units[-1] == "msec":
tr = tr / 1000.0
elif units[-1] == "usec":
tr = tr / 1000000.0
elif units[-1] != "sec":
NIWORKFLOWS_LOG.warning(
"Unknown repetition time units " "specified - assuming seconds"
)
else:
NIWORKFLOWS_LOG.warning(
"Repetition time units not specified - assuming seconds"
)
from nilearn.input_data import NiftiMasker
from nilearn.plotting import cm
if not report_mask:
nifti_masker = NiftiMasker(mask_strategy="epi")
nifti_masker.fit(index_img(in_nii, range(2)))
mask_img = nifti_masker.mask_img_
else:
mask_img = nb.load(report_mask)
mask_sl = []
for j in range(3):
mask_sl.append(transform_to_2d(mask_img.get_fdata(), j))
if not keywords:
raise NotThisMethod("no keywords at all, weird")
date = keywords.get("date")
if date is not None:
# git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
# datestamp. However we prefer "%ci" (which expands to an "ISO-8601
# -like" string, which we must then edit to make compliant), because
# it's been around since git-1.5.3, and it's too difficult to
# discover which version we're using, or to work around using an
# older one.
date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
refnames = keywords["refnames"].strip()
if refnames.startswith("$Format"):
if verbose:
print("keywords are unexpanded, not using")
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
if not tags:
# Either we're using git < 1.8.3, or there really are no tags. We use
# a heuristic: assume all version tags have a digit. The old git %d
# expansion behaves like git log --decorate=short and strips out the
# refs/heads/ and refs/tags/ prefixes that would let us distinguish
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r'\d', r)])
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
def git_versions_from_keywords(keywords, tag_prefix, verbose):
"""Get version information from git keywords."""
if not keywords:
raise NotThisMethod("no keywords at all, weird")
date = keywords.get("date")
if date is not None:
# git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
# datestamp. However we prefer "%ci" (which expands to an "ISO-8601
# -like" string, which we must then edit to make compliant), because
# it's been around since git-1.5.3, and it's too difficult to
# discover which version we're using, or to work around using an
# older one.
date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
refnames = keywords["refnames"].strip()
if refnames.startswith("$Format"):
if verbose:
print("keywords are unexpanded, not using")
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
from matplotlib.gridspec import GridSpec
import os
sns.set_style("white")
current_palette = sns.color_palette()
in_nii = nb.load(in_file)
if not tr:
tr = in_nii.header.get_zooms()[3]
units = in_nii.header.get_xyzt_units()
if units:
if units[-1] == "msec":
tr = tr / 1000.0
elif units[-1] == "usec":
tr = tr / 1000000.0
elif units[-1] != "sec":
NIWORKFLOWS_LOG.warning(
"Unknown repetition time units " "specified - assuming seconds"
)
else:
NIWORKFLOWS_LOG.warning(
"Repetition time units not specified - assuming seconds"
)
from nilearn.input_data import NiftiMasker
from nilearn.plotting import cm
if not report_mask:
nifti_masker = NiftiMasker(mask_strategy="epi")
nifti_masker.fit(index_img(in_nii, range(2)))
mask_img = nifti_masker.mask_img_
else:
mask_img = nb.load(report_mask)
# option was called without any output spaces, so user does not want outputs
spaces.checkpoint()
for val in values:
val = val.rstrip(":")
if (
val not in NONSTANDARD_REFERENCES
and not val.split(":")[0].startswith("fs")
and ":res-" not in val
and ":resolution-" not in val
):
# by default, explicitly set volumetric resolution to native
# relevant discussions:
# https://github.com/nipreps/niworkflows/pull/457#discussion_r375510227
# https://github.com/nipreps/niworkflows/pull/494
val = ":".join((val, "res-native"))
for sp in Reference.from_string(val):
spaces.add(sp)
setattr(namespace, self.dest, spaces)