Fastr User Reference

fastr.tools

A ToolManager containing all versions of all Tools loaded into the FASTR environment. The ToolManager can be indexed using the Tool id string or a tool id string and a version. For example if you have two versions (4.5 and 4.8) of a tool called Elastix:

>>> fastr.tools['elastix.Elastix']
Tool Elastix v4.8 (Elastix Registration)
                           Inputs                              |             Outputs
--------------------------------------------------------------------------------------------------
fixed_image       (ITKImageFile)                               |  directory (Directory)
moving_image      (ITKImageFile)                               |  transform (ElastixTransformFile)
parameters        (ElastixParameterFile)                       |  log_file  (ElastixLogFile)
fixed_mask        (ITKImageFile)                               |
moving_mask       (ITKImageFile)                               |
initial_transform (ElastixTransformFile)                       |
priority          (__Elastix_4.8_interface__priority__Enum__)  |
threads           (Int)                                        |

>>> fastr.tools['elastix.Elastix', '4.5']
Tool Elastix v4.5 (Elastix Registration)
                           Inputs                              |             Outputs
--------------------------------------------------------------------------------------------------
fixed_image       (ITKImageFile)                               |  directory (Directory)
moving_image      (ITKImageFile)                               |  transform (ElastixTransformFile)
parameters        (ElastixParameterFile)                       |  log_file  (ElastixLogFile)
fixed_mask        (ITKImageFile)                               |
moving_mask       (ITKImageFile)                               |
initial_transform (ElastixTransformFile)                       |
priority          (__Elastix_4.5_interface__priority__Enum__)  |
threads           (Int)                                        |
fastr.types

A dictionary containing all types loaded into the FASTR environment. The keys are the typenames and the values are the classes.

fastr.networks

A dictionary containing all networks loaded in fastr

api.create_network(version=None)

Create a new Network object

Parameters
Return type

Network

Returns

api.create_network_copy()

Create a network based on another Network state. The network state can be a Network or the state gotten from a Network with __getstate__.

Parameters

network_state (Union[Network, Network, dict]) – Network (state) to create a copy of

Return type

Network

Returns

The rebuilt network

class fastr.api.Network(id, version=None)[source]

Representation of a Network for the creating and adapting Networks

create_constant(datatype, data, id=None, step_id=None, resources=None, node_group=None)[source]

Create a ConstantNode in this Network. The Node will be automatically added to the Network.

Parameters
Return type

Node

Returns

the newly created constant node

Create a link between two Nodes and add it to the current Network.

Parameters
Return type

Link

Returns

the created link

create_macro(network, id=None)[source]

Create macro node (a node which actually contains a network used as node inside another network).

Parameters
  • network (Union[Network, Network, dict, Tool, str]) – The network to use, this can be a network (state), a macro tool, or the path to a python file that contains a function create_network which returns the desired network.

  • id (Optional[str]) – The id of the node to be created

Return type

Node

Returns

the newly created node

create_node(tool, tool_version, id=None, step_id=None, resources=None, node_group=None)[source]

Create a Node in this Network. The Node will be automatically added to the Network.

Parameters
  • tool (Union[Tool, str]) – The Tool to base the Node on in the form: name/space/toolname:version

  • tool_version (str) – The version of the tool wrapper to use

  • id (Optional[str]) – The id of the node to be created

  • step_id (Optional[str]) – The step to add the created node to

  • resources (Optional[ResourceLimit]) – The resources required to run this node

  • node_group (Optional[str]) – The group the node belongs to, this can be important for FlowNodes and such, as they will have matching dimension names.

Return type

Node

Returns

the newly created node

create_sink(datatype, id=None, step_id=None, resources=None, node_group=None)[source]

Create a SinkNode in this Network. The Node will be automatically added to the Network.

Parameters
  • datatype (Union[BaseDataType, str]) – The DataType of the sink node

  • id (Optional[str]) – The id of the sink node to be created

  • step_id (Optional[str]) – The step to add the created sink node to

  • resources (Optional[ResourceLimit]) – The resources required to run this node

  • node_group (str) – The group the node belongs to, this can be important for FlowNodes and such, as they will have matching dimension names.

Return type

Node

Returns

the newly created sink node

create_source(datatype, id=None, step_id=None, resources=None, node_group=None)[source]

Create a SourceNode in this Network. The Node will be automatically added to the Network.

