#!/usr/bin/env python # http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg---------- # import logger
return tuple([self[k] for k in keys])
sphase = m.group(1) color = m.group(2) phase_colors[sphase] = plot.str_to_mpl_color(color)
return sphase
required=(), optional=(), args=sys.argv, usage='%prog [options]', descr=None):
prog='cake', usage=usage, description=descr.capitalize()+'.', add_help_option=False, formatter=util.BetterHelpFormatter())
'-h', '--help', action='help', help='Show help message and exit.')
Seismic phase arrivals may be either specified as traditional phase names (e.g. P, S, PP, PcP, ...) or in Cake's own syntax which is more powerful. Use the --classic option, for traditional phase names. Use the --phase option if you want to define phases in Cake's syntax.
''') '--phase', '--phases', dest='phases', action="append", default=[], metavar='PHASE1,PHASE2,...', help='''Comma separated list of seismic phases in Cake\'s syntax.
The definition of a seismic propagation path in Cake's phase syntax is a string consisting of an alternating sequence of "legs" and "knees".
A "leg" represents seismic wave propagation without any conversions, encountering only super-critical reflections. Legs are denoted by "P", "p", "S", or "s". The capital letters are used when the take-off of the "leg" is in downward direction, while the lower case letters indicate a take-off in upward direction.
A "knee" is an interaction with an interface. It can be a mode conversion, a reflection, or propagation as a headwave or diffracted wave.
* conversion is simply denoted as: "(INTERFACE)" or "DEPTH" * upperside reflection: "v(INTERFACE)" or "vDEPTH" * underside reflection: "^(INTERFACE)" or "^DEPTH" * normal kind headwave or diffracted wave: "v_(INTERFACE)" or "v_DEPTH"
The interface may be given by name or by depth: INTERFACE is the name of an interface defined in the model, DEPTH is the depth of an interface in [km] (the interface closest to that depth is chosen). If two legs appear consecutively without an explicit "knee", surface interaction is assumed.
The preferred standard interface names in cake are "conrad", "moho", "cmb" (core-mantle boundary), and "cb" (inner core boundary).
The phase definition may end with a backslash "\\", to indicate that the ray should arrive at the receiver from above instead of from below. It is possible to restrict the maximum and minimum depth of a "leg" by appending "<(INTERFACE)" or "<DEPTH" or ">(INTERFACE)" or ">DEPTH" after the leg character, respectively.
When plotting rays or travel-time curves, the color can be set by appending "{COLOR}" to the phase definition, where COLOR is the name of a color or an RGB or RGBA color tuple in the format "R/G/B" or "R/G/B/A", respectively. The values can be normalized to the range [0, 1] or to [0, 255]. The latter is only assumed when any of the values given exceeds 1.0. ''')
'--classic', dest='classic_phases', action='append', default=[], metavar='PHASE1,PHASE2,...', help='''Comma separated list of seismic phases in classic nomenclature. Run "cake list-phase-map" for a list of available phase names. When plotting, color can be specified in the same way as in --phases.''')
'--model', dest='model_filename', metavar='(NAME or FILENAME)', help='Use builtin model named NAME or user model from file ' 'FILENAME. By default, the "ak135-f-continental.m" model is ' 'used. Run "cake list-models" for a list of builtin models.')
'--format', dest='model_format', metavar='FORMAT', choices=['nd', 'hyposat'], default='nd', help='Set model file format (available: nd, hyposat; default: ' 'nd).') '--crust2loc', dest='crust2loc', metavar='LAT,LON', help='Set model from CRUST2.0 profile at location (LAT,LON).') '--crust2profile', dest='crust2profile', metavar='KEY', help='Set model from CRUST2.0 profile with given KEY.')
'zstart', 'zstop', 'distances', 'sloc', 'rloc')):
'--sdepth', dest='sdepth', type='float', default=0.0, metavar='FLOAT', help='Source depth [km] (default: 0)') '--rdepth', dest='rdepth', type='float', default=0.0, metavar='FLOAT', help='Receiver depth [km] (default: 0)') '--distances', dest='sdist', metavar='DISTANCES', help='Surface distances as "start:stop:n" or ' '"dist1,dist2,..." [km]') '--sloc', dest='sloc', metavar='LAT,LON', help='Source location (LAT,LON).') '--rloc', dest='rloc', metavar='LAT,LON', help='Receiver location (LAT,LON).')
parser, 'Material', 'An isotropic elastic material may be specified by giving ' 'a combination of some of the following options. ') '--vp', dest='vp', default=None, type='float', metavar='FLOAT', help='P-wave velocity [km/s]') '--vs', dest='vs', default=None, type='float', metavar='FLOAT', help='S-wave velocity [km/s]') '--rho', dest='rho', default=None, type='float', metavar='FLOAT', help='density [g/cm**3]') '--qp', dest='qp', default=None, type='float', metavar='FLOAT', help='P-wave attenuation Qp (default: 1456)') '--qs', dest='qs', default=None, type='float', metavar='FLOAT', help='S-wave attenuation Qs (default: 600)') '--poisson', dest='poisson', default=None, type='float', metavar='FLOAT', help='Poisson ratio') '--lambda', dest='lame_lambda', default=None, type='float', metavar='FLOAT', help='Lame parameter lambda [GPa]') '--mu', dest='lame_mu', default=None, type='float', metavar='FLOAT', help='Shear modulus [GPa]') '--qk', dest='qk', default=None, type='float', metavar='FLOAT', help='Bulk attenuation Qk') '--qmu', dest='qmu', default=None, type='float', metavar='FLOAT', help='Shear attenuation Qmu')
'vred', 'as_degrees', 'accuracy', 'slowness', 'interface', 'aspect', 'shade_model')):
'--vred', dest='vred', type='float', metavar='FLOAT', help='Velocity for time reduction in plot [km/s]')
'--degrees', dest='as_degrees', action='store_true', default=False, help='Distances are in [deg] instead of [km], velocities in ' '[deg/s] instead of [km/s], slownesses in [s/deg] ' 'instead of [s/km].')
'--accuracy', dest='accuracy', type='float', metavar='MAXIMUM_RELATIVE_RMS', default=0.002, help='Set accuracy for model simplification.')
'--slowness', dest='slowness', type='float', metavar='FLOAT', default=0.0, help='Select surface slowness [s/km] (default: 0)')
'--interface', dest='interface', metavar='(NAME or DEPTH)', help='Name or depth [km] of interface to select')
'--aspect', dest='aspect', type='float', metavar='FLOAT', help='Aspect ratio for plot')
'--no-shade-model', dest='shade_model', action='store_false', default=True, help='Suppress shading of earth model layers')
'--output-format', dest='output_format', metavar='FORMAT', default='textual', choices=('textual', 'nd'), help='Set model output format (available: textual, nd, ' 'default: textual)') '-s', '--save', dest='save', metavar='PATH', help='saves plot to .png (default) or other py-supported\ endings without showing, use --show or -u for showing', default='') '--size', dest='size', type='string', default='a4', help='gives size of returned plot, use \'a5\' or \'a4\'') '-u', '--show', dest='show', action='store_true', help='shows plot when saving (-u for unhide)')
parser.print_help()
parser.error( 'Cake arguments should look like "--option" or "--option=...".')
for s in ss.split(','): s = process_color(s, phase_colors) phases.append(cake.PhaseDef(s))
for p in pp.split(','): p = process_color(p, phase_colors) phases.extend(cake.PhaseDef.classic(p))
except (cake.PhaseDefParseError, cake.UnknownClassicPhase) as e: parser.error(e)
d['model'] = cake.load_model( options.model_filename, options.model_format)
if options.crust2loc: try: args = tuple( [float(x) for x in options.crust2loc.split(',')]) except Exception: parser.error( 'format for --crust2loc option is ' '"LATITUDE,LONGITUDE"') elif options.crust2profile: args = (options.crust2profile.upper(),) else: assert False
if 'model' in d: d['model'] = d['model'].replaced_crust(args) else: from pyrocko import crust2x2 profile = crust2x2.get_profile(*args) d['model'] = cake.LayeredModel.from_scanlines( cake.from_crust2x2_profile(profile))
if not as_degrees: d['vred'] *= r2d * cake.km / cake.earthradius
if options.sdist.find(':') != -1: ssn = options.sdist.split(':') if len(ssn) != 3: parser.error( 'format for distances is ' '"min_distance:max_distance:n_distances"')
distances = num.linspace( float(ssn[0]), float(ssn[1]), int(ssn[2])) else: distances = num.array( list(map( float, options.sdist.split(','))), dtype=num.float)
if not as_degrees: distances *= r2d * cake.km / cake.earthradius
try: slat, slon = tuple([float(x) for x in options.sloc.split(',')]) rlat, rlon = tuple([float(x) for x in options.rloc.split(',')]) except Exception: parser.error( 'format for --sloc and --rloc options is ' '"LATITUDE,LONGITUDE"')
distance_sr = orthodrome.distance_accurate50m_numpy( slat, slon, rlat, rlon)
distance_sr *= r2d / cake.earthradius if distances is not None: distances = num.concatenate((distances, [distance_sr])) else: distances = num.array([distance_sr], dtype=num.float)
d['distances'] = distances else:
try: d['interface'] = float(options.interface)*cake.km except ValueError: d['interface'] = options.interface
else:
vp=1000., vs=1000., rho=1000., qp=1., qs=1., qmu=1., qk=1., lame_lambda=1.0e9, lame_mu=1.0e9, poisson=1.)
md[k] = getattr(options, k) * userfactor[k]
parser.error('lambda and mu must be specified both.') md['lame'] = md.pop('lame_lambda'), md.pop('lame_mu')
try: d['material'] = cake.Material(**md) except cake.InvalidArguments as e: parser.error(str(e))
/ cake.earthradius * r2d
elif k == 'phases': d['phases'] = list(map(cake.PhaseDef, 'Pp'))
else: parser.error('missing %s' % k)
else: mini_fmt(v*100, 5)
else:
discontinuities = [model.discontinuity(interface)] else:
in_direction == cake.UP]
continue
(out_direction, out_mode, discontinuity.efficiency( in_direction, out_direction, in_mode, out_mode, p)))
continue
' '*len(sin1), sout[0][1], sout[1][1]) sin1, sout[0][0], sout[1][0]) sin2, sout[2][0], sout[3][0]) ' '*len(sin2), sout[2][1], sout[3][1])
model, distances=[], phases=cake.PhaseDef('P'), zstart=0.0, zstop=0.0, as_degrees=False):
units = 's/deg deg s deg deg % %'.split() else:
distances=distances, phases=phases, zstart=zstart, zstop=zstop):
sd = ray.x slow = ray.p/cake.r2d else:
(slow, sd, ray.t, ray.takeoff_angle(), ray.incidence_angle(), 100*ray.efficiency(), 100*ray.spreading()*ray.surface_sphere()), space)) + tuple( x.ljust(17) for x in (ray.path.phase.definition(), su))))
try: fig.savefig(save) if show: plt.show() except OSError as e: raise CakeError(str(e)) except ValueError as e: raise CakeError(str(e))
args = sys.argv[1:]
'print': 'get information on model/phase/material properties', 'arrivals': 'print list of phase arrivals', 'paths': 'print ray path details', 'plot-xt': 'plot traveltime vs distance curves', 'plot-xp': 'plot ray parameter vs distance curves', 'plot-rays': 'plot ray propagation paths', 'plot': 'plot combination of ray and traveltime curves', 'plot-model': 'plot velocity model', 'list-models': 'list builtin velocity models', 'list-phase-map': 'show translation table for classic phase names', 'simplify-model': 'create a simplified version of a layered model', 'scatter': 'show details about scattering at model interfaces'}
Subcommands:
print %(print)s arrivals %(arrivals)s paths %(paths)s plot-xt %(plot_xt)s plot-xp %(plot_xp)s plot-rays %(plot_rays)s plot %(plot)s plot-model %(plot_model)s list-models %(list_models)s list-phase-map %(list_phase_map)s simplify-model %(simplify_model)s scatter %(scatter)s
To get further help and a list of available options for any subcommand run:
cake <subcommand> --help
'''.strip() % d2u(subcommand_descriptions)
sys.exit('Usage: %s' % usage)
(), ('model', 'phases', 'material', 'output_format'), usage=subusage, descr=descr, args=args)
if c.output_format == 'textual': print(c.model) print() elif c.output_format == 'nd': cake.write_nd_model_fh(c.model, sys.stdout)
for phase in c.phases: print(phase) print()
print(c.material.describe()) print()
('model', 'phases', 'distances'), ('zstart', 'zstop', 'as_degrees'), usage=subusage, descr=descr, args=args)
c.model, **c.getn('zstart', 'zstop', 'phases', 'distances', 'as_degrees'))
('model', 'phases'), ('zstart', 'zstop', 'as_degrees'), usage=subusage, descr=descr, args=args)
('model', 'phases',), ('zstart', 'zstop', 'distances', 'as_degrees', 'vred', 'phase_colors', 'save', 'size', 'show'), usage=subusage, descr=descr, args=args) else: ('model', 'phases'), ('zstart', 'zstop', 'distances', 'as_degrees', 'aspect', 'shade_model', 'phase_colors', 'save', 'size', 'show'), usage=subusage, descr=descr, args=args)
arrivals = mod.arrivals( **c.getn('phases', 'zstart', 'zstop', 'distances')) else:
paths, c.zstart, c.zstop, c.distances, c.as_degrees, show=showplt, phase_colors=c.phase_colors)
paths, c.zstart, c.zstop, c.distances, c.as_degrees, vred=c.vred, show=showplt, phase_colors=c.phase_colors)
plot.my_rays_plot_gcs( mod, paths, arrivals, c.zstart, c.zstop, c.distances, show=showplt, phase_colors=c.phase_colors)
else: mod, paths, arrivals, c.zstart, c.zstop, c.distances, show=showplt, aspect=c.aspect, shade_model=c.shade_model, phase_colors=c.phase_colors)
mod, paths, arrivals, c.zstart, c.zstop, c.distances, c.as_degrees, show=showplt, vred=c.vred, phase_colors=c.phase_colors)
except CakeError as e: exit('cake.py: %s' % str(e))
('model',), ('save', 'size', 'show'), usage=subusage, descr=descr, args=args) except CakeError as e: exit('cake.py: %s' % str(e))
usage=subusage, descr=descr, args=args)
('model',), ('slowness', 'interface', 'as_degrees'), usage=subusage, descr=descr, args=args)
optparse( (), ('model', 'accuracy', 'slowness', 'interface', 'phases', 'distances', 'zstart', 'zstop', 'distances', 'as_degrees', 'material', 'vred', 'save'), usage='cake help-options', descr='list all available options', args=args)
else: sys.exit('cake: no such subcommand: %s' % command)
if __name__ == '__main__': main(sys.argv[1:]) |