source: python.old/aubiocompare-onset @ 45f48576

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 45f48576 was b554e41, checked in by Paul Brossier <piem@piem.org>, 12 years ago

moved out old python interface

  • Property mode set to 100755
File size: 3.5 KB
Line 
1#! /usr/bin/python
2
3"""Copyright (C) 2004 Paul Brossier <piem@altern.org>
4
5print aubio.__LICENSE__ for the terms of use
6
7or see LICENSE.txt in the aubio installation directory.
8"""
9__LICENSE__ = """\
10  Copyright (C) 2004-2009 Paul Brossier <piem@aubio.org>
11
12  This file is part of aubio.
13
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.
18
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.
23
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/>.
26"""           
27
28
29__HELP__ = """\
30# required arguments
31 -c targetfilename
32 -o detectfilename
33(both must be text files with 1 time a line expressed in seconds)
34
35# optional arguments
36 -D <delay>     delay in seconds
37 -v             verbose mode
38 -d             debug mode
39
40# output
41results:number of correct detections
42        number of incorrect detections
43        number of doubled detections
44        number of total detections
45        number of total targets
46
47# example:
48$ aubioonset-comp -c checked-onsets.txt -o handlab-onsets.txt -v
49( gd fp dd ) tot / real
50( 5 4 0 ) 9 / 9
5155.5555555556 %GD       44.4444444444 %FP       0.0 %OD
52
53# bugs
54does not scale to very long lists
55"""
56
57import sys
58from aubio.onsetcompare import onset_roc, onset_diffs
59from aubio.txtfile import read_datafile
60
61# default values
62fileo=None;filec=None;vmode=None;dmode=None;delay=0.
63# default tolerance is 50 ms
64#tol = 0.050
65tol = 0.048
66# default mode is onset
67mode = 'onset'
68
69while 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'
79
80# arguments required
81if (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\'')
84
85# load files
86ltru, lres = read_datafile(fileo,depth=0),read_datafile(filec,depth=0)
87
88# delay onsets as required with -D
89if delay:
90    for i in range(len(lres)):
91        lres[i] = lres[i] + delay
92# compute errors types
93if mode == 'localisation':
94        l = onset_diffs(ltru,lres,tol)
95        for i in l: print "%.3f" % i
96else:
97        orig, missed, merged, expc, bad, doubled = onset_roc(ltru,lres,tol)
98       
99        # print results
100        #print "orig, missed, merged, expc, bad, doubled:"
101        if vmode=='verbose':
102            print "orig", orig
103            print "expc", expc
104            print "missed",missed
105            print "merged", merged
106            print "bad", bad
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))               
113        else:
114            print  orig, missed, merged, expc, bad, doubled
Note: See TracBrowser for help on using the repository browser.