Running Scripts
This section describes how users can run the scripts that they have written using the Iota Python Library.
Users can run their generic scripts in the Iota IPython terminal by using the command %run
. For example:
%run 'C:/Users/stephen/My Iota Scripts/Analysis backhoe.py'
Figure 3 - Start menu entry on Windows where Iota IPython Terminal is highlighted
The run(scenario)
scripts always take as argument a scenario
object and can be executed in different ways:
If a run(scenario)
script has been imported into a project/scenario, users can add those scripts to the section Post-Analysis. Once the scripts have been added to the Post-Analysis section, those scripts will be automatically run when running the coarse-graining for the scenario. A summary of the steps required to add and run the script as a Post-Analysis using the GUI is as follows:
Load a project
Import your
run(scenario)
to theScripts
section of the Project page.Load a scenario
Go to coarse-graining page.
Set your coarse-graining settings
In the Output tab of the coarse-graining page, go to section "Post-Analysis" and select the script imported in the step 2.
Click on
Start
button to run the coarse-graining analysis including therun(scenario)
script added in the previous step.
Note that if the script was added to the Post-Analysis sections and the coarse-graining settings were saved, executing the coarse-graining for that scenario in the Iota IPython Terminal will also run the coarse-graining analysis including the run(scenario)
. This can be useful for the users because they can import the scripts and set the coarse-graining for multiple scenarios using the GUI and then execute coarse-graining in batch using the Iota Python Library.
run(scenario)
scripts that have been imported into the project/scenario can be also executed using the run
method available for the iota scripts objects. The following example shows how to import and run a run(scenario)
script using the run
method:
import iota
my_session = iota.session('stephen','C:/Users/stephen/ParticleAnalytics/config.ini')
my_project = my_session.get_project('Backhoe optimization')
my_script = my_project.add_script(name = 'My new script', filepath = 'C:/Users/stephen/My Iota Scripts/my_run_scenario_script.py',description = 'My new run(scenario) script')
my_scenario = my_project.get_scenario('Initial design')
my_script.run(scenario = my_scenario)
If you had already imported the script into your projec/scenario you can replace the add_script
step by the get_script
:
import iota
my_session = iota.session('stephen','C:/Users/stephen/ParticleAnalytics/config.ini')
my_project = my_session.get_project('Backhoe optimization')
my_script = my_project.get_script(name = 'My script name in Iota')
my_scenario = my_project.get_scenario('Initial design')
my_script.run(scenario = my_scenario)
Users can also run run(scenario)
scripts using the standard Python import
command and then calling to the run
function already included in the run(scenario)
script. In this case, users may need to add the directory where the script is located into the Python paths by using the sys.path.append
function. See the example below:
import iota
import sys
sys.path.append('C:/Users/stephen/My Iota Python Scripts')
my_session = iota.session('stephen','C:/Users/stephen/ParticleAnalytics/config.ini')
my_project = my_session.get_project('Backhoe optimization')
my_scenario = my_project.get_scenario('Initial design')
import My_run_script
My_run_script.run(scenario)
Note that in this case, the script does not need to be imported into a Iota project/scenario in order to execute the script.
Last updated
Was this helpful?