Hello, I am trying to automate some processes which use the modules pseudoLMGenerator and ALPACA but cannot find any of the functions which are available in the GUI.
For example if I try and set the base mesh in the pseudoLMGenerator I expected to find something along the lines of:
slicer.modules.pseudolmgenerator.logic().setBaseMesh() but not such function or anything similar is available after inputting slicer.modules.pseudolmgenerator.logic().
I have similar issues when trying to automate the ALPACA module also. My question is, is it possible to automate all GUI functions through python scripting and if so how do I find the documentation describing the correct syntax for scripting for these particular modules?
Thanks in advance for any help. Happy to provide further details/screenshots if needed.
It is possible to automate ALPACA and the pseudoLMGenerator. You will need to read through the module’s code to see how to do this, but in general:
- parameters such as input files/folders set in the GUI will be defined in the
setup() function of the widget class
- the widget class contains functions that handle GUI interactions, such as button presses
- the logic class contains functions to run the algorithms. The input parameters can be passed directly, without needing to set GUI parameters.
For the PseudoLMGenerator module, there are multiple steps run by separate button presses. Looking at the button callbacks, you will find the logic functions called and input/output arguments.
ALPACA can be run in batch mode using a single call to the logic function here.
I’m happy to help here with any specific questions. You also might find these tutorials helpful.
Hi Sara, thank you for replying so quickly. I am trying to use the module code ( SlicerMorph/PseudoLMGenerator.py at dbd661146ef45b6f8d2f7778f9a4e8b65c28ff9b · SlicerMorph/SlicerMorph · GitHub )
to understand how to programmatically use the pseudoLMGenerator but I’m afraid I’m struggling to get it working.
To define the base mesh I try the following command:
Where modelNode is a loaded model. However I am met with the following error:
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘qMRMLNodeComboBox’ object is not callable
Would you be able to give example code on defining the base model for the pseudoLMGenerator followed by executing the “get subsample number” command? Many thanks for your help!
You won’t need to set the widget elements, like the
modelSelector to automate this module. The steps you will need are in the button callback functions.
I can help you with a code snippet, but first can you give me an idea of what you are trying to do? In a typical workflow, pseudo-landmarks are placed only once on an atlas model and transferred to other specimens using
projectSemiLM. Both of these modules preserve the relationship between the pseudo-landmarks, which running the
pseudoLMGenerator multiple times can not do.
I am trying to generate pseudo landmarks for a mesh which are then used for input as “Source Landmarks” in the ALPACA registration process. I have managed to do the entire process manually using the GUI but it is automating the process that is eluding me.
You mention button callback functions, where would I find documentation/examples of these functions?
To put it another way, would you be able to give example code that is able to execute all the actions demonstrated in the following slicermorph youtube tutorials using the python interface?
PseudoLMGenerator and MarkupEditor tutorial: PseudoLMGenerator and MarkupEditor tutorial - YouTube
Demo of ALPACA module in SlicerMorph tutorial: Demo of ALPACA module in SlicerMorph - YouTube