1 | #! /usr/bin/python |
---|
2 | |
---|
3 | """Copyright (C) 2004 Paul Brossier <piem@altern.org> |
---|
4 | |
---|
5 | print aubio.__LICENSE__ for the terms of use |
---|
6 | |
---|
7 | or see LICENSE.txt in the numarray installation directory. |
---|
8 | """ |
---|
9 | __LICENSE__ = """\ |
---|
10 | Copyright (C) 2004 Paul Brossier <piem@altern.org> |
---|
11 | |
---|
12 | This program is free software; you can redistribute it and/or modify |
---|
13 | it under the terms of the GNU General Public License as published by |
---|
14 | the Free Software Foundation; either version 2 of the License, or |
---|
15 | (at your option) any later version. |
---|
16 | |
---|
17 | This program is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | GNU General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
25 | """ |
---|
26 | |
---|
27 | |
---|
28 | __HELP__ = """\ |
---|
29 | # required arguments |
---|
30 | -c targetfilename |
---|
31 | -o detectfilename |
---|
32 | (both must be text files with 1 time a line expressed in seconds) |
---|
33 | |
---|
34 | # optional arguments |
---|
35 | -D <delay> delay in seconds |
---|
36 | -v verbose mode |
---|
37 | -d debug mode |
---|
38 | |
---|
39 | # output |
---|
40 | results:number of correct detections |
---|
41 | number of incorrect detections |
---|
42 | number of doubled detections |
---|
43 | number of total detections |
---|
44 | number of total targets |
---|
45 | |
---|
46 | # example: |
---|
47 | $ aubioonset-comp -c checked-onsets.txt -o handlab-onsets.txt -v |
---|
48 | ( gd fp dd ) tot / real |
---|
49 | ( 5 4 0 ) 9 / 9 |
---|
50 | 55.5555555556 %GD 44.4444444444 %FP 0.0 %OD |
---|
51 | |
---|
52 | # bugs |
---|
53 | does not scale to very long lists |
---|
54 | """ |
---|
55 | |
---|
56 | import sys |
---|
57 | from aubio.onsetcompare import onset_roc |
---|
58 | from aubio.txtfile import read_datafile |
---|
59 | |
---|
60 | # default values |
---|
61 | fileo=None;filec=None;vmode=None;dmode=None;delay=0. |
---|
62 | # default tolerance is 50 ms |
---|
63 | tol = 0.050 |
---|
64 | |
---|
65 | while len(sys.argv) >=2: |
---|
66 | option = sys.argv[1]; del sys.argv[1] |
---|
67 | if option == '-h': print __HELP__; sys.exit() |
---|
68 | if option == '-o': fileo = sys.argv[1]; del sys.argv[1] |
---|
69 | if option == '-c': filec = sys.argv[1]; del sys.argv[1] |
---|
70 | if option == '-v': vmode = 'verbose' |
---|
71 | if option == '-d': dmode = 'debug' |
---|
72 | if option == '-D': delay = float(sys.argv[1]); del sys.argv[1] |
---|
73 | |
---|
74 | # arguments required |
---|
75 | if (not fileo) or (not filec): |
---|
76 | print 'wrong set of arguments. use \'-h\' for help' |
---|
77 | sys.exit('error: needs at least \'-c targets.txt -o detected.txt\'') |
---|
78 | |
---|
79 | # load files |
---|
80 | ltru, lres = read_datafile(fileo,depth=0),read_datafile(filec,depth=0) |
---|
81 | |
---|
82 | # delay onsets as required with -D |
---|
83 | for i in range(len(lres)): |
---|
84 | lres[i] = lres[i] + delay |
---|
85 | # compute errors types |
---|
86 | ok, bad, missed, total, hits = onset_roc(ltru,lres,tol) |
---|
87 | |
---|
88 | # print results |
---|
89 | if vmode=='verbose': |
---|
90 | print '( ok bad missed ) tot / hits \t', |
---|
91 | print '(', ok, bad, missed, ')', total, '/', hits, |
---|
92 | print '\t', |
---|
93 | print 100*float(ok)/(ok+missed), '%GD\t', |
---|
94 | print 100*float(bad)/(hits+bad), '%FP\t' |
---|
95 | else: |
---|
96 | print ok, bad, missed, total, hits |
---|