PyGMT#

  • Author: Fu Yin

  • Update: July 30, 2022

  • Reading: 10 min


Introduction#

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.

Installation#

It’s recommended to install Pygmt into base environment.

Simple installation using conda:

$ conda install --channel conda-forge pygmt

If you use mamba:

$ mamba install --channel conda-forge pygmt

Configuration#

Data Set Config#

The directory that GMT automatically downloads the data file from the server is ~/.gmt/server. About the detailed info, please check GMT Chinese Manual about Geodata set session

Mirror

The GMT data server currently has multiple mirrors around the world. Run the following command to set your mirror channel:

# If you are in China
$ gmt set GMT_DATA_SERVER http://china.generic-mapping-tools.org

# If you are in US West Coast
$ gmt set GMT_DATA_SERVER http://sdsc-opentopography.generic-mapping-tools.org

# Show URL of the remote GMT data server
$ gmt --show-dataserver

Then the above command will generate a gmt.conf file in your current path, copy it to the GMT user directory ~/.gmt.

GMT Built-in Data

GMT Romote Data

  • Earth_relief: global relief data, automatically download into ~/.gmt/server/earth/earth_relief directory

  • Earth_age: the age of the earth’s oceanic crust, automatically download into ~/.gmt/server/earth/earth_age directory

  • More info please check GMT Chinese Manual …

I have downloaded the Earth_relief dataset into ~/.gmt/server/earth/earth_relief directory, with the resolution is 30s which equal to 1 kilometer(size of ~778M). Download data by the following command gmt get:

$ gmt get -Ddata=earth_relief -I30s

Custom Data

Users can also customize their own database directory to store their own data in it, compared with the default directory ~/.gmt/server. My database directory is ~/data/GMTDB/, add the following lines into your configuration file.

$ vim ~/.zshrc
# >>> pygmt(base) initialize >>>
export GMT_DATADIR=/Users/yinfu/data/GMTDB/
# <<< pygmt(base) initialize <<<

Then you can check the whether it has successed:

# Show full path of user's ~/.gmt dir
$ gmt --show-userdir

# Show directory/ies with user data.
$ gmt --show-datadir

My Data List#

Name

From

Directory

Earth_relief with 30s

GMT remote data

~/.gmt/server/earth/earth_relief

``

~/data/GMTDB/

Parameters Setting#

Please check GMT Chinese Manual about parameter configuration

pygmt use pygmt.config to set the default parameters.

import pygmt

pygmt.config(PARAMETER = value)

MAP#