pyrocko.plot.dynamic_rupture

Functions

make_colormap(gmt, vmin, vmax[, C, cmap, space])

Create gmt-readable colormap cpt file called my_<cmap>.cpt.

render_gif(fn, output_path[, loops])

Generate a gif based on a given mp4 using ffmpeg.

render_movie(fn_path, output_path[, framerate])

Generate a mp4 movie based on given png files using ffmpeg.

rupture_movie(source, store[, variable, ...])

Generate a movie based on a given source for dynamic parameter.

xy_to_latlon(source, x, y)

Convert x and y relative coordinates on extended ruptures into latlon.

xy_to_lw(source, x, y)

Convert relative coordinates on extended ruptures into length and width.

Classes

RuptureMap([source, fontcolor, width, ...])

Map plotting of attributes and results of the PseudoDynamicRupture.

RuptureView([source, figsize, fontsize])

Plot of attributes and results of the PseudoDynamicRupture.

make_colormap(gmt, vmin, vmax, C=None, cmap=None, space=False)[source]

Create gmt-readable colormap cpt file called my_<cmap>.cpt.

Parameters:
  • vmin (float) – Minimum value covered by the colormap.

  • vmax (float) – Maximum value covered by the colormap.

  • C (str) – Comma seperated R/G/B values for cmap definition.

  • cmap (str) – Name of the colormap. Colormap is stored as “my_<cmap>.cpt”. If name is equivalent to a matplotlib colormap, R/G/B strings are extracted from this colormap.

  • space (bool) – If True, the range of the colormap is broadened below vmin and above vmax.

xy_to_latlon(source, x, y)[source]

Convert x and y relative coordinates on extended ruptures into latlon.

Parameters:
Returns:

Latitude and Longitude of the given point in [deg].

Return type:

tuple of float

xy_to_lw(source, x, y)[source]

Convert relative coordinates on extended ruptures into length and width.

Parameters:
  • source (RectangularSource or PseudoDynamicRupture) – Extended source, on which the given points are located.

  • x (float or ndarray) – Relative point coordinates along strike (range: -1:1).

  • y (float or ndarray) – Relative downdip point coordinates (range: -1:1).

Returns:

Length and downdip width of the given points from the anchor in [m].

Return type:

tuple of float

class RuptureMap(source=None, fontcolor='darkslategrey', width=20.0, height=14.0, margins=None, color_wet=(216, 242, 254), color_dry=(238, 236, 230), topo_cpt_wet='light_sea_uniform', topo_cpt_dry='light_land_uniform', show_cities=False, *args, **kwargs)[source]

Bases: Map

Map plotting of attributes and results of the PseudoDynamicRupture.

property size

Figure size in [cm].

property font

Font style (size and type).

property source

PseudoDynamicRupture whose attributes are plotted.

Note, that source.patches attribute needs to be calculated in advance.

patch_data_to_grid(data, *args, **kwargs)[source]

Generate a grid file based on regular patch wise data.

Parameters:

data (ndarray) – Patchwise grid data.

xy_data_to_grid(x, y, data, *args, **kwargs)[source]

Generate a grid file based on gridded data using xy coordinates.

Convert a grid based on relative fault coordinates (range -1:1) along strike (x) and downdip (y) into a .grd file.

Parameters:
  • x (float or ndarray) – Relative point coordinate along strike (range: -1:1).

  • y (float or ndarray) – Relative downdip point coordinate (range: -1:1).

  • data (ndarray) – Patchwise grid data.

draw_image(gridfile, cmap, cbar=True, **kwargs)[source]

Draw grid data as image and include, if whished, a colorbar.

Parameters:
  • gridfile (str) – File of the grid which shall be plotted.

  • cmap (str) – Name of the colormap, which shall be used. A .cpt-file “my_<cmap>.cpt” must exist.

  • cbar (bool) – If True, a colorbar corresponding to the grid data is added. Keyword arguments are parsed to it.

draw_contour(gridfile, contour_int, anot_int, angle=None, unit='', color='', style='', **kwargs)[source]

Draw grid data as contour lines.

Parameters:
  • gridfile (str) – File of the grid which shall be plotted.

  • contour_int (float) – Interval of contour lines in units of the gridfile.

  • anot_int (float) – Interval of labelled contour lines in units of the gridfile. Must be a integer multiple of contour_int.

  • angle (float) – Rotation angle of the labels in [deg].

  • unit (str) – Name of the unit in the grid file. It will be displayed behind the label on labelled contour lines.

  • color (str) – GMT readable color code or string of the contour lines.

  • style (str) – Line style of the contour lines. If not given, solid lines are plotted.

draw_colorbar(cmap, label='', anchor='top_right', **kwargs)[source]

Draw a colorbar based on a existing colormap.

Parameters:
  • cmap (str) – Name of the colormap, which shall be used. A .cpt-file “my_<cmap>.cpt” must exist.

  • label (str) – Title of the colorbar.

  • anchor (str) – Placement of the colorbar. Combine ‘top’, ‘center’ and ‘bottom’ with ‘left’, None for middle and ‘right’.

