Processing Module¶
This module contains the logic for registering and dispatching to pre/post-processing functions during a run. It currently defines no actual processing functions: a couple have been defined in ablinfer.slicer.processing. Of primary interest is the method for defining new processing functions. The general format of a processing function is:
@register_processing(
typ = "input", ## Which type this function is: "input" (pre), "output" (post), or None (both)
name = "the_operation_name",
types = ("segmentation", "volume",), ## What input/output types this is valid for
actions = {
None: { ## Default action if the model doesn't provide one
"param1": { ## Same structure as the model specification parameters
"name": "Parameter 1",
"type": "int",
"min": 0,
"max": 10,
"default": 5,
},
...
},
"action1": {...}, ## Named action
}
)
def operation(op, op_config, node, node_config, model, model_config):
## Your code here, you don't need to return anything
Note that the actions section of register_processing is not required, though it is recommended: if present, model config normalization can use default values of missing parameters. If not, ABLInfer has no idea what your processing function’s parameters and actions are supposed to be, so you’re on your own for validating and normalizing user input. This behaviour is (lazily) used in the Slicer Segmentation Editor function (ablinfer.slicer.processing.seged()) to avoid gathering/formatting the bevy of segmentation editor actions/parameters.
The op parameter is the mapping from the model specification corresponding to this processing action, op_config is the corresponding section in the model config, node is the value of the node that this action is on, node_config is its correspoding model config section (i.e. node = node_config["value"]), model is the entire model specification, and model_config is the entire model config. You may retrieve the desired action as op["action"] (if given). If possible, processing functions should avoid using model and model_config.
-
ablinfer.processing.register_processing(typ: Union[str, Sequence[str], None], name: str, types: Sequence[str], actions: Optional[Mapping[KT, VT_co]]) → Callable[source]¶ Register a processing operation.
The format of actions is:
{ None: {...}, ## Default action "action1": {...}, ## Named action ... }
Each sub-dictionary is of the same form as the “inputs” or “outputs” object in a model JSON file, e.g.:
{ "param1": { "name": "Parameter 1", "type": "int", "min": 0, "max": 10, "default": 5 }, ... }
with the exception that any pre/post sections are invalid. The type may be “segmentation” or “volume”, but these MUST NOT be modified by any processing operations.
Parameters: - typ – Is either “input”, “output”, or None, in which case the processing is considered valid for both inputs and outputs.
- name – Is the name (not user-friendly) for the action
- types – Is the type of inputs/outputs (e.g. “segmentation”, “volume”) that this operation is valid for
- actions – Either None or a dictionary describing the types for each action
-
ablinfer.processing.dispatch_processing(op: Mapping[KT, VT_co], op_config: Mapping[KT, VT_co], node: Any, node_section: Mapping[KT, VT_co], model: Mapping[KT, VT_co], model_config: Mapping[KT, VT_co], inp: bool = True) → None[source]¶ Dispatch a processing operation.
Parameters: - op – the current operation’s section in the model
- op_config – the current operation’s config section from the model_config
- node – the node to operate on (e.g. filename)
- node_section – the node’s section from the model
- model – the entire model specification
- model – the entire model config
- inp – whether or not this is an input