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: 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 ofReturn 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: - datatype (
Union
[BaseDataType
,str
]) – The DataType of the constant node - data (
Dict
[str
,Union
[List
[Union
[str
,Tuple
[str
, …]]],Dict
[str
,Union
[str
,Tuple
[str
, …]]]]]) – The data to hold in the constant node - id (
Optional
[str
]) – The id of the constant node to be created - step_id (
Optional
[str
]) – The step to add the created constant 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: Returns: the newly created constant node
- datatype (
-
create_link
(source, target, id=None, collapse=None, expand=False)[source]¶ Create a link between two Nodes and add it to the current Network.
Parameters: - source (
Union
[Input
,BaseInput
]) – the output that is the source of the link - target (
Union
[Output
,BaseOutput
]) – the input that is the target of the link - id (
Optional
[str
]) – the id of the link - collapse (
Optional
[Tuple
[Union
[int
,str
], …]]) – The dimensions to collapse in this link. - expand (
bool
) – Flag to expand cardinality into a new dimension
Return type: Returns: the created link
- source (
-
create_macro
(network, id=None)[source]¶ Create macro node (a node which actually contains a network used as node inside another network).
Parameters: Return type: 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 - 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 - nodegroup – The group the node belongs to, this can be important for FlowNodes and such, as they will have matching dimension names.
Return type: Returns: the newly created node
- tool (
-
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: Returns: the newly created sink node
- datatype (
-
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
- datatype (
-
draw
(file_path=None, draw_dimensions=True, hide_unconnected=True, expand_macros=1)[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: Returns: path of the image created or None if failed
-
execute
(source_data, sink_data, tmpdir=None, timestamp=None, blocking=True)[source]¶ Execute the network with the given source and sink data.
Parameters: - source_data (
Dict
[str
,Union
[List
[Union
[str
,Tuple
[str
, …]]],Dict
[str
,Union
[str
,Tuple
[str
, …]]]]]) – Source data to use as an input - sink_data (
Union
[str
,Dict
[str
,str
]]) – Sink rules to use for determining the outputs - tmpdir (
Optional
[str
]) – The scratch directory to use for this network run, if an existing directory is given, fastr will try to resume a network run (see Continuing a Network) - timestamp (
Union
[datetime
,str
,None
]) – The timestamp of the network run (useful for retrying or continuing previous runs) - blocking (
bool
) – Flag to indicate if the execution should be blocking or launched in a background thread
Return type: Returns: The network run object for the started execution
- source_data (
-
classmethod
load
(filename)[source]¶ Load Network froma file
Parameters: filename (str) – Returns: loaded network Return type: Network
-
-
class
fastr.api.
Link
(parent)[source]¶ Representation of a link for editing the Network
-
collapse
¶ The dimensions which the link will collapse into the cardinality
Return type: Tuple
[Union
[int
,str
], …]
-
-
class
fastr.api.
Node
(parent)[source]¶ Representation of Node for editing the Network
-
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
-
inputs
¶ Mapping object containing all Inputs of a Node
Return type: InputMap
-
-
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 ConstantNodeReturn 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 fromReturn 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 createdReturn type: Link
Returns: The newly created link
-
input_group
¶ 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: key – 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
-