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 lib.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 places: The number of decimal places to print.
41 @type places: int
42 @keyword epsilon: The minimum value, below which is considered zero.
43 @type epsilon: float
44 @keyword integer: A flag which if true will only print the integer part of the number.
45 @type integer: bool
46 @keyword dot: A flag which if true replaces all zeros with dot characters.
47 @type dot: bool
48 @keyword comma: A flag which if true causes commas to be printed between the elements.
49 @type comma: bool
50 @keyword file: The file object to write to.
51 @type file: file object
52 """
53
54
55 if not name:
56 name = 'Frame Order matrix, 2nd degree'
57
58
59 if file == None:
60 file = sys.stdout
61
62
63 file.write("\n%s:\n" % name)
64 file.write('[[')
65
66
67 if isinstance(daeg, matrix):
68 daeg = array(daeg)
69
70
71 for i in range(len(daeg)):
72
73 if i != 0:
74 file.write(' [')
75
76
77 char2 = ''
78 if comma:
79 char2 = ','
80 if i == len(daeg) - 1:
81 char2 = ']'
82
83
84 for j in range(len(daeg[i])):
85
86 char1 = ''
87 if comma:
88 char1 = ','
89 if j == len(daeg[i]) - 1:
90 char1 = ']%s\n' % char2
91
92
93 if abs(daeg[i, j]) > epsilon:
94
95 if integer:
96 val = int(daeg[i, j])
97 format = "%" + repr(places) + "i%s"
98
99
100 else:
101 val = daeg[i, j]
102 format = "%" + repr(places+6) + "." + repr(places) + "f%s"
103
104
105 elif isNaN(daeg[i, j]):
106 val = 'NaN'
107 if integer:
108 format = "%" + repr(places) + "i%s"
109 else:
110 format = "%" + repr(places+6) + "s%s"
111
112
113 else:
114
115 if integer:
116 format = "%" + repr(places) + "s%s"
117
118
119 else:
120 format = "%" + repr(places+6) + "s%s"
121
122
123 if dot:
124 val = '.'
125 else:
126 val = '0'
127
128
129 file.write(format % (val, char1))
130