本文整理汇总了Python中nipype.Workflow.base_dir方法的典型用法代码示例。如果您正苦于以下问题:Python Workflow.base_dir方法的具体用法?Python Workflow.base_dir怎么用?Python Workflow.base_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nipype.Workflow
的用法示例。
在下文中一共展示了Workflow.base_dir方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_serial_input
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
def test_serial_input():
cwd = os.getcwd()
wd = mkdtemp()
os.chdir(wd)
from nipype import MapNode, Function, Workflow
def func1(in1):
return in1
n1 = MapNode(Function(input_names=['in1'],
output_names=['out'],
function=func1),
iterfield=['in1'],
name='n1')
n1.inputs.in1 = [1,2,3]
w1 = Workflow(name='test')
w1.base_dir = wd
w1.add_nodes([n1])
# set local check
w1.config['execution'] = {'stop_on_first_crash': 'true',
'local_hash_check': 'true',
'crashdump_dir': wd}
# test output of num_subnodes method when serial is default (False)
yield assert_equal, n1.num_subnodes(), len(n1.inputs.in1)
# test running the workflow on default conditions
error_raised = False
try:
w1.run(plugin='MultiProc')
except Exception, e:
pe.logger.info('Exception: %s' % str(e))
error_raised = True
示例2: test_serial_input
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
def test_serial_input(tmpdir):
tmpdir.chdir()
wd = os.getcwd()
from nipype import MapNode, Function, Workflow
def func1(in1):
return in1
n1 = MapNode(Function(input_names=['in1'],
output_names=['out'],
function=func1),
iterfield=['in1'],
name='n1')
n1.inputs.in1 = [1, 2, 3]
w1 = Workflow(name='test')
w1.base_dir = wd
w1.add_nodes([n1])
# set local check
w1.config['execution'] = {'stop_on_first_crash': 'true',
'local_hash_check': 'true',
'crashdump_dir': wd,
'poll_sleep_duration': 2}
# test output of num_subnodes method when serial is default (False)
assert n1.num_subnodes() == len(n1.inputs.in1)
# test running the workflow on default conditions
w1.run(plugin='MultiProc')
# test output of num_subnodes method when serial is True
n1._serial = True
assert n1.num_subnodes() == 1
# test running the workflow on serial conditions
w1.run(plugin='MultiProc')
示例3: test_mapnode_json
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
def test_mapnode_json():
"""Tests that mapnodes don't generate excess jsons
"""
cwd = os.getcwd()
wd = mkdtemp()
os.chdir(wd)
from nipype import MapNode, Function, Workflow
def func1(in1):
return in1 + 1
n1 = MapNode(Function(input_names=['in1'],
output_names=['out'],
function=func1),
iterfield=['in1'],
name='n1')
n1.inputs.in1 = [1]
w1 = Workflow(name='test')
w1.base_dir = wd
w1.config['execution']['crashdump_dir'] = wd
w1.add_nodes([n1])
w1.run()
n1.inputs.in1 = [2]
w1.run()
# should rerun
n1.inputs.in1 = [1]
eg = w1.run()
node = eg.nodes()[0]
outjson = glob(os.path.join(node.output_dir(), '_0x*.json'))
yield assert_equal, len(outjson), 1
# check that multiple json's don't trigger rerun
with open(os.path.join(node.output_dir(), 'test.json'), 'wt') as fp:
fp.write('dummy file')
w1.config['execution'].update(**{'stop_on_first_rerun': True})
error_raised = False
try:
w1.run()
except:
error_raised = True
yield assert_false, error_raised
os.chdir(cwd)
rmtree(wd)
示例4: test_mapnode_json
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
def test_mapnode_json(tmpdir):
"""Tests that mapnodes don't generate excess jsons
"""
tmpdir.chdir()
wd = os.getcwd()
from nipype import MapNode, Function, Workflow
def func1(in1):
return in1 + 1
n1 = MapNode(Function(input_names=['in1'],
output_names=['out'],
function=func1),
iterfield=['in1'],
name='n1')
n1.inputs.in1 = [1]
w1 = Workflow(name='test')
w1.base_dir = wd
w1.config['execution']['crashdump_dir'] = wd
w1.add_nodes([n1])
w1.run()
n1.inputs.in1 = [2]
w1.run()
# should rerun
n1.inputs.in1 = [1]
eg = w1.run()
node = list(eg.nodes())[0]
outjson = glob(os.path.join(node.output_dir(), '_0x*.json'))
assert len(outjson) == 1
# check that multiple json's don't trigger rerun
with open(os.path.join(node.output_dir(), 'test.json'), 'wt') as fp:
fp.write('dummy file')
w1.config['execution'].update(**{'stop_on_first_rerun': True})
w1.run()
示例5: group_onesample_openfmri
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
def group_onesample_openfmri(dataset_dir,model_id=None,task_id=None,l1output_dir=None,out_dir=None, no_reversal=False):
wk = Workflow(name='one_sample')
wk.base_dir = os.path.abspath(work_dir)
info = Node(util.IdentityInterface(fields=['model_id','task_id','dataset_dir']),
name='infosource')
info.inputs.model_id=model_id
info.inputs.task_id=task_id
info.inputs.dataset_dir=dataset_dir
num_copes=contrasts_num(model_id,task_id,dataset_dir)
dg = Node(DataGrabber(infields=['model_id','task_id','cope_id'],
outfields=['copes', 'varcopes']),name='grabber')
dg.inputs.template = os.path.join(l1output_dir,'model%03d/task%03d/*/%scopes/mni/%scope%02d.nii.gz')
dg.inputs.template_args['copes'] = [['model_id','task_id','', '', 'cope_id']]
dg.inputs.template_args['varcopes'] = [['model_id','task_id','var', 'var', 'cope_id']]
dg.iterables=('cope_id',num_copes)
dg.inputs.sort_filelist = True
wk.connect(info,'model_id',dg,'model_id')
wk.connect(info,'task_id',dg,'task_id')
model = Node(L2Model(), name='l2model')
wk.connect(dg, ('copes', get_len), model, 'num_copes')
mergecopes = Node(Merge(dimension='t'), name='merge_copes')
wk.connect(dg, 'copes', mergecopes, 'in_files')
mergevarcopes = Node(Merge(dimension='t'), name='merge_varcopes')
wk.connect(dg, 'varcopes', mergevarcopes, 'in_files')
mask_file = fsl.Info.standard_image('MNI152_T1_2mm_brain_mask.nii.gz')
flame = Node(FLAMEO(), name='flameo')
flame.inputs.mask_file = mask_file
flame.inputs.run_mode = 'flame1'
wk.connect(model, 'design_mat', flame, 'design_file')
wk.connect(model, 'design_con', flame, 't_con_file')
wk.connect(mergecopes, 'merged_file', flame, 'cope_file')
wk.connect(mergevarcopes, 'merged_file', flame, 'var_cope_file')
wk.connect(model, 'design_grp', flame, 'cov_split_file')
smoothest = Node(SmoothEstimate(), name='smooth_estimate')
wk.connect(flame, 'zstats', smoothest, 'zstat_file')
smoothest.inputs.mask_file = mask_file
cluster = Node(Cluster(), name='cluster')
wk.connect(smoothest,'dlh', cluster, 'dlh')
wk.connect(smoothest, 'volume', cluster, 'volume')
cluster.inputs.connectivity = 26
cluster.inputs.threshold=2.3
cluster.inputs.pthreshold = 0.05
cluster.inputs.out_threshold_file = True
cluster.inputs.out_index_file = True
cluster.inputs.out_localmax_txt_file = True
wk.connect(flame, 'zstats', cluster, 'in_file')
ztopval = Node(ImageMaths(op_string='-ztop', suffix='_pval'),
name='z2pval')
wk.connect(flame, 'zstats', ztopval,'in_file')
sinker = Node(DataSink(), name='sinker')
sinker.inputs.base_directory = os.path.abspath(out_dir)
sinker.inputs.substitutions = [('_cope_id', 'contrast'),
('_maths__', '_reversed_')]
wk.connect(flame, 'zstats', sinker, 'stats')
wk.connect(cluster, 'threshold_file', sinker, '[email protected]')
wk.connect(cluster, 'index_file', sinker, '[email protected]')
wk.connect(cluster, 'localmax_txt_file', sinker, '[email protected]')
if no_reversal == False:
zstats_reverse = Node( BinaryMaths() , name='zstats_reverse')
zstats_reverse.inputs.operation = 'mul'
zstats_reverse.inputs.operand_value= -1
wk.connect(flame, 'zstats', zstats_reverse, 'in_file')
cluster2=cluster.clone(name='cluster2')
wk.connect(smoothest,'dlh',cluster2,'dlh')
wk.connect(smoothest,'volume',cluster2,'volume')
wk.connect(zstats_reverse,'out_file',cluster2,'in_file')
ztopval2 = ztopval.clone(name='ztopval2')
wk.connect(zstats_reverse,'out_file',ztopval2,'in_file')
wk.connect(zstats_reverse,'out_file',sinker,'[email protected]')
wk.connect(cluster2,'threshold_file',sinker,'[email protected]_thr')
wk.connect(cluster2,'index_file',sinker,'[email protected]_index')
wk.connect(cluster2,'localmax_txt_file',sinker,'[email protected]_localmax')
return wk
示例6: group_multregress_openfmri
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
def group_multregress_openfmri(dataset_dir, model_id=None, task_id=None, l1output_dir=None, out_dir=None,
no_reversal=False, plugin=None, plugin_args=None, flamemodel='flame1',
nonparametric=False, use_spm=False):
meta_workflow = Workflow(name='mult_regress')
meta_workflow.base_dir = work_dir
for task in task_id:
task_name = get_taskname(dataset_dir, task)
cope_ids = l1_contrasts_num(model_id, task_name, dataset_dir)
regressors_needed, contrasts, groups, subj_list = get_sub_vars(dataset_dir, task_name, model_id)
for idx, contrast in enumerate(contrasts):
wk = Workflow(name='model_%03d_task_%03d_contrast_%s' % (model_id, task, contrast[0][0]))
info = Node(util.IdentityInterface(fields=['model_id', 'task_id', 'dataset_dir', 'subj_list']),
name='infosource')
info.inputs.model_id = model_id
info.inputs.task_id = task
info.inputs.dataset_dir = dataset_dir
dg = Node(DataGrabber(infields=['model_id', 'task_id', 'cope_id'],
outfields=['copes', 'varcopes']), name='grabber')
dg.inputs.template = os.path.join(l1output_dir,
'model%03d/task%03d/%s/%scopes/%smni/%scope%02d.nii%s')
if use_spm:
dg.inputs.template_args['copes'] = [['model_id', 'task_id', subj_list, '', 'spm/',
'', 'cope_id', '']]
dg.inputs.template_args['varcopes'] = [['model_id', 'task_id', subj_list, 'var', 'spm/',
'var', 'cope_id', '.gz']]
else:
dg.inputs.template_args['copes'] = [['model_id', 'task_id', subj_list, '', '', '',
'cope_id', '.gz']]
dg.inputs.template_args['varcopes'] = [['model_id', 'task_id', subj_list, 'var', '',
'var', 'cope_id', '.gz']]
dg.iterables=('cope_id', cope_ids)
dg.inputs.sort_filelist = False
wk.connect(info, 'model_id', dg, 'model_id')
wk.connect(info, 'task_id', dg, 'task_id')
model = Node(MultipleRegressDesign(), name='l2model')
model.inputs.groups = groups
model.inputs.contrasts = contrasts[idx]
model.inputs.regressors = regressors_needed[idx]
mergecopes = Node(Merge(dimension='t'), name='merge_copes')
wk.connect(dg, 'copes', mergecopes, 'in_files')
if flamemodel != 'ols':
mergevarcopes = Node(Merge(dimension='t'), name='merge_varcopes')
wk.connect(dg, 'varcopes', mergevarcopes, 'in_files')
mask_file = fsl.Info.standard_image('MNI152_T1_2mm_brain_mask.nii.gz')
flame = Node(FLAMEO(), name='flameo')
flame.inputs.mask_file = mask_file
flame.inputs.run_mode = flamemodel
#flame.inputs.infer_outliers = True
wk.connect(model, 'design_mat', flame, 'design_file')
wk.connect(model, 'design_con', flame, 't_con_file')
wk.connect(mergecopes, 'merged_file', flame, 'cope_file')
if flamemodel != 'ols':
wk.connect(mergevarcopes, 'merged_file', flame, 'var_cope_file')
wk.connect(model, 'design_grp', flame, 'cov_split_file')
if nonparametric:
palm = Node(Function(input_names=['cope_file', 'design_file', 'contrast_file',
'group_file', 'mask_file', 'cluster_threshold'],
output_names=['palm_outputs'],
function=run_palm),
name='palm')
palm.inputs.cluster_threshold = 3.09
palm.inputs.mask_file = mask_file
palm.plugin_args = {'sbatch_args': '-p om_all_nodes -N1 -c2 --mem=10G', 'overwrite': True}
wk.connect(model, 'design_mat', palm, 'design_file')
wk.connect(model, 'design_con', palm, 'contrast_file')
wk.connect(mergecopes, 'merged_file', palm, 'cope_file')
wk.connect(model, 'design_grp', palm, 'group_file')
smoothest = Node(SmoothEstimate(), name='smooth_estimate')
wk.connect(flame, 'zstats', smoothest, 'zstat_file')
smoothest.inputs.mask_file = mask_file
cluster = Node(Cluster(), name='cluster')
wk.connect(smoothest,'dlh', cluster, 'dlh')
wk.connect(smoothest, 'volume', cluster, 'volume')
cluster.inputs.connectivity = 26
cluster.inputs.threshold = 2.3
cluster.inputs.pthreshold = 0.05
cluster.inputs.out_threshold_file = True
cluster.inputs.out_index_file = True
cluster.inputs.out_localmax_txt_file = True
wk.connect(flame, 'zstats', cluster, 'in_file')
ztopval = Node(ImageMaths(op_string='-ztop', suffix='_pval'),
name='z2pval')
wk.connect(flame, 'zstats', ztopval,'in_file')
sinker = Node(DataSink(), name='sinker')
sinker.inputs.base_directory = os.path.join(out_dir, 'task%03d' % task, contrast[0][0])
#.........这里部分代码省略.........
示例7: StringIO
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
else:
from io import StringIO
data = StringIO(r.content.decode())
df = pd.read_csv(data)
max_subjects = df.shape[0]
if args.num_subjects:
max_subjects = args.num_subjects
elif ('CIRCLECI' in os.environ and os.environ['CIRCLECI'] == 'true'):
max_subjects = 1
meta_wf = Workflow('metaflow')
count = 0
for row in df.iterrows():
wf = create_workflow(row[1].Subject, sink_dir, row[1]['File Path'])
meta_wf.add_nodes([wf])
print('Added workflow for: {}'.format(row[1].Subject))
count = count + 1
# run this for only one person on CircleCI
if count >= max_subjects:
break
meta_wf.base_dir = work_dir
meta_wf.config['execution']['remove_unnecessary_files'] = False
meta_wf.config['execution']['poll_sleep_duration'] = 2
meta_wf.config['execution']['crashdump_dir'] = work_dir
if args.plugin_args:
meta_wf.run(args.plugin, plugin_args=eval(args.plugin_args))
else:
meta_wf.run(args.plugin)
示例8: dict
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
info = dict(T1=[['subject_id']])
infosource = Node(IdentityInterface(fields=['subject_id']), name='infosource')
infosource.iterables = ('subject_id', sids)
# Create a datasource node to get the T1 file
datasource = Node(DataGrabber(infields=['subject_id'],outfields=info.keys()),name = 'datasource')
datasource.inputs.template = '%s/%s'
datasource.inputs.base_directory = os.path.abspath('/home/data/madlab/data/mri/seqtrd/')
datasource.inputs.field_template = dict(T1='%s/anatomy/T1_*.nii.gz')
datasource.inputs.template_args = info
datasource.inputs.sort_filelist = True
reconall_node = Node(ReconAll(), name='reconall_node')
reconall_node.inputs.openmp = 2
reconall_node.inputs.subjects_dir = os.environ['SUBJECTS_DIR']
reconall_node.inputs.terminal_output = 'allatonce'
reconall_node.plugin_args={'bsub_args': ('-q PQ_madlab -n 2'), 'overwrite': True}
wf = Workflow(name='fsrecon')
wf.connect(infosource, 'subject_id', datasource, 'subject_id')
wf.connect(infosource, 'subject_id', reconall_node, 'subject_id')
wf.connect(datasource, 'T1', reconall_node, 'T1_files')
wf.base_dir = os.path.abspath('/scratch/madlab/surfaces/seqtrd')
#wf.config['execution']['job_finished_timeout'] = 65
wf.run(plugin='LSF', plugin_args={'bsub_args': ('-q PQ_madlab')})
示例9: Workflow
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
wf = Workflow("MachineLearning_Baseline_{0}".format(session_id))
datasink = Node(DataSink(), name="DataSink")
datasink.inputs.base_directory = os.path.join(results_dir, session_id)
for hemisphere in ("lh", "rh"):
for matter in ("gm", "wm"):
wf.connect(
logb_wf,
"output_spec.{0}_{1}surface_file".format(hemisphere, matter),
datasink,
"[email protected]{0}_{1}".format(hemisphere, matter),
)
logb_wf.inputs.input_spec.t1_file = t1_file
logb_wf.inputs.input_spec.orig_t1 = t1_file
logb_wf.inputs.input_spec.t2_file = t2_file
logb_wf.inputs.input_spec.posteriors = posterior_files
logb_wf.inputs.input_spec.hncma_file = hncma_atlas
logb_wf.inputs.input_spec.abc_file = abc_file
# logb_wf.inputs.input_spec.acpc_transform = identity_transform_file
logb_wf.inputs.input_spec.rho = direction_files["rho"]
logb_wf.inputs.input_spec.theta = direction_files["theta"]
logb_wf.inputs.input_spec.phi = direction_files["phi"]
logb_wf.inputs.input_spec.lh_white_surface_file = lh_white_surface_file
logb_wf.inputs.input_spec.rh_white_surface_file = rh_white_surface_file
logb_wf.inputs.input_spec.wm_classifier_file = wm_classifier_file
logb_wf.inputs.input_spec.gm_classifier_file = gm_classifier_file
wf.base_dir = base_dir
# wf.run(plugin="SGE", plugin_args={"qsub_args": "-q HJ,all.q,COE,UI"})
# wf.run(plugin="MultiProc", plugin_args={"n_procs": 24})
wf.run()
示例10: Node
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
# Datasink - creates output folder for important outputs
datasink = Node(DataSink(base_directory=experiment_dir,
container=output_dir),
name="datasink")
# Use the following DataSink output substitutions
substitutions = [('_subject_id_', '')]
datasink.inputs.substitutions = substitutions
###
# Specify Normalization Workflow & Connect Nodes
# Initiation of the ANTS normalization workflow
regflow = Workflow(name='regflow')
regflow.base_dir = opj(experiment_dir, working_dir)
# Connect workflow nodes
regflow.connect([(infosource, selectfiles, [('subject_id', 'subject_id')]),
(selectfiles, antsreg, [('anat', 'moving_image')]),
(antsreg, datasink, [('warped_image',
'[email protected]_image'),
('inverse_warped_image',
'[email protected]_warped_image'),
('composite_transform',
'[email protected]'),
('inverse_composite_transform',
'[email protected]_transform')]),
])
###
示例11: Workflow
# 需要导入模块: from nipype import Workflow [as 别名]
# 或者: from nipype.Workflow import base_dir [as 别名]
import os
import numpy as np
from nipype import Function
from nipype import Node
from nipype import Workflow
from nipype import IdentityInterface
ds="/storage/gablab001/data/genus/GIT/genus/fs_cog/pred_diag/data_sets"
data_sets = [os.path.join(ds, x) for x in os.listdir(ds) if ".csv" in x]
response_var = os.path.join(ds, "response.txt")
wf = Workflow(name="classify_disease")
wf.base_dir = "/om/scratch/Sat/ysa"
Iternode = Node(IdentityInterface(fields=['data', 'classifier']), name="Iternode")
Iternode.iterables = [
('data', data_sets),
('classifier', ['et', 'lg'])
]
def run(data, classifier, response):
import numpy as np
import pandas as pd
from custom import Mods
from custom import utils
y = np.genfromtxt(response)
X = pd.read_csv(data)
data_mod = data.split('/')[-1].replace('.csv', '')
if classifier == 'et':