File: aggregate.py

package info (click to toggle)
vtk6 6.3.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 118,532 kB
  • ctags: 138,251
  • sloc: cpp: 1,443,749; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,127; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 471; makefile: 95; objc: 17
file content (103 lines) | stat: -rw-r--r-- 3,199 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
from vtk import *
import os.path

# Set database parameters
data_dir = "../../../../VTKData/Data/Infovis/SQLite/"
if not os.path.exists( data_dir):
  data_dir = "../../../../../VTKData/Data/Infovis/SQLite/"
if not os.path.exists( data_dir):
  data_dir = "../../../../../../VTKData/Data/Infovis/SQLite/"
sqlite_file = data_dir + "temperatures.db"
databaseToTable = vtkSQLDatabaseTableSource()
databaseToTable.SetURL("sqlite://" + sqlite_file)

# Pull the first data set from the database
databaseToTable.SetQuery("select * from main_tbl where CompId==2")

# Calculate primary descriptive statistics for first batch
print "# Calculate primary model of descriptive statistics for first data set:"
ds1 = vtkDescriptiveStatistics()
ds1.AddInputConnection( databaseToTable.GetOutputPort() )
ds1.AddColumn("Temp1")
ds1.AddColumn("Temp2")
ds1.SetLearnOption( 1 )
ds1.SetDeriveOption( 0 )
ds1.SetAssessOption( 0 )
ds1.SetTestOption( 0 )
ds1.Update()

# Show primary descriptive statistics for first batch
dStats1 = ds1.GetOutputDataObject( 1 )
dPrimary1 = dStats1.GetBlock( 0 )
dPrimary1.Dump( 15 )
print

# Pull the second data set from the database
databaseToTable.SetQuery("select * from main_tbl where CompId==3")

# Calculate primary descriptive statistics for second batch
print "# Calculate primary model of descriptive statistics for second data set:"
ds2 = vtkDescriptiveStatistics()
ds2.AddInputConnection( databaseToTable.GetOutputPort() )
ds2.AddColumn("Temp1")
ds2.AddColumn("Temp2")
ds2.SetLearnOption( 1 )
ds2.SetDeriveOption( 0 )
ds2.SetAssessOption( 0 )
ds2.SetTestOption( 0 )
ds2.Update()

# Show primary descriptive statistics for second batch
dStats2 = ds2.GetOutputDataObject( 1 )
dPrimary2 = dStats2.GetBlock( 0 )
dPrimary2.Dump( 15 )
print

# Finally aggregate both models to get a new primary model for the whole ensemble
print "# Aggregate  both primary models:"
collection = vtkDataObjectCollection()
collection.AddItem( dStats1 )
collection.AddItem( dStats2 )
ds = vtkDescriptiveStatistics()
aggregated = vtkMultiBlockDataSet()
ds.Aggregate( collection, aggregated )
dPrimary = aggregated.GetBlock( 0 )
dPrimary.Dump( 15 )
print

# Calculate derived model for whole ensemble
print "# Now calculating derived statistics for whole ensemble:"
ds.SetInputData( 2, aggregated )
ds.SetLearnOption( 0 )
ds.SetDeriveOption( 1 )
ds.SetAssessOption( 0 )
ds.SetTestOption( 0 )
ds.Update()
dStats = ds.GetOutputDataObject( 1 )
dDerived = dStats.GetBlock( 1 )
dDerived.Dump( 15 )
print

# Pull entire data set from the database
databaseToTable.SetQuery("select * from main_tbl")

# Verify with calculation for whole ensemble at once
print "# Finally verifying by directly calculating statistics for whole ensemble:"
ds0 = vtkDescriptiveStatistics()
ds0.AddInputConnection( databaseToTable.GetOutputPort() )
ds0.AddColumn("Temp1")
ds0.AddColumn("Temp2")
ds0.SetLearnOption( 1 )
ds0.SetDeriveOption( 1 )
ds0.SetAssessOption( 0 )
ds0.SetTestOption( 0 )
ds0.Update()

# Show all descriptive statistics for whole ensemble
dStats0 = ds0.GetOutputDataObject( 1 )
dPrimary0 = dStats0.GetBlock( 0 )
dPrimary0.Dump( 15 )
dDerived0 = dStats0.GetBlock( 1 )
dDerived0.Dump( 15 )
print