31
2013 Page | 1 PlotCreator Tutorial This tutorial will show you how to use the “PlotCreator” component in Introspect IESP. The PlotCreator component provides an easy way to create plots of your data – e.g. the data measured by some other IESP component. There are two varieties of the PlotCreator component: PlotCreatorBasic: basic plotting for the majority of needs PlotCreator: fully-configurable plotting We’ll start with PlotCreatorBasic. Create a new Test in Introspect ESP and then remove the “globalClockConfig” component if one has automatically been created. (We will use mathematically generated data and will not connect to the IESP hardware at all – this allows you to do this tutorial without access to the hardware.) Then use the “Add” button to add an instance of “PlotCreatorBasic”. Your Test should now look like Figure 1. Figure 1 Initial view of PlotCreatorBasic component.

PlotCreator Tutorial - Introspect Technologyintrospect.ca/.../10/IntrospectEsp_PlotCreatorTutorial.pdfeasy to crea Test in Int obalClockCo tances of Pl otCreatorBa tances since togram

Embed Size (px)

Citation preview

2013 Page | 1

PlotCreator Tutorial

This tutorial will show you how to use the “PlotCreator” component in Introspect IESP. The PlotCreator component provides an easy way to create plots of your data – e.g. the data measured by some other IESP component. There are two varieties of the PlotCreator component:

• PlotCreatorBasic: basic plotting for the majority of needs

• PlotCreator: fully-configurable plotting

We’ll start with PlotCreatorBasic. Create a new Test in Introspect ESP and then remove the “globalClockConfig” component if one has automatically been created. (We will use mathematically generated data and will not connect to the IESP hardware at all – this allows you to do this tutorial without access to the hardware.)

Then use the “Add” button to add an instance of “PlotCreatorBasic”. Your Test should now look like Figure 1.

Figure 1 Initial view of PlotCreatorBasic component.

2013 Page | 2

Now enter the following lines in the Test Procedure above the call to the ‘run’ method of plotCreatorBasic1:

myXValues = arange(0, 10, 0.1) myYValues = sin(myXValues)

The ‘arange’ function comes from “numpy” (part of the scientific computing library installed by the Introspect ESP installer) – this function returns an array of equally spaced values between the limits specified. Here we are using it to set the variable ‘myXValues’ to the numbers [0.0, 0.1, 0.2, … 9.9]. And we set the variable ‘myYValues’ to the sine of those x-values.

Enter the names of the above variables (myXValues and myYValues) in the ‘xValues’ and ‘yValues’ slots of the properties table for plotCreatorBasic1. Your Test should now look like the image in Figure 2.

Now click on the “Run” button. (Since the Test Procedure doesn’t use any component that “talks” to the IESP hardware, there is no attempt to connect to the hardware when you run this Test.) After the run has completed, you should see the window change to the “Results” tab to show the Result of this Test run as in Figure 3.

Figure 2 Adding entries to the x and y values of the plot.

2013 Page | 3

Figure 3 Result of running the last Test Procedure.

The Result of calling the ‘run’ method of a PlotCreator component is a folder (called by default “PlotCreatorImages”) with the image file(s) created by the PlotCreator. (You can see the contents of that folder by right-clicking on the icon for the Result and using the “Show Folder” menu item.) Double-click on the icon for the Result and you should see the image file with the plot of the above data (it will appear in whatever application is registered in Windows for viewing images). A sample is shown in Figure 4.

You could use the “HtmlReportWriter” component to put this image into an HTML report, but in this tutorial we’ll just look at the images – we won’t do anything with them.

2013

Multip

ple Data

Figure 4

a Sets YothaPlo‘mybef

my

Chplo

myY

Ancol

[bl

Yo

NoshoResho

Sample o

u can plot man one list ofotCreator pryYValues1’ ifore the call

yYValues2 =

hange the valotCreatorBas

YValues1,

nd in order tolors, change

lue, green

ur Test shou

ow click on thould see the

esult of this Tould show an

output of P

multiple dataf values for ‘operties tabln the Test P to the ‘run’ m

= cos(myXV

lue for ‘yValusic1 to be:

myYValues2

o make the t the ‘plotCol

n]

uld now look

he “Run” bu window chaTest run, andn image like

PlotCreator

a sets in the sxValues’ andle. Rename trocedure anmethod of p

Values)

