Module ortho_batch_fft_fiat
|
|
1
2
3 import math
4 import ortho_poly
5 import die
6 import sys
7 import g2_select
8 import os
9 sys.path.insert(0, '%s/lib' % os.environ['OXIROOT'])
10 import read_fft_fiat
11
12
13 """Do a batch reconstruction of orthogonal polynomial fits,
14 based on input which is contains coefficients
15 fft.fiat format.
16 """
17
18
19 try:
20 enumerate([])
21 except NameError:
22 from g_enumerate import enumerate
23
24 N = 100
25 YRANGE = None
26 XRANGE = None
27
29 return 12.0*math.log(1+y)/math.log(2.0)
30
31 if __name__ == '__main__':
32 arglist = sys.argv[1:]
33 s = None
34 pr = 'print'
35 id = '"%s/%s" % (d, phid)'
36 while arglist and arglist[0].startswith('-'):
37 arg = arglist.pop(0)
38 if arg == '-n':
39 N = int(arglist.pop(0))
40 elif arg == '-select':
41 s = arglist.pop(0)
42 elif arg == '-plot':
43 pr = 'plot'
44 elif arg == '-order':
45 pr = 'order'
46 elif arg == '-id':
47 id = arglist.pop(0)
48 elif arg == '-yr':
49 a = float(arglist.pop(0))
50 b = float(arglist.pop(0))
51 YRANGE = (a, b)
52 elif arg == '-xr':
53 a = float(arglist.pop(0))
54 b = float(arglist.pop(0))
55 XRANGE = (a, b)
56 elif arg == '--':
57 break
58 else:
59 die.die('Bad arg: %s' % arg)
60
61 filename = arglist[0]
62 h, data, c = read_fft_fiat.read(open(filename, 'r'))
63 if s is not None:
64 data = g2_select.filterlist(s, data)
65 OPNAME = h['ORTHONAME']
66 op = ortho_poly.F(OPNAME, n=N)
67 if pr == 'print':
68 for datum in data:
69 ae = ['%.3f' % x for x in op.expand(datum['A']) ]
70 print g2_select.evaluate(id, datum), ' '.join(ae)
71 elif pr == 'order':
72 for datum in data:
73 print g2_select.evaluate(id, datum), datum['A'].shape[0]
74 else:
75 import graphite
76 import os
77 g = graphite.Graph()
78 g.formats[0].lineStyle.width = 0.1
79 g.axes[graphite.X].tickMarks[0].labels = graphite.AUTO
80 g.axes[graphite.Y].tickMarks[0].labels = graphite.AUTO
81 g.axes[graphite.X].label.text = 'time, normalized'
82 g.axes[graphite.Y].label.text = 'f0 (semitones)'
83 g.title.text = '%s/%s' % (os.environ.get('PWD', '?'), str(s))
84 if YRANGE:
85 g.axes[graphite.Y].range = YRANGE
86 if XRANGE:
87 g.axes[graphite.X].range = XRANGE
88 for datum in data:
89 ds = []
90 for (i, y) in enumerate( op.expand(datum['A']) ):
91 ds.append( (i,yscale(y)) )
92 g.datasets.append(graphite.Dataset(ds))
93 graphite.genOutput(g, 'PS', canvasname='plot.ps')
94