API Reference
PyGMT is a library for processing geospatial and geophysical data and making publication-quality maps and figures. It provides a Pythonic interface for the Generic Mapping Tools (GMT), a command-line program widely used across the Earth, Ocean, and Planetary sciences and beyond. Besides making GMT more accessible to new users, PyGMT aims to provide integration with the scientific Python ecosystem as well as support for rich display in Jupyter notebooks.
Main Features
Here are just a few of the things that PyGMT does well:
Easy handling of individual types of data like Cartesian, geographic, or time-series data.
Processing of (geo)spatial data including gridding, filtering, and masking.
Plotting of a large spectrum of objects on figures including lines, vectors, polygons, and symbols (pre-defined and customized).
Generating publication-quality illustrations and making animations.
Plotting
Figure class overview
All plotting is handled through the pygmt.Figure
class and its methods.
|
A GMT figure to handle all plotting. |
Plotting map elements
|
Plot base maps and frames for the figure. |
|
Plot continents, shorelines, rivers, and borders on maps. |
|
Plot colorbars on figures. |
|
Create an inset figure to be placed within a larger figure. |
|
Plot legends on maps. |
|
Plot the GMT logo. |
|
Plot day-light terminators or twilights. |
|
Plot or typeset text strings of variable size, font type, and orientation. |
|
Plot the GMT timestamp logo. |
Plotting tabular data
|
Contour table data by direct triangulation. |
|
Plot Cartesian histograms. |
|
Plot focal mechanisms. |
|
Plot lines, polygons, and symbols in 2-D. |
|
Plot lines, polygons, and symbols in 3-D. |
|
Plot windrose diagrams or polar histograms. |
|
Plot ternary diagrams. |
|
Plot velocity vectors, crosses, anisotropy bars, and wedges. |
|
Plot z=f(x,y) anomalies along tracks. |
Plotting raster data
|
Convert grids or images to contours and plot them on maps. |
|
Project and plot grids or images. |
|
Create 3-D perspective image or surface mesh from a grid. |
|
Place images or EPS files on maps. |
|
Plot an XYZ tile map. |
Configuring layout
|
Set the current subplot panel to plot on. |
|
Shift plot origin in x and/or y directions. |
|
Create multi-panel subplot figures. |
Saving and displaying the figure
|
Save the figure to an image file. |
|
Display a preview of the figure. |
|
Convert [E]PS file(s) to other formats. |
Configuring the display settings
The following function is provided directly through the pygmt
top level
package.
|
Set the display method when calling |
Color palette table generation
The following functions are provided directly through the pygmt
top level
package.
|
Make GMT color palette tables from a grid file. |
|
Make GMT color palette tables. |
Data Processing
Operations on tabular data
|
Bin spatial data and determine statistics per bin. |
|
Block average (x, y, z) data tables by mean estimation. |
|
Block average (x, y, z) data tables by median estimation. |
|
Block average (x, y, z) data tables by mode estimation. |
|
Time domain filtering of 1-D data tables. |
|
Grid table data using a "Nearest neighbor" algorithm. |
|
Project data onto lines or great circles, or generate tracks. |
|
Select data table subsets based on multiple spatial criteria. |
|
Create spherical grid files in tension of data. |
|
Create Voronoi distance, node, or natural nearest-neighbor grid on a sphere. |
|
Create spherical grid files in tension of data. |
|
Grid table data using adjustable tension continuous curvature splines. |
Delaunay triangulation or Voronoi partitioning and gridding of Cartesian data. |
|
|
Delaunay triangle based gridding of Cartesian data. |
|
Delaunay triangle based gridding of Cartesian data. |
|
Create a grid file from table data. |
Operations on raster data
|
Filter a grid by dividing the filter circle. |
|
Convert grid to data table. |
|
Set values in a grid that meet certain criteria to a new value. |
|
Extract subregion from a grid. |
|
Fill blank areas from a grid file. |
|
Filter a grid in the space (or time) domain. |
|
Compute the directional derivative of the vector gradient of the data. |
Perform histogram equalization for a grid. |
|
|
Perform histogram equalization for a grid. |
|
Perform histogram equalization for a grid. |
|
Create a grid file with set values for land and water. |
|
Change projection of gridded data between geographical and rectangular. |
|
Change the registration, spacing, or nodes in a grid file. |
|
Sample grids at specified (x,y) locations. |
|
Determine the volume between the surface of a grid and a plane. |
Crossover analysis with x2sys
|
Initialize a new x2sys track database. |
|
Calculate crossovers between track data files. |
Input/output
|
Open, load into memory, and close a DataArray from a file or file-like object containing a single data variable. |
GMT Defaults
Operations on GMT defaults:
|
Set GMT defaults globally or locally. |
Metadata
Getting metadata from tabular or grid data:
|
GMT accessor for |
|
Get information about data tables. |
|
Get information about a grid. |
Miscellaneous
|
Find the full path to specified files. |
|
Print various dependency versions which are useful when submitting bug reports. |
Datasets
PyGMT provides access to GMT’s datasets through the pygmt.datasets
module.
These functions will download the datasets automatically the first time they are used
and store them in GMT’s user data directory.
Report datasets available for tests and documentation examples. |
|
|
Load NASA Black Marble images in various resolutions. |
|
Load NASA Blue Marble images in various resolutions. |
|
Load the Earth seafloor crustal age dataset in various resolutions. |
Load the IGPP Earth free-air anomaly dataset in various resolutions. |
|
|
Load the EGM2008 Earth geoid dataset in various resolutions. |
Load the Earth magnetic anomaly datasets in various resolutions. |
|
|
Load the GSHHG Earth mask dataset in various resolutions. |
|
Load the Earth relief datasets (topography and bathymetry) in various resolutions. |
Load the IGPP Earth vertical gravity gradient dataset in various resolutions. |
|
|
Load the Mars relief dataset in various resolutions. |
|
Load the Mercury relief dataset in various resolutions. |
|
Load the Moon relief dataset in various resolutions. |
|
Load the Pluto relief dataset in various resolutions. |
|
Load the Venus relief dataset in various resolutions. |
Load an example dataset from the GMT server. |
In addition, there is also a special function to load XYZ tile maps via contextily to be used as base maps.
|
Load a georeferenced raster tile map from XYZ tile providers. |
Exceptions
All custom exceptions are derived from pygmt.exceptions.GMTError
.
Base class for all GMT related errors. |
|
Raised when the input of a function/method is invalid. |
|
Raised when an incompatible version of GMT is being used. |
|
Unsupported operating system. |
|
Error encountered when running a function from the GMT shared library. |
|
Tried to access GMT API without a currently open GMT session. |
|
Could not find the GMT shared library. |
GMT C API
The pygmt.clib
package is a wrapper for the GMT C API built using ctypes
.
Most calls to the C API happen through the pygmt.clib.Session
class.
A GMT API session where most operations involving the C API happen. |
GMT modules are executed through
the call_module
method:
|
Call a GMT module with the given arguments. |
Passing memory blocks between Python data objects (e.g. numpy.ndarray
,
pandas.Series
, xarray.DataArray
, etc) and GMT happens through
virtual files. These methods are context managers that automate the conversion of
Python objects to and from GMT virtual files:
|
Store any data inside a virtual file. |
|
Create a virtual file or an actual file for storing output data. |
Output a tabular dataset stored in a virtual file to a different format. |
|
|
Output raster data stored in a virtual file to an |
Low level access (these are mostly used by the pygmt.clib
package):
|
Create a new GMT C API session. |
Destroy the currently open GMT API session. |
|
|
Get the value of a GMT constant. |
Create a GMT API session. |
|
|
Destroy the currently open GMT API session. |
|
Get the value of a GMT configuration parameter or a GMT API parameter. |
|
Inquire if a GMT common option has been set and return its current value if possible. |
|
Create an empty GMT data container. |
|
Attach a numpy 2-D array to a GMT dataset. |
|
Attach a numpy 1-D array of dtype str as a column on a GMT dataset. |
|
Attach a numpy 1-D array as a column on a GMT dataset. |
|
Read a data file into a GMT data container. |
|
Write a GMT data container to a file. |
|
Open a GMT virtual file to pass data to and from a module. |
|
Read data from a virtual file and optionally cast into a GMT data container. |
Extract the region of the currently active figure. |
|
|
Get a ctypes function from the libgmt shared library. |
Store any data inside a virtual file. |
|
Store a grid in a virtual file. |
|
|
Store a |
Store a 2-D array as a table inside a virtual file. |
|
|
Store 1-D arrays as columns of a table inside a virtual file. |