|
63 | 63 | from capsul.api import Pipeline |
64 | 64 | from capsul.attributes.completion_engine import ProcessCompletionEngine |
65 | 65 | from soma.qt_gui import qt_backend |
| 66 | +from soma.controller import Controller |
66 | 67 | import os |
67 | 68 | import logging |
68 | 69 | import sys |
@@ -138,6 +139,53 @@ def set_process_param_from_str(process, k, arg): |
138 | 139 | pass |
139 | 140 |
|
140 | 141 |
|
| 142 | +def parse_pipeline_steps(process, kwargs): |
| 143 | + if not isinstance(process, Pipeline): |
| 144 | + return |
| 145 | + |
| 146 | + param_steps = kwargs.get('pipeline_steps') |
| 147 | + if param_steps is None: |
| 148 | + return |
| 149 | + |
| 150 | + del kwargs['pipeline_steps'] |
| 151 | + |
| 152 | + pipeline_steps = getattr(process, 'pipeline_steps') |
| 153 | + if not isinstance(pipeline_steps, Controller): |
| 154 | + return |
| 155 | + |
| 156 | + if isinstance(param_steps, str): |
| 157 | + param_steps = [s.strip() for s in param_steps.split(',')] |
| 158 | + steps = [[s.strip() for s in p.split('=')] for p in param_steps] |
| 159 | + for s in steps: |
| 160 | + if len(s) == 1: |
| 161 | + s.append(True) |
| 162 | + else: |
| 163 | + val = s[1] |
| 164 | + if val in (0, '0', 'False'): |
| 165 | + val = False |
| 166 | + else: |
| 167 | + val = True |
| 168 | + s[1] = val |
| 169 | + steps = [[[s.strip() for s in p[0].split('-')]] + p[1:] for p in steps] |
| 170 | + if len(steps) >= 1 and steps[0][1]: |
| 171 | + # set all steps to False |
| 172 | + steps.insert(0, [['', ''], False]) |
| 173 | + |
| 174 | + for srange, val in steps: |
| 175 | + if len(srange) == 2: |
| 176 | + if srange[0] == '': |
| 177 | + s0 = 0 |
| 178 | + else: |
| 179 | + s0 = pipeline_steps.user_traits().index(srange[0]) |
| 180 | + if srange[1] == '': |
| 181 | + s1 = len(pipeline_steps.user_traits()) - 1 |
| 182 | + else: |
| 183 | + s1 = pipeline_steps.user_traits().index(srange[1]) |
| 184 | + srange = list(pipeline_steps.user_traits())[s0:s1+1] |
| 185 | + for s in srange: |
| 186 | + setattr(pipeline_steps, s, val) |
| 187 | + |
| 188 | + |
141 | 189 | def get_process_with_params(process_name, study_config, iterated_params=[], |
142 | 190 | attributes={}, *args, **kwargs): |
143 | 191 | ''' Instantiate a process, or an iteration over processes, and fill in its |
@@ -169,6 +217,8 @@ def get_process_with_params(process_name, study_config, iterated_params=[], |
169 | 217 | signature = process.user_traits() |
170 | 218 | params = list(signature.keys()) |
171 | 219 |
|
| 220 | + steps = parse_pipeline_steps(process, kwargs) |
| 221 | + |
172 | 222 | # check for iterations |
173 | 223 | if iterated_params: |
174 | 224 |
|
@@ -338,6 +388,24 @@ def main(): |
338 | 388 | their node in the parent pipeline: |
339 | 389 |
|
340 | 390 | python -m capsul morphologist.capsul.morphologist Renorm.enabled=False |
| 391 | +
|
| 392 | + Pipeline steps: |
| 393 | +
|
| 394 | + Some pipelines define steps that can be enabled or disabled in order to |
| 395 | + process only part of the pipeline. They are kind of groups of nodes, but |
| 396 | + behave a bit differently for the pipeline parameters completion and checks. |
| 397 | +
|
| 398 | + Steps can be specified as the "pipeline_steps" parameter, with a syntax |
| 399 | + which can mix ranges and values, ex:: |
| 400 | +
|
| 401 | + python -m capsul morphologist.capsul.morphologist pipeline_steps="importation,bias_correction" |
| 402 | +
|
| 403 | + will do only these 2 steps. While:: |
| 404 | +
|
| 405 | + python -m capsul morphologist.capsul.morphologist pipeline_steps="brain_extraction, head_mesh-, sulci_labelling=False" |
| 406 | +
|
| 407 | + will do brain_extraction, then all steps from head_mesh, except |
| 408 | + sulci_labelling which is disabled. |
341 | 409 | ''' |
342 | 410 |
|
343 | 411 | # Set up logging on stderr. This must be called before any logging takes |
|
0 commit comments