本文整理汇总了Python中nipype.interfaces.base.isdefined函数的典型用法代码示例。如果您正苦于以下问题:Python isdefined函数的具体用法?Python isdefined怎么用?Python isdefined使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isdefined函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _list_outputs
def _list_outputs(self):
"""Execute this module.
"""
outdir = self.inputs.base_directory
if not isdefined(outdir):
outdir = os.path.abspath('.')
if isdefined(self.inputs.container):
print "container defined", self.inputs.container
outdir = os.path.join(outdir, self.inputs.container)
print outdir
cwd = os.getcwd()
dst = self._get_dst(os.path.join(cwd,self.inputs.json_name+'.json'))
print "dst = ", dst
outdir = os.path.join(outdir,dst)
print "new outdir = ", outdir
outdir = self._substitute(outdir)
print "substituted outdir = ", outdir
if not os.path.exists(outdir):
try:
os.makedirs(outdir)
except OSError, inst:
if 'File exists' in inst:
pass
else:
raise(inst)
示例2: _run_interface
def _run_interface(self, runtime):
if not isdefined(self.inputs.screenshot_stem):
stem = "%s_%s_%s" % (
self.inputs.subject_id, self.inputs.hemi, self.inputs.surface)
else:
stem = self.inputs.screenshot_stem
stem_args = self.inputs.stem_template_args
if isdefined(stem_args):
args = tuple([getattr(self.inputs, arg) for arg in stem_args])
stem = stem % args
# Check if the DISPLAY variable is set -- should avoid crashes (might not?)
if not "DISPLAY" in os.environ:
raise RuntimeError("Graphics are not enabled -- cannot run tksurfer")
runtime.environ["_SNAPSHOT_STEM"] = stem
self._write_tcl_script()
runtime = super(SurfaceSnapshots, self)._run_interface(runtime)
# If a display window can't be opened, this will crash on
# aggregate_outputs. Let's try to parse stderr and raise a
# better exception here if that happened.
errors = ["surfer: failed, no suitable display found",
"Fatal Error in tksurfer.bin: could not open display"]
for err in errors:
if err in runtime.stderr:
self.raise_exception(runtime)
# Tksurfer always (or at least always when you run a tcl script)
# exits with a nonzero returncode. We have to force it to 0 here.
runtime.returncode = 0
return runtime
示例3: _gen_outfilename
def _gen_outfilename(self):
out_file = self.inputs.out_file
if not isdefined(out_file) and isdefined(self.inputs.in_file):
out_file = self._gen_fname(self.inputs.in_file, suffix="_surf")
#out_file = self._gen_fname(self.inputs.in_file, suffix="_surf")
return out_file
示例4: _check_mlab_inputs
def _check_mlab_inputs(self):
if not isdefined(self.inputs.matlab_cmd) and self._matlab_cmd:
self.inputs.matlab_cmd = self._matlab_cmd
if not isdefined(self.inputs.paths) and self._paths:
self.inputs.paths = self._paths
if not isdefined(self.inputs.use_mcr) and self._use_mcr:
self.inputs.use_mcr = self._use_mcr
示例5: _run_interface
def _run_interface(self, runtime):
tracks, header = trk.read(self.inputs.in_file)
if not isdefined(self.inputs.data_dims):
data_dims = header['dim']
else:
data_dims = self.inputs.data_dims
if not isdefined(self.inputs.voxel_dims):
voxel_size = header['voxel_size']
else:
voxel_size = self.inputs.voxel_dims
affine = header['vox_to_ras']
streams = ((ii[0]) for ii in tracks)
data = density_map(streams, data_dims, voxel_size)
if data.max() < 2**15:
data = data.astype('int16')
img = nb.Nifti1Image(data,affine)
out_file = op.abspath(self.inputs.out_filename)
nb.save(img, out_file)
iflogger.info('Track density map saved as {i}'.format(i=out_file))
iflogger.info('Data Dimensions {d}'.format(d=data_dims))
iflogger.info('Voxel Dimensions {v}'.format(v=voxel_size))
return runtime
示例6: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
outputs["out_file"] = self.inputs.out_file
if not isdefined(outputs["out_file"]):
source = self.inputs.source_file
# Some recon-all files don't have a proper extension (e.g. "lh.thickness")
# so we have to account for that here
bad_extensions = [".%s" % e for e in ["area", "mid", "pial", "avg_curv", "curv", "inflated",
"jacobian_white", "orig", "nofix", "smoothwm", "crv",
"sphere", "sulc", "thickness", "volume", "white"]]
use_ext = True
if split_filename(source)[2] in bad_extensions:
source = source + ".stripme"
use_ext = False
ext = ""
if isdefined(self.inputs.target_type):
ext = "." + filemap[self.inputs.target_type]
use_ext = False
outputs["out_file"] = fname_presuffix(source,
suffix=".%s%s" % (self.inputs.target_subject, ext),
newpath=os.getcwd(),
use_ext=use_ext)
else:
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
return outputs
示例7: _list_outputs
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.out_file
if not isdefined(outputs['out_file']) and isdefined(self.inputs.in_file):
outputs['out_file']=self._gen_fname(self.inputs.in_file,
suffix='_sigloss')
return outputs
示例8: _list_outputs
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["out_reg_file"] = self.inputs.out_reg_file
if not isdefined(self.inputs.out_reg_file) and self.inputs.source_file:
outputs["out_reg_file"] = fname_presuffix(self.inputs.source_file, suffix="_robustreg.lta", use_ext=False)
prefices = dict(src=self.inputs.source_file, trg=self.inputs.target_file)
suffices = dict(
registered_file=("src", "_robustreg", True),
weights_file=("src", "_robustweights", True),
half_source=("src", "_halfway", True),
half_targ=("trg", "_halfway", True),
half_weights=("src", "_halfweights", True),
half_source_xfm=("src", "_robustxfm.lta", False),
half_targ_xfm=("trg", "_robustxfm.lta", False),
)
for name, sufftup in suffices.items():
value = getattr(self.inputs, name)
if isdefined(value):
if isinstance(value, bool):
outputs[name] = fname_presuffix(
prefices[sufftup[0]], suffix=sufftup[1], newpath=os.getcwd(), use_ext=sufftup[2]
)
else:
outputs[name] = value
return outputs
示例9: _list_outputs
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = os.path.join(os.getcwd(),
self.inputs.out_base + '.nii.gz')
if not (isdefined(self.inputs.no_fmapreg) and self.inputs.no_fmapreg) and isdefined(self.inputs.fmap):
outputs['out_1vol'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_1vol.nii.gz')
outputs['fmap2str_mat'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmap2str.mat')
outputs['fmap2epi_mat'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2epi.mat')
outputs['fmap_epi'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2epi.nii.gz')
outputs['fmap_str'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2str.ni `i.gz')
outputs['fmapmag_str'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmap2str.nii.gz')
outputs['shiftmap'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fieldmaprads2epi_shift.nii.gz')
outputs['fullwarp'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_warp.nii.gz')
outputs['epi2str_inv'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_inv.mat')
outputs['epi2str_mat'] = os.path.join(os.getcwd(),
self.inputs.out_base + '.mat')
outputs['wmedge'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fast_wmedge.nii.gz')
outputs['wmseg'] = os.path.join(os.getcwd(),
self.inputs.out_base + '_fast_wmseg.nii.gz')
return outputs
示例10: _run_interface
def _run_interface(self, runtime):
out_file = op.abspath(self._gen_outfilename())
settings = dict(mask=None,
rician=(self.inputs.noise_model == 'rician'))
if isdefined(self.inputs.in_mask):
settings['mask'] = nb.load(self.inputs.in_mask).get_data()
if isdefined(self.inputs.patch_radius):
settings['patch_radius'] = self.inputs.patch_radius
if isdefined(self.inputs.block_radius):
settings['block_radius'] = self.inputs.block_radius
noise_mask = None
if isdefined(self.inputs.in_mask):
noise_mask = nb.load(self.inputs.noise_mask).get_data()
_, s = nlmeans_proxy(self.inputs.in_file,
settings,
noise_mask=noise_mask,
out_file=out_file)
iflogger.info(('Denoised image saved as {i}, estimated '
'sigma={s}').format(i=out_file, s=s))
return runtime
示例11: _run_interface
def _run_interface(self, runtime):
in_file_ref = Path(self.inputs.in_file)
if isdefined(self.inputs.out_file):
in_file_ref = Path(self.inputs.out_file)
fname = in_file_ref.name.rstrip(
''.join(in_file_ref.suffixes))
out_file = (Path(runtime.cwd) / ('plot_%s_contours.svg' % fname)).resolve()
self._results['out_file'] = str(out_file)
vmax = None if not isdefined(self.inputs.vmax) else self.inputs.vmax
vmin = None if not isdefined(self.inputs.vmin) else self.inputs.vmin
plot_segmentation(
self.inputs.in_file,
self.inputs.in_contours,
out_file=str(out_file),
cut_coords=self.inputs.cut_coords,
display_mode=self.inputs.display_mode,
levels=self.inputs.levels,
colors=self.inputs.colors,
saturate=self.inputs.saturate,
vmin=vmin, vmax=vmax)
return runtime
示例12: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
jobtype = self.inputs.jobtype
if jobtype.startswith('est'):
outputs['normalization_parameters'] = []
for imgf in filename_to_list(self.inputs.source):
outputs['normalization_parameters'].append(fname_presuffix(imgf, suffix='_sn.mat', use_ext=False))
outputs['normalization_parameters'] = list_to_filename(outputs['normalization_parameters'])
if self.inputs.jobtype == "estimate":
if isdefined(self.inputs.apply_to_files):
outputs['normalized_files'] = self.inputs.apply_to_files
outputs['normalized_source'] = self.inputs.source
elif 'write' in self.inputs.jobtype:
outputs['normalized_files'] = []
if isdefined(self.inputs.apply_to_files):
for imgf in filename_to_list(self.inputs.apply_to_files):
outputs['normalized_files'].append(fname_presuffix(imgf, prefix='w'))
if isdefined(self.inputs.source):
outputs['normalized_source'] = []
for imgf in filename_to_list(self.inputs.source):
outputs['normalized_source'].append(fname_presuffix(imgf, prefix='w'))
return outputs
示例13: _list_outputs
def _list_outputs(self):
outputs = self._outputs().get()
jobtype = self.inputs.jobtype
if jobtype.startswith('est'):
outputs['normalization_parameters'] = []
for imgf in filename_to_list(self.inputs.source):
outputs['normalization_parameters'].append(fname_presuffix(imgf, suffix='_sn.mat', use_ext=False))
outputs['normalization_parameters'] = list_to_filename(outputs['normalization_parameters'])
if self.inputs.jobtype == "estimate":
if isdefined(self.inputs.apply_to_files):
outputs['normalized_files'] = self.inputs.apply_to_files
outputs['normalized_source'] = self.inputs.source
elif 'write' in self.inputs.jobtype:
outputs['normalized_files'] = []
if isdefined(self.inputs.apply_to_files):
filelist = filename_to_list(self.inputs.apply_to_files)
for f in filelist:
if isinstance(f, list):
run = [fname_presuffix(in_f, prefix=self.inputs.out_prefix) for in_f in f]
else:
run = [fname_presuffix(f, prefix=self.inputs.out_prefix)]
outputs['normalized_files'].extend(run)
if isdefined(self.inputs.source):
outputs['normalized_source'] = fname_presuffix(self.inputs.source, prefix=self.inputs.out_prefix)
return outputs
示例14: _generate_design
def _generate_design(self, infolist=None):
"""Generate design specification for a typical fmri paradigm
"""
realignment_parameters = []
if isdefined(self.inputs.realignment_parameters):
for parfile in self.inputs.realignment_parameters:
realignment_parameters.append(np.loadtxt(parfile))
outliers = []
if isdefined(self.inputs.outlier_files):
for filename in self.inputs.outlier_files:
try:
outindices = np.loadtxt(filename, dtype=int)
except IOError:
outliers.append([])
else:
if outindices.size == 1:
outliers.append([outindices.tolist()])
else:
outliers.append(outindices.tolist())
if infolist is None:
if isdefined(self.inputs.subject_info):
infolist = self.inputs.subject_info
else:
infolist = gen_info(self.inputs.event_files)
self._sessinfo = self._generate_standard_design(
infolist,
functional_runs=self.inputs.functional_runs,
realignment_parameters=realignment_parameters,
outliers=outliers,
)
示例15: _run_interface
def _run_interface(self, runtime):
mask_erode_mm = self.inputs.mask_erode_mm
if not isdefined(mask_erode_mm):
mask_erode_mm = None
erode_mm = self.inputs.erode_mm
if not isdefined(erode_mm):
erode_mm = None
mask_erode_prop = self.inputs.mask_erode_prop
if not isdefined(mask_erode_prop):
mask_erode_prop = None
erode_prop = self.inputs.erode_prop
if not isdefined(erode_prop):
erode_prop = None
roi_file, eroded_mask = _tpm2roi(
self.inputs.in_tpm,
self.inputs.in_mask,
mask_erode_mm,
erode_mm,
mask_erode_prop,
erode_prop,
self.inputs.prob_thresh,
newpath=runtime.cwd,
)
self._results['roi_file'] = roi_file
self._results['eroded_mask'] = eroded_mask
return runtime