Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -5,25 +5,83 @@ from aubio.tasks import * · 4 unmodified lines | |||
| 5 | 5 | ||
| 6 | class benchpitch(bench): | 6 | class benchpitch(bench): |
| 7 | 7 | ||
| 8 | """ list of values to store per file """ | ||
| 9 | valuenames = ['mode'] | ||
| 10 | """ list of lists to store per file """ | ||
| 11 | valuelists = ['orig', 'mean', 'med'] | ||
| 12 | """ list of values to print per dir """ | ||
| 13 | printnames = [ 'mode'] | ||
| 14 | |||
| 15 | """ per dir """ | ||
| 16 | formats = {'mode': "%12s" , 'thres': "%5.4s", | ||
| 17 | 'dist': "%5.4s", 'prec': "%5.4s", 'recl': "%5.4s", | ||
| 18 | 'Ttrue': "%5.4s", 'Tfp': "%5.4s", 'Tfn': "%5.4s", | ||
| 19 | 'Tm': "%5.4s", 'Td': "%5.4s", | ||
| 20 | 'aTtrue':"%5.4s", 'aTfp': "%5.4s", 'aTfn': "%5.4s", | ||
| 21 | 'aTm': "%5.4s", 'aTd': "%5.4s", | ||
| 22 | 'mean': "%5.40s", 'smean': "%5.40s", | ||
| 23 | 'amean': "%5.40s", 'samean': "%5.40s"} | ||
| 24 | |||
| 25 | def dir_eval(self): | ||
| 26 | """ evaluate statistical data over the directory """ | ||
| 27 | v = self.v | ||
| 28 | |||
| 29 | v['mode'] = self.params.pitchmode | ||
| 30 | |||
| 8 | def file_exec(self,input,output): | 31 | def file_exec(self,input,output): |
| 9 | filetask = self.task(input,params=self.params) | 32 | filetask = self.task(input,params=self.params) |
| 10 | computed_data = filetask.compute_all() | 33 | computed_data = filetask.compute_all() |
| 11 | results = filetask.eval(computed_data) | 34 | orig,mean,med = filetask.eval(computed_data) |
| 12 | self.results.append(results) | 35 | |
| 13 | truth = filetask.gettruth() | 36 | self.v['orig'].append(orig) |
| 37 | self.v['mean'].append(mean) | ||
| 38 | self.v['med'].append(med) | ||
| 39 | #print results#, computed_data | ||
| 14 | #print input, results, results - float(input.split('.')[-2]) | 40 | #print input, results, results - float(input.split('.')[-2]) |
| 15 | self.pretty_print((self.params.pitchmode, truth, | ||
| 16 | truth - results[0], results[0], | ||
| 17 | truth - results[1], results[1])) | ||
| 18 | 41 | ||
| 19 | def run_bench(self,modes=['schmitt']): | 42 | def run_bench(self,modes=['schmitt']): |
| 43 | from os.path import basename | ||
| 44 | d = [] | ||
| 20 | self.modes = modes | 45 | self.modes = modes |
| 21 | self.pretty_print(self.titles) | 46 | self.pretty_titles() |
| 22 | for mode in self.modes: | 47 | for mode in self.modes: |
| 23 | self.params.pitchmode = mode | 48 | self.params.pitchmode = mode |
| 24 | self.dir_exec() | 49 | self.dir_eval_print() |
| 25 | self.dir_eval() | 50 | self.plotpitchtessiture(d, |
| 26 | self.dir_plot() | 51 | self.v['orig'], |
| 52 | self.v['med'], | ||
| 53 | plottitle=self.v['mode'], | ||
| 54 | plotmode='points') | ||
| 55 | #d.append('beta = .25,orig(x) title \"-2 octave\"') | ||
| 56 | d.append('beta = .50,orig(x) title \"-1 octave\"') | ||
| 57 | d.append('beta = 1.0,orig(x) title \"original\"') | ||
| 58 | d.append('beta = 2.0,orig(x) title \"+1 octave\"') | ||
| 59 | title = basename(self.datadir) | ||
| 60 | outplot = "_-_".join(('pitchtessiture',title)) | ||
| 61 | for ext in ('ps','png','svg',''): | ||
| 62 | self.plotplotpitchtessiture(d, | ||
| 63 | plottitle=title, | ||
| 64 | outplot=outplot, | ||
| 65 | extension=ext) | ||
| 66 | |||
| 67 | """ | ||
| 68 | Plot functions | ||
| 69 | """ | ||
| 70 | |||
| 71 | def plotpitchtessiture(self,d,lx,ly,plottitle="",plotmode='linespoints'): | ||
| 72 | import Gnuplot, Gnuplot.funcutils | ||
| 73 | d.append(Gnuplot.Data(lx, ly, with=plotmode, title="%s" % (plottitle) )) | ||
| 74 | |||
| 75 | def plotplotpitchtessiture(self,d,plottitle='',outplot=0,extension=''): | ||
| 76 | from aubio.gnuplot import gnuplot_create | ||
| 77 | g = gnuplot_create(outplot=outplot,extension=extension) | ||
| 78 | g.title(plottitle) | ||
| 79 | g('orig(x) = beta*x') | ||
| 80 | g.xlabel('original pitch (Hz)') | ||
| 81 | g.ylabel('detected pitch (Hz)') | ||
| 82 | g('set log xy') | ||
| 83 | g.plot(*d) | ||
| 84 | |||
| 27 | 85 | ||
| 28 | if __name__ == "__main__": | 86 | if __name__ == "__main__": |
| 29 | import sys | 87 | import sys |
| @@ -31,15 +89,17 @@ if __name__ == "__main__": · 1 unmodified line | |||
| 31 | else: print "error: a path is required"; sys.exit(1) | 89 | else: print "error: a path is required"; sys.exit(1) |
| 32 | if len(sys.argv) > 2: | 90 | if len(sys.argv) > 2: |
| 33 | for each in sys.argv[3:-1]: print each | 91 | for each in sys.argv[3:-1]: print each |
| 34 | modes = ['yin', 'schmitt', 'mcomb', 'fcomb'] | 92 | modes = ['schmitt', 'yin', 'mcomb', 'fcomb'] |
| 93 | #modes = ['fcomb'] | ||
| 35 | 94 | ||
| 36 | benchpitch = benchpitch(datapath) | 95 | params = taskparams() |
| 37 | benchpitch.params = taskparams() | 96 | params.bufsize = 2048 |
| 97 | params.hopsize = params.bufsize/2 | ||
| 98 | benchpitch = benchpitch(datapath,params=params) | ||
| 38 | benchpitch.task = taskpitch | 99 | benchpitch.task = taskpitch |
| 39 | 100 | ||
| 40 | 101 | #benchpitch.titles = [ 'mode', 'thres', 'avg', 'avgdist' ] | |
| 41 | benchpitch.titles = [ 'mode', 'thres', 'avg', 'avgdist' ] | 102 | #benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ] |
| 42 | benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ] | ||
| 43 | try: | 103 | try: |
| 44 | benchpitch.run_bench(modes=modes) | 104 | benchpitch.run_bench(modes=modes) |
| 45 | except KeyboardInterrupt: | 105 | except KeyboardInterrupt: |