ues’ in the p

2

two data setslors’ propert

k like Figure

utton. After tange to the “d double-clice Figure 6.

rBasic.

same plot byd/or ‘yValuethe variable

nd add the foplotCreatorB

roperties tab

s be plotted ity to be:

5.

the run has cResults” tabcking on the

Page

y supplying mes’ in the ‘myYValues

ollowing lineBasic1:

ble for

in different

completed, yb to show thee Result icon

e | 4

more

s’ to e just

you e

n

2013

Fig

gure 5 Pllotting mul

Figure 6

tiple data

Result of

sets in one

plotting m

e PlotCreat

multiple dat

orBasic com

a sets.

Page

mponent.

e | 5

2013

Optio

Movin

F

ns for P

ng Code

Figure 7

Plotting LetChsetthelike

into a FIn thabutcom(“fuit onamnew(enthePro

cre

and

Illustration

t’s explore a

hange the ‘plot the ‘title’ pren click on the Figure 7.

Function order to avoat creates thitton in the Tmponent, thfunction1”) toon the left sidme and it shw name.) Thnding with the ‘code’ area ocedure shou

eateTrigPl

d your Test s

n of scatter

few more ofotType’ proproperty to “The “Run” bu

n oid clutter inis plot into a

Test windowhen rename to “createTrigde of the Tes

hould go intohen cut/pasthe call to the of the “creauld now hav

lot()

should look

r plot gene

f the plottingperty to “scaTrig Functionutton. The im

n the Test Proa Function co

w to add an inthat newly crgPlot”. (To st window, to renaming mte the first 4e ‘run’ methoteTrigPlot” F

ve only the o

like Figure 8

ration and

g options foratter” (insteans” (without

mage that res

ocedure, let’omponent. Unstance of threated comp rename a co

then click (onmode so you

4 lines of the od of plotCreFunction. Thne line:

8.

adding plo

Page

r these data ad of “line”) at the quotes)sults should

’s move the cUse the “Addhe “Functionponent omponent: snce) on the

u can type in Test ProcedeatorBasic1)he Test

ot titles.

e | 6

sets. and ) and look

code d”

n”

select

the dure ) into

2013 Page | 7

Figure 8 Encapsulating the plot code into a function.

The contents of the “createTrigPlot” tab should look like:

By the way, the reason that the background colors in the above screen captures are different from what you see in your Test is that I have the following preference settings in my “IntrospectESP_GUI.ini” file:

testProcedureBackgroundColor = #F0EEFF functionCodeBackgroundColor = LightBlue

If you try to run the Test as it is now, you will get a runtime error. This is because any variables defined in the Python code you supply for a Function are local to that Function and thus the variables “myXValues”, “myYValues1”, “myYValues2” are not accessible to the plotCreatorBasic1 component. This is different from the case with variables you define in the Test Procedure

2013 Page | 8

which are global and hence are available for use anywhere in the Test.

We will send the data sets to the plotCreatorBasic1 component via arguments to its ‘run’ method. Change the last line of the code for the “createTrigPlot” Function to:

plotCreatorBasic1.run(myXValues, myYValues1, myYValues2)

Change the ‘xValues’ property for plotCreatorBasic1 (in the properties table) to be:

args[0]

and change the ‘yValues’ property for plotCreatorBasic1 to be:

args[1], args[2]

The “args” variable gets whatever arguments are passed to the ‘run’ method of the PlotCreator component. (args[0] is the first argument, args[1] is the second argument, etc.)

Your Test should look like Figure 9.

Figure 9 Modification of the PlotCreatorBasic component to pass arguments from the Test Procedure fuctions.

2013 Page | 9

