Documentation:Tutorial:QuickDataPlots - MdsWiki
Navigation
Personal tools

From MdsWiki

Jump to: navigation, search

Quick Data Plots

When MDSplus has been installed including its java components, there is a quick way to preview data stored in (subclasses of) Data objects. The method plot() is in fact defined for all Data objects and when called, if the data is plottable (i.e. when evaluated it returns an array or a signal), a window is open and the data content is plotted. The window is implemented by the same Java class used by jScope and therefore it is possible to manipulate (zoom, drag, ...) the displayed waveform as moving a cursor on it in order to display the current values.
The following code snippet shows how to read a data object from a Tree and to plot it.

C++:

Tree *myTree = new Tree("my_tree", 23000); 
TreeNode *node = myTree->getNode("IP");
node->plot();

Java:

Tree myTree = new Tree("my_tree", 23000);
TreeNode node = myTree.getNode("IP");
node.plot()

Python:

>>> myTree = Tree("my_tree", 23000)
>>> node = myTree.getNode('IP')
>>> node.plot()


If the node IP has been saved in the tree as a signal, the plot will display the true times. In fact the Signal object brings information on both the signal samples and the associated times. Consider instead the following example, in which the same tree is accessed remotely via a Connection object:
C++:

Connection *c = new Connection("my_host_ip");
c->openTree("my_tree", 23000);
Data *d = c->get("IP");
d->plot();

Java:

Connection c = new Connection("my_host_ip");
c.openTree("my_tree", 23000);
Data d = c.get("IP");
d.plot();

Python:

>>> c = Connection("my_host_ip")
>>> c.openTree('my_tree', 23000)
>>> d = c.get("IP")
>>> d.plot()


In this case you will see that time information is lost and only sample numbers are plotted on X axis. The reason is that the accessing data through the Connection object, data are returned a scalar or arrays, losing additional information, such as the dimension information for a signal. In order to plot correctly the times you need to do the following:
C++:

Connection *c = new Connection("my_host_ip");
c->openTree("my_tree", 23000);
Data *d = c->get("IP");
Data *t = c->get("DIM_OF(IP)");
Data *s = new Signal(d, d, t);
s->plot();

Java:

Connection c = new Connection("my_host_ip");
c.openTree("my_tree", 23000);
Data d = c.get("IP");
Data t = c->get("DIM_OF(IP)");
Data s = new Signal(d, d, t);
s.plot();

Python:

>>> c = Connection("my_host_ip")
>>> c.openTree('my_tree', 23000)
>>> d = c.get("IP")
>>> t = c.get("DIM_OF(IP)")
>>> s = Signal(d, d, t);
>>> s.plot()


That is a new Signal object is built starting from the samples and the times retrieved by the Connection object.

More sophisticated Plots

It is possible to provide more flexible waveform visualization by plotting multiple waveforms onto the same panel as well as defining windows with multiple panels. In this case it is necessary to use the Scope object.
The constructor of class Scope requires the a name which is then displayed in the associated window. Other optional parameters are the X and Y coordinates of the top left border and the width and height of the window. A signal is then plotted to the selected panel of the Scope window using method plot() which requires the Y and X axis (Data instances) and, optionally, the indexes (starting from 1) of the panel and the color of the displayed waveform. New waveforms can be added using method oplot() with the same parameters. Method show() displays the waveform panels. In the following example a 2x1 panel is displayed showing waveforms whose X and Y axis are stored in Data instances x1, x2 and y1, y2, respectively.
C++:

Scope *sc = new Scope("MYPLOT", 100, 100, 200, 300);
sc->show();
sc->plot(x1, y1, 1, 1, "blue");
sc->plot(x2,y2, 1,2,"red");

Java:

Scope sc = new Scope("MYPLOT", 100, 100, 200, 300);
sc.show();
sc.plot(x1, y1, 1, 1, "blue");
sc.plot(x2,y2, 1,2,"red");

Python:

>>> sc = Scope("MYPLOT", 100, 100, 200, 300)
>>> sc.show()
>>> sc.plot(x1, y1, 1, 1, "blue")
>>> sc.plot(x2, y2, 1, 2, "red")


In the example below the two waveforms are instead plotted onto the same panel.
C++:

Scope *sc = new Scope("MYPLOT", 100, 100, 200, 300);
sc->show();
sc->plot(x1, y1, 1, 1, "blue");
sc->oplot(x2,y2, 1,1,"red");

Java:

Scope sc = new Scope("MYPLOT", 100, 100, 200, 300);
sc.show();
sc.plot(x1, y1, 1, 1, "blue");
sc.oplot(x2,y2, 1,1,"red");

Python:

>>> sc = Scope("MYPLOT", 100, 100, 200, 300)
>>> sc.show()
>>> sc.plot(x1, y1, 1, 1, "blue")
>>> sc.oplot(x2, y2, 1, 1,"red")


Using jScope waveforms in MATLAB programs

It is possible to use the interactive jScope panels for data visualization also within MATLAB, using the MDSplus Data and Scope classes from MATLAB programs.
To use jScope panels within MATLAB it suffices create exactly the same classes as shown in the above Java examples, after importing the MDSplus classes with the command

>> import MDSplus.Tree 

it is necessary to make sure that the package MDSobjects.jar is included in CLASSPATH.