anuga.SWW_plotter

class anuga.SWW_plotter(swwfile='domain.sww', plot_dir='_plot', min_depth=0.001, absolute=False)[source]

Bases: object

A class to wrap ANUGA swwfile centroid values for stage, height, elevation xmomentum and ymomentum, and triangulation information.

Plotting functions are provided to plot depth, speed, speed_depth, stage and mesh, and to create animations of depth, speed, speed_depth (momentum) and stage.

Plotting based on matplotlib’s tripcolor and triplot functions.

Example

Open an SWW file and plot various quantities.

>>> import anuga
>>> import matplotlib.pyplot as plt
>>>
>>> # Enable interactive mode
>>> plot.ion()
>>>
>>> # Create SWW plotter object by opening an SWW file
>>> splotter = anuga.SWW_plotter('domain.sww')
>>>
>>> # Find min and max depth for plotting
>>> vmin = splotter.depth.min()
>>> vmax = splotter.depth.max()
>>>
>>> # Plot depth at last frame.
>>> fig, ax = splotter.plot_depth_frame(-1, vmin=vmin, vmax=vmax)
>>> ax.set_title('Depth at final time')
>>>
>>> # Plot speed at second frame
>>> fig, ax = splotter.plot_speed_frame(1)
>>> ax.set_title('Speed at second frame')
>>>
>>> # Plot Mesh
>>> fig, ax, im = splotter.plot_mesh()
>>> ax.set_title('Mesh')
>>>
>>> # Animate depth
>>> for frame in range(len(splotter.time)):
...     splotter.save_depth_frame(frame, vmin=vmin, vmax=vmax)
>>> anim = splotter.make_depth_animation()
__init__(swwfile='domain.sww', plot_dir='_plot', min_depth=0.001, absolute=False)[source]

Methods

__init__([swwfile, plot_dir, min_depth, ...])

get_flow_through_cross_section(polyline[, ...])

Calculate flow through a cross-section defined by a polyline.

get_triangles_inside_polygon(polygon[, verbose])

Get list of triangle IDs whose centroids lie within a given polygon.

make_depth_animation()

make_plot_dir([clobber])

Utility function to create a directory for storing a sequence of plot files, or if the directory already exists, clear out any old plots.

make_speed_animation()

make_speed_depth_animation()

make_stage_animation()

plot_depth_frame([frame, figsize, dpi, ...])

plot_elev_frame([frame, figsize, dpi, vmin, ...])

plot_mesh([figsize, dpi])

plot_speed_depth_frame([frame, figsize, ...])

plot_speed_frame([frame, figsize, dpi, ...])

plot_stage_frame([frame, figsize, dpi, ...])

save_depth_frame([frame, figsize, dpi, ...])

save_elev_delta_frame([frame, figsize, dpi, ...])

Save one elevation-change frame (elev[t] - elev[0]) to disk.

save_elev_frame([frame, figsize, dpi, vmin, ...])

Save one elevation frame to disk.

save_max_depth_frame([frame, figsize, dpi, ...])

Save a single frame showing the maximum depth at each triangle.

save_max_speed_depth_frame([frame, figsize, ...])

Save a single frame showing the maximum speed×depth at each triangle.

save_max_speed_frame([frame, figsize, dpi, ...])

Save a single frame showing the maximum speed at each triangle.

save_max_stage_frame([frame, figsize, dpi, ...])

Save a single frame showing the maximum stage at each triangle.

save_speed_depth_frame([frame, figsize, ...])

save_speed_frame([frame, figsize, dpi, ...])

save_stage_frame([frame, figsize, dpi, ...])

set_epsg(epsg)

Set (or override) the EPSG code and rebuild the absolute-coordinate triangulation used for basemap overlays.

tripcolor([figsize, dpi])

Create a tripcolor plot of the mesh.

triplot([figsize, dpi])

Create a triplot of the mesh.

water_volume([per_unit_area, triangle_ids, ...])

Compute the water volume associated within a subset of triangles or within a polygon.

Attributes

elev_delta

shape (n_time, n_tri), or None for static.

max_depth

precomputed from SWW if available, else max over time.

max_speed

precomputed from SWW if available, else max over time.

max_speed_depth

precomputed (max_uh_c) or max over time.

max_stage

precomputed from SWW if available, else max over time.

property elev_delta

shape (n_time, n_tri), or None for static.

Type:

Bed elevation change from t=0

get_flow_through_cross_section(polyline: list, verbose: bool = False) tuple[ndarray, list][source]

Calculate flow through a cross-section defined by a polyline.

Parameters:
  • polyline – List of [x, y] coordinates defining the cross-section

  • verbose – Whether to print debug information

Returns:

  • time: numpy array of time values

  • Q: list of flow values at each timestep

Return type:

tuple containing

get_triangles_inside_polygon(polygon: list | ndarray, verbose: bool = False) list | ndarray[source]