Now we are ready to run this Test. Click on the “Run” button and the result should be the same as previously. What we have accomplished is cleaning up the Test Procedure – it now has only the one line that calls the “createTrigPlot” function. The details are nicely hidden away inside the function.

Setting Plot Properties Programmatically We’ve also ended up with a “plotCreatorBasic1” component that is more general (the data that it plots is parametrized via the “args”) – except for the ‘title’ which is still hard-coded as “Trig Functions”. The ‘title’ property doesn’t support the “args” mechanism so we cannot parameterize it that way, but we could specify the ‘title’ programmatically in the “createTrigPlot” Function code with a line like:

plotCreatorBasic1.title = "Trig Functions"

If we did that, then we could remove the ‘title’ value from the properties table for plotCreatorBasic1 and then plotCreatorBasic1 would be completely general. It might be used in some other place where we wanted to plot two data sets on the same graph. (Maybe it should then be renamed to something like “plotTwoDataSets” to make it easier to remember what it does.)

If you want a bit more control over the way the plotting is done, the PlotCreatorBasic component provides some plotting options that don’t appear in the properties table but which you can set programmatically.

You may have noticed when we switched to a “scatter” plot instead of a “line” plot above, that the plots were shown with more space around them. This is a consequence of different defaults for the scatter and line plots in the underlying “matplotlib” library. The attributes ‘xAxisLimits’ and ‘yAxisLimits’ of the PlotCreatorBasic component can be used to control the area of “x” and “y” shown in the plot. (We refer to these as “attributes” rather than “properties” since they don’t appear on the properties table and hence can only be set programmatically.)

For example, to make the scatter plot be as tight as the previous line plot, add the following lines to the “createTrigPlot” Function code:

plotCreatorBasic1.xAxisLimits = [0.0, 10.0] plotCreatorBasic1.yAxisLimits = [-1.0, 1.0]

2013 Page | 10

To change the way the plot looks, you can use the PlotCreatorBasic attribute ‘plotOptions’. This attribute is a Python dictionary indexed by the option names. The possible options are those provided by “matplotlib” – see documentation at: http://matplotlib.sourceforge.net/api/pyplot_api.html

For example, to change the marker type used in our scatter plot, add the following lines to the “createTrigPlot” Function code:

plotCreatorBasic1.plotOptions['marker'] = '+' plotCreatorBasic1.plotOptions['markersize'] = 100

After these changes, your Test should look like Figure 10, and the resulting image (after execution) will look like Figure 11.

Figure 10 Test Procedure after the introduction of additional plot options.

2013

Figure 1Procedu

Histog

11 Resulture.

grams

ting graph

It’snew“glins“plinshismasecthe

dat

Thnu

Chplo

dat

andandFig

from PlotC

s easy to creaw Test in IntlobalClockCostances of PllotCreatorBastances sincestogram plotake both plotction of this e Test Proced

ta = randn

his generatesmpy functio

hange the ‘yVotCreator2 to

ta

d change thed “histogramgure 12.

CreatorBasi

ate histogramtrospect ESPonfig” as befotCreatorBaasic1” and “pe we will be mt. If we used ts with the o tutorial.) Addure:

n(500)

s random valon ‘randn’.

Values’ propeo:

e ‘plotType’ pm” for plotCr

ic customiz

m plots usinP and then rfore. Use theasic to the TeplotCreatorBmaking two the full-fled

one instance dd the follow

lues with a n

erty of both

property to breator2. You

zation in th

ng PlotCreatoemove the

e “Add” buttoest – they wi

Basic2”. (We plots: a scat

dged PlotCre as you will swing line at t

normal distri

plotCreator1

be “scatter” ur Test shoul

Page

he Test

orBasic. Cre

on to add twill be called e need two tter plot andeator, we cousee in a laterthe beginnin

ibution usin

1 and

for plotCreald look like

| 11

ate a

wo

d a uld r ng of

ng the

ator1

2013

Figure 1(b) histo

Figu

plotCsame

13 Resultogram plot

ure 12 Sa

When yoCreatorBasie folder), w

