GroundModel

GroundModel class definition.

class GroundModel(thickness, vp, vs, density, identifier=0, misfit=0.0)

Bases: object

Class for creating and manipulating GroundModel objects.

Variables:
  • vp, vs, rh (tk,) – Thickness, compression-wave velocity (Vp), shear-wave velocity (Vs), and mass density defining each layer of the GroundModel, respectively.
  • identifier (int, optional) – Model numeric identifier, default is 0.
  • misfit (float, optional) – Model misfit, default is 0.0.
__init__(thickness, vp, vs, density, identifier=0, misfit=0.0)

Initialize a GroundModel object.

Parameters:
  • thickness (iterable) – Container of float or int denoting layer thickness (one per layer) in meters starting from the ground surface.
  • vp, vs (iterable) – Container of float or int denoting the P- and S-wave velocity of each layer in m/s.
  • density (iterable) – Container of float or int denoting the mass density of each layer in kg/m3.
  • identifier (int, optional) – Model numeric identifier, default is 0.
  • misfit (float, optional) – Model misfit, default is 0.0.
Returns:

GroundModel – Instantiated GroundModel object.

Raises:

Various – See :meth: check_input_type <GroundModel.check_input_type and :meth: check_input_value <GroundModel.check_input_value for details.

static calc_pr(vp, vs)

Calculate Poisson’s ratio from iterable of vp and vs.

Parameters:vp, vs (float, int, or iterable) – Vp and Vs values, respectively
Returns:float or list – Poisson’s ratio, calculated from each vp, vs pair.
Raises:ValueError – If vs>vp or Poisson’s ratio is negative (i.e., vp/vs too close to 1).
check_input(**kwargs)

Check input values and types.

static check_input_type(**kwargs)

Check inputs are of the appropriate type.

Specifically: 1. Cast GroundModel input to a list of float. 2. Cast meta-information (identifier and misfit to int and float).

Parameters:**kwargs – Keyword arguments containing name and value pairs.
Raises:TypeError – If values do not pass the aforementioned criteria.
static check_input_value(**kwargs)

Check values have appropriate values.

Specifically: 1. Check that all GroundModel parameters are greater than zero. 2. Check that identifier and misfit are greater than zero. 3. Check that vp > vs.

Parameters:**kwargs – Keyword arguments containing name and value pairs.
Raises:ValueError – If inputs does not pass the aforementioned criteria.
depth

Return stair-step version of depth profile.

static depth_to_thick(depths)

Convert depths (top of each layer) to thicknesses

Parameters:depth (list) – List of consecutive depths.
Returns:list – Thickness for each layer. Half-space is defined with zero thickness.
discretize(dmax, dy=0.5, parameter='vs')

Discretize a parameter of the GroundModel.

The GroundModel is discretized in terms of depth from the surface to dmax by dy such that depth will be a list of the form [0:dy:dmax]. When the discretization encounters a parameter boundary the velocity of the upper layer is assigned.

Do not use these discretized models for plotting unless dy is very small, as they may be misleading.

Parameters:
  • dmax (float) – Maximum depth of discretization.
  • dy (float, optional) – Linear step of discretization in terms of depth, default is 0.5 meter.
  • parameter ({‘vp’, ‘vs’, ‘rh’, ‘pr’}, optional) – Parameter to be discretized, default is ‘vs’.
Returns:

Tuple – Tuple of the form (depth, param) where depth is a list of the discretized depths, and parameter is a list of the discretized parameter at those depths.

Raises:

KeyError – If parameter is not one of those options specified.

classmethod from_geopsy(fname)

Create from a text file following the Geopsy format.

Parameters:fname (fname) – File name, may contain a relative or the full path.
Returns:GroundModel – Initialized GroundModel object.
Raises:Various – If file does not follow the Geopsy format.
classmethod from_simple_profiles(vp_tk, vp, vs_tk, vs, rh_tk, rh)

Instantiate GroundModel from simple profiles.

Parameters:
  • vp_tk, vs_tk, rh_tk (iterable) – Iterable denoting the thicknesses of each parameter, one per layer.
  • vp, vs, rh (iterable) – Iterable denoting the value of Vp, Vs, and mass density respectively.
Returns:

GroundModel – Instantiated GroundModel object.

gm2(parameter)

Parameter of GroundModel in stair-step form.

Parameters:parameter ({‘depth’, ‘vp’, ‘vs’, ‘density’, ‘pr’}) – Desired parameter to transform to stair-step profile.
Returns:list – Defining the specified parameter.
Raises:KeyError – If parameter is not one of those specified.
nlay
pr2

Return stair-step version of Poisson’s ratio profile.

rh
rh2

Return stair-step version of density profile.

simplify(parameter='vs')

Remove unnecessary breaks in the parameter specified.

This will typically be used for calculating the median across many profiles.

parameter : {‘vs’,’vp’,’rh’,’density’}, optional
String denoting parameter to be simplified, default is ‘vs’.
Returns:tuple – Of the form (thickness, parameter) where thickness is a list of simplified thicknesses and parameter is a list of the simplified parameter.
static thick_to_depth(thicknesses)

Convert thickness to depth (at top of each layer).

Parameters:thickness (list) – List of thicknesses defining a ground model.
Returns:list – List of depths at the top of each layer.
tk
txt_repr

Text representation of the current GroundModel.

vp2

Return stair-step version of Vp profile.

vs2

Return stair-step version of Vs profile.

vs30

Calculate Vs30 of the GroundModel.

Vs0 is the time-averaged shear-wave velocity in the upper 30m.

Returns:float – Vs30 of GroundModel.
write_model(fileobj)

Write model to open file object following Geopsy format.

Parameters:fileobj (_io.TextIOWrapper) – Name of file, may be a relative or the full path.
Returns:None – Writes file to disk.
write_to_mat(fname_prefix)

Save GroundModel information to .mat format.

Parameters:fname_prefix (str) – Name of file (excluding the .mat extension) where the file should be saved, may be a relative or the full path.
Returns:None – Writes file to disk.
write_to_txt(fname)

Write GroundModel to file that follows the Geospy format.

Parameters:fname (str) – Name of file, may contain a relative or the full path.
Returns:None – Writes file to disk.