Skip to main content

Tool to convert GMT scripts to the new modern execution mode

Project description

Latest version on PyPI Travis CI build status Test coverage status Compatible Python versions.


This is work in progress. So far, it can convert some of the test and example scripts from the GMT repository.

About modern mode

GMT is introducing a “modern” execution mode that reduces the amount of arguments needed for many programs and handles the PostScript layer-caking in the background.

For example, the following classic mode script:
gmt grdgradient -Nt0.2 -A45
gmt makecpt -Cgeo -T-8000/2000 > t.cpt
gmt grdimage -Ct.cpt -JM6i -P -K > $ps
gmt pscoast -J -O -Dh -Baf -W0.75p -K >> $ps
echo "Japan Trench" | gmt pstext -F+f32p+cTC -Dj0/0.2i -Gwhite -R -J -O -K >> $ps
gmt psxy -W2p lines.txt -R -J -O -K >> $ps
gmt psscale -R -J -O -DjBL+w3i/0.1i+h+o0.3i/0.4i -Ct.cpt -W0.001 -F+gwhite+p0.5p -Bxaf -By+l"km" >> $ps

is equivalent to the following in modern mode:


gmt begin $ps ps

gmt grdgradient -Nt0.2 -A45
gmt makecpt -Cgeo -T-8000/2000 > t.cpt
gmt grdimage -Ct.cpt -JM6i -P
gmt pscoast -Dh -Baf -W0.75p
echo "Japan Trench" | gmt pstext -F+f32p+cTC -Dj0/0.2i -Gwhite
gmt psxy -W2p lines.txt
gmt psscale -DjBL+w3i/0.1i+h+o0.3i/0.4i -Ct.cpt -W0.001 -F+gwhite+p0.5p -Bxaf -By+l"km"
rm -f t.cpt

gmt end

See the scripts and data in the example folder.

Read more about modern mode at the Modernization wiki page.


Install the latest release using the pip package manager:

pip install gmtmodernize

To install the development version from the Github master branch:

git clone
cd gmtmodernize
pip install .


Command line

The package provides a command-line interface through the gmtmodernize program:

$ gmtmodernize --help
Convert GMT shell scripts from classic to modern mode.

Prints the converted modern mode script to standard output (stdout).

    gmtmodernize SCRIPT
    gmtmodernize --recursive FOLDER_CLASSIC FOLDER_MODERN
    gmtmodernize --help
    gmtmodernize --version

    SCRIPT          Classic mode script to convert.
    FOLDER_CLASSIC  Folder with classic mode scripts (can have multiple
    FOLDER_MODERN   Name of output folder with converted modern mode scripts.
                    Mirrors the folder structure of FOLDER_CLASSIC and copies
                    all non-script files.

    -r --recursive  Recursively transverse a folder structure with GMT scripts
                    and other files instead of converting a single file.
                    Creates a new folder with the same structure and non-script
                    files copied over, plus the converted GMT scripts.
    -h --help       Show this help message and exit.
    --version       Show the version and exit.


    Convert a single GMT script to modern mode:

        $ gmtmodernize >

    Convert a folder with GMT scripts, data files, etc, (optionally inside
    multiple sub-folders):

        $ gmtmodernize -r gmt_classic_scripts/ gmt_modern_scripts/

    This will create a folder 'gmt_modern_scripts' with the same sub-folders
    and non-script files in 'gmt_classic_scripts' but with the scripts
    converted to modern mode.


Alternatively, you can run the conversion using the gmtmodernize Python library. It exposes a modernize function that takes a classic script (as a single string) and outputs a modern script (also as a single string).


from gmtmodernize import modernize

with open('') as f:
    classic =
with open('', 'w') as f:


gmtmodernize is free software: you can redistribute it and/or modify it under the terms of the BSD 3-clause License. A copy of this license is provided in LICENSE.txt.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gmtmodernize-1.2.tar.gz (30.6 kB view hashes)

Uploaded source

Built Distribution

gmtmodernize-1.2-py3-none-any.whl (24.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page