|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -import os |
3 | 2 | import sys |
4 | | -from shutil import rmtree |
5 | | -from multiprocessing import cpu_count |
6 | | - |
7 | | - |
8 | | -def run_examples(example, pipelines, data_path, plugin=None, rm_base_dir=True): |
9 | | - from nipype import config |
10 | | - from nipype.interfaces.base import CommandLine |
11 | | - |
12 | | - if plugin is None: |
13 | | - plugin = "MultiProc" |
14 | | - |
15 | | - print("running example: %s with plugin: %s" % (example, plugin)) |
16 | | - config.enable_debug_mode() |
17 | | - config.enable_provenance() |
18 | | - CommandLine.set_default_terminal_output("stream") |
19 | | - |
20 | | - plugin_args = {} |
21 | | - if plugin == "MultiProc": |
22 | | - plugin_args["n_procs"] = int(os.getenv("NIPYPE_NUMBER_OF_CPUS", cpu_count())) |
23 | | - |
24 | | - __import__(example) |
25 | | - for pipeline in pipelines: |
26 | | - wf = getattr(sys.modules[example], pipeline) |
27 | | - wf.base_dir = os.path.join(os.getcwd(), "output", example, plugin) |
28 | | - |
29 | | - results_dir = os.path.join(wf.base_dir, wf.name) |
30 | | - if rm_base_dir and os.path.exists(results_dir): |
31 | | - rmtree(results_dir) |
32 | | - |
33 | | - # Handle a logging directory |
34 | | - log_dir = os.path.join(os.getcwd(), "logs", example) |
35 | | - if not os.path.exists(log_dir): |
36 | | - os.makedirs(log_dir) |
37 | | - wf.config = { |
38 | | - "execution": { |
39 | | - "hash_method": "timestamp", |
40 | | - "stop_on_first_rerun": "true", |
41 | | - "write_provenance": "true", |
42 | | - "poll_sleep_duration": 2, |
43 | | - }, |
44 | | - "logging": {"log_directory": log_dir, "log_to_file": True}, |
45 | | - } |
46 | | - try: |
47 | | - wf.inputs.inputnode.in_data = os.path.abspath(data_path) |
48 | | - except AttributeError: |
49 | | - pass # the workflow does not have inputnode.in_data |
50 | | - |
51 | | - wf.run(plugin=plugin, plugin_args=plugin_args) |
52 | | - # run twice to check if nothing is rerunning |
53 | | - wf.run(plugin=plugin) |
| 3 | +from textwrap import dedent |
54 | 4 |
|
55 | 5 |
|
56 | 6 | if __name__ == "__main__": |
57 | | - path, file = os.path.split(__file__) |
58 | | - sys.path.insert(0, os.path.realpath(os.path.join(path, "..", "examples"))) |
59 | | - examples = { |
60 | | - "fmri_fsl_reuse": ["level1_workflow"], |
61 | | - "fmri_spm_nested": ["level1", "l2pipeline"], |
62 | | - # 'fmri_spm_dartel':['level1','l2pipeline'], |
63 | | - # 'fmri_fsl_feeds':['l1pipeline'] |
64 | | - } |
65 | | - example = sys.argv[1] |
66 | | - plugin = sys.argv[2] |
67 | | - data_path = sys.argv[3] |
68 | | - pipelines = sys.argv[4:] |
69 | | - run_examples(example, pipelines, data_path, plugin) |
| 7 | + print(dedent("""Nipype examples have been moved to niflow-nipype1-examples. |
| 8 | +
|
| 9 | +Install with: pip install niflow-nipype1-examples""")) |
| 10 | + if sys.argv[1:]: |
| 11 | + print("Run this command with: niflow-nipype1-examples " + " ".join(sys.argv[1:])) |
| 12 | + sys.exit(1) |
0 commit comments