draw_vector(x_gridfile, y_gridfile, vcolor='', **kwargs)[source]

Draw vectors based on two grid files.

Two grid files for vector lengths in x and y need to be given. The function calls gmt.grdvector. All arguments defined for this function in gmt can be passed as keyword arguments. Different standard settings are applied if not defined differently.

Parameters:
  • x_gridfile (str) – File of the grid defining vector lengths in x.

  • y_gridfile (str) – File of the grid defining vector lengths in y.

  • vcolor (str) – Vector face color as defined in “G” option.

draw_dynamic_data(data, **kwargs)[source]

Draw an image of any data gridded on the patches e.g dislocation.

Parameters:

data (ndarray) – Patchwise grid data.

draw_patch_parameter(attribute, **kwargs)[source]

Draw an image of a chosen patch attribute e.g traction.

Parameters:

attribute (str) – Patch attribute, which is plotted. All patch attributes can be taken (see doc of OkadaSource) and also traction, tx, ty or tz to display the length or the single components of the traction vector.

draw_time_contour(store, clevel=[], **kwargs)[source]

Draw high contour lines of the rupture front propgation time.

Parameters:
  • store (Store) – Greens function store, which is used for time calculation.

  • clevel (list of float) – List of times, for which contour lines are drawn.

draw_points(lats, lons, symbol='point', size=None, **kwargs)[source]

Draw points at given locations.

Parameters:
  • lats (iterable of float) – Point latitude coordinates in [deg].

  • lons (iterable of float) – Point longitude coordinates in [deg].

  • symbol (str) – Define symbol of the points ('star', 'circle', 'point', 'triangle') - default is point.

  • size (float) – Size of the points in [points].

draw_nucleation_point(**kwargs)[source]

Plot the nucleation point onto the map.

draw_dislocation(time=None, component='', **kwargs)[source]

Draw dislocation onto map at any time.

For a given time (if time is None, tmax is used) and given component the patchwise dislocation is plotted onto the map.

Parameters:
  • time (float) – Time after origin, for which dislocation is computed. If None, tmax is taken.

  • component (str) – Dislocation component, which shall be plotted: x along strike, y along updip, z normal. If None, the length of the dislocation vector is plotted.

draw_dislocation_contour(time=None, component=None, clevel=[], **kwargs)[source]

Draw dislocation contour onto map at any time.

For a given time (if time is None, tmax is used) and given component the patchwise dislocation is plotted as contour onto the map.

Parameters:
  • time (float) – Time after origin, for which dislocation is computed. If None, tmax is taken.

  • component (str) – Dislocation component, which shall be plotted: x along strike, y along updip, z normal``. If None, the length of the dislocation vector is plotted.

  • clevel (list of float) – Times, for which contour lines are drawn.

draw_dislocation_vector(time=None, **kwargs)[source]

Draw vector arrows onto map indicating direction of dislocation.

For a given time (if time is None, tmax is used) and given component the dislocation is plotted as vectors onto the map.

Parameters:

time (float) – Time after origin [s], for which dislocation is computed. If None, tmax is used.

draw_top_edge(**kwargs)[source]

Indicate rupture top edge on map.

class RuptureView(source=None, figsize=None, fontsize=None)[source]

Bases: Object

Plot of attributes and results of the PseudoDynamicRupture.

property source

PseudoDynamicRupture whose attributes are plotted.

Note, that source.patches attribute needs to be calculated for :type source: PseudoDynamicRupture.

draw_points(length, width, *args, **kwargs)[source]

Draw a point onto the figure.

Args and kwargs can be defined according to matplotlib.pyplot.scatter().

Parameters:
  • length (float, ndarray) – Point(s) coordinate on the rupture plane along strike relative to the anchor point in [m].

  • width (float, ndarray) – Point(s) coordinate on the rupture plane along downdip relative to the anchor point in [m].

draw_dynamic_data(data, **kwargs)[source]

Draw an image of any data gridded on the patches e.g dislocation.

Parameters:

data (ndarray) – Patchwise grid data.

draw_patch_parameter(attribute, **kwargs)[source]

Draw an image of a chosen patch attribute e.g traction.

Parameters:

attribute (str) – Patch attribute, which is plotted. All patch attributes can be taken (see doc of OkadaSource) and also 'traction', 'tx', 'ty', 'tz' to display the length or the single components of the traction vector.

draw_time_contour(store, clevel=[], **kwargs)[source]

Draw high resolution contours of the rupture front propgation time

Parameters:
  • store (Store) – Greens function store, which is used for time calculation.

  • clevel (list) – Levels of the contour lines. If no levels are given, they are automatically computed based on tmin and tmax.

draw_nucleation_point(**kwargs)[source]

Draw the nucleation point onto the map.

draw_dislocation(time=None, component='', **kwargs)[source]

Draw dislocation onto map at any time.

For a given time (if time is None, tmax is used) and given component the patchwise dislocation is plotted onto the map.

Parameters:
  • time (float) – Time after origin [s], for which dislocation is computed. If None, tmax is taken.

  • component (str) – Dislocation component, which shall be plotted: x along strike, y along updip, z normal. If None, the length of the dislocation vector is plotted