Get list of triangle IDs whose centroids lie within a given polygon.

Parameters:
  • polygon – List of [x, y] coordinates defining the polygon

  • verbose – Whether to print debug information

Returns:

List of triangle IDs inside the polygon

make_plot_dir(clobber=True)[source]

Utility function to create a directory for storing a sequence of plot files, or if the directory already exists, clear out any old plots. If clobber==False then it will abort instead of deleting existing files.

property max_depth

precomputed from SWW if available, else max over time.

Type:

Max depth per triangle

property max_speed

precomputed from SWW if available, else max over time.

Type:

Max speed per triangle

property max_speed_depth

precomputed (max_uh_c) or max over time.

Type:

Max momentum magnitude per triangle

property max_stage

precomputed from SWW if available, else max over time.

Type:

Max stage per triangle

save_elev_delta_frame(frame=-1, figsize=(10, 6), dpi=160, vmin=-5.0, vmax=5.0, cmap='RdBu_r', basemap=False, alpha=1.0, basemap_provider='OpenStreetMap.Mapnik', xlim=None, ylim=None, smooth=False, show_elev=False, elev_levels=10, show_mesh=False)[source]

Save one elevation-change frame (elev[t] - elev[0]) to disk.

save_elev_frame(frame=-1, figsize=(10, 6), dpi=160, vmin=-20.0, vmax=100.0, cmap='terrain', basemap=False, alpha=1.0, basemap_provider='OpenStreetMap.Mapnik', xlim=None, ylim=None, smooth=False, show_elev=False, elev_levels=10, show_mesh=False)[source]

Save one elevation frame to disk.

For static elevation (1-D) the frame argument is ignored.

save_max_depth_frame(frame=None, figsize=(10, 6), dpi=160, vmin=0.0, vmax=20.0, cmap='viridis', basemap=False, alpha=1.0, basemap_provider='OpenStreetMap.Mapnik', xlim=None, ylim=None, smooth=False, show_elev=False, elev_levels=10, show_mesh=False)[source]

Save a single frame showing the maximum depth at each triangle.

save_max_speed_depth_frame(frame=None, figsize=(10, 6), dpi=160, vmin=0.0, vmax=20.0, cmap='viridis', basemap=False, alpha=1.0, basemap_provider='OpenStreetMap.Mapnik', xlim=None, ylim=None, smooth=False, show_elev=False, elev_levels=10, show_mesh=False)[source]

Save a single frame showing the maximum speed×depth at each triangle.

save_max_speed_frame(frame=None, figsize=(10, 6), dpi=160, vmin=0.0, vmax=10.0, cmap='viridis', basemap=False, alpha=1.0, basemap_provider='OpenStreetMap.Mapnik', xlim=None, ylim=None, smooth=False, show_elev=False, elev_levels=10, show_mesh=False)[source]

Save a single frame showing the maximum speed at each triangle.

save_max_stage_frame(frame=None, figsize=(10, 6), dpi=160, vmin=-20.0, vmax=20.0, cmap='viridis', basemap=False, alpha=1.0, basemap_provider='OpenStreetMap.Mapnik', xlim=None, ylim=None, smooth=False, show_elev=False, elev_levels=10, show_mesh=False)[source]

Save a single frame showing the maximum stage at each triangle.

set_epsg(epsg)[source]

Set (or override) the EPSG code and rebuild the absolute-coordinate triangulation used for basemap overlays.

Useful when the SWW file pre-dates EPSG storage (older files lack the attribute). Call this before generating frames with basemap=True.

Parameters:

epsg (int or None) – EPSG code of the coordinate system, e.g. 32756 for UTM zone 56 S. Pass None to clear the code and disable basemap support.

tripcolor(figsize=(10, 6), dpi=80, **kwargs)[source]

Create a tripcolor plot of the mesh.

Parameters:
  • figsize – Figure size

  • dpi – Dots per inch

  • **kwargs – Additional arguments to pass to tripcolor

Returns:

Matplotlib figure object ax: Matplotlib axes object im: The image created by tripcolor

Return type:

fig

triplot(figsize=(10, 6), dpi=80, **kwargs)[source]

Create a triplot of the mesh.

Parameters:
  • figsize – Figure size

  • dpi – Dots per inch

  • **kwargs – Additional arguments to pass to triplot

Returns:

Matplotlib figure object ax: Matplotlib axes object lines: The lines created by triplot

Return type:

fig

water_volume(per_unit_area=False, triangle_ids=None, polygon=None, verbose=False) ndarray[source]

Compute the water volume associated within a subset of triangles or within a polygon.

Parameters:
  • per_unit_area – If True, return volume per unit area

  • triangle_ids – List of triangle IDs to include

  • polygon – Polygon defining area of interest

  • verbose – Whether to print debug information

Returns:

Numpy array of water volume at each timestep