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 in the Earth Sciences. Besides making GMT more accessible to new users, PyGMT aims to provide integration with the PyData 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
Allows plotting of a large spectrum of objects on figures including lines, vectors, polygons, and symbols (pre-defined and customized)
Generate publication-quality illustrations and make 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 a gray or color scale-bar on maps. |
|
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. |
Plotting tabular data
|
Contour table data by direct triangulation. |
|
Plots a histogram, and can read data from a file or list, array, or dataframe. |
|
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 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. |
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 a file. |
|
Display a preview of the figure. |
|
Convert [E]PS file(s) to other formats. |
Configuring the display settings
The following module is provided directly through the pygmt
top level
package.
|
Set the display method. |
Color palette table generation
The following modules 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
|
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. |
|
Fit coordinators to create vectors on a sphere. |
|
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. |
|
Grids table data using adjustable tension continuous curvature splines. |
|
Create a grid file from table data. |
Operations on grids
|
Convert grid to data table. |
|
Sets 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. |
|
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:
|
This is the GMT extension for |
|
Get information about data tables. |
|
Get information about a grid. |
Miscellaneous
|
Find the full path to specified files. |
|
Run the test suite. |
Print information about the GMT shared library that we can find. |
|
Prints various dependency versions useful when submitting bug reports. |
Datasets
PyGMT provides access to GMT’s datasets through the pygmt.datasets
package.
These functions will download the datasets automatically the first time they are used
and store them in the GMT cache folder.
Report datasets available for tests and documentation examples. |
|
|
Load Earth seafloor crustal ages in various resolutions. |
|
Load Earth relief grids (topography and bathymetry) in various resolutions. |
Load an example dataset from the GMT server. |
|
|
(Deprecated) Load a table of fracture lengths and azimuths as hypothetically digitized from geological maps as a pandas.DataFrame. |
|
(Deprecated) Load a table with the locations, names, and suggested symbol sizes of hotspots. |
|
(Deprecated) Load a table of earthquakes around Japan as a pandas.DataFrame. |
|
(Deprecated) Load a table of data for the shape of Mars. |
|
(Deprecated) Load a table of ocean ridge points for the entire world as a pandas.DataFrame. |
|
(Deprecated) Load a table of ship observations of bathymetry off Baja California as a pandas.DataFrame. |
|
(Deprecated) Load a table of global earthquakes from the USGS as a pandas.DataFrame. |
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 variables to GMT virtual files:
Store any data inside a virtual file. |
|
Store a 2d array as a table inside a virtual file. |
|
|
Store 1d arrays as columns of a table inside a virtual file. |
Store a grid in a virtual file. |
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 (C enum) from gmt_resources.h. |
Create a GMT API session and check the libgmt version. |
|
|
Destroy the currently open GMT API session. |
|
Get the value of a GMT default parameter (library version, paths, etc). |
|
Create an empty GMT data container. |
|
Attach a numpy 2D array to a GMT dataset. |
|
Attach a numpy 1D array of dtype str as a column on a GMT dataset. |
|
Attach a numpy 1D array as a column on a GMT dataset. |
|
Write a GMT data container to a file. |
|
Open a GMT Virtual File to pass data to and from a module. |
Extract the WESN bounding box of the currently active figure. |
|
|
Get a ctypes function from the libgmt shared library. |