Exemple #1
0
 def __init__(self, configfile=None, **kwargs):
     self.readconfig(configfile)
     self.options.update(kwargs)
     self.filter = postfilter.pitchfilter(configfile=configfile, **kwargs)
Exemple #2
0
 def __init__(self, configfile=None):
     self.configfile = configfile
     self.filter = postfilter.pitchfilter(configfile=configfile)
     self.masker = geom.masker(configfile=configfile)
     self.trace_h = []
Exemple #3
0
 def __init__(self, configfile=None, **kwargs):
     """ Initialize the object with a config file """
     from chirp.common import postfilter
     self.readconfig(configfile)
     self.options.update(kwargs)
     self.postfilter = postfilter.pitchfilter(configfile, **kwargs)
Exemple #4
0
def multiplotter(outfile, config, cout=None, show_pitch=True, pitchdir=None):
    """
    A coroutine for plotting a bunch of motifs on the same page. A
    useful entry point for scripts that want to do something similar
    to cplotpitch, but with control over which motifs get plotted.
    """
    matplotlib.use('PDF')
    from matplotlib.backends.backend_pdf import PdfPages as multipdf
    from matplotlib.pyplot import close as close_figure
    from chirp.version import version
    from chirp.common.graphics import axgriditer
    from chirp.common.signal import spectrogram

    def gridfun(**kwargs):
        from matplotlib.pyplot import subplots
        return subplots(_nrows, _ncols, sharex=True, sharey=True, figsize=_figsize)

    def figfun(fig):
        maxx = max(ax.dataLim.x1 for ax in fig.axes)
        ax = fig.axes[0]
        ax.set_xticklabels('')
        ax.set_yticklabels('')
        ax.set_xlim(0, maxx)
        for ax in fig.axes:
            ax.yaxis.set_ticks_position('left')
            ax.xaxis.set_ticks_position('bottom')
        fig.subplots_adjust(left=0.05, right=0.95, wspace=0)
        pp.savefig(fig)
        close_figure(fig)

    # set up plotting
    pp = multipdf(outfile)
    axg = axgriditer(gridfun, figfun)
    spectrogram = spectrogram(configfile=config)
    plt = plotter(configfile=config)

    filt = postfilter.pitchfilter(configfile=config)
    print >> cout, filt.options_str()

    print >> cout, "* Plotting signals:"
    try:
        # first call to yield won't return anything
        ax = None
        while 1:
            # receives filename from caller and returns last axes
            basename = yield ax
            ax = axg.next()

            try:
                signal, Fs, t, p = load_data(basename, filt, pitchdir)
                print >> cout, "** %s" % basename
            except Exception, e:
                print >> cout, "** %s: error loading data (%s)" % (basename, e)
                continue
            spec, extent = spectrogram.dbspect(signal, Fs)
            plt.plot_spectrogram(ax, spec, extent)
            if show_pitch and t is not None:
                plt.plot_trace(ax, t, p)

        # loop will break when caller sends stop()
    finally:
        axg.close()
        pp.close()