Beispiel #1
0
    def __call__(self, plgfile):
        """
        Calculate summary statistics for the input file.  Returns a
        dictionary if the operation succeeded; raises a ValueError object if
        not.
        """
        import numpy as nx
        from chirp.common import plg
        estimator = self.options['estimator']

        p = plg.read(plgfile)
        if estimator not in p.dtype.names: raise ValueError, "estimator %s is missing" % estimator

        ind = self.postfilter(p)
        ind &= nx.isfinite(p[estimator])
        pfilt = p[ind]
        pitch = pfilt[estimator]
        if pfilt.size == 0: raise ValueError("no valid points after filtering")
        return {'nelements': nx.unique(pfilt['element']).size,
                'duration': pfilt['time'].max() - pfilt['time'].min(),
                'pitch.mean': nx.mean(pitch),
                'pitch.std': nx.std(pitch),
                'pitch.median': nx.median(pitch),
                'pitch.max': nx.max(pitch),
                'pitch.min': nx.min(pitch),
                'pow.mean': nx.mean(pfilt['stim.pow']),
                'dropped.points': p.size - pfilt.size}
Beispiel #2
0
def load_data(basename, filterer=None, pitchdir=None):
    """
    Load data from wav and plg files. If filterer is not None, filters
    pitch trace.
    """
    from ewave import wavfile
    from chirp.common import plg
    fp = wavfile(basename + ".wav")
    signal, Fs = fp.read(), fp.sampling_rate

    if isinstance(pitchdir, basestring):
        plgfile = os.path.join(pitchdir, os.path.split(basename)[1] + '.plg')
    else:
        plgfile = basename + '.plg'
    if not os.path.exists(plgfile):
        return signal, Fs / 1000., None, None

    pitch = plg.read(plgfile)
    if filterer is not None:
        ind = postfilter.ind_endpoints(filterer(pitch))
        if ind is None:
            return signal, Fs / 1000., None, None
        pitch = pitch[ind[0]:ind[1] + 1]
    t = pitch['time']
    if 'p.map' in pitch.dtype.names:
        p = pitch['p.map']
    else:
        p = pitch['p.mmse']
    return signal, Fs / 1000., t, p
Beispiel #3
0
def _load_plg(locator, filt, estimator):
    """
    Load a pitch trace and filters it. If no points are
    reliable, returns None.
    """
    from chirp.common import plg
    pest = plg.read(locator)
    ind = filt(pest)
    if not any(ind):
        return None
    else:
        ind = postfilter.ind_endpoints(ind)
        return pest[estimator][ind[0]:ind[1] + 1]
Beispiel #4
0
 def plot_plg(self, plgfile):
     """
     Read data from a plg file and plot it.  This is a single trace
     because estimates are collapsed across chains.
     """
     pest = plg.read(plgfile)
     t = pest['time']
     if 'p.map' in pest.dtype.names:
         f = pest['p.map']
     else:
         f = pest['p.mmse']
     ind = self.filter(pest)
     self.remove_trace()
     self.add_trace(t[ind], f[ind])
     self.add_trace(t[~ind], f[~ind], color='k')