# https://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
'init': 'create a new empty GF store', 'build': 'compute GFs and fill into store', 'stats': 'print information about a GF store', 'check': 'check for problems in GF store', 'decimate': 'build decimated variant of a GF store', 'redeploy': 'copy traces from one GF store into another', 'view': 'view selected traces', 'extract': 'extract selected traces', 'import': 'convert Kiwi GFDB to GF store format', 'export': 'convert GF store to Kiwi GFDB format', 'ttt': 'create travel time tables', 'tttview': 'plot travel time table', 'tttextract': 'extract selected travel times', 'tttlsd': 'fix holes in travel time tables', 'server': 'run seismosizer server', 'download': 'download GF store from a server', 'modelview': 'plot earthmodels', 'upgrade': 'upgrade store format to latest version', 'addref': 'import citation references to GF store config', 'qc': 'quality check', 'report': 'report for Green\'s Function databases', }
'init': ['init <type> <store-dir> [options]', 'init redeploy <source> <destination> [options]'], 'build': 'build [store-dir] [options]', 'stats': 'stats [store-dir] [options]', 'check': 'check [store-dir] [options]', 'decimate': 'decimate [store-dir] <factor> [options]', 'redeploy': 'redeploy <source> <destination> [options]', 'view': 'view [store-dir] ... [options]', 'extract': 'extract [store-dir] <selection>', 'import': 'import <source> <destination> [options]', 'export': 'export [store-dir] <destination> [options]', 'ttt': 'ttt [store-dir] [options]', 'tttview': 'tttview [store-dir] <phase-ids> [options]', 'tttextract': 'tttextract [store-dir] <phase> <selection>', 'tttlsd': 'tttlsd [store-dir] <phase>', 'server': 'server [options] <store-super-dir> ...', 'download': 'download [options] <site> <store-id>', 'modelview': 'modelview <selection>', 'upgrade': 'upgrade [store-dir] ...', 'addref': 'addref [store-dir] ... <filename> ...', 'qc': 'qc [store-dir]', 'report': 'report <subcommand> <arguments>... [options]' }
Subcommands:
init %(init)s build %(build)s stats %(stats)s check %(check)s decimate %(decimate)s redeploy %(redeploy)s view %(view)s extract %(extract)s import %(import)s export %(export)s ttt %(ttt)s tttview %(tttview)s tttextract %(tttextract)s tttlsd %(tttlsd)s server %(server)s download %(download)s modelview %(modelview)s upgrade %(upgrade)s addref %(addref)s qc %(qc)s report %(report)s
To get further help and a list of available options for any subcommand run:
fomosto <subcommand> --help
''' % d2u(subcommand_descriptions)
'--loglevel', action='store', dest='loglevel', type='choice', choices=('critical', 'error', 'warning', 'info', 'debug'), default='info', help='set logger level to ' '"critical", "error", "warning", "info", or "debug". ' 'Default is "%default".')
sys.exit('%s: error: %s \n %s' % (program_name, message, err))
raise ValueError('invalid name')
else:
except ValueError: die('invalid modelling code wrapper name')
except ImportError: die('''modelling code wrapper "%s" not available or not installed (module probed: "%s")''' % (name, modname))
Available modelling backends: %s
More information at https://pyrocko.org/docs/current/apps/fomosto/backends.html ''' % '\n'.join([' * %s' % b for b in fomosto.AVAILABLE_BACKENDS])
'init', args, details=details)
parser.error('incorrect number of arguments')
except gf.StoreError as e: die(e)
dest_dir, config=config)
except gf.StoreError as e: die(e)
except gf.StoreError as e: die(e)
source_fn = source.get_extra_path(k) dest_fn = dest.get_extra_path(k) shutil.copyfile(source_fn, dest_fn)
'(1) configure settings in files:\n %s' % '\n '.join(config_filenames))
'(2) run "fomosto redeploy <source> <dest>", as needed')
else: parser.error('incorrect number of arguments')
except gf.StoreError as e: die(e)
% '\n '.join(config_filenames))
else:
die('not a directory: %s' % store_dir)
else:
die('not a directory: %s' % store_dir)
'--force', dest='force', action='store_true', help='overwrite existing files')
'--nworkers', dest='nworkers', type='int', metavar='N', help='run N worker processes in parallel')
'--continue', dest='continue_', action='store_true', help='continue suspended build')
'--step', dest='step', type='int', metavar='I', help='process block number IBLOCK')
'--block', dest='iblock', type='int', metavar='I', help='process block number IBLOCK')
step = options.step - 1 else:
iblock = options.iblock - 1 else:
store_dir, force=options.force, nworkers=options.nworkers, continue_=options.continue_, step=step, iblock=iblock)
except gf.StoreError as e: die(e)
except gf.StoreError as e: die(e)
die('problems detected with gf store: %s' % store_dir)
except gf.StoreError as e: die(e)
try: config = gf.meta.load(filename=fn) assert isinstance(config, gf.Config)
except Exception: die('cannot load gf config from file: %s' % fn)
return config
'--config', dest='config_fn', metavar='FILE', help='use modified spacial sampling given in FILE')
'--force', dest='force', action='store_true', help='overwrite existing files')
except Exception: parser.error('cannot get <factor> argument')
config = load_config(options.config_fn)
show_progress=True)
except gf.StoreError as e: die(e)
return '(%s)' % ', '.join('%g' % x for x in args)
sys.exit(parser.format_help())
except gf.StoreError as e: die(e)
except gf.StoreError: pass
except gf.StoreError as e: die(e)
except (gf.meta.OutOfBounds, gf.store.NotAllowedToInterpolate) as e: logger.debug('skipping %s, (%s)' % (sindex(args), e))
except gf.store.StoreError as e: logger.warn('cannot insert %s, (%s)' % (sindex(args), e))
dest='extract', metavar='start:stop[:step|@num],...', help='specify which traces to show')
dest='showphases', default=None, metavar='[phase_id1,phase_id2,...|all]', help='add phase markers from ttt')
dest='gui_toolkit_qt5', action='store_true', default=False, help='use Qt5 for the GUI')
dest='gui_toolkit_qt4', action='store_true', default=False, help='use Qt4 for the GUI')
dest='opengl', action='store_true', default=False, help='use OpenGL for drawing')
config.override_gui_toolkit = 'qt4'
config.override_gui_toolkit = 'qt5'
except gf.meta.GridSpecError as e: die(e)
elif options.showphases is not None: phasenames = options.showphases.split(',')
ii, ','.join('%gk' % (x/1000.) for x in args[:-1]))
'', sta_code, loc_code, '%02i' % args[-1], ydata=gtr.data, deltat=gtr.deltat, tmin=tmin)
[('', sta_code, loc_code, '%02i' % args[-1])], phase_tmin, phase_tmin, 0, phasename=phasename)
except (gf.meta.GridSpecError, gf.StoreError, gf.meta.OutOfBounds) as e: die(e)
'--format', dest='format', default='mseed', choices=['mseed', 'sac', 'text', 'yaff'], help='export to format "mseed", "sac", "text", or "yaff". ' 'Default is "mseed".')
'--output', dest='output_fn', default=fndfl, metavar='TEMPLATE', help='output path template [default: "%s"]' % fndfl)
except Exception: parser.error('cannot get <selection> argument')
except gf.meta.GridSpecError as e: die(e)
'mseed': 'mseed', 'sac': 'sac', 'text': 'txt', 'yaff': 'yaff'}
'', '', '', util.zfmt(store.config.ncomponents) % args[-1], ydata=gtr.data, deltat=gtr.deltat, tmin=gtr.deltat * gtr.itmin)
args='_'.join('%g' % x for x in args), irecord=store.str_irecord(args), extension=extensions[options.format])
tr, options.output_fn, format=options.format, additional=additional)
except (gf.meta.GridSpecError, gf.StoreError, gf.meta.OutOfBounds) as e: die(e)
try: from tunguska import gfdb except ImportError: die('the kiwi tools must be installed to use this feature')
parser, options, args = cl_parse('import', args)
show_progress = True
if not len(args) == 2: sys.exit(parser.format_help())
source_path, dest_store_dir = args
if op.isdir(source_path): source_path = op.join(source_path, 'db')
source_path = re.sub(r'(\.\d+\.chunk|\.index)$', '', source_path)
db = gfdb.Gfdb(source_path)
config = gf.meta.ConfigTypeA( id='imported_gfs', distance_min=db.firstx, distance_max=db.firstx + (db.nx-1) * db.dx, distance_delta=db.dx, source_depth_min=db.firstz, source_depth_max=db.firstz + (db.nz-1) * db.dz, source_depth_delta=db.dz, sample_rate=1.0/db.dt, ncomponents=db.ng )
try: gf.store.Store.create(dest_store_dir, config=config) dest = gf.Store(dest_store_dir, 'w') if show_progress: pbar = util.progressbar( 'importing', dest.config.nrecords/dest.config.ncomponents)
for i, args in enumerate(dest.config.iter_nodes(level=-1)): source_depth, distance = [float(x) for x in args] traces = db.get_traces_pyrocko(distance, source_depth) ig_to_trace = dict((tr.meta['ig']-1, tr) for tr in traces) for ig in range(db.ng): if ig in ig_to_trace: tr = ig_to_trace[ig] gf_tr = gf.store.GFTrace( tr.get_ydata(), int(round(tr.tmin / tr.deltat)), tr.deltat)
else: gf_tr = gf.store.Zero
dest.put((source_depth, distance, ig), gf_tr)
if show_progress: pbar.update(i+1)
if show_progress: pbar.finish()
dest.close()
except gf.StoreError as e: die(e)
from subprocess import Popen, PIPE
try: from tunguska import gfdb except ImportError as err: die('the kiwi tools must be installed to use this feature', err)
def setup(parser): parser.add_option( '--nchunks', dest='nchunks', type='int', default=1, metavar='N', help='split output gfdb into N chunks')
parser, options, args = cl_parse('export', args, setup=setup)
show_progress = True
if len(args) not in (1, 2): sys.exit(parser.format_help())
target_path = args.pop() if op.isdir(target_path): target_path = op.join(target_path, 'kiwi_gfdb') logger.warn('exported gfdb will be named as "%s.*"' % target_path)
source_store_dir = get_store_dir(args)
source = gf.Store(source_store_dir, 'r') config = source.config
if not isinstance(config, gf.meta.ConfigTypeA): die('only stores of type A can be exported to Kiwi format')
if op.isfile(target_path + '.index'): die('destation already exists')
cmd = [str(x) for x in [ 'gfdb_build', target_path, options.nchunks, config.ndistances, config.nsource_depths, config.ncomponents, config.deltat, config.distance_delta, config.source_depth_delta, config.distance_min, config.source_depth_min]]
p = Popen(cmd, stdin=PIPE) p.communicate()
out_db = gfdb.Gfdb(target_path)
if show_progress: pbar = util.progressbar( 'exporting', config.nrecords/config.ncomponents)
for i, (z, x) in enumerate(config.iter_nodes(level=-1)):
data_out = [] for ig in range(config.ncomponents): try: tr = source.get((z, x, ig), interpolation='off') data_out.append((tr.t, tr.data * config.factor))
except gf.store.StoreError as e: logger.warn('cannot get %s, (%s)' % (sindex((z, x, ig)), e)) data_out.append(None)
# put a zero valued sample to no-data zero-traces at a compatible time tmins = [ entry[0][0] for entry in data_out if entry is not None and entry[0].size != 0]
if tmins: tmin = min(tmins) for entry in data_out: if entry is not None and entry[0].size == 0: entry[0].resize(1) entry[1].resize(1) entry[0][0] = tmin entry[1][0] = 0.0
out_db.put_traces_slow(x, z, data_out)
if show_progress: pbar.update(i+1)
if show_progress: pbar.finish()
source.close()
try: return float(x) except ValueError: return cake.PhaseDef(x)
return [phasedef_or_horvel(ps) for ps in s.split(',')]
'--force', dest='force', action='store_true', help='overwrite existing files')
except gf.StoreError as e: die(e)
'--source-depth', dest='source_depth', type=float, help='Source depth in km')
'--receiver-depth', dest='receiver_depth', type=float, help='Receiver depth in km')
'tttview', args, setup=setup, details="Comma seperated <phase-ids>, eg. 'fomosto tttview Pdiff,S'.")
except Exception: parser.error('cannot get <phase-ids> argument')
receiver_depth = options.receiver_depth * 1000.0 else:
elif isinstance(store.config, gf.ConfigTypeB): receiver_depth = store.config.receiver_depth_min
else: receiver_depth = 0.0
x = (receiver_depth, None, None)
except gf.StoreError as e: die(e)
store.config.distance_max, num_d)
source_depth = options.source_depth * 1000.0 else: store.config.source_depth_max - store.config.source_depth_min)/2.
'--output', dest='output_fn', metavar='TEMPLATE', help='output to text files instead of stdout ' '(example TEMPLATE: "extracted/%(args)s.txt")')
except Exception: parser.error('cannot get <selection> argument')
except Exception: parser.error('cannot get <phase> argument')
except gf.meta.InvalidTimingSpecification: parser.error('invalid phase specification: "%s"' % sphase)
except gf.meta.GridSpecError as e: die(e)
else: s.append('nan')
args='_'.join('%e' % x for x in args), extension='txt')
else:
except (gf.meta.GridSpecError, gf.StoreError, gf.meta.OutOfBounds) as e: die(e)
def setup(parser): pass
parser, options, args = cl_parse('tttlsd', args, setup=setup)
try: sphase_ids = args.pop() except Exception: parser.error('cannot get <phase> argument')
try: phase_ids = [x.strip() for x in sphase_ids.split(',')] except gf.meta.InvalidTimingSpecification: parser.error('invalid phase specification: "%s"' % sphase_ids)
store_dir = get_store_dir(args)
try: store = gf.Store(store_dir) for phase_id in phase_ids: store.fix_ttt_holes(phase_id)
except gf.StoreError as e: die(e)
from pyrocko.gf import server
def setup(parser): parser.add_option( '--port', dest='port', metavar='PORT', type='int', default=8080, help='serve on port PORT')
parser.add_option( '--ip', dest='ip', metavar='IP', default='', help='serve on ip address IP')
parser, options, args = cl_parse('server', args, setup=setup)
engine = gf.LocalEngine(store_superdirs=args) server.run(options.ip, options.port, engine)
from pyrocko.gf import ws
details = '''
Browse pre-calculated Green's function stores online:
https://greens-mill.pyrocko.org '''
def setup(parser): parser.add_option( '--force', dest='force', action='store_true', help='overwrite existing files')
parser, options, args = cl_parse( 'download', args, setup=setup, details=details) if not len(args) in (1, 2): sys.exit(parser.format_help())
if len(args) == 2: site, store_id = args if not re.match(gf.meta.StringID.pattern, store_id): die('invalid store ID') else: site, store_id = args[0], None
if site not in gf.ws.g_site_abbr: if -1 == site.find('://'): site = 'http://' + site
try: ws.download_gf_store(site=site, store_id=store_id, force=options.force) except ws.DownloadError as e: die(str(e))
'vp': '$v_p$', 'vs': '$v_s$', 'qp': '$Q_p$', 'qs': '$Q_s$', 'rho': '$\\rho$'}
'--parameters', dest='parameters', default='vp,vs', metavar='vp,vs,....', help='select one or several of vp, vs, rho, qp, qs, vp/vs, qp/qs')
len(parameters), sharey=True, figsize=(len(parameters)*3, 5))
axes = [axes]
else:
except gf.StoreError as e: die(e)
else: lab = p
handles, labels, bbox_to_anchor=(0.5, 0.12), bbox_transform=fig.transFigure, ncol=3, loc='upper center', fancybox=True)
wspace=0.05)
else: print('%s: %i file%s upgraded.' % ( store_dir, nup, ['s', ''][nup == 1]))
except gf.StoreError as e: die(e)
store_dirs.append(arg) else: die('invalid argument: %s' % arg)
except ImportError: die('pybtex module must be installed to use this function')
die('no references found')
die('duplicate reference id: %s' % ref.id)
except gf.StoreError as e: die(e)
print('has empty records')
except gf.StoreError as e: die(e)
from pyrocko.fomosto.report import report_call report_call.run_program(args)
args = sys.argv[1:]
acommand = args[0] if acommand in subcommands: globals()['command_' + acommand](['--help'])
else: sys.exit('fomosto: error: no such subcommand: %s' % command)
if __name__ == '__main__': main(sys.argv[1:]) |