You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pythonic implementation for the "series" parameter that accept xmin/xmax/inc and comma-separated sequence #4898
From the CLI, the option accepts four kinds of arguments:
min/max/inc — three slash-separated values for min, max, and inc
inc — a single increment value; min and max are usually inferred from the data or -R
val1,val2,val3,... — a comma-separated list of values
file — a file containing the values, one per line
Proposa
Python users generally prefer to pass a list, tuple, or array instead of a hand-written string. For example, bins=np.arange(0, 100, 10) in matplotlib's hist. To accommodate this, PyGMT should accept the following inputs for -T:
Input
Interpretation
Passed to GMT as
A single float
inc
<inc>
A string
Used verbatim; may be a file name, min/max/inc, or val1,val2,...
<string>
A tuple/list of length 3
(min, max, inc)
<min>/<max>/<inc>
A tuple/list whose length is not 3
A sequence of values
<val1>,<val2>,<val3>,...
Any other sequence (e.g. range(), numpy.ndarray, pandas.Series)
A sequence of values
<val1>,<val2>,<val3>,...
Caveats
A tuple/list with exactly three values is ambiguous: (-1000, 0, 100) could mean either -1000/0/100 or -1000,0,100. We define three-element tuples/lists as always being min/max/inc and we should document it clearly.
numpy.arange excludes the stop value, whereas GMT's -Tmin/max/inc includes it. For example, numpy.arange(1, 5, 1) becomes 1,2,3,4, while -T1/5/1 means 1,2,3,4,5.、
-T option also supports many modifiers, e.g., +b for evenly spaced values in log2-domain. I feel these uses cases can be done by generating sequences using numpy, so I don't think we need to worry about Pythonic implementaitions of these modifiers. Anyway, users can always pass strings like series="1/5/1+b".
Implementation details
A comma-separated string becomes very long when the sequence contains many values or long floats (e.g. 0.1111111111). GMT may crash if the resulting CLI string exceeds an internal length limit (I don't know the limits yet). To avoid the length limit, long sequences should be passed using the -Tfile syntax rather than inlined. Because GMT supports passing files through virtual files, this can be done without creating any temporary files on disk.
Activity