pyrocko.cake¶
Classical seismic ray theory for layered earth models (layer cake models).
This module can be used to e.g. calculate arrival times, ray paths, reflection and transmission coefficients, take-off and incidence angles and geometrical spreading factors for arbitrary seismic phases. Computations are done for a spherical earth, even though the module name may suggests something flat.
The main classes defined in this module are:
Material
- Defines an isotropic elastic material.PhaseDef
- Defines a seismic phase arrival / wave propagationhistory.
LayeredModel
- Representation of a layer cake model.Layer
- A layer in aLayeredModel
.HomogeneousLayer
- A homogeneousLayer
.GradientLayer
- A gradientLayer
.
Discontinuity
- A discontinuity in aLayeredModel
.Interface
- ADiscontinuity
between twoLayer
instances.Surface
- The surfaceDiscontinuity
on top of aLayeredModel
.
RayPath
- A fan of rays running through a common sequence of layers / interfaces.Ray
- A specific ray with a specific (ray parameter, distance, arrival time) choice.RayElement
- An element of aRayPath
.Straight
- A ray segment representing propagation through oneLayer
.Kink
- An interaction of a ray with aDiscontinuity
.
Module Attributes
Constant indicating P wave propagation. |
|
Constant indicating S wave propagation |
|
Constant indicating downward direction. |
|
Constant indicating upward direction. |
Functions
Calculate vp from vs using Castagna's relation. |
|
Calculate vp from vs using Castagna's relation. |
|
|
Create NumPy array filled with given value. |
|
Load layered earth model from file. |
|
Scatter matrix for solid-solid interface. |
|
Get indices to select the appropriate element from scatter matrix for solid-solid interface. |
|
Scatter matrix for free surface reflection/conversions. |
|
Get indices to select the appropriate element from scatter matrix for free surface. |
Reader for HYPOSAT earth model files. |
|
|
Reader for TauP style '.nd' (named discontinuity) files. |
Classes
|
Base class for discontinuities in layered earth model. |
|
Representation of a gradient layer in a layered earth model. |
|
Representation of a homogeneous layer in a layered earth model. |
|
Representation of an interface in a layered earth model. |
|
An interaction of a ray with a |
|
Represents a change in wave propagation within a |
|
Representation of a layer in a layered earth model. |
Representation of a layer cake model. |
|
|
Represents a continuous piece of wave propagation in a phase definition. |
|
Isotropic elastic material. |
|
Definition of a seismic phase arrival, based on ray propagation path. |
|
Representation of a ray with a specific (path, ray parameter, distance, arrival time) choice. |
An element of a |
|
|
Representation of a fan of rays running through a common sequence of layers / interfaces. |
|
A ray segment representing wave propagation through one |
|
Representation of the surface discontinuity in a layered earth model. |
Exceptions
Raised when the potential interpolation for gradient layers has failed. |
|
Raised when the ray exits the bottom of the model before completing the phase requirements. |
|
Base class for exceptions raised in |
|
|
Raised when the phase requirements cannot be met. |
Invalid arguments. |
|
Invalid definition of a cake |
|
Raised when the phase's maximum depth has been exceeded. |
|
Raised when the phase's minimum depth has been underrun. |
|
Raised when the phase requirements cannot be met. |
|
Raised when the ray path computation failed. |
|
|
Exception raised when an error occures during parsing of a phase definition string. |
Raised when the ray hits the surface before completing the phase requirements. |
|
Raised when the ray has been trapped and therefore cannot satisfy the phase requirements. |
|
|
Raised when an invalid classic phase name has been specified.' |
- P = 1¶
Constant indicating P wave propagation.
- S = 2¶
Constant indicating S wave propagation
- DOWN = 4¶
Constant indicating downward direction.
- UP = -4¶
Constant indicating upward direction.
- exception CakeError[source]¶
Bases:
Exception
Base class for exceptions raised in
pyrocko.cake
.
- class Material(vp=None, vs=None, rho=2600.0, qp=None, qs=None, poisson=None, lame=None, qk=None, qmu=None, burgers=None)[source]¶
Bases:
object
Isotropic elastic material.
- Parameters:
vp – P-wave velocity [m/s]
vs – S-wave velocity [m/s]
rho – density [kg/m^3]
qp – P-wave attenuation Qp
qs – S-wave attenuation Qs
poisson – Poisson ratio
lame – tuple with Lame parameter lambda and shear modulus [Pa]
qk – bulk attenuation Qk
qmu – shear attenuation Qmu
burgers (tuple) – Burgers rheology paramerters as tuple. transient viscosity [Pa], <= 0 means infinite value, steady-state viscosity [Pa] and alpha, the ratio between the effective and unreleaxed shear modulus, mu1/(mu1 + mu2).
If no velocities and no lame parameters are given, standard crustal values of vp = 5800 m/s and vs = 3200 m/s are used. If no Q values are given, standard crustal values of qp = 1456 and qs = 600 are used. If no Burgers material parameters are given, transient and steady-state viscosities are 0 and alpha=1.
Everything is in SI units (m/s, Pa, kg/m^3) unless explicitly stated.
The main material properties are considered independant and are accessible as attributes (it is allowed to assign to these):
- vp, vs, rho, qp, qs
Other material properties are considered dependant and can be queried by instance methods.
- astuple()[source]¶
Get independant material properties as a tuple.
Returns a tuple with
(vp, vs, rho, qp, qs)
.
- class Leg(departure=None, mode=None)[source]¶
Bases:
object
Represents a continuous piece of wave propagation in a phase definition.
- class Knee(*args)[source]¶
Bases:
object
Represents a change in wave propagation within a
PhaseDef
.Attributes:
To be considered as read-only.
- exception UnknownClassicPhase(phasename)[source]¶
Bases:
CakeError
Raised when an invalid classic phase name has been specified.’
- exception PhaseDefParseError(definition, position, exception)[source]¶
Bases:
CakeError
Exception raised when an error occures during parsing of a phase definition string.
- class PhaseDef(definition=None, classicname=None)[source]¶
Bases:
object
Definition of a seismic phase arrival, based on ray propagation path.
- Parameters:
definition – string representation of the phase in Cake’s phase syntax
Seismic phases are conventionally named e.g. P, Pn, PP, PcP, etc. In Cake, a slightly different terminology is adapted, which allows to specify arbitrary conversion/reflection histories for seismic ray paths. The conventions used here are inspired by those used in the TauP toolkit, but are not completely compatible with those.
The definition of a seismic ray 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
, ors
. 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)
orDEPTH
upperside reflection:
v(INTERFACE)
orvDEPTH
underside reflection:
^(INTERFACE)
or^DEPTH
normal kind headwave or diffracted wave:
v_(INTERFACE)
orv_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 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.Examples:
P
- like the classical P, but includes PKP, PKIKP, PgP<(moho)
- like classical Pg, but must leave source downwardspP
- leaves source upward, reflects at surface, then travels as PP(moho)s
- conversion from P to S at the Moho on upgoing pathP(moho)S
- conversion from P to S at the Moho on downgoing pathPv12p
- P with reflection at 12 km deep interface (or the interface closest to that)Pv_(moho)p
- classical PnPv_(cmb)p
- classical PdiffP^(conrad)P
- underside reflection of P at the Conrad discontinuity
Usage:
>>> from pyrocko.cake import PhaseDef # must escape the backslash >>> my_crazy_phase = PhaseDef('pPv(moho)sP\\') >>> print my_crazy_phase Phase definition "pPv(moho)sP": - P mode propagation, departing upward - surface reflection - P mode propagation, departing downward - upperside reflection with conversion from P to S at moho - S mode propagation, departing upward - surface reflection with conversion from S to P - P mode propagation, departing downward - arriving at target from above
Note
These conventions might be extended in a way to allow to fix wave propagation to SH mode, possibly by specifying SH, or a single character (e.g. H) instead of S. This would be benificial for the selection of conversion and reflection coefficients, which currently only deal with the P-SV case.
- static classic(phasename)[source]¶
Get phase definitions based on classic phase name.
- Parameters:
phasename – classic name of a phase
- Returns:
list of PhaseDef objects
This returns a list of PhaseDef objects, because some classic phases (like e.g. Pg) can only be represented by two Cake style PhaseDef objects (one with downgoing and one with upgoing first leg).
- legs()[source]¶
Iterate over the continuous pieces of wave propagation (legs) defined within this phase definition.
- psv_surface_ind(in_mode, out_mode)[source]¶
Get indices to select the appropriate element from scatter matrix for free surface.
- psv_surface(material, p, energy=False)[source]¶
Scatter matrix for free surface reflection/conversions.
- Parameters:
material – material, object of type
Material
p – flat ray parameter [s/m]
energy – bool, when
True
energy normalized coefficients are returned
- Returns:
Scatter matrix
The scatter matrix is ordered as follows:
[[PP, PS], [SP, SS]]
The formulas given in Aki & Richards are used.
- psv_solid_ind(in_direction, out_direction, in_mode, out_mode)[source]¶
Get indices to select the appropriate element from scatter matrix for solid-solid interface.
- psv_solid(material1, material2, p, energy=False)[source]¶
Scatter matrix for solid-solid interface.
- Parameters:
- Returns:
Scatter matrix
The scatter matrix is ordered as follows:
[[P1P1, S1P1, P2P1, S2P1], [P1S1, S1S1, P2S1, S2S1], [P1P2, S1P2, P2P2, S2P2], [P1S2, S1S2, P2S2, S2S2]]
The formulas given in Aki & Richards are used.
- exception BadPotIntCoefs[source]¶
Bases:
CakeError
Raised when the potential interpolation for gradient layers has failed.
- exception SurfaceReached[source]¶
Bases:
PathFailed
Raised when the ray hits the surface before completing the phase requirements.
- exception BottomReached[source]¶
Bases:
PathFailed
Raised when the ray exits the bottom of the model before completing the phase requirements.
- exception MaxDepthReached[source]¶
Bases:
PathFailed
Raised when the phase’s maximum depth has been exceeded.
- exception MinDepthReached[source]¶
Bases:
PathFailed
Raised when the phase’s minimum depth has been underrun.
- exception Trapped[source]¶
Bases:
PathFailed
Raised when the ray has been trapped and therefore cannot satisfy the phase requirements.
- exception NotPhaseConform[source]¶
Bases:
PathFailed
Raised when the phase requirements cannot be met.
- exception CannotPropagate(direction, ilayer)[source]¶
Bases:
PathFailed
Raised when the phase requirements cannot be met.
- class Layer(ztop, zbot, name=None)[source]¶
Bases:
object
Representation of a layer in a layered earth model.
- Parameters:
ztop – depth of top of layer
zbot – depth of bottom of layer
name – name of layer (optional)
Subclasses are:
HomogeneousLayer
andGradientLayer
.- pflat_bottom(p)[source]¶
Convert spherical ray parameter to local flat ray parameter for bottom of layer.
- xt_potint(p, mode, zpart=None)[source]¶
Get travel time and distance for for traversal with given mode and ray parameter.
- Parameters:
This implementation uses analytic formulas valid for a spherical earth in the case where the velocity c within the layer is given by potential interpolation of the form
c(z) = a*z^b
- test(p, mode, z)[source]¶
Check if wave mode can exist for given ray parameter at given depth within the layer.
- class HomogeneousLayer(ztop, zbot, m, name=None)[source]¶
Bases:
Layer
Representation of a homogeneous layer in a layered earth model.
Base class:
Layer
.
- class GradientLayer(ztop, zbot, mtop, mbot, name=None)[source]¶
Bases:
Layer
Representation of a gradient layer in a layered earth model.
Base class:
Layer
.
- class Discontinuity(z, name=None)[source]¶
Bases:
object
Base class for discontinuities in layered earth model.
- class Interface(z, mabove, mbelow, name=None)[source]¶
Bases:
Discontinuity
Representation of an interface in a layered earth model.
Base class:
Discontinuity
.
- class Surface(z, mbelow)[source]¶
Bases:
Discontinuity
Representation of the surface discontinuity in a layered earth model.
Base class:
Discontinuity
.
- class Straight(direction_in, direction_out, mode, layer)[source]¶
Bases:
RayElement
A ray segment representing wave propagation through one
Layer
.
- class Kink(in_direction, out_direction, in_mode, out_mode, discontinuity)[source]¶
Bases:
RayElement
An interaction of a ray with a
Discontinuity
.
- class RayPath(phase)[source]¶
Bases:
object
Representation of a fan of rays running through a common sequence of layers / interfaces.
- xt_endgaps(p, endgaps, which='both')[source]¶
Get amount of distance/traveltime to be subtracted at the generic ray path’s ends.
- iter_zxt(p)[source]¶
Iterate over (depth, distance, traveltime) at each layer interface on ray path.
- zxt_path_subdivided(p, endgaps, points_per_straight=20, x_for_headwave=None)[source]¶
Get geometrical representation of ray path.
- class Ray(path, p, x, t, endgaps, draft_pxt)[source]¶
Bases:
object
Representation of a ray with a specific (path, ray parameter, distance, arrival time) choice.
Attributes:
- given_phase()[source]¶
Get phase definition which was used to create the ray.
- Returns:
PhaseDef
object
- efficiency()[source]¶
Get conversion/reflection efficiency of the ray.
A value between 0 and 1 is returned, reflecting the relative amount of energy which is transmitted along the ray and not lost by reflections or conversions.
- zxt_path_subdivided(points_per_straight=20)[source]¶
Get geometrical representation of ray path.
Three arrays (depth, distance, time) with points on the ray’s path of propagation are returned. The number of points which are used in each ray segment (passage through one layer) may be controlled by the
points_per_straight
parameter.
- class LayeredModel[source]¶
Bases:
object
Representation of a layer cake model.
There are several ways to initialize an instance of this class.
Use the module function
load_model()
to read a model from a file.Create an empty model with the default constructor and append layers and discontinuities with the
append()
method (from top to bottom).Use the constructor
LayeredModel.from_scanlines()
, to automatically create theLayer
andDiscontinuity
objects from a given velocity profile.
An earth model is represented by as stack of
Layer
andDiscontinuity
objects. The methodarrivals()
returnsRay
objects which may be e.g. queried for arrival times of specific phases. Each ray is associated with aRayPath
object. Ray objects share common ray paths if they have the same conversion/reflection/propagation history. Creating the ray path objects is relatively expensive (this is done ingather_paths()
), but they are cached for reuse in successive invocations.- copy_with_elevation(elevation)[source]¶
Get copy of the model with surface layer stretched to given elevation.
- Parameters:
elevation – new surface elevation in [m]
Elevation is positiv upward, contrary to the layered models downward z axis.
- append(element)[source]¶
Add a layer or discontinuity at bottom of model.
- Parameters:
element – object of subclass of
Layer
orDiscontinuity
.
- elements(direction=4)[source]¶
Iterate over all elements of the model.
Objects derived from the
Discontinuity
andLayer
classes are yielded.
- layers(direction=4)[source]¶
Iterate over all layers of model.
Objects derived from the
Layer
class are yielded.
- layer(z, direction=4)[source]¶
Get layer for given depth.
Returns first layer which touches depth
z
(tolerant at boundaries).
- material(z, direction=4)[source]¶
Get material at given depth.
- Parameters:
- Returns:
object of type
Material
If given depth
z
happens to be at an interface, the material of the first layer with respect to the the traversal ordering is returned.
- discontinuity(name_or_z)[source]¶
Get discontinuity by name or depth.
- Parameters:
name_or_z – name of discontinuity or depth [m] as float value
- adapt_phase(phase)[source]¶
Adapt a phase definition for use with this model.
This returns a copy of the phase definition, where named discontinuities are replaced with the actual depth of these, as defined in the model.
- path(p, phase, layer_start, layer_stop)[source]¶
Get ray path for given combination of ray parameter, phase definition, source and receiver layers.
- Parameters:
p – ray parameter (spherical) [s/rad]
phase – phase definition (
PhaseDef
object)layer_start – layer with source
layer_stop – layer with receiver
- Returns:
RayPath
object
If it is not possible to find a solution, an exception of type
NotPhaseConform
,MinDepthReached
,MaxDepthReached
,CannotPropagate
,BottomReached
orSurfaceReached
is raised.
- gather_paths(phases=PhaseDef('P'), zstart=0.0, zstop=0.0)[source]¶
Get all possible ray paths for given source and receiver depths for one or more phase definitions.
- Parameters:
- Returns:
a list of
RayPath
objects
Results of this method are cached internally. Cached results are returned, when a given combination of source layer, receiver layer and phase definition has been used before.
- arrivals(distances=[], phases=PhaseDef('P'), zstart=0.0, zstop=0.0, refine=True)[source]¶
Compute rays and traveltimes for given distances.
- Parameters:
distances – list or array of distances [deg]
phases – a
PhaseDef
object or a list of such objects. Comma-separated strings and lists of such strings are also accepted and are converted toPhaseDef
objects for convenience.zstart – source depth [m]
zstop – receiver depth [m]
refine – bool flag, whether to use bisectioning to improve (p, x, t) estimated from interpolation
- Returns:
a list of
Ray
objects, sorted by (distance, arrival time)
- classmethod from_scanlines(producer)[source]¶
Create layer cake model from sequence of materials at depths.
- Parameters:
producer – iterable yielding (depth, material, name) tuples
Creates a new
LayeredModel
object and uses itsappend()
method to add layers and discontinuities as needed.
- profile(get)[source]¶
Get parameter profile along depth of the earthmodel.
- Parameters:
get (str) – property to be queried (
'vp'
,'vs'
,'rho'
,'qp'
, or'qs'
, or'z'
)
- min(get='vp')[source]¶
Find minimum value of a material property or depth.
- Parameters:
get – property to be queried (
'vp'
,'vs'
,'rho'
,'qp'
, or'qs'
, or'z'
)
- max(get='vp')[source]¶
Find maximum value of a material property or depth.
- Parameters:
get – property to be queried (
'vp'
,'vs'
,'rho'
,'qp'
,'qs'
, or'z'
)
- simplify(max_rel_error=0.001)[source]¶
Get representation of model with lower resolution.
Returns an approximation of the model. All discontinuities are kept, but layer stacks with continuous model parameters are represented, if possible, by a lower number of layers. Piecewise linear functions are fitted against the original model parameter’s piecewise linear functions. Successively larger numbers of layers are tried, until the difference to the original model is below
max_rel_error
. The difference is measured as the RMS error of the fit normalized by the mean of the input (i.e. the fitted curves should deviate, on average, less than 0.1% from the input curves ifmax_rel_error
= 0.001).
- extract(depth_min=None, depth_max=None)[source]¶
Extract
LayeredModel
fromLayeredModel
.- Parameters:
Interpolates a
GradientLayer
atdepth_min
and/ordepth_max
.
- perturb(rstate=None, keep_vp_vs=False, zmax=None, **kwargs)[source]¶
Create a perturbed variant of the earth model.
Randomly change the thickness and material parameters of the earth model from a uniform distribution.
- Parameters:
kwargs (dict) – Maximum change fraction (e.g. 0.1) of the parameters. Name the parameter, prefixed by
p
. Supported parameters areph, pvp, pvs, prho, pqs, pqp
.rstate (
numpy.random.RandomState
) – Random state to draw from, defaults toNone
keep_vp_vs (bool) – Keep the Vp/Vs ratio, defaults to False
- Returns:
A new, perturbed earth model
- Return type:
perturbed_model = model.perturb(ph=.1, pvp=.05, prho=.1)
- read_hyposat_model(fn)[source]¶
Reader for HYPOSAT earth model files.
To be used as producer in
LayeredModel.from_scanlines()
.Interface names are translated as follows:
'MOHO'
->'moho'
,'CONR'
->'conrad'
- read_nd_model(fn)[source]¶
Reader for TauP style ‘.nd’ (named discontinuity) files.
To be used as producer in
LayeredModel.from_scanlines()
.Interface names are translated as follows:
'mantle'
->'moho'
,'outer-core'
->'cmb'
,'inner-core'
->'icb'
.The format has been modified to include Burgers materials parameters in columns 7 (burger_eta1), 8 (burger_eta2) and 9. eta(3).
- load_model(fn='ak135-f-continental.m', format='nd', crust2_profile=None)[source]¶
Load layered earth model from file.
- Parameters:
fn – filename
format – format
crust2_profile –
(lat, lon)
orpyrocko.dataset.crust2x2.Crust2Profile
object, merge model with crustal profile. Iffn
is forced to beNone
only the converted CRUST2.0 profile is returned.
- Returns:
object of type
LayeredModel
The following formats are currently supported:
format
description
'nd'
‘named discontinuity’ format used by the TauP programs
'hyposat'
format used by the HYPOSAT location program
The naming of interfaces is translated from the file format’s native naming to Cake’s own convention (See
read_nd_model()
andread_hyposat_model()
for details). Cake likes the following internal names:'conrad'
,'moho'
,'cmb'
(core-mantle boundary),'icb'
(inner core boundary).
- castagna_vs_to_vp(vs)[source]¶
Calculate vp from vs using Castagna’s relation.
Castagna’s relation (the mudrock line) is an empirical relation for vp/vs for siliciclastic rocks (i.e. sandstones and shales). [Castagna et al., 1985]
vp = 1.16 * vs + 1360 [m/s]
- Parameters:
vs – S-wave velocity [m/s]
- Returns:
P-wave velocity [m/s]
- castagna_vp_to_vs(vp)[source]¶
Calculate vp from vs using Castagna’s relation.
Castagna’s relation (the mudrock line) is an empirical relation for vp/vs for siliciclastic rocks (i.e. sandstones and shales). [Castagna et al., 1985]
vp = 1.16 * vs + 1360 [m/s]
- Parameters:
vp – P-wave velocity [m/s]
- Returns:
S-wave velocity [m/s]
- filled(v, *args, **kwargs)[source]¶
Create NumPy array filled with given value.
This works like
numpy.ones()
but initializes the array withv
instead of ones.