-
Notifications
You must be signed in to change notification settings - Fork 0
/
whats_in_dict.py
102 lines (71 loc) · 2.68 KB
/
whats_in_dict.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
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
import open_h5 as oh
import os
import numpy as np
def print_files_available():
print "Files available:"
files_h5 = []
for i,filenames in enumerate(os.listdir(os.getcwd())):
if filenames.endswith(".hdf5"):
files_h5.append(filenames)
if filenames.endswith('.h5'):
files_h5.append(filenames)
return files_h5
def which_file():
print_h5_files = print_files_available()
print print_h5_files
file_to_read = raw_input("Introduce file to read (file.h5): ")
if file_to_read =='':
if len(print_h5_files) != 0:
print 'Loading file %s by default'%print_h5_files[0]
print print_h5_files
file_to_read = print_h5_files[0]
if file_to_read.find('.h5') == -1 and file_to_read.find('.hdf5') == -1:
print 'File %s has no .h5 nor .hdf5 extensions.'%file_to_read
file_to_read = raw_input("Introduce file to read (file.h5): ")
print file_to_read
return file_to_read
def make_dict():
file_to_read = which_file()
dictionary = oh.main(file_to_read)
if dictionary != None:
all_dictionary = dictionary.keys()
#print all_dictionary
first_entry = dictionary.get('entry01')
return first_entry
else:
print 'Dictionary was not produced'
def get_parameters(index_M,index_Ix,index_Iy):
first_entry = make_dict()
Qx = first_entry.get('Qx')
Qy = first_entry.get('Qy')
Qz = first_entry.get('Qz')
I = first_entry.get('I')
M = first_entry.get('M')
C = [I, M, Qx, Qy, Qz]
print "I = %f"%C[0][index_M][index_Ix][index_Iy]
print "M = %f"%C[1][index_M]
print "Qx = %f"%C[2][index_Ix][index_Iy]
print "Qy = %f"%C[3][index_Ix][index_Iy]
print "Qz = %f"%C[4][index_Ix][index_Iy]
return C
def get_keys():
first_entry = make_dict()
return first_entry, first_entry.keys()
def get_type(object):
if type(object) == np.ndarray:
return object.shape, object.size
else:
type_object = str(object)
print '%s not an array'%type_object
if __name__ == '__main__':
#get_parameters(0,60,100)
keys = get_keys()
print keys[1]
for i, key in enumerate(keys[1]):
one_key = keys[1][i]
#get_type(one_key)
key_length = len(keys[0].get(one_key))
get_type(keys[0].get(one_key))
shape = str(get_type(keys[0].get(one_key))[0])
size = str(get_type(keys[0].get(one_key))[1])
print '%s has shape %s and size %s'%(one_key, shape, size)