openquake.hmtk.plotting package

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
xx
xy
xz
yy
yz
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.mapping module

Module openquake.hmtk.plotting.catalogue.map is a graphical function for plotting the spatial distribution of events

class openquake.hmtk.plotting.mapping.HMTKBaseMap(config, title=None, dpi=300, ax=None, lat_lon_spacing=2.0)[source]

Bases: object

Class to plot the spatial distribution of events based in the Catalogue imported from openquake.hmtk.

add_catalogue(catalogue, overlay=False)[source]
Parameters
  • catalogue – Earthquake catalogue as instance of openquake.hmtk.seismicity.catalogue.Catalogue

  • config (dict) – Configuration parameters of the algorithm, containing the following information: ‘min_lat’ Minimum value of latitude (in degrees, float) ‘max_lat’ Minimum value of longitude (in degrees, float) (min_lat, min_lon) Defines the inferior corner of the map ‘min_lon’ Maximum value of latitude (in degrees, float) ‘max_lon’ Maximum value of longitude (in degrees, float) (min_lon, max_lon) Defines the upper corner of the map

Returns

Figure with the spatial distribution of the events.

add_catalogue_cluster(catalogue, vcl, flagvector, cluster_id=None, overlay=True)[source]

Creates a plot of a catalogue showing where particular clusters exist

add_colour_scaled_points(longitude, latitude, data, shape='s', alpha=1.0, size=20, norm=None, overlay=False)[source]

Overlays a set of points on a map with a fixed size but colour scaled according to the data

Parameters
  • longitude (np.ndarray) – Longitude

  • latitude (np.ndarray) – Latitude

  • data (np.ndarray) – Data for plotting

  • shape (str) – Marker style

  • alpha (float) – Sets the transparency of the marker (0 for transparent, 1 opaque)

  • size (int) – Marker size

  • norm – Normalisation as instance of :class: matplotlib.colors.Normalize

add_focal_mechanism(catalogue, magnitude=None, overlay=True)[source]

Plots a the the focal mechanism based on the beachball representation. The focal_menchanism flag must contain: strike, dip, rake.

add_size_scaled_points(longitude, latitude, data, shape='o', logplot=False, alpha=1.0, colour='b', smin=2.0, sscale=2.0, overlay=False)[source]

Plots a set of points with size scaled according to the data

Parameters
  • logplot (bool) – Choose to scale according to the logarithm (base 10) of the data

  • smin (float) – Minimum scale size

  • sscale (float) – Scaling factor

add_source_model(model, area_border='k-', border_width=1.0, point_marker='ks', point_size=2.0, overlay=False, min_depth=0.0, max_depth=None, alpha=1.0)[source]

Adds a source model to the map

Parameters

model – Source model of mixed typologies as instance of :class: openquake.hmtk.sources.source_model.mtkSourceModel

savemap(filename, filetype='png', papertype='a4')[source]

Save the figure

openquake.hmtk.plotting.plotting_utils module

Module contents