DWModeling error execution in Python console

smati_wissem
Thu, 18 Apr 2024 14:32:50 +0000
Support

Hello everyone,

I’ve created this code to execute DWModeling in the Python console, but it appears that I’m encountering an issue assigning parameters to the model. Could someone please help me?

Thank you.
def runDWModeling(inputVolumeNode):
“”“Run diffusion weighting modeling from an input volume node.”“”
# Check if the inputVolumeNode is valid
if inputVolumeNode is None:
raise ValueError(“The input volume node is None. Please check the node ID.”)

# Set parameters
parameters = {}
parameters["Input image"] = inputVolumeNode.GetID()  # Adjusted parameter name
if not parameters["Input image"]:
    raise ValueError("Failed to get a valid ID from the input volume node. Check if the node is correct.")

outputModelNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode")
parameters["MonoExp diffusion map"] = outputModelNode
parameters["modelName"] = "MonoExponential"

# Setup the CLI module
dwModelingLogic = slicer.modules.dwmodeling

# Execute the CLI module
cliNode = slicer.cli.runSync(slicer.modules.dwmodeling, None, parameters)

# Process results
if cliNode.GetStatus() & cliNode.ErrorsMask:
    # Handle errors
    errorText = cliNode.GetErrorText()
    slicer.mrmlScene.RemoveNode(cliNode)
    raise ValueError("CLI execution failed: " + errorText)

# Success, cleanup
slicer.mrmlScene.RemoveNode(cliNode)
print("Modeling completed successfully.")
return cliNode

usage:

try:
inputVolumeNode = slicer.util.getNode(‘vtkMRMLMultiVolumeNode1’)
if not inputVolumeNode:
raise Exception(“Node not found. Please check the node ID.”)
modelNode = runDWModeling(inputVolumeNode)

except Exception as e:
print(str(e))

Thank you.

1 post - 1 participant