Hi! I am trying to compile some powerful function from brainstorm into package that can be called in python codes. By now I have finished a script that can run Brainstorm codes that I need in MATLAB command line, but I am not sure whether I should use the compile tool in MATLAB to do the job or other scripts in Brainstorm. If the latter is the answer, could you show me more guide information? Thanks a lot!
To do so, use the Standalone version of Brainstorm. In this way, you can run a Brainstorm script from the system terminal. So your Python script can call it below (or other equivalent code):
import os
os.system("./brainstorm3.command YOUR_SCRIPT.m")
Check the installation page for more details on how to setup the Standalone version of Brainstorm:
https://neuroimage.usc.edu/brainstorm/Installation
Thank you for giving me the insights, thanks to it I've successfully run BST scripts in my remote server. However I still have a problem that whether I can have my script run with args input from python codes? Such as the path to the raw file to be imported in BST scripts. In MATLAB environment I could do it by converting the script into a function with input args, but unable to run in external command line like this.
Yes, this is possible.
Your Matlab script can be a function, with expected arguments:
function your_script(argument1, argument2)
Then call it as:
./brainstorm3.command your_script.m argument1 argument2
Yeah, it does work well. That's very helpful. Thanks a lot!
Hi Raymundo, I recently met another problem about this topic that if I have to execute a function stored in another .m file in main script your_script.m, then how could I make the setting? Thanks!
This is the expected behaviour. The Matlab Runtime is the same as a full installation of Matlab, so it does not behave the same. In the standalone Brainstorm, the provided "script.m" is evaluated line by line with the eval() function, as if it were typed in the Matlab command line.
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Without_Matlab
A walkaround to this would be perform a custom compilation of Brainstorm including your another_script.m file.
https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#How_to_compile_Brainstorm
Indeed, it is much more limited to run a Bst script under Runtime. It is very instructive, by the way. Thanks a lot!