Skip to content

What's the most Pythonic way for long GMT arguments? #1082

Open
@seisman

Description

@seisman

For each GMT option, PyGMT usually provides a long-form parameter. For example, GMT CLI option -B is equivalent to frame in PyGMT. This is done by the alias system (the use_alias decorator), which automatically converts long-form PyGMT parameters to short-form GMT options. The alias system works well but has known limitations and issues (e.g., #256, #262).

Sometimes, GMT arguments are still specified using long unreadable strings. For example,

As these common options are used a lot, we may take some time to find and implement a more Pythonic way to specify projection, frame et al.

However, there are still a lot of other long GMT arguments. Here is a simple example showing how to plot a GMT logo on maps.

import pygmt

fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 2], projection="X6c", frame=["WSen", "xaf", "yaf"])
fig.logo(position="jTR+o0.3c/0.6c+w3c", box="+p1p+glightblue")
fig.show()

The above Python script is equivalent to the following GMT CLI script:

gmt begin
gmt basemap -R0/10/0/2 -JX6c -B
gmt logo -DjTR+o0.3c/0.6c+w3c -F+p1p+glightblue
gmt end show

The long argument for position and box are really difficult to remember and write. There are definitely some better and more Pythonic ways to specify these arguments. As GMT has too many options, we must provide a universal way to specify these long arguments.

Perhaps the simplest way is to pass these long arguments as dict, i.e.,

fig.logo(
    position={
        location: "jTR",
        offset: [0.3, 0.6],
        width: "3c",
    },
    box={
        pen: "1p",
        fill: "lightblue"
    }
)

Are there any better ways?

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionsNeed more discussion before taking further actionsfeature requestNew feature wantedhelp wantedHelping hands are appreciatedlongtermLong standing issues that need to be resolved

    Type

    No type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions