def command_extract(args): def setup(parser): parser.add_option( '--format', dest='format', default='mseed', choices=['mseed', 'sac', 'text', 'yaff'], help='export to format "mseed", "sac", "text", or "yaff". ' 'Default is "mseed".') fndfl = 'extracted/%(irecord)s_%(args)s.%(extension)s' parser.add_option( '--output', dest='output_fn', default=fndfl, metavar='TEMPLATE', help='output path template [default: "%s"]' % fndfl) parser, options, args = cl_parse('extract', args, setup=setup) try: sdef = args.pop() except Exception: parser.error('cannot get <selection> argument') try: gdef = gf.meta.parse_grid_spec(sdef) except gf.meta.GridSpecError as e: die(e) store_dir = get_store_dir(args) extensions = { 'mseed': 'mseed', 'sac': 'sac', 'text': 'txt', 'yaff': 'yaff'} try: store = gf.Store(store_dir) for args in store.config.iter_extraction(gdef): gtr = store.get(args) if gtr: tr = trace.Trace( '', '', '', util.zfmt(store.config.ncomponents) % args[-1], ydata=gtr.data, deltat=gtr.deltat, tmin=gtr.deltat * gtr.itmin) additional = dict( args='_'.join('%g' % x for x in args), irecord=store.str_irecord(args), extension=extensions[options.format]) io.save( tr, options.output_fn, format=options.format, additional=additional) except (gf.meta.GridSpecError, gf.StoreError, gf.meta.OutOfBounds) as e: die(e)
def command_extract(args): def setup(parser): parser.add_option( '--format', dest='format', default='mseed', choices=['mseed', 'sac', 'text', 'yaff'], help='export to format "mseed", "sac", "text", or "yaff". ' 'Default is "mseed".') fndfl = 'extracted/%(irecord)s_%(args)s.%(extension)s' parser.add_option( '--output', dest='output_fn', default=fndfl, metavar='TEMPLATE', help='output path template [default: "%s"]' % fndfl) parser, options, args = cl_parse('extract', args, setup=setup) try: sdef = args.pop() except Exception: parser.error('cannot get <selection> argument') try: gdef = gf.meta.parse_grid_spec(sdef) except gf.meta.GridSpecError as e: die(e) store_dir = get_store_dir(args) extensions = { 'mseed': 'mseed', 'sac': 'sac', 'text': 'txt', 'yaff': 'yaff'} try: store = gf.Store(store_dir) for args in store.config.iter_extraction(gdef): gtr = store.get(args) if gtr: tr = trace.Trace( '', '', '', util.zfmt(store.config.ncomponents) % args[-1], ydata=gtr.data, deltat=gtr.deltat, tmin=gtr.deltat * gtr.itmin) additional = dict( args='_'.join('%g' % x for x in args), irecord=store.str_irecord(args), extension=extensions[options.format]) io.save( tr, options.output_fn, format=options.format, additional=additional) except (gf.meta.GridSpecError, gf.StoreError, gf.meta.OutOfBounds) as e: die(e)
def irecord_format(self): return util.zfmt(self._nrecords)
def irecord_format(self): return util.zfmt(self._nrecords)