-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyse.py
59 lines (45 loc) · 1.3 KB
/
analyse.py
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
import xlrd
from helpers import *
import hist
def readData(fname, sname):
#read in the book and the sheet
book = xlrd.open_workbook(fname)
sheet = book.sheet_by_name(sname)
#get data column and lables
data = [sheet.cell_value(r, 0) for r in range(sheet.nrows)]
titles = [sheet.cell_value(r, 1) for r in range(3)]
return data, titles
def analyse(fname, sname, nbins):
#get data tuple
read = readData(fname, sname)
data = read[0] #data vector
labels = read[1] #plot labels
if not nbins:
nbins = setBins(data)['nbins']
#key word arguments for labels
lkeys = ['title', 'xlabel', 'ylabel']
largs = dict(zip(lkeys, labels))
#print setup
print 'label options:'
print largs
print 'DATA:'
print data
mean = calcMean(data)
mode = calcMode(data)
median = calcMed(data)
sdev = calcSD(data)
#print statistical values
print '\n\n'
print 'MEAN: ', str(mean)
print 'MODE: ', str(mode)
print 'MEDIAN: ', str(median)
print 'STD DEV: ', str(sdev)
print '\n\n'
#create histogram
hist.plotData(data, nbins, sname, **largs)
return {
'mean': mean,
'mode': mode,
'median': median,
'sdev': sdev
}