File: statistics_temperatures.py

package info (click to toggle)
paraview 5.0.0%2Bdfsg1-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 225,112 kB
  • sloc: cpp: 2,432,495; ansic: 204,338; python: 97,967; xml: 79,887; tcl: 46,936; fortran: 26,923; yacc: 4,926; java: 4,413; perl: 3,108; sh: 2,775; lex: 1,934; f90: 748; asm: 471; pascal: 228; makefile: 192; objc: 17
file content (77 lines) | stat: -rw-r--r-- 2,101 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
import os.path
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists( data_dir ):
  data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists( data_dir ):
  data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "temperatures.db"

# Pull the table from the database
databaseToTable = vtkSQLDatabaseTableSource()
databaseToTable.SetURL("sqlite://" + sqlite_file)
databaseToTable.SetQuery("select * from main_tbl")

# Calculate descriptive statistics
print("# Calculate descriptive statistics:")
ds = vtkDescriptiveStatistics()
ds.AddInputConnection( databaseToTable.GetOutputPort() )
ds.AddColumn("Temp1")
ds.AddColumn("Temp2")
ds.Update()

dStats = ds.GetOutputDataObject( 1 )
dPrimary = dStats.GetBlock( 0 )
dDerived = dStats.GetBlock( 1 )
dPrimary.Dump( 15 )
dDerived.Dump( 15 )
print()

print("# Calculate 5-point statistics:")
# Calculate 5-point statistics
os = vtkOrderStatistics()
os.AddInputConnection( databaseToTable.GetOutputPort() )
os.AddColumn("Temp1")
os.AddColumn("Temp2")
os.Update()

oStats = os.GetOutputDataObject( 1 )
oQuantiles = oStats.GetBlock( 2 )
oQuantiles.Dump( 15 )
print()

print("# Calculate deciles:")
# Calculate deciles
os.SetNumberOfIntervals(10)
os.Update()

oStats = os.GetOutputDataObject( 1 )
oQuantiles = oStats.GetBlock( 2 )
oQuantiles.Dump( 9 )
print()

print("# Calculate correlation and linear regression:")
# Calculate correlation and linear regression
cs = vtkCorrelativeStatistics()
cs.AddInputConnection( databaseToTable.GetOutputPort() )
cs.AddColumnPair("Temp1","Temp2")
cs.SetAssessOption(1)
cs.Update()

cStats = cs.GetOutputDataObject( 1 )
cPrimary = cStats.GetBlock(0)
cDerived = cStats.GetBlock(1)
cPrimary.Dump( 15 )
cDerived.Dump( 15 )
print()

print("# Report corresponding deviations (squared Mahalanobis distance):")
# Report corresponding deviations (squared Mahalanobis distance):"
cData = cs.GetOutput(0)
cData.Dump( 15 )
print()