This tutorial subsection presents how to create and use user-made Python3 scripts for IMASViz.
1.1.1. 5.1 Creating an IMAS local data source
- Launch IMASViz tool as explained in section 1. Getting Started
- From the main GUI, select the Scripting tab. An IMASViz embedded Python3 Shell will open.
In Scripting window write the following code:
api = Browser_API() datasourceFactory = DataSourceFactory() datasource = datasourceFactory.create(52682,0,'g2lfleur','test','NATIVE')
When typing api = Browser_API(), do not forget the parenthesis at the end of the command! No error will be displayed, however, other following commands (using api object) will fail!
While editing code in the Script window, you can recall a command by pressing CTRL button + UP ARROW once or several times to get previously edited commands.
By running this code a data source object, attached to the shot 52682 in the test database of user g2lfleur, will be created.
1.1.2. 5.2 Loading IDS data
This subsection will show how to load, as an example, the magnetics IDS from the data source, created in the previous step, and populate the view.
First, IMAS_VIZ needs to build a 'view' (a wx.TreeCtrl component) that will be later populated with magnetics nodes.
This is done by running the following code:view = api.CreateDataTree(datasource)
The view is displayed by running the following code:
view.Show()
To load the magnetics IDS data, run the following code:
api.LoadIDSData(view, 'magnetics', occurrence=0)
The view is updated with the nodes of the magnetics IDS.
At the end of this session, the scripting window should look something like this:
1.1.3. 5.3 Plotting multiple FLT_1D array nodes
In this part of the tutorial, it will be shown how to plot multiple FLT_1D arrays by scripting.
1.1.3.1. 5.3.1 Selecting FLT_1D arrays nodes
In this case, an example of handling 6 flux loops from the magnetics IDS nodes will be shown.
Run the following code
paths = [] for i in range(0,6): paths.append('magnetics/flux_loop(' + str(i) + ')/flux') api.SelectSignals(view)
Check if the wanted nodes have been selected (selected nodes are red) by expanding the magnetics node in the view
Selecting nodes for the first time without calling LoadIDSData() previously will load the IDS data (occurrence 0 by default)
1.1.3.2. 5.3.2 Plotting selected FLT_1D array nodes
In order to plot all selected FLT_1D array nodes in the previous step:
Run the following code:
api.PlotSelectedSignals(view)
You should get the image below.
1.1.3.3. 5.3.3 Plotting selected FLT_1D arrays nodes to multiplot frame
In order to plot all selected FLT_1D array nodes, done in step 5.3.1, to a multiplot frame:
- Run the following code:
api.PlotSelectedSignalsInMultiPlotFrame(view)
An image similar to the one below should be displayed.
1.1.3.4.
5.3.4 Applying a multiplot configuration to a shot
In order to create a multiplot configuration:
- Create a multiplot configuration using the GUI (see tutorial, 5. Scripting (advanced)) with the name
Magnetics_flux_loop_bpol_probes Run the following code:
api = Browser_API() datasourceFactory = DataSourceFactory() datasource = datasourceFactory.create(52344,0,'g2lfleur','test','NATIVE') view = api.CreateDataTree(datasource) multiPlotConfiguration = api.GetMultiplotConfigurationPath('Magnetics_flux_loop_bpol_probes') api.ApplyMultiPlotConfiguration(view, multiPlotConfiguration )
An image similar to the one below should be displayed.
1.1.3.5. 5.3.5 Comparing FLT_1D arrays of 2 different shots
In order to compare FLT_1D arrays of two different shots (in this case magnetics/flux_loop(0)/flux/data of shots 52344 and 52682) do the following
Run the following code:
api = Browser_API() datasourceFactory = DataSourceFactory() #Create datasource for shot 52344 datasource_52344 = datasourceFactory.create(52344,0,'g2lfleur','test','NATIVE') #Create datasource for shot 52682 datasource_52682 = datasourceFactory.create(52682,0,'g2lfleur','test','NATIVE') #Create the view for shot 52344 view_52344 = api.CreateDataTree(datasource_52344) #Create the view for shot 52682 view_52682 = api.CreateDataTree(datasource_52682) #Selection path (paths is Python list) paths = ['magnetics/flux_loop(0)/flux'] #Selection of the nodes api.SelectSignals(view_52344,paths) api.SelectSignals(view_52682,paths) api.PlotSelectedSignals(view_52344) figureKeys = api.GetFiguresKeys() api.PlotSelectedSignals(view_52682,figureKeys[0])
An image similar to the one below should be displayed.
1.1.4. 5.4 Executing the user-made script outside IMASViz
The script created in the previous steps of this tutorial subsection can be executed outside IMASViz. To achieve that, do the following:
Complement your IMASViz script code as shown below:
#!/usr/bin/python import wx from imasviz.Browser_API import Browser_API from imasviz.data_source.DataSourceFactory import DataSourceFactory from imasviz.util.GlobalValues import GlobalValues from imasviz.util.GlobalOperations import GlobalOperations app = wx.App() GlobalOperations.checkEnvSettings() #Insert your IMASViz script code here app.MainLoop()
Add IMASViz project in the PYTHONPATH
export PYTHONPATH=/gw/swimas/vis/imas-viz/rc:$PYTHONPATH
Execute your script:
python3 myscript.py
@Gateway
Make sure to have the cineca, imas and imas-viz modules loaded before executing the script:
$ module load cineca $ module load imasenv/3.15.1 $ module load imas-viz