draw_dislocation_contour(time=None, component=None, clevel=[], **kwargs)[source]

Draw dislocation contour onto map at any time.

For a given time (if time is None, tmax is used) and given component the patchwise dislocation is plotted as contour onto the map.

Parameters:
  • time (float) – Time after origin, for which dislocation is computed. If None, tmax is taken.

  • component (str) – Dislocation component, which shall be plotted. x along strike, y along updip, z - normal. If None is given, the length of the dislocation vector is plotted.

draw_source_dynamics(variable, store, deltat=None, *args, **kwargs)[source]

Display dynamic source parameter.

Fast inspection possibility for the cumulative moment and the source time function approximation (assuming equal paths between different patches and observation point - valid for an observation point in the far field perpendicular to the source strike), so the cumulative moment rate function.

Parameters:
  • variable (str) – Dynamic parameter, which shall be plotted. Choose between ‘moment_rate’ (‘stf’) or ‘cumulative_moment’ (‘moment’)

  • store (Store) – Greens function store, whose store.config.deltat defines the time increment between two parameter snapshots. If store is not given, the time increment is defined is taken from deltat.

  • deltat (float) – Time increment between two parameter snapshots. If not given, store.config.deltat is used to define deltat.

draw_patch_dynamics(variable, nx, ny, store=None, deltat=None, *args, **kwargs)[source]

Display dynamic boundary element / patch parameter.

Fast inspection possibility for different dynamic parameter for a single patch / boundary element. The chosen parameter is plotted for the chosen patch.

Parameters:
  • variable (str) – Dynamic parameter, which shall be plotted. Choose between ‘moment_rate’ (‘stf’) or ‘cumulative_moment’ (‘moment’).

  • nx (int) – Patch index along strike (range: 0:source.nx - 1).

  • nx – Patch index downdip (range: 0:source.ny - 1).

  • store (Store) – Greens function store, whose store.config.deltat defines the time increment between two parameter snapshots. If store is not given, the time increment is defined is taken from deltat.

  • deltat (float) – Time increment between two parameter snapshots. If not given, store.config.deltat is used to define deltat.

save(filename, dpi=None)[source]

Save plot to file.

Parameters:
  • filename (str) – Filename and path, where the plot is stored.

  • dpi (int) – Resolution of the output plot in [dpi].

show_plot()[source]

Show plot.

render_movie(fn_path, output_path, framerate=20)[source]

Generate a mp4 movie based on given png files using ffmpeg.

Render a movie based on a set of given .png files in fn_path. All files must have a filename specified by fn_path (e.g. giving fn_path with /temp/f%04.png a valid png filename would be /temp/f0001.png). The files must have a numbering, indicating their order in the movie.

Parameters:
  • fn_path (str) – Path and fileformat specification of the input .png files.

  • output_path (str) – Path and filename of the output .mp4 movie file.

  • deltat (float) – Time between individual frames (1 / framerate) in [s].

render_gif(fn, output_path, loops=-1)[source]

Generate a gif based on a given mp4 using ffmpeg.

Render a gif based on a given .mp4 movie file in fn path.

Parameters:
  • fn (str) – Path and file name of the input .mp4 file.

  • output_path (str) – Path and filename of the output animated gif file.

  • loops (int) – Number of gif repeats (loops). -1 is not repetition, 0 infinite.

rupture_movie(source, store, variable='dislocation', draw_time_contours=False, fn_path='.', prefix='', plot_type='map', deltat=None, framerate=None, store_images=False, render_as_gif=False, gif_loops=-1, **kwargs)[source]

Generate a movie based on a given source for dynamic parameter.

Create a MPEG-4 movie or gif of one of the following dynamic parameters (dislocation, dislocation_x (along strike), dislocation_y (along updip), dislocation_z (normal), slip_rate, moment_rate). If desired, the single snap shots can be stored as images as well. kwargs have to be given according to the chosen plot_type.

Parameters:
  • source (PseudoDynamicRupture) – Pseudo dynamic rupture, for which the movie is produced.

  • store (Store) – Greens function store, which is used for time calculation. If deltat is not given, it is taken from the store.config.deltat

  • variable (str) – Dynamic parameter, which shall be plotted. Choose between dislocation, dislocation_x (along strike), dislocation_y (along updip), dislocation_z (normal), slip_rate and moment_rate, default dislocation.

  • draw_time_contours (bool) – If True, corresponding isochrones are drawn on the each plots.

  • fn_path (str) – Absolut or relative path, where movie (and optional images) are stored.

  • prefix (str) – File prefix used for the movie (and optional image) files.

  • plot_type (str) – Choice of plot type: map, view (map plot using RuptureMap or plane view using RuptureView).

  • deltat (float) – Time between parameter snapshots. If not given, store.config.deltat is used to define deltat.

  • store_images (bool) – Choice to store the single .png parameter snapshots in fn_path or not.

  • render_as_gif (bool) – If True, the movie is converted into a gif. If False, the movie is returned as mp4.

  • gif_loops (int) – If render_as_gif is True, a gif with gif_loops number of loops (repetitions) is returned. -1 is no repetition, 0 infinite.