This repository has been archived by the owner on Mar 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_correlation_table.py
executable file
·71 lines (57 loc) · 2.88 KB
/
create_correlation_table.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
60
61
62
63
64
65
66
67
68
69
70
71
from tables import openFile, IsDescription, Float64Col, Int16Col
from scipy import array
import numpy as np
from get_number_of_plates import get_number_of_plates
def create_correlation_table(plot_variable1, plot_variable2, values1, values2, seconds):
if len(values2) == len(values1):
print ''
print 'Creating new table...'
print ''
number_of_plates1 = 0
number_of_plates2 = 0
if plot_variable1[0][0] in ('pulseheights', 'integrals'):
number_of_plates1 = get_number_of_plates(values1[0])
if plot_variable2[0][0] in ('pulseheights', 'integrals'):
number_of_plates2 = get_number_of_plates(values2[0])
# declare a class
class Variable1(IsDescription):
if number_of_plates1 in range(1, 5) and number_of_plates2 in range(1, 5):
variable1 = Float64Col(shape=(number_of_plates1,))
variable2 = Float64Col(shape=[number_of_plates2,])
elif number_of_plates1 in range(1, 5) and number_of_plates2 not in range(1, 5):
variable1 = Float64Col(shape=(number_of_plates1,))
variable2 = Float64Col()
elif number_of_plates1 not in range(1, 5) and number_of_plates2 in range(1, 5):
variable1 = Float64Col()
variable2 = Float64Col(shape=(number_of_plates2,))
elif number_of_plates1 not in range(1, 5) and number_of_plates2 not in range(1, 5):
variable1 = Float64Col()
variable2 = Float64Col()
else:
print 'weird'
# create filename for correlation table from data filenames
intermediate1 = plot_variable1[0][1].replace('data_s%s_' % plot_variable1[0][2], '')
intermediate2 = intermediate1.partition('_')
start_date = intermediate2[0]
intermediate3 = intermediate2[2][1:]
end_date = intermediate3.replace('.h5', '')
filename = (('interpolated_table_%s_station%s_with_%s_station%s_%s_%s'
'_timeinterval_%d.h5') %
(plot_variable1[0][0], plot_variable1[0][2],
plot_variable2[0][0], plot_variable2[0][2],
start_date, end_date, seconds))
# make new table
with openFile(filename, 'w') as data_cor:
group_variable1 = data_cor.createGroup("/", 'correlation')
table_variable1 = data_cor.createTable(group_variable1, 'table', Variable1)
# Insert a new particle record
particle = table_variable1.row
for i in range(len(values1)):
particle['variable1'] = values1[i]
particle['variable2'] = values2[i]
particle.append()
table_variable1.flush()
print 'Done.'
return filename
else:
print 'Your variable lists are not of the same length. Interpolation is necessary.'