3 """Copyright (C) 2004 Paul Brossier <piem@altern.org>
5 print aubio.__LICENSE__ for the terms of use
7 or see LICENSE.txt in the aubio installation directory.
10 Copyright (C) 2004-2009 Paul Brossier <piem@aubio.org>
12 This file is part of aubio.
14 aubio is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
19 aubio is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with aubio. If not, see <http://www.gnu.org/licenses/>.
33 (both must be text files with 1 time a line expressed in seconds)
36 -D <delay> delay in seconds
41 results:number of correct detections
42 number of incorrect detections
43 number of doubled detections
44 number of total detections
45 number of total targets
48 $ aubioonset-comp -c checked-onsets.txt -o handlab-onsets.txt -v
49 ( gd fp dd ) tot / real
51 55.5555555556 %GD 44.4444444444 %FP 0.0 %OD
54 does not scale to very long lists
58 from aubio.onsetcompare import onset_roc, onset_diffs
59 from aubio.txtfile import read_datafile
62 fileo=None;filec=None;vmode=None;dmode=None;delay=0.
63 # default tolerance is 50 ms
66 # default mode is onset
69 while len(sys.argv) >=2:
70 option = sys.argv[1]; del sys.argv[1]
71 if option == '-h': print __HELP__; sys.exit()
72 if option == '-o': fileo = sys.argv[1]; del sys.argv[1]
73 if option == '-c': filec = sys.argv[1]; del sys.argv[1]
74 if option == '-v': vmode = 'verbose'
75 if option == '-d': dmode = 'debug'
76 if option == '-D': delay = float(sys.argv[1]); del sys.argv[1]
77 if option == '-tol': tol = float(sys.argv[1]); del sys.argv[1]
78 if option == '-l': mode = 'localisation'
81 if (not fileo) or (not filec):
82 print 'wrong set of arguments. use \'-h\' for help'
83 sys.exit('error: needs at least \'-c targets.txt -o detected.txt\'')
86 ltru, lres = read_datafile(fileo,depth=0),read_datafile(filec,depth=0)
88 # delay onsets as required with -D
90 for i in range(len(lres)):
91 lres[i] = lres[i] + delay
92 # compute errors types
93 if mode == 'localisation':
94 l = onset_diffs(ltru,lres,tol)
95 for i in l: print "%.3f" % i
97 orig, missed, merged, expc, bad, doubled = onset_roc(ltru,lres,tol)
100 #print "orig, missed, merged, expc, bad, doubled:"
104 print "missed",missed
105 print "merged", merged
107 print "doubled", doubled
108 print "correct", orig-missed-merged
109 print "GD %2.8f\t" % (100*float(orig-missed-merged)/(orig)),
110 print "FP %2.8f\t" % (100*float(bad+doubled)/(orig)) ,
111 print "GD-merged %2.8f\t" % (100*float(orig-missed)/(orig)) ,
112 print "FP-pruned %2.8f\t" % (100*float(bad)/(orig))
114 print orig, missed, merged, expc, bad, doubled