Writing Scripts
Users can write their own Python scripts (.py) using the methods provided with the Iota Python Library. This allows users to customize and create more sophisticated analysis workflows that then can be reproduced by running the scripts instead of executing manually one by one the commands on the Iota IPython Terminal. The scripts can be written using text editor or Python Editor that use the Iota Python Library.
This is an example of generic Python script using Iota Python Library:
''' This scripts loads an existing project and for each scenario of the project, it runs
coarse-graining using the coarse-graining settings that were previously set via the GUI'''
### Import Python modules and add IOTA installation path to Python paths
import sys
import os
import iota
sys.path.append(os.getenv('IOTA_PATH'))
### Set your Iota username and home directory
username = 'stephen'
home_path = 'C:/Users/stephen/'
### Star a new iota session
my_session = iota.session(username,home_path + 'ParticleAnalytics/config.ini')
### Main actions
project = my_session.get_project('Backhoe optimization')
ListOfScenarios = project.get_scenarios()
for sc in ListOfScenarios:
print('Starting coarse-graining of {}'.format(sc.name))
sc.run_coarse_graining()
print('Finished coarse-graining of {}'.format(sc.name))The script can be split in different sections:
Script description (optional): summary of that describes what the script intends to do.
Importing modules & adding IOTA installation path: this section imports the Iota Python Library (
iota) and the Python modulessysandosthat are used to add the installation path of Iota to the Python paths:Setting your Iota username and home directory: this section assign your Iota username and home directory path to the variables
usernameandhome_path. This variable are used in the next section of the script to start your Iota session.Starting a new Iota session: this section starts a new Iota session using the username and home directory set in the previous section:
Main actions: this section includes the main actions that you want to conduct and automate with the script. In this particular example:
Note that the sections 2 - 5 of the scripts can be re-used for any other generic script so that users just need to modify sections 1 and 5 depending on the description and actions that they want to perform with the script.
An example of run Script can be found below. The difference with the generic scripts is that this scripts need to include the definition of the function def run(scenario) and the actions to be performed by the script are included inside that function. This kind of scripts can be imported into a project/scenario and then also attached as Post-Analysis when setting the coarse-graining analysis (for more details see the "Scritps" and "Post-Analysis" sections of the Iota User Mananul.
The script can be split in different sections:
Script description: summary of that describes what the script intends to do.
```python
''' This scripts load the coarse-graining dataset of the scenario and create a cut-plane of the mesh called "Simulation_domain" with results for each timestep of the dataset. The cut-planes are automatically saved into the coarse-graining dataset'''
Importing modules: in this example, only the Iota Python Library (
iota) is imported but user can import any other available python modules.definition of the "run" method: the method
runis defined as takes as argument a variable calledscenario(i.e, ascenarioobject of the Iota Python Library)Main actions: this section includes the main actions that to be conducted with the script. In this particular example:
Last updated
Was this helpful?