Dr. Xiao-Le Deng

PyGMT: Pythonic Generic Mapping Tools

2020-10-28 17:00
#Researchsoftware #Python

1. 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.

Documentation: https://www.pygmt.org/dev/

GitHub: https://github.com/GenericMappingTools/pygmt

Install: https://www.pygmt.org/dev/install.html

# install pygmt environment
conda config --prepend channels conda-forge
conda create --name pygmt python=3.8 pip numpy pandas xarray netcdf4 packaging gmt
# open pygmt environment
conda activate pygmt
# install pygmt
conda install pygmt
# test
conda install pytest pytest-mpl ipython
import pygmt

2. Finding the GMT shared library

Sometimes, PyGMT will be unable to find the correct version of the GMT shared library. This can happen if you have multiple versions of GMT installed.

You can tell PyGMT exactly where to look for libgmt by setting the GMT_LIBRARY_PATH environment variable. This should be set to the directory where libgmt.so, libgmt.dylib or gmt.dll can be found for Linux, macOS and Windows respectively. e.g. in a terminal run:

# Linux/macOS
export GMT_LIBRARY_PATH=$HOME/anaconda3/envs/pygmt/lib
# Windows
set "GMT_LIBRARY_PATH=C:\Users\USERNAME\Anaconda3\envs\pygmt\Library\bin\"