(a)

t of executt

ample Test

u run the Tc1 and one

which look l

ing two Plo

t used for h

Test, you se from plotlike Figure

otCreatorB

histogram g

should get tCreatorBa 13.

(b

asic comm

generation

two imagesic2, but b

b)

mands: (a)

Page

.

s (one fromboth in the

scatter plo

| 12

m

ot,

2013 Page | 13

Plotting Data from Other Components So far we’ve been using mathematically generated data. But the real use of PlotCreator and PlotCreatorBasic is in plotting the data measured by other Introspect ESP components. Let’s look at how we could plot the data from the BertScan component. Create a new Test in Introspect and use the “BERT Scan” wizard to add the components needed for a BERT scan. One of these components will be of class BertScan - the component instance will be named “bertScan1”.

Add an instance of TxChannelList to your Test and change its ‘pattern’ and ‘channels’ properties to match what is used by the RxChannelList component. Edit the Test Procedure to put the call to the “setup” method of “txChannelList1” before the call to the ‘run’ method of “bertScan1”. And add external loopback connections between the RX and TX channels on the hardware.

The BertScan ‘run’ method returns the BERT measurement data, but since we usually just look at the data in the BertScan Viewer, this return value is ignored in the default call to the ‘run’ method that is inserted in the Test Procedure. But if you want to do some post-processing on the data, you need to put the data returned from the ‘run’ method into variables for later use. So change the line in the Test Procedure that calls the ‘run’ method of “bertScan1” to the following:

(phases, errCounts, jitterAnalysis) = bertScan1.run()

See the component classes documentation (available via the Help menu) for details about the data returned from the BertScan ‘run’ method.

To illustrate how to work with this data, we will use PlotCreatorBasic to create a plot of the BertScan data that is similar to that shown in the BertScan Viewer. So add an instance of PlotCreatorBasic to your Test (using the “Add” button), and then add the following lines to the Test Procedure just before the call to the ‘run’ method of “plotCreatorBasic1”:

channel = 1 phasesForCh = phases[channel] errCountsForCh = errCounts[channel]

And change the call to the ‘run’ method of “plotCreatorBasic1” to pass this data as arguments:

plotCreatorBasic1.run(phasesForCh, errCountsForCh)

The above code gets the data for channel 1 from the variables “phases” and “errCounts” which are Python dictionaries indexed by channel number (see documentation). I’ve used channel 1

2013 Page | 14

above since I’m assuming that is one of the channels used in the BERT scan – if not, change that line to use an appropriate channel. (Note that if you get a “Key Error” when running Python code, it usually means that you are using a non-existent key when accessing a dictionary – e.g. if you try to use errCounts[channel] for a channel which didn’t participate in the BERT scan.)

Change the ‘xValues’ property for plotCreatorBasic1 (in the properties table) to be:

args[0]

and change the ‘yValues’ property for plotCreatorBasic1 to be:

args[1]

Your Test should look like Figure 14. Now click on the “Run” button and (assuming your computer is connected via USB to the IESP hardware), the BERT scan will be run and then the data for channel 1 will be plotted via “plotCreatorBasic1”. The resulting image should look something like Figure 15.

Figure 14 Test showing how to plot data from other IESP components in the Test Procedure.

2013

Figuree 15 Bert

AbthePro

chafor

err

whthe

Insof cdocthekeythethecha

Notakinderr

Sintim

tScan data

bove, we plote data for allocedure to th

annels = sr channel

phaseserrCouplotCr

rCountsFor

here the last e formatting

stead of hardchannels frocumentatione list of chanys in arbitrae phases ande ‘run’ methoannel.

ote that indeke care that adented the saror message

nce we are cames (once for

as display

tted the BERl the channelhe following

sorted(errCin channelsForCh = phuntsForCh =reatorBasicrCh)

command isg in this docu

d-coding theom the keys on) a dictionannels since thry order.) T

d error countod of plotCre

ntation is sigall of the lineame amount about incon

alling the ‘rur each chann

