Assume you have a Python code which provides one or more specific functionalities when dealing with IMAS data. For example, specific plots, statistics data or specific informations
on shot data. Now you want to make these features available from IMASViz. This section explains how to build a IMASViz plugin from your code and how to register this new plugin to IMASViz.
When a user click on a node in a IMASViz shot (tree) view, the IMASViz framework requests all registered plugins by sending a list of subjects attached to the node (for example, '1DPlot' could be 
a subject attached to a FLT1D array node). Each plugin will return a list of entries for each subject. 

If the list of entries is empty for a given subject, this means that the plugin does not handle this subject.

We will now create a very simple plugin which has 3 functionalities:

  • displays 'Hello' in the log window when user clicks at the root node of the tree and select 'Hello from DemoPlugin' in the popup menu
  • displays the path of a FLT_1D array node in the log window when user clicks on a FLT_1D array node and select 'FLT1D array path from DemoPlugin' in the popup menu
  • displays the size of a FLT_1D array node in the log window when user clicks on a FLT_1D array node and select 'FLT1D array size from DemoPlugin' in the popup menu


Here are the steps:

  1. Clone the IMASViz project
  2. Create a Python file with name 'DemoPlugin.py'
  3. Put the file in the imasviz/plugins directory of the IMASViz project
  4. Edit the file as below

 

from imasviz.plugins.VIZPlugins import VIZPlugins
import traceback

class DemoPlugin(VIZPlugins):
def __init__(self):
VIZPlugins.__init__(self)

def execute(self, app, pluginsConfig):
try:
	print ('DemoPlugin to be executed...')
	app.MainLoop()
except :
	traceback.print_exc()
	self.view.log.error(traceback.format_exc())

def getEntriesPerSubject(self):
	return {'overview':[0], '1DPlot':[1,2]}

#list of (config number, description)
def getAllEntries(self): 
	return [(0, 'Hello from DemoPlugin...'), 
	(1, 'FLT1D array path from DemoPlugin'),
	(2, 'FLT1D array size from DemoPlugin')]


The DemoPlugin class should inherit from VIZPlugins and implement 2 required methods:

  • getAllEntries() which returns a list of pairs (configIndex, description) where each pair will be called an 'entry'.
  • getEntriesPerSubject() which returns a map where each key is a subject (like 'overview'). The corresponding value in the map is a list of index (as list [1,2] for the key (sublect) '1DPlot') where each index refers to a entry. An entry consists in a pair (configIndex,itemName) where configIndex refers to a plugin configuration stored in an array which contains all available configurations of the plugin. When the user click a node in the tree and select the item whose name is given by the itemName variable, the application will call the right plugin with configuration (which is simply a map of key/value pairs) defined by configIndex.

In getEntriesPerSubject(), for the [0] list, 0 refers to the first entry (0, 'Hello from DemoPlugin...')
In getEntriesPerSubject(), for the [1,2] list, 1 refers to the entry (0, 'FLT1D array path from DemoPlugin') which is the second element of the entries list  returned by getAllEntries(); 2 refers to the entry (0, 'FLT1D array size from DemoPlugin') which is the third element of the entries list  returned by getAllEntries()

Edit the top of the file VIZPlugins.py in the imasviz/plugins directory as below

 

import importlib

RegisteredPlugins = {'equilibriumcharts':'viz_equi.equilibriumcharts', 
'DemoPlugin':'viz_tests.DemoPlugin'}

RegisteredPluginsConfiguration = {'equilibriumcharts':[{'time_i': 31.880, \
'time_e': 32.020, \
'delta_t': 0.02, \
'shot': 50642, \
'run': 0, \
'machine': 'west_equinox', \
'user': 'imas_private'}],
'ECEOverviewPlugin':[{'param1':1, 'param2':2}, {'param1':3, 'param2':4}],
'TFOverviewPlugin':[{}],
'DemoPlugin':[{'option':1}, {'option':2}, {'option':3}]}

First, we have registered the DemoPlugin plugin in the global variable RegisteredPlugins. The syntax is the following:

'plugin name':'full relative class name'. In this example, the DemoPlugin class is found in the module DemoPlugin.py in the directory viz_tests (relative to the imasviz directory which is the base package of the viz project).

Second, we have defined 3 configurations for the 'DemoPlugin' plugin. The syntax is the following:
'plugin name':list of configurations. Each configuration is a map of key/values as for example {'option':1} which defines the parameter 'option' with value 1.

Now, if the user selects 'FLT1D array path from DemoPlugin' in the popup menu, the plugin will be called with the configuration 1 as indicated by the implementation of getAllEntries() in the DemoPlugin.py file.

 

 

  • No labels