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