1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module containing functions related to the Frame Order theories."""
24
25
26 from numpy import array, matrix
27 import sys
28
29
30 from float import isNaN
31
32
34 """Nicely print out the Frame Order matrix of the 2nd degree.
35
36 @param daeg: The 3D, rank-4 Frame Order matrix.
37 @type daeg: numpy 3D, rank-4 array
38 @keyword name: The name of the matrix.
39 @type name: None or str
40 @keyword epsilon: The minimum value, below which is considered zero.
41 @type epsilon: float
42 @keyword integer: A flag which if true will only print the integer part of the number.
43 @type integer: bool
44 @keyword dot: A flag which if true replaces all zeros with dot characters.
45 @type dot: bool
46 @keyword comma: A flag which if true causes commas to be printed between the elements.
47 @type comma: bool
48 """
49
50
51 if not name:
52 name = 'Frame Order matrix, 2nd degree'
53
54
55 sys.stdout.write("\n%s:\n" % name)
56 sys.stdout.write('[[')
57
58
59 if isinstance(daeg, matrix):
60 daeg = array(daeg)
61
62
63 for i in range(len(daeg)):
64
65 if i != 0:
66 sys.stdout.write(' [')
67
68
69 char2 = ''
70 if comma:
71 char2 = ','
72 if i == len(daeg) - 1:
73 char2 = ']'
74
75
76 for j in range(len(daeg[i])):
77
78 char1 = ''
79 if comma:
80 char1 = ','
81 if j == len(daeg[i]) - 1:
82 char1 = ']%s\n' % char2
83
84
85 if abs(daeg[i, j]) > epsilon:
86
87 if integer:
88 val = int(daeg[i, j])
89 format = "%4i%s"
90
91
92 else:
93 val = daeg[i, j]
94 format = "%10.4f%s"
95
96
97 elif isNaN(daeg[i, j]):
98 val = 'NaN'
99 if integer:
100 format = "%4i%s"
101 else:
102 format = "%10s%s"
103
104
105 else:
106
107 if integer:
108 format = "%4s%s"
109
110
111 else:
112 format = "%10s%s"
113
114
115 if dot:
116 val = '.'
117 else:
118 val = '0'
119
120
121 sys.stdout.write(format % (val, char1))
122