From: Paul Brossier Date: Wed, 2 Aug 2006 15:25:09 +0000 (+0000) Subject: factorise gnuplot_create options, update aubioplot-spec/audio X-Git-Tag: bzr2git~571 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0ab19df22676e5ef57ae16f014b7c0f6d4c91085;p=aubio.git factorise gnuplot_create options, update aubioplot-spec/audio factorise gnuplot_create options, update aubioplot-spec/audio --- diff --git a/python/aubio/gnuplot.py b/python/aubio/gnuplot.py index c1e7307d..f93f141c 100644 --- a/python/aubio/gnuplot.py +++ b/python/aubio/gnuplot.py @@ -162,18 +162,36 @@ def make_audio_plot(time,data,maxpoints=10000): x,y = downsample_audio(time,data,maxpoints=maxpoints) return Gnuplot.Data(x,y,with='lines') -def gnuplot_create(outplot='',extension='',debug=0,persist=1, xsize=1., ysize=1.): - import Gnuplot - g = Gnuplot.Gnuplot(debug=debug, persist=persist) - if not extension or not outplot: return g - if extension == 'ps': ext, extension = '.ps' , 'postscript' - elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced' - elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color' - elif extension == 'png': ext, extension = '.png', 'png' - elif extension == 'svg': ext, extension = '.svg', 'svg' - else: exit("ERR: unknown plot extension") - g('set terminal %s' % extension) - if outplot != "stdout": - g('set output \'%s%s\'' % (outplot,ext)) - g('set size %f,%f' % (xsize, ysize)) - return g +def gnuplot_addargs(parser): + """ add common gnuplot argument to OptParser object """ + parser.add_option("-x","--xsize", + action="store", dest="xsize", default=1., + type='float',help="define xsize for plot") + parser.add_option("-y","--ysize", + action="store", dest="ysize", default=1., + type='float',help="define ysize for plot") + parser.add_option("-d","--debug", + action="store_true", dest="debug", default=False, + help="use gnuplot debug mode") + parser.add_option("-p","--persist", + action="store_false", dest="persist", default=True, + help="do not use gnuplot persistant mode") + parser.add_option("-O","--outplot", + action="store", dest="outplot", default=None, + help="save plot to output.{ps,png}") + +def gnuplot_create(outplot='',extension='', options=None): + import Gnuplot + g = Gnuplot.Gnuplot(debug=options.debug, persist=options.persist) + if not extension or not outplot: return g + if extension == 'ps': ext, extension = '.ps' , 'postscript' + elif extension == 'eps': ext, extension = '.eps' , 'postscript enhanced' + elif extension == 'epsc': ext, extension = '.eps' , 'postscript enhanced color' + elif extension == 'png': ext, extension = '.png', 'png' + elif extension == 'svg': ext, extension = '.svg', 'svg' + else: exit("ERR: unknown plot extension") + g('set terminal %s' % extension) + if outplot != "stdout": + g('set output \'%s%s\'' % (outplot,ext)) + g('set size %f,%f' % (options.xsize, options.ysize)) + return g diff --git a/python/aubioplot-audio b/python/aubioplot-audio index 402943e0..f4cb0909 100755 --- a/python/aubioplot-audio +++ b/python/aubioplot-audio @@ -1,6 +1,7 @@ #!/usr/bin/python -import aubio.gnuplot, sys +import sys +from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_audio usage = "usage: %s [options] -i soundfile" % sys.argv[0] @@ -10,15 +11,7 @@ def parse_args(): parser.add_option("-i","--input", action="store", dest="filename", help="input sound file") - parser.add_option("-x","--xsize", - action="store", dest="xsize", default=1., - type='float',help="define xsize for plot") - parser.add_option("-y","--ysize", - action="store", dest="ysize", default=1., - type='float',help="define ysize for plot") - parser.add_option("-O","--outplot", - action="store", dest="outplot", default=None, - help="save plot to output.{ps,png}") + gnuplot_addargs(parser) (options, args) = parser.parse_args() if not options.filename: print "no file name given\n", usage @@ -34,7 +27,7 @@ else: extension = '' outplot = None -g = aubio.gnuplot.gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.xsize) -aubio.gnuplot.plot_audio(options.filename.split(','), g, +g = gnuplot_create(outplot,extension,options) +plot_audio(options.filename.split(','), g, xsize=options.xsize, ysize=options.ysize) diff --git a/python/aubioplot-spec b/python/aubioplot-spec index f7c8a357..6925728b 100755 --- a/python/aubioplot-spec +++ b/python/aubioplot-spec @@ -5,7 +5,7 @@ """ import sys -from aubio.gnuplot import * +from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_spec usage = "usage: %s [options] -i soundfile" % sys.argv[0] @@ -21,24 +21,16 @@ def parse_args(): parser.add_option("-L","--minf", action="store", dest="minf", default=0., type='float',help="lower frequency limit") - parser.add_option("-x","--xsize", - action="store", dest="xsize", default=1., - type='float',help="define xsize for plot") - parser.add_option("-y","--ysize", - action="store", dest="ysize", default=1., - type='float',help="define ysize for plot") parser.add_option("-l","--log", action="store_true", dest="log", default=False, help="plot on a logarithmic scale") - parser.add_option("-O","--outplot", - action="store", dest="outplot", default=None, - help="save plot to output.{ps,png}") parser.add_option("-B","--bufsize", type='int', action="store", dest="bufsize", default=8192, help="buffer size [default=8192]") parser.add_option("-H","--hopsize", type='int', action="store", dest="hopsize", default=1024, help="overlap size [default=1024]") + gnuplot_addargs(parser) (options, args) = parser.parse_args() if not options.filename: print "no file name given\n", usage @@ -55,7 +47,7 @@ else: extension = '' outplot = None -g = gnuplot_create(outplot,extension,xsize=options.xsize, ysize=options.ysize) +g = gnuplot_create(outplot,extension,options) plot_spec(filename, g, log=options.log, maxf = options.maxf, minf = options.minf, xsize = options.xsize, ysize = options.ysize,