def main(argv=None, cout=None, cerr=None, **kwargs): import sys from chirp.version import version if argv is None: argv = sys.argv[1:] if cout is None: cout = sys.stdout if cerr is None: cerr = sys.stderr import getopt from chirp.common.config import configoptions config = configoptions() opts, args = getopt.getopt(argv, 'hvc:m:') if len(args) < 1: print _scriptdoc return -1 for o, a in opts: if o == '-h': print _scriptdoc return -1 elif o == '-v': print "cpitchstats version %s" % version return -1 elif o == '-c': config.read(a) print >> cout, "* Program: cpitchstats" print >> cout, "** Version: %s" % version summary(config).summarize(args, cout, header=True) return 0
def __init__(self, title='chirp', size=(1000, 450), configfile=None): super(ChirpGui, self).__init__(None, -1, title, size=size) # load configuration file if one's supplied self.configfile = config.configoptions(configfile) self.create_menu() self.create_main_panel() self.filename = None
def main(argv=None, cout=None): import sys import getopt import glob from chirp.version import version if argv is None: argv = sys.argv[1:] if cout is None: cout = sys.stdout signals = None pitchdir = None config = configoptions() opts, args = getopt.getopt(sys.argv[1:], 'c:p:hv@') for o, a in opts: if o == '-h': print __doc__ return -1 elif o == '-v': print "%s version %s" % (_scriptname, version) return -1 elif o == '-p': pitchdir = a elif o == '-c': if not os.path.exists(a): print >> cout, "ERROR: config file %s doesn't exist" % a return -1 config.read(a) elif o == '-@': signals = (f.strip() for f in sys.stdin.readlines()) if len(args) < 1: print __doc__ sys.exit(-1) if not signals: if len(args) < 2: print __doc__ sys.exit(-1) signals = args[:-1] print >> cout, "* Program: cplotpitch" print >> cout, "** Version: %s" % version print >> cout, "** Loading pitch from %s" % (pitchdir or "same directory as signal") print >> cout, "** Output file: %s" % args[-1] plotter = multiplotter(args[-1], config, cout, pitchdir=pitchdir) for fname in signals: basename = os.path.splitext(fname)[0] ax = plotter.send(basename) ax.set_title(basename, ha='left', position=(0.0, 1.0), fontsize=4) return 0
def load_params(self, infile): self.configfile = config.configoptions(infile) # this is sort of kludgy, but it's not too much sig, Fs = self.spec.handler.signal, self.spec.handler.Fs self.spec.handler = SpecHandler(self.configfile) self.spec.handler.set_axes(self.spec.axes) self.win_size.SetValue(str(self.spec.handler.window_len)) self.shift_size.SetValue(str(self.spec.handler.shift)) self.dynrange.SetValue(str(self.spec.handler.dynrange)) self.cmap.SetValue(self.spec.handler.colormap) self.spec_method.SetValue(self.spec.handler.method) if sig is not None: self.spec.handler.plot_data(sig, Fs)
def main(argv=None, cout=None, cerr=None, **kwargs): import os import sys from chirp.version import version if argv is None: argv = sys.argv[1:] if cout is None: cout = sys.stdout if cerr is None: cerr = sys.stderr import getopt from chirp.common.config import configoptions config = configoptions() opts, args = getopt.getopt(argv, 'hvc:') for o, a in opts: if o == '-h': print _scriptdoc return -1 elif o == '-v': print " %s version %s" % (_scriptname, version) return -1 elif o == '-c': config.read(a) if len(args) < 1: print _scriptdoc return -1 wavfile = args[0] basename = os.path.splitext(wavfile)[0] if len(args) > 1: maskfile = args[1] else: maskfile = basename + ".ebl" print >> cout, "* Program: %s" % _scriptname print >> cout, "** Version: %s" % version print >> cout, "* Sound file: %s" % wavfile print >> cout, "* Mask file: %s" % maskfile splt = splitter(config) print >> cout, splt.options_str() for i, signal, Fs in splt.splitfile(wavfile, maskfile, cout=cout): outfile = "%s_e%03d.wav" % (os.path.split(basename)[1], i) print "** Writing extracted signal to %s" % outfile fp = ewave.wavfile(outfile, 'w', sampling_rate=Fs * 1000) fp.write(signal)
def on_start(self, event): # load data from controls. I wind up duplicating a lot # # of stuff in ccompare.main, unfortunately filedir = self.filedir.GetPath() if len(filedir) == 0: self.status.SetStatusText("No analyis directory selected") return store_loc = self.storageloc.GetValue() if len(store_loc) == 0: self.status.SetStatusText("No storage location selected") return config = configoptions() cfg = self.config.GetPath() if len(cfg) > 0: config.read(cfg) store_options = dict() store_options['restrict'] = self.restrict.GetValue() store_options['skip'] = self.skipcompl.GetValue() nw = self.nworkers.GetValue() # load classes compare_class = plugins.methods.load(self.method.GetStringSelection()) storage_class = plugins.storage.load(self.storage.GetStringSelection()) comparator = compare_class(configfile=config) storager = storage_class(comparator, location=store_loc, signals=filedir, **store_options) storager.write_metadata(comparator.options_str()) storager.write_metadata(storager.options_str()) # load the signals self._disable_interface() try: self.batch_thread = CompareThread(self, storager, comparator, nw) self.batch_thread.daemon = True self.batch_thread.start() except Exception, e: self._enable_interface() self.status.SetStatusText("Error: %s" % e)
def cpitch(argv=None, cout=None, cerr=None, **kwargs): """ The script front-end """ import sys from chirp.version import version if argv is None: argv = sys.argv[1:] if cout is None: cout = sys.stdout if cerr is None: cerr = sys.stderr import getopt from chirp.common.config import configoptions config = configoptions() maskfile = None opts, args = getopt.getopt(argv, 'hvc:m:') for o, a in opts: if o == '-h': print _scriptdoc return -1 elif o == '-v': print "cpitch version %s" % version return -1 elif o == '-c': if not os.path.exists(a): print >> cout, "ERROR: config file %s doesn't exist" % a return -1 config.read(a) elif o == '-m': maskfile = a if len(args) < 1: print _scriptdoc return -1 print >> cout, "* Program: cpitch" print >> cout, "** Version: %s" % version print >> cout, "* Input: %s" % args[0] from ewave import wavfile try: fp = wavfile(args[0]) except IOError: print >> cerr, "No such file %s" % args[0] return -2 except: print >> cerr, "Input file %s must be in WAV format" % args[0] return -2 pcm = fp.read() samplerate = fp.sampling_rate / 1000. print >> cout, "** Samples:", pcm.size print >> cout, "** Samplerate: %.2f (kHz)" % samplerate pt = tracker(configfile=config, samplerate=samplerate * 1000, **kwargs) print >> cout, pt.spectrogram_options_str() print >> cout, pt.template_options_str() print >> cout, "* DLFT spectrogram:" spec, tgrid, fgrid = pt.matched_spectrogram(pcm, samplerate) print >> cout, "** Dimensions:", spec.shape print >> cout, pt.particle_options_str() if maskfile is not None and os.path.exists(maskfile): from chirp.common.geom import elementlist, masker print >> cout, "* Mask file:", maskfile elems = elementlist.read(maskfile) mask = masker(configfile=config, **kwargs) for startcol, mspec, imask in mask.split(spec, elems, tgrid, fgrid, cout=cout): try: startframe, pitch_mmse, pitch_var, pitch_map, stats = pt.track(mspec, cout=cout, mask=imask) stats['p.map'] = None if pitch_map is None else pitch_map * samplerate T = tgrid[startframe + startcol:startframe + startcol + pitch_mmse.shape[0]] # + tracker.options['winsize'] / (samplerate * 1000) ?? ptrace = pitchtrace(T, pitch_mmse * samplerate, pitch_var * samplerate * samplerate, **stats) print >> cout, "*** Pitch calculations:" ptrace.write(cout) except ValueError, e: print >> cout, "*** Pitch calculation error: %s" % e continue
def main(argv=None, cout=None): import sys import os from chirp.version import version if argv is None: argv = sys.argv[1:] if cout is None: cout = sys.stdout import getopt from chirp.common.config import configoptions config = configoptions() opts, args = getopt.getopt(argv, 'hvc:m:s:j:', ['skip-completed', 'restrict', 'test']) method = None store_descr = None store_options = dict() do_test = False nworkers = 1 for o, a in opts: if o == '-h': print _scriptdoc + '\n' + methods.make_scriptdoc() + '\n\n' + storage.make_scriptdoc() return -1 elif o == '-v': print "cpitch version %s" % version return -1 elif o == '-c': if not os.path.exists(a): print >> cout, "ERROR: config file %s doesn't exist" % a return -1 config.read(a) elif o == '-m': method = a elif o == '-s': store_descr = a elif o == '-j': nworkers = max(1, int(a)) elif o == '--skip-completed': store_options['skip'] = True elif o == '--restrict': store_options['restrict'] = True elif o == '--test': do_test = True if len(args) == 0: signal_dir = os.getcwd() else: signal_dir = args[0] print >> cout, "* Program: ccompare" print >> cout, "** Version: %s" % version print >> cout, "* Input directory: %s" % signal_dir print >> cout, "* Number of workers: %d" % nworkers if method is None: print >> cout, "* Comparison method: None; aborting" print >> sys.stderr, "Please specify a comparison method. Options are %s" % ','.join(methods.names()) return -1 try: compare_class = methods.load(method) print >> cout, "* Comparison method: %s %s" % (method, compare_class) except ImportError, e: print >> cout, "* ERROR: bad method descriptor: %s" % e return -1