Module ortho_batch_r
[frames] | no frames]

Source Code for Module ortho_batch_r

 1  #!/usr/bin/env python 
 2   
 3  import ortho_poly 
 4  import sys 
 5  import die 
 6  import avio 
 7   
 8   
 9  """Do a batch reconstruction of orthogonal polynomial fits, 
10  based on input which is contains coefficients 
11  in avio format, with names specified by PATTERN. 
12  """ 
13   
14   
15  try: 
16          enumerate([]) 
17  except NameError: 
18          from g_enumerate import enumerate 
19   
20  PATTERN = 'i%02d' 
21  N = 100 
22   
23   
24  if __name__ == '__main__': 
25          xa = None 
26          arglist = sys.argv[1:] 
27          excel = 0 
28          OPNAME = Legendre 
29          while arglist and arglist[0].startswith('-'): 
30                  arg = arglist.pop(0) 
31                  if arg == '-name': 
32                          OPNAME = arglist.pop(0) 
33                  elif arg == '-n': 
34                          N = int(arglist.pop(0)) 
35                  elif arg == '-excel': 
36                          excel = 1 
37                  elif arg == '--': 
38                          break 
39                  else: 
40                          die.die('Bad arg: %s' % arg) 
41   
42          out = [] 
43          for x in sys.stdin: 
44                  if x.startswith('#'): 
45                          continue 
46                  x = x.strip() 
47                  if x == '': 
48                          continue 
49                  a = avio.parse(x) 
50                  i = 0 
51                  c = [] 
52                  while PATTERN%i in a: 
53                          c.append( float(a[PATTERN%i]) ) 
54                          i += 1 
55                  op = ortho_poly.F(OPNAME, n=N) 
56                  out.append( op.expand(c) ) 
57          for j in range(N): 
58                  tmp = [] 
59                  if not excel: 
60                          tmp.append('%d' % j) 
61                          tmp.append('%g' % op.x[j]) 
62                  for k in range(len(out)): 
63                          if excel: 
64                                  tmp.append('%d' % j) 
65                          tmp.append( '%g' % out[k][j]) 
66                  print '\t'.join(tmp) 
67