openquake.hmtk.plotting package

Subpackages

Submodules

openquake.hmtk.plotting.beachball module

Draws a beachball diagram of an earthquake focal mechanism

Most source code provided here are adopted from

  1. MatLab script bb.m written by Andy Michael and Oliver Boyd.

  2. ps_meca program from the Generic Mapping Tools (GMT).

copyright

The ObsPy Development Team (devs@obspy.org)

license

GNU General Public License (GPL) (http://www.gnu.org/licenses/gpl.txt)

openquake.hmtk.plotting.beachball.AuxPlane(s1, d1, r1)[source]

Get Strike and dip of second plane.

Adapted from MATLAB script bb.m written by Andy Michael and Oliver Boyd.

openquake.hmtk.plotting.beachball.Beach(fm, linewidth=2, facecolor='b', bgcolor='w', edgecolor='k', alpha=1.0, xy=(0, 0), width=200, size=100, nofill=False, zorder=100, axes=None)[source]

Return a beach ball as a collection which can be connected to an current matplotlib axes instance (ax.add_collection).

S1, D1, and R1, the strike, dip and rake of one of the focal planes, can be vectors of multiple focal mechanisms.

Parameters
  • fm – Focal mechanism that is either number of mechanisms (NM) by 3 (strike, dip, and rake) or NM x 6 (M11, M22, M33, M12, M13, M23 - the six independent components of the moment tensor, where the coordinate system is 1,2,3 = Up,South,East which equals r,theta,phi). The strike is of the first plane, clockwise relative to north. The dip is of the first plane, defined clockwise and perpendicular to strike, relative to horizontal such that 0 is horizontal and 90 is vertical. The rake is of the first focal plane solution. 90 moves the hanging wall up-dip (thrust), 0 moves it in the strike direction (left-lateral), -90 moves it down-dip (normal), and 180 moves it opposite to strike (right-lateral).

  • facecolor – Color to use for quadrants of tension; can be a string, e.g. 'r', 'b' or three component color vector, [R G B]. Defaults to 'b' (blue).

  • bgcolor – The background color. Defaults to 'w' (white).

  • edgecolor – Color of the edges. Defaults to 'k' (black).

  • alpha – The alpha level of the beach ball. Defaults to 1.0 (opaque).

  • xy – Origin position of the beach ball as tuple. Defaults to (0, 0).

  • width (int or tuple) – Symbol size of beach ball, or tuple for elliptically shaped patches. Defaults to size 200.

  • size – Controls the number of interpolation points for the curves. Minimum is automatically set to 100.

  • nofill – Do not fill the beach ball, but only plot the planes.

  • zorder – Set zorder. Artists with lower zorder values are drawn first.

  • axes (matplotlib.axes.Axes) – Used to make beach balls circular on non-scaled axes. Also maintains the aspect ratio when resizing the figure. Will not add the returned collection to the axes instance.

openquake.hmtk.plotting.beachball.Beachball(fm, linewidth=2, facecolor='b', bgcolor='w', edgecolor='k', alpha=1.0, xy=(0, 0), width=200, size=100, nofill=False, zorder=100, outfile=None, format=None, fig=None)[source]

Draws a beach ball diagram of an earthquake focal mechanism.

S1, D1, and R1, the strike, dip and rake of one of the focal planes, can be vectors of multiple focal mechanisms.

Parameters
  • fm – Focal mechanism that is either number of mechanisms (NM) by 3 (strike, dip, and rake) or NM x 6 (M11, M22, M33, M12, M13, M23 - the six independent components of the moment tensor, where the coordinate system is 1,2,3 = Up,South,East which equals r,theta,phi). The strike is of the first plane, clockwise relative to north. The dip is of the first plane, defined clockwise and perpendicular to strike, relative to horizontal such that 0 is horizontal and 90 is vertical. The rake is of the first focal plane solution. 90 moves the hanging wall up-dip (thrust), 0 moves it in the strike direction (left-lateral), -90 moves it down-dip (normal), and 180 moves it opposite to strike (right-lateral).

  • facecolor – Color to use for quadrants of tension; can be a string, e.g. 'r', 'b' or three component color vector, [R G B]. Defaults to 'b' (blue).

  • bgcolor – The background color. Defaults to 'w' (white).

  • edgecolor – Color of the edges. Defaults to 'k' (black).

  • alpha – The alpha level of the beach ball. Defaults to 1.0 (opaque).

  • xy – Origin position of the beach ball as tuple. Defaults to (0, 0).

  • width (int) – Symbol size of beach ball. Defaults to 200.

  • size – Controls the number of interpolation points for the curves. Minimum is automatically set to 100.

  • nofill – Do not fill the beach ball, but only plot the planes.

  • zorder – Set zorder. Artists with lower zorder values are drawn first.

  • outfile – Output file string. Also used to automatically determine the output format. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg. Defaults to None.

  • format – Format of the graph picture. If no format is given the outfile parameter will be used to try to automatically determine the output format. If no format is found it defaults to png output. If no outfile is specified but a format is, than a binary imagestring will be returned. Defaults to None.

  • fig – Give an existing figure instance to plot into. New Figure if set to None.

openquake.hmtk.plotting.beachball.MT2Axes(mt)[source]

Calculates the principal axes of a given moment tensor.

Parameters

mtMomentTensor

Returns

tuple of PrincipalAxis T, N and P

Adapted from ps_tensor / utilmeca.c / Generic Mapping Tools (GMT).

openquake.hmtk.plotting.beachball.MT2Plane(mt)[source]

Calculates a nodal plane of a given moment tensor.

Parameters

mtMomentTensor

Returns

NodalPlane

Adapted from MATLAB script bb.m written by Andy Michael and Oliver Boyd.

class openquake.hmtk.plotting.beachball.MomentTensor(*args)[source]

Bases: object

A moment tensor.

>>> a = MomentTensor(1, 1, 0, 0, 0, -1, 26)
>>> b = MomentTensor(np.array([1, 1, 0, 0, 0, -1]), 26)
>>> c = MomentTensor(np.array([[1, 0, 0], [0, 1, -1], [0, -1, 0]]), 26)
>>> a.mt
array([[ 1,  0,  0],
       [ 0,  1, -1],
       [ 0, -1,  0]])
>>> b.yz
-1
>>> a.expo
26
property xx
property xy
property xz
property yy
property yz
property zz
class openquake.hmtk.plotting.beachball.NodalPlane(strike=0, dip=0, rake=0)[source]

Bases: object

A nodal plane.

All values are in degrees.

>>> a = NodalPlane(13, 20, 50)
>>> a.strike
13
>>> a.dip
20
>>> a.rake
50
openquake.hmtk.plotting.beachball.Pol2Cart(th, r)[source]
class openquake.hmtk.plotting.beachball.PrincipalAxis(val=0, strike=0, dip=0)[source]

Bases: object

A principal axis.

Strike and dip values are in degrees.

>>> a = PrincipalAxis(1.3, 20, 50)
>>> a.dip
50
>>> a.strike
20
>>> a.val
1.3
openquake.hmtk.plotting.beachball.StrikeDip(n, e, u)[source]

Finds strike and dip of plane given normal vector having components n, e, and u.

Adapted from MATLAB script bb.m written by Andy Michael and Oliver Boyd.

openquake.hmtk.plotting.beachball.TDL(AN, BN)[source]

Helper function for MT2Plane.

Adapted from MATLAB script bb.m written by Andy Michael and Oliver Boyd.

openquake.hmtk.plotting.beachball.plotDC(np1, size=200, xy=(0, 0), width=200)[source]

Uses one nodal plane of a double couple to draw a beach ball plot.

Parameters
  • ax – axis object of a matplotlib figure

  • np1NodalPlane

Adapted from MATLAB script bb.m written by Andy Michael and Oliver Boyd.

openquake.hmtk.plotting.beachball.plotMT(T, N, P, size=200, plot_zerotrace=True, x0=0, y0=0, xy=(0, 0), width=200)[source]

Uses a principal axis T, N and P to draw a beach ball plot.

Parameters

Adapted from ps_tensor / utilmeca.c / Generic Mapping Tools (GMT).

openquake.hmtk.plotting.beachball.xy2patch(x, y, res, xy)[source]

openquake.hmtk.plotting.plotting_utils module

Module contents