yed by PlotC

RT scan datals. Change th

g:

Counts.keyls: hases[chan= errCountc1.run(pha

s entered onument).

e channels thof the “errCo

ary indexed bhe dictionary

Then we loopts for each cheatorBasic1 w

gnificant in es in the bodt – otherwis

nsistent inde

un’ method onel), it will cr

CreatorBas

a for channelhe plotting c

ys())

nnel] ts[channel]asesForCh,

one line (no

hat are used,ounts” variabby channel ny ‘keys’ meth

p over the chhannel sepawith the dat

Python and dy of the aboe you will ge

entation.

of plotCreatoreate severa

Page

sic.

l 1. Now let’scode in the T

]

otwithstandi

, we get the lble which is

number. (Wehod returns

hannels and garately and cata for each

so you needove ‘for’ loopet a runtime

orBasic1 seveal image files

| 15

s plot Test

ing

list (see e sort the get all

d to p are

eral s for

2013 Page | 16

each Run of the Test, but all of the files will go into the same “PlotCreatorImages” folder.

Compare the plots you get with those from the BertScan Viewer. You will note that the BertScan Viewer shows the BER values (instead of the error counts) and it uses a log scale. Let’s change our plots to be more similar to those of the BertScan Viewer. To convert from error counts to BER values, we need to divide the error counts by the number of bits measured. The number of bits can be obtained from the ‘durationInBits’ property of “bertEngine1”. Change the plotting code to the following:

numBits = bertEngine1.durationInBits channels = sorted(errCounts.keys()) for channel in channels:

phasesForCh = phases[channel] errCountsForCh = errCounts[channel] berValuesForCh = array(errCountsForCh) /

numBits plotCreatorBasic1.run(phasesForCh,

berValuesForCh)

In the above, we create a numpy ‘array’ from the “errCountsForCh” list since with a numpy array, we can do the division without needing to explicitly loop over the elements of the list. We pass “berValuesForCh” to the ‘run’ method of plotCreatorBasic1 instead of “errCountsForCh”.

To use a log scale for the BER values, change the ‘yAxisScale’ property of plotCreatorBasic1 to ‘log’.

Your Test should look like Figure 16. Executing the Test results in an image similar to Figure 17.

Advanced Plotting with the Full-Fledged PlotCreator The full-fledged (non-Basic) “PlotCreator” component makes it relatively easy to do the most advanced plotting, with almost complete configurability of the plot options. “PlotCreator” can do everything that “PlotCreatorBasic” can do (its capabilities are a superset of those of PlotCreatorBasic) but it can also handle:

• Multiple sub-plots, each with multiple data sets

• Plot options specified per data set (instead of per plot)

• Reuse of data sets (and plot options) across several instances of PlotCreator

2013

Figure 1replicate

16 Convees what th

Figure

erting errore BertScan

17 PlotC

r counts intn does auto

CreatorBas

to error ratomatically

sic output w

tes before when it ge

with a loga

plotting. Tnerates ba

rithmic sca

Page

This operatathtub plots

ale.

| 17

ion s.

2013 Page | 18

It has several additional properties beyond those of PlotCreatorBasic:

• grid - to enable/disable the grid

• xAxisLimits, yAxisLimits - to specify the area to be shown on the plot

• projection - to specify polar coordinates or rectilinear

• folderName, filename - to specify the image file and folder names

• layout - to specify the layout of the sub-plots

• codeToSetupPlots - to specify Python code to be run for the plots

Most of the above additional properties are available as attributes for programmatic use in PlotCreatorBasic, but having them as properties (settable via the properties table in the GUI) can make PlotCreator more convenient than PlotCreatorBasic if you need the control offered by these properties. In general, the only reason to prefer PlotCreatorBasic over PlotCreator is that the properties table of PlotCreatorBasic is shorter and so perhaps less intimidating. While it is necessary to write some simple Python code to make use of the advanced features of PlotCreator, if you are just using the basic features, you can use PlotCreator in exactly the same way as you would PlotCreatorBasic.

Let’s start by reproducing one of the plots that we did above with PlotCreatorBasic, only this time we’ll use PlotCreator. Create a new Test in Introspect ESP and then remove the “globalClockConfig” as before. Use the “Add” button to add an instance of PlotCreator to the Test – it will be called “plotCreator1”. Put the following lines into the Test Procedure above the call to the ‘run’ method of plotCreator1:

myXValues = arange(0, 10, 0.1) myYValues1 = sin(myXValues) myYValues2 = cos(myXValues)

Set the ‘xValues’ property of plotCreator1 to: myXValues

the ‘yValues’ property to: myYValues1, myYValues2

and the ‘plotColors’ property to: [blue, green]

Your Test should look like Figure 18. Executing this Test will produce an image that is identical to Figure 6.

2013 Page | 19

Figure 18 Using PlotCreator to reproduce the result of Figure 6.

Multiple Plots in One Image One of the things you can do with PlotCreator that you can’t do with PlotCreatorBasic is create multiple plots in one image. This is useful if you want to compare two or multiple data sets. PlotCreator’s ‘layout’ property controls how many sub-plots will be created and the way that these sub-plots are arranged. The default value for ‘layout’ is “A” which gives a single plot just like PlotCreatorBasic as you’ve seen above. The format for the ‘layout’ property is capital letters in alphabetic order, with optional semi-colons. Each semi-colon represents the start of a new row. Figure 19 specifies the mechanism for defining sub-plot layouts. As can be seen, multiple columns are declared by having adjacent characters, whereas multiple rows are declared by inserging semi-colons.

2013 Page | 20

Figure 19 Defining multiple sub-plot layouts with upper-case characters.

Now, let us try this on our existing Test. Change the ‘layout’ property of plotCreator1 (in the properties table) to be: AB. Now click on the “Run” button to run the Test. The resulting image should look like Figure 20.

2013

Figuure 20 Re

Thsubso wiloutchablaval

Thcal

datdatploplo

ThSvthastherun

esult of sel

he “AB” layoub-plots are s let’s change ll specify thet the ‘xValueange these pank out the ‘plue.

hen add the fll to the ‘run

taSet1 = StaSet2 = SotCreator1otCreator1

his creates twtPlotDataSets the cosine e second withnning it prod

ecting layo

ut gives us twshowing the it so that ea

e data sets pres’ and ‘yValproperties baplotColors’ p

following lin’ method of

SvtPlotDataSvtPlotData1.plotA.add1.plotB.add

wo data set ot) – the first values. We ah plotB. Youduces an ima

out AB in P

wo sub-plots same data seach sub-plot rogrammatilues’ propertack to their dproperty so i

es in the Tes plotCreator1

aSet(myXVaaSet(myXVadDataSet(ddDataSet(d

objects (instat one has theassociate theur Test shoulage that is si

PlotCreator

s side by sideets which isn has a differecally, so starties of plotCrdefault emptit will go bac

st Procedure1:

alues, myYValues, myYVdataSet1) dataSet2)

ances of the ce sine valuese first data sld look like Fimilar to Fig

Page

.

e. Here bothn’t too usefuent data set.rt by blankinreator1. (I.e.ty state.) Alsck to its defa

e, just above

Values1) Values2)

class , the secondet with plotAFigure 21, angure 22.

| 21

h ul – We

ng . so

ault

the

d one A, nd

2013

Figure

Figu

e 22 Out

ure 21 D

tput of Plot

efining diff

tCreator wi

ferent data

th two diff

a sets for P

ferent data

lotCreator.

sets on tw

Page

.

wo sub-plot

| 22

ts.

2013

Figure

Figure 2plots.

23 Upda

24 Outpu

Noplolin

datploplo

WespespedocspeploFig

ated Test P

ut of PlotCr

ow, let’s makots. Add the es that creat

taSet2.setotCreator1otCreator1

e are calling ecify the plotecified via thcumentationecified via thotB are instagure 23, and

Procedure w

reator exec

ke the cosine following linte the data se

tColor("gre1.plotA.set1.plotB.set

the ‘setColot color for th

he methods on). Options he methods oances). Yourd the output l

with individ

cution with

e plot be in gnes to the Teet objects:

een") tTitle("SitTitle("Co

or’ method onhat data set. of the SvtPlo that apply toof the SvtPlor Test Procedlooks like Fi

dual param

separate p

green, and adest Procedur

ine") osine")

n the “dataS Various plototDataSet clao the plot asot class (of wdure should igure 24.

meters for e

parameters

Page

dd titles to thre just below

Set2” object tt options canass (see a whole can

which plotA a now look lik

each sub-p

s for the su

| 23

he w the

to n be

n be and ke

lot.

ub-

2013 Page | 24

In an earlier section of this tutorial, we cleaned up our Test Procedure by moving the code for creating a plot using PlotCreatorBasic into a Function component. We could do the same here, but the PlotCreator component has a ‘codeToSetupPlots’ property which can make this more convenient. Here we will leave the lines that define “myXValues”, “myYValues1”, “myYValues2” in the Test Procedure, but move all the remaining lines into the ‘codeToSetupPlots’ property. Cut and paste the 7 lines that are just above the call to the ‘run’ method of plotCreator1 into the ‘codeToSetupPlots’ property (replacing the commented-out example code that is there). If you click on the little “…” button that appears on the right-hand side when you select that property in the property table, you will get a dialog window that makes it easier to edit the code for this property. Edit the code in ‘codeToSetupPlots’ to change the data set creation lines to use the “args” variables like we did before:

dataSet1 = SvtPlotDataSet(args[0], args[1]) dataSet2 = SvtPlotDataSet(args[0], args[2])

And remove the “plotCreator1” references so that the lines that call ‘setTitle’ and ‘addDataSet’ look like this:

plotA.setTitle("Sine") plotB.setTitle("Cosine") plotA.addDataSet(dataSet1) plotB.addDataSet(dataSet2)

In the code for the ‘codeToSetupPlots’ property, the variables “plotA”, “plotB”, etc are available as local variables so there is no need for the “plotCreator1” prefix. The ‘codeToSetupPlots’ property should look like Figure 25.

Figure 25 Illustration of code to setup plots.

2013 Page | 25

Finally, change the call to the ‘run’ method of plotCreator1 in the Test Procedure so that the data values are passed as arguments. The final Test Procedure should look like this:

myXValues = arange(0, 10, 0.1) myYValues1 = sin(myXValues) myYValues2 = cos(myXValues) plotCreator1.run(myXValues, myYValues1, myYValues2)

If you run the Test at this point, you should get exactly the same image as before since we haven’t changed anything – we just reorganized the code. Let’s add another data set to each of the two sub-plots. Our new data sets will have the sine and cosine values but with noise added. Edit the ‘‘codeToSetupPlots’ property to add the following lines:

noiseLevel = 0.1 noise = normal(0, noiseLevel, len(args[0])) dataSet3 = SvtPlotDataSet(args[0], args[1] + noise) dataSet4 = SvtPlotDataSet(args[0], args[2] + noise) dataSet3.setColor("red") dataSet4.setColor("red") plotA.addDataSet(dataSet3) plotB.addDataSet(dataSet4)

We are using the numpy ‘normal’ function to add Gaussian noise to the data. The ‘codeToSetupPlots’ property should now look like Figure 26, and the ensuing execution produces a result that is similar to Figure 27.

Figure 26 Code to setup plot with random noise added to the sine waves.

2013

Figure 277 Result

NoCh

Ed

fftfftdatdatploplo

Wenoishoprotwotheare

of executi

ow we’ll add hange the ‘lay

dit the ‘‘codeT

t1 = abs(ft2 = abs(ftaSet5 = StaSet6 = SotC.addDatotD.addDat

e are using thisy sine and ould now loooduces an imo new sub-pe two new dae displayed i

ng the late

two more suyout’ proper

ToSetupPlot

fft(args[1]fft(args[2]SvtPlotDataSvtPlotDatataSet(dataStaSet(dataS

he numpy ‘ff cosine valueok like Figur

mage like theplots are addata sets (conin the new su

est code wi

ub-plots to srty of plotCre

ts’ property t

] + noise)] + noise)aSet(None,aSet(None,Set5) Set6)

fft’ function tes. The ‘codere 28. Execue one in Figued to the lay

ntaining frequb-plot area

th noise ad

how the FFTeator1 to: A

to add the fo

) ) fft1) fft2)

to calculate teToSetupPloting the Test

ure 29. As cayout of the imquency doma

s.

Page

dded.

T of this dataAB;CD

ollowing line

the FFT of thots’ propertyt Procedure

an be seen, thmage file. Alain informati

| 26

a.

es:

he y now he so, ion)

2013

Figure 2

Figure

29 Final P

e 28 Upda

PlotCreator

ated code w

r output wi

with FFT im

ith four sub

mplementat

b-plots and

tion include

d frequency

Page

ed.

y domain d

| 27

data.

2013 Page | 28

Histograms: A More Sophisticated Example This last section of the tutorial will explore a more complicated version of the histogram plot we did earlier. Create a new Test in Introspect ESP and then remove the “globalClockConfig” as before. Use the “Add” button to add an instance of PlotCreator to the Test, and then rename that newly created component (“plotCreator1”) to “plotGaussianData”. Use the “Add” button to add an instance of the “Function” component, and then rename that newly created component (“function1”) to “gaussianTest”. Enter the following lines into the Test Procedure:

numRuns = 3 numPoints = 1000 gaussianTest(numPoints, numRuns) numPoints = 10000 gaussianTest(numPoints, numRuns)

Set the args of the “gaussianTest” Function to:

numPoints, numRuns

Enter the following lines into the code area of the “gaussianTest” Function:

mu = 0 sigma = 20 binWidth = sigma / 10 minus5sigma = mu - 5 * sigma plus5sigma = mu + 5 * sigma # set up the bins for the histogram from minus5sigma to plus5sigma bins = arange(minus5sigma, plus5sigma, binWidth) # use 'normpdf' function to calculate a gaussian curve for comparison expected = numPoints * binWidth * normpdf(bins, mu, sigma) plotGaussianData.folderName = "Gaussian%d" % numPoints for i in range(numRuns):

plotTitle = ("run %d (numPoints: %d)" % ((i + 1), numPoints)) # generate random data using the 'randn'

function data = sigma * randn(numPoints) + mu plotGaussianData.run(bins, data, expected,

plotTitle)

Enter the following lines in the ‘codeToSetupPlots’ property of plotGaussianData:

2013 Page | 29

bins = args[0] data = args[1] expected = args[2] plotTitle = args[3] dataSet1 = SvtPlotDataSet(None, data, 'histogram') dataSet1.setHistogramBins(bins) dataSet2 = SvtPlotDataSet(bins, expected) dataSet2.setColor('orange') dataSet2.setLineStyle('-', 2) plotA.addDataSet(dataSet1) plotA.addDataSet(dataSet2) maxExpected = max(expected) plotA.setYLim([0, 1.5 * maxExpected]) plotA.setTitle(plotTitle)

Your test procedure should look like Figure 30. Similarly, Figure 31 and Figure 32 show the final contents of the function “gaussianTest” and of the code to set up the plots.

Figure 30 Test Procedure with function to compute & plot Gaussian data.

2013 Page | 30

Figure 31 Contents of the gaussianTest function in this example.

Figure 32 Contents of the code to set plots in this example.

Finally, Figure 33 shows the resulting two images from the example in this section. As can be seen, the bar graph correlates more with the orange curve for a larger data set, and this is expected. We also see how it is possible to create advanced scientific plots using Introspect ESP’s PlotCreator utility.

2013

Figure 3this Tut

33 Resultorial.

ting two im

mages from

(a)

(b)

m the advannced histoggram plotti

Page

ng exampl

| 31

e in