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 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      @keyword file:      The file object to write to. 
 49      @type file:         file object 
 50      """ 
 51   
 52       
 53      if not name: 
 54          name = 'Frame Order matrix, 2nd degree' 
 55   
 56       
 57      if file == None: 
 58          file = sys.stdout 
 59   
 60       
 61      file.write("\n%s:\n" % name) 
 62      file.write('[[') 
 63   
 64       
 65      if isinstance(daeg, matrix): 
 66          daeg = array(daeg) 
 67   
 68       
 69      for i in range(len(daeg)): 
 70           
 71          if i != 0: 
 72              file.write(' [') 
 73   
 74           
 75          char2 = '' 
 76          if comma: 
 77              char2 = ',' 
 78          if i == len(daeg) - 1: 
 79              char2 = ']' 
 80   
 81           
 82          for j in range(len(daeg[i])): 
 83               
 84              char1 = '' 
 85              if comma: 
 86                  char1 = ',' 
 87              if j == len(daeg[i]) - 1: 
 88                  char1 = ']%s\n' % char2 
 89   
 90               
 91              if abs(daeg[i, j]) > epsilon: 
 92                   
 93                  if integer: 
 94                      val = int(daeg[i, j]) 
 95                      format = "%4i%s" 
 96   
 97                   
 98                  else: 
 99                      val = daeg[i, j] 
100                      format = "%10.4f%s" 
101   
102               
103              elif isNaN(daeg[i, j]): 
104                  val = 'NaN' 
105                  if integer: 
106                      format = "%4i%s" 
107                  else: 
108                      format = "%10s%s" 
109   
110               
111              else: 
112                   
113                  if integer: 
114                      format = "%4s%s" 
115   
116                   
117                  else: 
118                      format = "%10s%s" 
119   
120                   
121                  if dot: 
122                      val = '.' 
123                  else: 
124                      val = '0' 
125   
126               
127              file.write(format % (val, char1)) 
 128