.. currentmodule:: physiomotion4d
High-level workflow classes that orchestrate complete processing pipelines.
PhysioMotion4D provides workflow classes that combine multiple processing steps into complete pipelines. Each workflow handles a specific medical imaging task from input to USD output.
.. autoclass:: WorkflowConvertHeartGatedCTToUSD :members: :undoc-members: :show-inheritance: :inherited-members:
Purpose: Convert cardiac-gated CT sequences to animated USD models.
- Features:
- Automatic segmentation of cardiac structures
- Motion field computation using deep learning registration
- USD timeline animation generation
- Support for both contrast-enhanced and non-contrast CT
Example:
from physiomotion4d import WorkflowConvertHeartGatedCTToUSD
workflow = WorkflowConvertHeartGatedCTToUSD(
input_filenames=["cardiac_phase_00.nrrd", "cardiac_phase_01.nrrd"],
contrast_enhanced=True,
output_directory="./heart_results",
verbose=True
)
result = workflow.process().. autoclass:: WorkflowFitStatisticalModelToPatient :members: :undoc-members: :show-inheritance: :inherited-members:
Purpose: Register a template heart model to patient-specific imaging data.
- Features:
- Multi-scale registration pipeline
- PCA-based shape matching
- Distance map optimization
- Physiological constraint preservation
Example:
from physiomotion4d import WorkflowFitStatisticalModelToPatient
workflow = WorkflowFitStatisticalModelToPatient(
model_file="heart_template.vtk",
patient_image="patient_ct.nrrd",
output_directory="./registration_results",
verbose=True
)
registered_model = workflow.process()All workflows support step-based execution with checkpointing:
# Create workflow
workflow = WorkflowConvertHeartGatedCTToUSD(
input_filenames=file_list,
output_directory="./results"
)
# Run specific steps
workflow.run_step(1) # Segmentation
workflow.run_step(2) # Registration
workflow.run_step(3) # USD generation
# Or run all steps
workflow.process()Monitor workflow progress with logging:
workflow = WorkflowConvertHeartGatedCTToUSD(
input_filenames=file_list,
output_directory="./results",
verbose=True # Enable detailed logging
)
# Workflow provides detailed progress updates
result = workflow.process()
# Access log file
log_file = workflow.get_log_file_path()Customize workflow parameters:
workflow = WorkflowConvertHeartGatedCTToUSD(
input_filenames=file_list,
output_directory="./results",
# Segmentation options
segmentation_method="vista3d", # or "totalsegmentator"
contrast_enhanced=True,
# Registration options
registration_device="cuda:0",
registration_iterations=100,
# USD options
usd_format="polymesh", # or "tetmesh"
colormap="rainbow",
verbose=True
)
result = workflow.process()Workflows include comprehensive error handling:
try:
workflow = WorkflowConvertHeartGatedCTToUSD(
input_filenames=file_list,
output_directory="./results"
)
result = workflow.process()
except FileNotFoundError as e:
print(f"Input file not found: {e}")
except RuntimeError as e:
print(f"Processing failed: {e}")
# Workflow automatically saves checkpoint
# Can resume from last successful stepCreate custom workflows by inheriting from base classes:
from physiomotion4d import PhysioMotion4DBase
class CustomWorkflow(PhysioMotion4DBase):
"""Custom medical imaging workflow."""
def __init__(self, input_files, output_dir, **kwargs):
super().__init__(verbose=kwargs.get('verbose', False))
self.input_files = input_files
self.output_dir = output_dir
def process(self):
"""Execute workflow steps."""
self.log("Starting custom workflow", level="INFO")
# Step 1: Load data
data = self.load_data()
# Step 2: Process
result = self.process_data(data)
# Step 3: Save results
self.save_results(result)
self.log("Workflow complete", level="INFO")
return resultCombine multiple workflows:
# First workflow: Process heart CT
heart_workflow = WorkflowConvertHeartGatedCTToUSD(
input_filenames=ct_files,
output_directory="./heart_output"
)
heart_result = heart_workflow.process()
# Second workflow: Register model
registration_workflow = WorkflowFitStatisticalModelToPatient(
model_file=heart_result['model'],
patient_image=patient_ct,
output_directory="./registration_output"
)
final_result = registration_workflow.process()- Always validate inputs before starting workflow
- Use verbose mode during development and debugging
- Check intermediate results after each step
- Save checkpoints for long-running workflows
- Handle exceptions appropriately for production use
- Use GPU acceleration when available (set
device="cuda:0") - Enable fast mode for segmentation (
fast=True) - Process multiple time points in batch
- Monitor memory usage for large datasets
- :doc:`../cli_scripts/overview` - Command-line workflow execution
- :doc:`../developer/workflows` - Workflow development guide
- :doc:`segmentation/index` - Segmentation modules
- :doc:`registration/index` - Registration modules
- :doc:`usd/index` - USD generation modules
Navigation