Parameters
  • datatype (BaseDataType) – The DataType of the source source_node

  • id (str) – The id of the source source_node to be created

  • step_id (str) – The step to add the created source source_node to

  • resources (Optional[ResourceLimit]) – The resources required to run this node

  • node_group (str) – The group the node belongs to, this can be important for FlowNodes and such, as they will have matching dimension names.

Returns

the newly created source source_node

Return type

SourceNode

draw(file_path=None, draw_dimensions=True, hide_unconnected=True, expand_macros=1, font_size=14)[source]

Draw a graphical representation of the Network

Parameters
  • file_path (str) – The path of the file to create, the extension will control the image type

  • draw_dimensions (bool) – Flag to control if the dimension sizes should be drawn in the figure, default is true

  • expand_macros (bool) – Flag to control if and how macro nodes should be expanded, by default 1 level is expanded

Return type

Optional[str]

Returns

path of the image created or None if failed

execute(source_data, sink_data, tmpdir=None, timestamp=None, blocking=True, execution_plugin=None, tracking_id=None)[source]

Execute the network with the given source and sink data.

Parameters
Return type

NetworkRun

Returns

The network run object for the started execution

property id: str

The unique id describing this resource

Return type

str

classmethod load(filename)[source]

Load Network from a YAML file

Parameters

filename (str) –

Returns

loaded network

Return type

Network

save(filename)[source]

Save the Network to a YAML file

Parameters

filename (Union[str, Path]) – Path of the file to save to

property version: Version

Version of the Network (so users can keep track of their version)

Return type

Version

Representation of a link for editing the Network

property collapse: Tuple[Union[int, str], ...]

The dimensions which the link will collapse into the cardinality

Return type

Tuple[Union[int, str], …]

property expand: bool

Flag that indicates if the Link will expand the cardinality into a new dimension.

Return type

bool

property id: str

The unique id describing this resource

Return type

str

class fastr.api.Node(parent)[source]

Representation of Node for editing the Network

property id: str

The unique id describing this resource

Return type

str

property input: Input

In case there is only a single Inputs in a Node, this can be used as a short hand. In that case it is basically the same as list(node.inputs.values()[0]).

Return type

Input

property inputs: InputMap

Mapping object containing all Inputs of a Node

Return type

InputMap

property output: Output

In case there is only a single Outputs in a Node, this can be used as a short hand. In that case it is basically the same as list(node.outputs.values()[0]).

Return type

Output

property outputs: SubObjectMap[Output]

Mapping object containing all Outputs of a Node

Return type

SubObjectMap[Output]

class fastr.api.Input(parent)[source]

Representation of an Input of a Node

__lshift__(other)[source]

This operator allows the easy creation of Links to this Input using the << operator. Creating links can be done by:

# Generic form
>> link = input << output
>> link = input << ['some', 'data']  # Create a constant node

# Examples
>> link1 = addint.inputs['left_hand'] << source1.input
>> link2 = addint.inputs['right_hand'] << [1, 2, 3]

# Mutliple links
>> links = addints.inputs['left_hand'] << (source1.output, source2.output, source3.output)

The last example would return a tuple with three links.

Parameters

other (Union[Output, BaseOutput, list, dict, tuple]) – the target to create the link from, this can be an Output, a tuple of Outputs, or a data structure that can be used as the data for a ConstantNode

Return type

Union[Link, Tuple[Link, …]]

Returns

Newly created link(s)

__rrshift__(other)[source]

This operator allows to use the >> operator as alternative to using the << operator. See the __lshift__ operator for details.

Parameters

other (Union[Output, BaseOutput, list, dict, tuple]) – the target to create the link from

Return type

Union[Link, Tuple[Link, …]]

Returns

Newly created link(s)

append(value)[source]

Create a link from give resource to a new SubInput.

Parameters

value (Union[Output, BaseOutput, list, dict, tuple]) – The source for the link to be created

Return type

Link

Returns

The newly created link

property id: str

The unique id describing this resource

Return type

str

property input_group: str

The input group of this Input. This property can be read and changed. Changing the input group of an Input will influence the data flow in a Node (see Advanced flows in a Node for details).

Return type

str

class fastr.api.Output(parent)[source]

Representation of an Output of a Node

__getitem__(item)[source]

Get a SubOuput of this Ouput. The SubOutput selects some data from the parent Output based on an index or slice of the cardinalty.

Parameters

item (Union[int, slice]) – the key of the requested item, can be an index or slice

Return type

Output

Returns

the requested SubOutput with a view of the data in this Output

property id: str

The unique id describing this resource

Return type

str