Table of Content
Search clouds
Licenses
Author's resources
The SCaVis data containers are designed for scientific data analysis and are well suited for data manipulation, input/output and data representation using various canvaces. Unlike Data Collections, they are mainly designed for the data visualisation purpose and high-level operations. If you are interested in high-speed numerical calculations, use Data Collections which typically over-perform these data structures (typically by a factor 5) and have very small memory footprint.)
Such arrays are based on the Java class
jhplot.P0D.
One can fill such arrays using the method “add” and display its content.
The statistical summary can also be easily obtained:
The example below shows how to build such arrays using the Python syntax. We fill an array with 10 sequential numbers from 0 to 9 and then we convert it into a string (for printing). Finally, we evaluate a complete statistical summary using the “getStat” method:
from jhplot import * p0=P0D("test") for i in range(10): p0.add(i) print p0.toString()
This prints in the prompt:
Click to display ⇲
Click to hide ⇱
P0D test 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
One can view the data containers using several methods. One is “toString()” which converts data into a string. One can write data into a file (including a compression) using the method “toFile(file)”). One can also view data in a sortable table using the method “toTable()”, or calling the “HTable(obj)” directly, where “obj” is one of the containers discusses above. This works even for SCaVis histograms. For example, the executing this line after the above example is
HTable(p0)
brings up a table where data can be sorted and searched:
As for any SCaVis data object, one can write and read arrays into files using the method “toFile” and read using the method “read()”
p0.toFile("data.txt")
and read it back as:
p0.read("data.txt")
If a file was zipped use the method “readZip()”. Read more about IO in the Section io.
One can access various statistical characteristics of the
jhplot.P0D arrays as:
print p0.getStatString()
The output of this script is shown below:
Click to display ⇲
Click to hide ⇱
cern.hep.aida.bin.DynamicBin1D ------------- Size: 10 Sum: 45.0 SumOfSquares: 285.0 Min: 0.0 Max: 9.0 Mean: 4.5 RMS: 5.338539126015656 Variance: 9.166666666666666 Standard deviation: 3.0276503540974917 Standard error: 0.9574271077563381 Geometric mean: 0.0 Product: 0.0 Harmonic mean: 0.0 Sum of inversions: Infinity Skew: 0.0 Kurtosis: -1.5616363636363637 Sum of powers(3): 2025.0 Sum of powers(4): 15333.0 Sum of powers(5): 120825.0 Sum of powers(6): 978405.0 Moment(0,0): 1.0 Moment(1,0): 4.5 Moment(2,0): 28.5 Moment(3,0): 202.5 Moment(4,0): 1533.3 Moment(5,0): 12082.5 Moment(6,0): 97840.5 Moment(0,mean()): 1.0 Moment(1,mean()): 0.0 Moment(2,mean()): 8.25 Moment(3,mean()): 0.0 Moment(4,mean()): 120.8625 Moment(5,mean()): 0.0 Moment(6,mean()): 2079.515625 25%, 50%, 75% Quantiles: 2.25, 4.5, 6.75 quantileInverse(median): 0.55 Distinct elements: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] Frequencies: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
You can access all such characteristics using the method getStat() which return Java Map (or Jython dictionary) where the key identifies each statistical value.
Since it is useful to re-bin 1D arrays using Histograms, consider using
jhplot.HPlotJas
canvas which offers a GUI with a slider for on-fly rebinning. This is explained in more detail in the Section Interactive fit.
2D arrays are based on the Java class
jhplot.P1D. This is one of the reachest data collections
that can be used to keep values, (X,Y, Err) values, where “Err” is an error on “Y”, and
any (X,Y) values with asymmetric errors on X, Y.
As before, one can fill such arrays using the method “add(x,y)”. It is one of the most advanced containers since data can contain up to 8 errors: 1st level (usually statistical) and 2nd level (usually systematic uncertainty). The dimension of this array can grow and shrink. If you need to keep only 2 values, X and Y, set the dimension of this object to 2 (which is anyway the default). But the dimension can also be up to 10, with 8 additional values necessary to set errors on X and Y.
This is also a high-performance container, which is faster than Jython list or java list. For example, you will need
2 Python list to keep X and Y. Instead, use a single
jhplot.P1D.
Read about the performance of this container in Section data_collections.
The dimensions of this array are below. Use the “setDimension(dimension)” to initialize the container:
Here are errY means a 1st level error (usually statistical), while errYsys means second-level errors (usually systematic).
jhplot.P1Ddepends on its dimension. If you keep only (X,Y) values with the default dimension 2, the memory footprint is exactly 5 times smaller than if you store (X,Y) and 6 errors on X and Y separately (1st and 2nd level).
For example, let us make a simple (X,Y) array:
from jhplot import * p=P1D("XY") p.add(x,y)
You can get arrays back as:
x=p.getArrayX() y=p.getArrayY()
The main advantage in using
jhplot.P1D in its ability to handle various operations together with error propagations.
The example below shows how to build such arrays using the Python syntax. We fill an array with 10 sequential numbers from 0 to 9 and then we convert it into a string (for printing). Finally, we evaluate a complete statistical summary using the “getStat” method:
1: # Data arrays | C | 1.7 | S.Chekanov | Data in X-Y, plotting on 2D canvas 2: 3: from jhplot import * 4: from java.awt import Color 5: 6: p1=P1D("1st data set") 7: p1.add(1,2) 8: p1.add(2,3) 9: p1.add(4,5) 10: 11: p2=P1D("2nd data set") 12: p2.add(-1,3) 13: p2.add(5,-2) 14: p2.add(1,0) 15: p2.setColor(Color.red) 16: 17: c1 = HPlot("Canvas") 18: c1.visible() 19: c1.setAutoRange() 20: 21: c1.draw(p1) 22: c1.draw(p2)
The output of this script is shown here
The
jhplot.P1D data container
can also show errors in X and Y for each data points, as well it has
advanced mathematical operations with proper error propagation. For example,
p1.add(x,y,err) # fills X,Y and symmetric error on Y
where “err” is a statistical error on the Y value, assuming that yUpper=yLower. You can get values back as arrays using:
x=p1.getArrayX() y=p1.getArrayX() error=p1.getArrayErr()
If the error on Y is asymmetric, use this method:
p1.add(x,y,err_up, err_down)
where “err” and “err_down” are symmetric upper and lower error on Y.
The SCaVis contains advanced error propagation algorithms and can handle statistical errors (on X and Y) as well as systematic error (2nd level errors) Here is a small example which illustrate how to draw points with 1st-level (statistical) errors:
1: # Data arrays | P | 1.7 | S.Chekanov | Data in X-Y with error on Y, plotting on 2D canvas 2: 3: from jhplot import * 4: 5: c1 = HPlot("Canvas") 6: c1.visible() 7: c1.setAutoRange() 8: c1.setGTitle("X-Y with errors") 9: 10: p1= P1D("Data") 11: p1.add(1,100,7,5) # x, y, error UP and DOWN 12: p1.add(2,80,5,4) 13: p1.add(3,90,5,2) 14: c1.draw(p1)
In this code, errors on the y-axis are asymmetric (jut to show that this is possible). The “add()” method has many variations, so one can assign errors for x-axis, y-axis (plus 2-level errors).
Analogously, one can plot data in 3D. Use
jhplot.P2D class to add values and plot them.
1: # Data arrays | P | 1.7 | S.Chekanov | Data in X-Y-Y with errors and plot in 3D 2: 3: from jhplot import * 4: 5: c1 = HPlot3D("Canvas") 6: c1.visible() 7: c1.setAutoRange() 8: 9: p1=P2D("3D") 10: p1.add(1,2,3) 11: p1.add(2,1,3) 12: p1.add(3,2,0) 13: c1.draw(p1)
Here is more advanced example:
1: # Plots/3D | C | 1.7 | S.Chekanov | X-Y-Z data in 3D (P2D) using HPlot3D 2: 3: from java.awt import Color 4: from jhplot import HPlot3D,P2D 5: 6: d1 = P2D("data1") 7: d2 = P2D("data2") 8: d3 = P2D("data3") 9: d1.setSymbolColor(Color.red) 10: d2.setSymbolColor(Color.blue) 11: d3.setSymbolSize(2) 12: for i in range(0,10): 13: for j in range(0,10): 14: d1.add(i,j,0.5) 15: d2.add(i,j,0.6) 16: 17: for i in range(0,50): 18: for j in range(0,50): 19: d3.add(0.2*i,0.2*j,0.9) 20: 21: c1 = HPlot3D("plot",600,700,1,2); 22: c1.setRange(0.0,10,0.0,10,0,2) 23: c1.visible() 24: 25: c1.cd(1,1) 26: c1.draw(d1) 27: c1.draw(d2) 28: 29: c1.cd(1,2) 30: c1.setRange(0.0,10,0.0,10,0.2,1.0) 31: c1.draw(d1) 32: c1.draw(d2) 33: c1.draw(d3)
Which generates the output: SCaVis data container designed to keep such data and do some manipulation.
Our preference is to read a data from a prepared file located on the Web:
from jhplot import * pn=PND('data','/scavis/examples/data/pnd.d') print pn.toString()
Here we create a PND object from the file “pnd.d” stored on the Web and print it for checking. Theython shell (which is used for output of the print command).
Let us continue with the analysis of our data. First thing we want to do is to extract the numbers from the 2nd column and display(); c1.setAutoRange() # set auto-range h1=p0.getH1D(10) # convert 1D array into a histogram with 10 bins c1.draw(h1) # draw the histogram
The next step in our analysis is to extract the 2 columns and to make a X-Y scatter plot in order find a correlation between the numbers from these columns. In the example below we extract the 2nd and 3rd column, plot them auto-range c1.draw(p1)
This code should follow after the code which creates the object “pn” as discussed before. The execution of this code makes a X-Y graph with the values of the 2nd and 3rd columns
A complete description of how to use Java, Jython and SCaVis for scientific analysis is described in the book Scientific data analysis using Jython and Java published by Springer Verlag, London, 2010 (by S.V.Chekanov)