Skip to content

pygmt.grdvolume: Calculate grid volume and area constrained by a contour #4558

Closed

Description

@seisman

This issue serves as the central place for discussing and tracking the implementation of the pygmt.grdvolume function in PyGMT. The issue will be closed when the initial implementation is complete. Progress is tracked at PyGMT: Wrapping GMT modules.

Documentation

GMT Option Flags and Modifiers

☑️: Implemented; ⬜: To be implemented/discussed; Strikethrough: Won't implement.

  • ☑️ -C (contour): Contour level(s) defining the integration surface; accepts a single value, a low/high/delta range, or an "r" prefix to compute the outside volume between two planes.
  • ⬜ -L (base_level): Integrate below the grid and above base, setting grid NaN nodes to base first.
  • ☑️ -R (region): Subsample the grid to this subregion before computing.
  • ⬜ -T (mode): Find the contour that maximises enclosed volume ("c") or the contour at the median height ("h").
  • ☑️ -V (verbose): Verbosity level.
  • -X/-Y: Use Figure.shift_origin instead.
  • ☑️ -S (unit): Convert areas from internal square degrees to km² ("k") or miles² ("M").
  • ⬜ -Z (scale): Multiply all heights by factor and optionally add shift before integration (useful for unit conversion of z-values).
  • --PAR=value: Use pygmt.config instead.

Notes on Input Formats

  • grid: Accepts a file path or xarray.DataArray.
  • output_type: "pandas" (default), "numpy", or "file". Use "file" together with outfile.
  • The output table has four columns: contour level, area, volume, and maximum mean height (volume/area).
  • When no contour is specified, the entire grid is integrated and the contour column reports 0.
  • contour with the "r" prefix computes the volume below the lower plane and above the upper plane (outside volume), useful for computing the volume of water between two depth contours.

Linked Pull Requests

Related Issues and Discussions

  • Works naturally after pygmt.grdcut to restrict the integration to a geographic sub-domain.
  • Commonly used together with pygmt.grdinfo to first inspect the z-range before choosing contour levels.
  • The -T (optimisation) option is particularly useful for finding the topographic divide contour that separates a basin into two drainage areas.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions