elvispy

Python programs can send data to ElVis for display in graphs.  The elvispy python package is available on the PPPL portal cluster. 
It is an application programming interface (API) for python programs.

To begin using ElVis from python, load the elvis module.  At the Linux command line:

module load elvis

That will set up your execution path to include running ElVis on portal.
It will also set up your Python import path so it will find elvispy.py.

The elvispy package will automatically start ElVis running or can connect to one already running.  Data is sent over a socket connection between your Python program and ElVis.  The 2 programs can be running on the same computer or different ones.

Here is an example Python program that sends graph data to ElVis for display:

import elvispy
import platform

host = platform.node()     # get name of host computer
port = 7654                # default port that ElVis listens to

s1 = elvispy.open_session(host, port, True)   # launch ElVis if it is not running

x = [3., 4., 5.]           # list of x values
y = [5., 10., 15.]         # list of y values

elvispy.draw_graph(s1, x, y, "My Title", "my x label", "my y label")

This example will start ElVis on your sunfireXX computer (if it is not already running).   Some connections messages will be printed and ElVis will start within a few seconds.  Be sure to ssh -X into portal so the graphics display is forwarded to your local computer.

The example draws an f(x) graph.  It creates a List variable named x that contains the X coordinate of each point in the graph and another List variable named y for the Y coordinate of each point.

elvispy.draw_graph() sends the 2 lists to ElVis where the graph is drawn.  You can specify the text for the title of the graph, the X-Axis label, and the Y-Axis label.



To draw a multigraph with several f(x) functions in the same graph:

import elvispy
import platform

host = platform.node()     # get name of host computer
port = 7654                # default port that ElVis listens to

s1 = elvispy.open_session(host, port, True)   # launch ElVis if it is not running

xy = []                                       # xy will be a list of lists
                                              # first list has x values
                                              # each subsequent list has y values for a dataset
names = ["Alpha", "Beta", "Gamma"]            # list of dataset names

x = [10., 20., 30., 40.]                # list of x values
signal1 = [5., 10., 15., 20.]        # list of y values for dataset 1
signal2 = [4., 8., 5., 1.]          # list of y values for dataset 2
signal3 = [6., 5., 10., 9.]         # list of y values for dataset 3

xy.append(x)
xy.append(signal1)
xy.append(signal2)
xy.append(signal3)

elvispy.draw_multigraph(s1, xy, "My Title", "my x label", "my y label", names)


To draw an indexed graph, f(x,i), that will be drawn as one curve that changes over time:

import elvispy
import platform

host = platform.node()     # get name of local computer
port = 7654                # default port that ElVis listens to

s1 = elvispy.open_session(host, port, True)   # launch ElVis if it is not running

xy = []                       # list of tuples
                              # first tuples has x values
                              # each subsequent tuple has y values

x = (10., 20., 30., 40.)            # tuple of x values
step1 = (5., 10., 15., 20.)         # tuple of y values for first index
step2 = (4., 8., 5., 1.)            # tuple of y values for second index
step3 = (6., 5., 10., 9.)           # tuple of y values for third index

times = [.2, .4, .6]          # list of index values

xy.append(x)
xy.append(step1)
xy.append(step2)
xy.append(step3)

elvispy.draw_indexed_graph(s1, xy, "My Title", "my x", "my y", times)




Some in-line help about elvispy is available by running the python interpreter:

python
import elvispy
help(elvispy)



Run ElVis Locally

ElVis will run faster and more smoothly on your local computer compared to running it on portal.
Get started by downloading ElVis to your computer from the ElVis download page.
Then start running ElVis on your computer.

In your Python program on portal, set the host to the name of your computer and do not try to launch ElVis on portal.
For example, if the name of your computer is smith-pc:

s1 = elvispy.open_session("smith-pc", port, False)

The default port number is 7654.