DataNode
- class mitk_workbench_remote.node.PropertyScope(*values)
-
Valid scopes for node property operations.
- Variables:
ALL – Include both node-scope and data-scope properties (read-only).
NODE – Node-level display properties (e.g. visible, opacity, color).
DATA – Data-level properties embedded in the data object.
- ALL = 'all'
- NODE = 'node'
- DATA = 'data'
- class mitk_workbench_remote.node.DataRepresentation(*values)
-
Return type selection for
DataNode.get_data().- Variables:
AUTO – Return
mitk.Imageif themitkpackage is importable, otherwise fall back toImage.REMOTE – Always return the remote Python type (
ImageorMultiLabelSegmentation).MITK – Always return
mitk.Image; raisesImportErrorif themitkpackage is absent.
- AUTO = 'auto'
- REMOTE = 'remote'
- MITK = 'mitk'
- class mitk_workbench_remote.node.DataNode(uid, *, name, data_type, path, parent_uid, transport)
Bases:
objectA single node in the MITK DataStorage.
Wrapper that represents one node with property shortcuts (name, visible, opacity, color), data access (get_data, set_data), child management, and batch property updates.
Do not construct directly — obtain instances from
DataStorage.Display-only caches (
_name,_path,_parent_uid) are seeded from the node dict at construction and refreshed byrefresh(). Property getters forname,visible,opacity, andcoloralways make a live REST call.- Parameters:
uid (
str) – Immutable node identifier.name (
str) – Initial display name (cached; used by__repr__).data_type (
str|None) – MITK data type string (e.g."Image"), updated byrefresh().path (
str) – Full storage path (e.g."/CT_Scan/seg"), updated byrefresh().parent_uid (
str|None) – UID of the parent node, orNonefor top-level nodes.transport (
RestTransport) – Transport used for all HTTP calls.
- property transport: RestTransport
REST transport used for all HTTP calls. Read-only.
Exposed so callers can verify two handles share the same Workbench instance (
node.transport is other.transport) without reaching into private state.
- property color: tuple[float, float, float]
Node color as an (r, g, b) tuple. Always fetches from the server.
- update_properties(*, scope=PropertyScope.NODE, context=None, **kwargs)
Update multiple properties in a single PATCH request.
Property values are serialized using the same rules as
set_property(). Passcoloras a(r, g, b)tuple; all other built-in properties accept plain Python values.- Parameters:
- Return type:
- get_properties(*, scope=PropertyScope.ALL, context=None)
Fetch all properties for this node.
- get_property(key, *, scope=PropertyScope.ALL, context=None)
Fetch a single property by key.
- Parameters:
key (
str) – Property name (e.g."name","visible").scope (
PropertyScope(default:<PropertyScope.ALL: 'all'>)) – Property scope filter.context (
str|None(default:None)) – Optional renderer context identifier.
- Return type:
- Returns:
Deserialized property value.
- Raises:
NodeNotFoundError – If the node or property does not exist.
- set_property(key, value, *, scope=PropertyScope.NODE, context=None)
Set a single property by key.
Pass
coloras a(r, g, b)tuple. Unknown complex types can be round-tripped by passing the raw wire dict (any dict that has a"type"key is passed through unchanged).- Parameters:
key (
str) – Property name.value (
Any) – New value. Built-in types are serialized automatically; raw dicts with a"type"key are forwarded as-is.scope (
PropertyScope(default:<PropertyScope.NODE: 'node'>)) – Property scope (NODEorDATA).context (
str|None(default:None)) – Optional renderer context identifier. Only relevant for scopeNODE; ignored at data scope.
- Return type:
- remove_property(key, *, scope=PropertyScope.NODE)
Remove a property by key.
- Parameters:
key (
str) – Property name to remove.scope (
PropertyScope(default:<PropertyScope.NODE: 'node'>)) – Property scope (NODEorDATA).
- Return type:
- remove(*, recursive=False)
Remove this node from the DataStorage.
- Parameters:
recursive (
bool(default:False)) – WhenTrue, also remove all child nodes.- Raises:
NodeNotFoundError – If the node no longer exists.
- Return type:
- refresh()
Refresh cached properties from the server.
Updates
data_type,path, and the display caches for_nameand_parent_uid.- Raises:
NodeNotFoundError – If the node no longer exists.
- Return type:
- get_data(*, include_properties=False, as_type=DataRepresentation.AUTO)
Download this node’s data and return a typed Python object.
The returned type depends on the node’s
data_typeand theas_typeparameter:"Image"withas_type=AUTO– returnsmitk.Imageif themitkpackage is importable, otherwiseImage."Image"withas_type=REMOTE– always returnsImage."Image"withas_type=MITK– always returnsmitk.Image; raisesImportErrorif themitkpackage is absent."MultiLabelSegmentation"withas_type=AUTO– returnsmitk.MultiLabelSegmentationif themitkpackage is importable, otherwiseMultiLabelSegmentation."MultiLabelSegmentation"withas_type=REMOTE– always returnsMultiLabelSegmentation."MultiLabelSegmentation"withas_type=MITK– always returnsmitk.MultiLabelSegmentation; raisesImportErrorif themitkpackage is absent.
The transfer mode (direct or file-reference) is negotiated automatically based on the transport’s
transfer_mode.- Parameters:
include_properties (
bool(default:False)) – IfTrue, also fetch data-scope properties and store them in the returned object’s properties. Formitk.Imageresults, scalar properties (str/bool/int/float/ 3-tuple) are applied viamitk.Image.set_property; exotic types that cannot be auto-wrapped are logged at WARNING and skipped.as_type (
DataRepresentation(default:<DataRepresentation.AUTO: 'auto'>)) – Controls the Python type of the returned image object. Defaults toDataRepresentation.AUTO.
- Return type:
- Returns:
A typed Python object matching the node’s data type.
- Raises:
UnsupportedDataTypeError – If the data type cannot be represented in Python. Use
save_data()to download raw bytes instead.ImportError – If
as_type=MITKand themitkpackage is not installed.
- save_data(path)
Download this node’s data and save the raw bytes to a file.
This works for any data type, including types that cannot be represented in Python (e.g. Surface, PointSet). The file is saved in NRRD format as delivered by the server.
- set_data(data, *, include_properties=False)
Upload data to this node.
Accepts an
Image, a numpy ndarray, or any type handled by the converter registry (e.g.SimpleITK.Image,mlarray.MLArray,mitk.Image,mitk.MultiLabelSegmentation). The transfer mode is chosen automatically.After a successful upload,
data_typeis updated locally to reflect the uploaded type without requiring an explicitrefresh()call.Property behavior for
mitk.*types: Whendatais amitk.Imageormitk.MultiLabelSegmentation, MITK’s NRRD serialization embeds the full C++ property list in the uploaded bytes. Data-scope properties are therefore always transferred, regardless ofinclude_properties. This differs fromImageandMultiLabelSegmentationwhereinclude_properties=False(the default) leaves existing server-side properties untouched.- Parameters:
- Raises:
UnsupportedDataTypeError – If the node’s data type does not match the data being uploaded.
TypeError – If no converter is registered for
data’s type.
- Return type:
- reinit()
Fit render window cameras to this node’s geometry.
Convenience wrapper around
POST /rendering/reinitfor a single node. Equivalent toworkbench.reinit([self]).- Raises:
ApiError – If this node has no data (code
NO_DATA) or no usable geometry (codeNO_GEOMETRY).RenderingError – If the rendering framework reports a failure.
- Return type: