Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use longname placeholders in the docstrings for common options #1932

Merged
merged 48 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6580b8c
Use longname placeholders in the docstrings
seisman May 25, 2022
fa92fa3
Replace {J} with {projection}
seisman Jun 1, 2022
d2a4f85
Replace {V} with {verbose}
seisman Jun 1, 2022
3433876
Replace {U} with {timestamp}
seisman Jun 1, 2022
c26bea0
Replace {R} with {region}
seisman Jun 1, 2022
d40ee56
Replace {B} with {frame}
seisman Jun 1, 2022
4af5955
Replace {a} with {aspatial}
seisman Jun 1, 2022
d097e09
Replace {b} with {binary}
seisman Jun 1, 2022
2a3b60c
Replace {d} with {nodata}
seisman Jun 1, 2022
e1b6b9d
Replace {c} with {panel}
seisman Jun 1, 2022
7c7ce4a
Replace {e} with {find}
seisman Jun 1, 2022
eb42d8e
Replace {f} with {coltypes}
seisman Jun 1, 2022
4f6de92
Replace {g} with {gap}
seisman Jun 1, 2022
4c68f79
Replace {h} with {header}
seisman Jun 1, 2022
bba4149
Replace {i} with {incols}
seisman Jun 1, 2022
f916de1
Replace {j} with {distcalc}
seisman Jun 1, 2022
cfe9221
Replace {l} with {label}
seisman Jun 1, 2022
f1419a8
Replace {n} with {interpolation}
seisman Jun 1, 2022
66a35c9
Replace {o} with {outcols}
seisman Jun 1, 2022
dbff502
Replace {p} with {perspective}
seisman Jun 1, 2022
de754c2
Replace {r} with {registration}
seisman Jun 1, 2022
cbef92e
Replace {s} with {skiprows}
seisman Jun 1, 2022
d0ef6aa
Replace {t} with {transparency}
seisman Jun 1, 2022
65f6f90
Replace {w} with {wrap}
seisman Jun 1, 2022
8cfa283
Replace {x} with {cores}
seisman Jun 1, 2022
e39d0c3
Replace {XY} with {xyshift}
seisman Jun 1, 2022
6de914e
Replace {CPT} with {cmap}
seisman Jun 1, 2022
dc55b4a
Replace {A} with {area_thresh}
seisman Jun 1, 2022
cb1fa23
Replace {G} with {color}
seisman Jun 1, 2022
e0cc783
Replace {W} with {pen}
seisman Jun 1, 2022
5fdb82f
Revert incorrect replacements during the batch replacements
seisman Jun 1, 2022
4a8b60c
Merge branch 'main' into longname-docstrings
seisman Jun 1, 2022
ef59237
Merge branch 'main' into longname-docstrings
seisman Jun 4, 2022
9dccaa4
Remove unmaintained list of placeholders in the fmt_docstring function
seisman Jun 6, 2022
6f9818f
Merge branch 'main' into longname-docstrings
seisman Jun 6, 2022
8e175dc
Merge branch 'main' into longname-docstrings
seisman Jun 13, 2022
ec5d76c
Use longname docstrings in binstats
seisman Jun 13, 2022
eecece5
Merge branch 'main' into longname-docstrings
seisman Jun 14, 2022
3e3b33f
Merge branch 'main' into longname-docstrings
seisman Jul 7, 2022
32023f7
Merge branch 'main' into longname-docstrings
seisman Jul 11, 2022
60c159f
Merge branch 'main' into longname-docstrings
seisman Aug 19, 2022
b4a7fa8
Merge branch 'main' into longname-docstrings
seisman Aug 27, 2022
f9d3155
Merge branch 'main' into longname-docstrings
seisman Aug 31, 2022
d8fabc4
Merge branch 'main' into longname-docstrings
seisman Sep 9, 2022
328414e
Merge branch 'main' into longname-docstrings
seisman Sep 16, 2022
e51785b
Update ternary.py
seisman Sep 16, 2022
8c8c36f
Fix
seisman Sep 16, 2022
819120e
Merge branch 'main' into longname-docstrings
seisman Sep 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def psconvert(self, icc_gray=False, **kwargs):
both an EPS and a PDF file. Using **F** creates a multi-page PDF
file from the list of input PS or PDF files. It requires the
``prefix`` parameter.
{V}
{verbose}
"""
kwargs = self._preprocess(**kwargs)
# Default cropping the figure to True
Expand Down
79 changes: 34 additions & 45 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers.utils import is_nonstr_iter

COMMON_OPTIONS = {
"R": r"""
COMMON_DOCSTRINGS = {
"region": r"""
region : str or list
*xmin/xmax/ymin/ymax*\ [**+r**][**+u**\ *unit*].
Specify the :doc:`region </tutorials/basics/regions>` of interest.""",
"J": r"""
"projection": r"""
projection : str
*projcode*\[*projparams*/]\ *width*.
Select map :doc:`projection </projections/index>`.""",
"A": r"""
"area_thresh": r"""
area_thresh : int or float or str
*min_area*\ [/*min_level*/*max_level*][**+a**\[**g**\|\ **i**]\
[**s**\|\ **S**]][**+l**\|\ **r**][**+p**\ *percent*].
Features with an area smaller than *min_area* in km\ :sup:`2` or of
hierarchical level that is lower than *min_level* or higher than
*max_level* will not be plotted [Default is 0/0/4 (all
features)].""",
"B": r"""
"frame": r"""
frame : bool or str or list
Set map boundary
:doc:`frame and axes attributes </tutorials/basics/frames>`. """,
"U": """\
"timestamp": """\
timestamp : bool or str
Draw GMT time stamp logo on plot.""",
"CPT": r"""
"cmap": r"""
cmap : str
File name of a CPT file or a series of comma-separated colors
(e.g., *color1*,\ *color2*,\ *color3*) to build a linear continuous
CPT from those colors automatically.""",
"G": """\
"color": """\
color : str or 1d array
Select color or pattern for filling of symbols or polygons. Default
is no fill.""",
"I": r"""
"spacing": r"""
spacing : str
*x_inc*\ [**+e**\|\ **n**][/\ *y_inc*\ [**+e**\|\ **n**]].
*x_inc* [and optionally *y_inc*] is the grid spacing.
Expand Down Expand Up @@ -78,7 +78,7 @@
**Note**: If ``region=grdfile`` is used then the grid spacing and
the registration have already been initialized; use ``spacing`` and
``registration`` to override these values.""",
"V": """\
"verbose": """\
verbose : bool or str
Select verbosity level [Default is **w**], which modulates the messages
written to stderr. Choose among 7 levels of verbosity:
Expand All @@ -90,10 +90,10 @@
- **i** - Informational messages (same as ``verbose=True``)
- **c** - Compatibility warnings
- **d** - Debugging messages""",
"W": """\
"pen": """\
pen : str
Set pen attributes for lines or the outline of symbols.""",
"XY": r"""
"xyshift": r"""
xshift : str
[**a**\|\ **c**\|\ **f**\|\ **r**\][*xshift*].
Shift plot origin in x-direction.
Expand All @@ -102,13 +102,13 @@
Shift plot origin in y-direction. Full documentation is at
:gmt-docs:`gmt.html#xy-full`.
""",
"a": r"""
"aspatial": r"""
aspatial : bool or str
[*col*\ =]\ *name*\ [,...].
Control how aspatial data are handled during input and output.
Full documentation is at :gmt-docs:`gmt.html#aspatial-full`.
""",
"b": r"""
"binary": r"""
binary : bool or str
**i**\|\ **o**\ [*ncols*][*type*][**w**][**+l**\|\ **b**].
Select native binary input (using ``binary="i"``) or output
Expand Down Expand Up @@ -136,15 +136,15 @@
be read as little- or big-endian, respectively.

Full documentation is at :gmt-docs:`gmt.html#bi-full`.""",
"d": r"""
"nodata": r"""
nodata : str
**i**\|\ **o**\ *nodata*.
Substitute specific values with NaN (for tabular data). For
example, ``d="-9999"`` will replace all values equal to -9999 with
NaN during input and all NaN values with -9999 during output.
Prepend **i** to the *nodata* value for input columns only. Prepend
**o** to the *nodata* value for output columns only.""",
"c": r"""
"panel": r"""
panel : bool or int or list
[*row,col*\|\ *index*].
Select a specific subplot panel. Only allowed when in subplot
Expand All @@ -154,21 +154,21 @@
when the subplot was defined. **Note**: *row*, *col*, and *index*
all start at 0.
""",
"e": r"""
"find": r"""
find : str
[**~**]\ *"pattern"* \| [**~**]/\ *regexp*/[**i**].
Only pass records that match the given *pattern* or regular
expressions [Default processes all records]. Prepend **~** to
the *pattern* or *regexp* to instead only pass data expressions
that do not match the pattern. Append **i** for case insensitive
matching. This does not apply to headers or segment headers.""",
"f": r"""
"coltypes": r"""
coltypes : str
[**i**\|\ **o**]\ *colinfo*.
Specify data types of input and/or output columns (time or
geographical data). Full documentation is at
:gmt-docs:`gmt.html#f-full`.""",
"g": r"""
"gap": r"""
gap : str or list
**x**\|\ **y**\|\ **z**\|\ **d**\|\ **X**\|\ **Y**\|\
**D**\ *gap*\ [**u**][**+a**][**+c**\ *col*][**+n**\|\ **p**].
Expand Down Expand Up @@ -209,7 +209,7 @@
column value must exceed *gap* for a break to be imposed.
- **+p** - specify that the current value minus the previous
value must exceed *gap* for a break to be imposed.""",
"h": r"""
"header": r"""
header : str
[**i**\|\ **o**][*n*][**+c**][**+d**][**+m**\ *segheader*][**+r**\
*remark*][**+t**\ *title*].
Expand All @@ -231,7 +231,7 @@
line-breaks.

Blank lines and lines starting with \# are always skipped.""",
"i": r"""
"incols": r"""
incols : str or 1d array
Specify data columns for primary input in arbitrary order. Columns
can be repeated and columns not listed will be skipped [Default
Expand Down Expand Up @@ -261,7 +261,7 @@
[Default is 1].
- **+o** to add the given *offset* to the input values [Default
is 0].""",
"j": r"""
"distcalc": r"""
distcalc : str
**e**\|\ **f**\|\ **g**.
Determine how spherical distances are calculated.
Expand All @@ -275,11 +275,11 @@
(:gmt-term:`PROJ_MEAN_RADIUS`), and the specification of latitude type
(:gmt-term:`PROJ_AUX_LATITUDE`). Geodesic distance calculations is also
controlled by method (:gmt-term:`PROJ_GEODESIC`).""",
"l": r"""
"label": r"""
label : str
Add a legend entry for the symbol or line being plotted. Full
documentation is at :gmt-docs:`gmt.html#l-full`.""",
"n": r"""
"interpolation": r"""
interpolation : str
[**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**][**+t**\ *threshold*].
Select interpolation mode for grids. You can select the type of
Expand All @@ -289,7 +289,7 @@
- **c** for bicubic [Default]
- **l** for bilinear
- **n** for nearest-neighbor""",
"o": r"""
"outcols": r"""
outcols : str or 1d array
*cols*\ [,...][,\ **t**\ [*word*]].
Specify data columns for primary output in arbitrary order. Columns
Expand All @@ -312,21 +312,21 @@
input and skip trailing text. **Note**: If ``incols`` is also
used then the columns given to ``outcols`` correspond to the
order after the ``incols`` selection has taken place.""",
"p": r"""
"perspective": r"""
perspective : list or str
[**x**\|\ **y**\|\ **z**]\ *azim*\[/*elev*\[/*zlevel*]]\
[**+w**\ *lon0*/*lat0*\[/*z0*]][**+v**\ *x0*/*y0*].
Select perspective view and set the azimuth and elevation angle of
the viewpoint. Default is [180, 90]. Full documentation is at
:gmt-docs:`gmt.html#perspective-full`.
""",
"r": r"""
"registration": r"""
registration : str
**g**\|\ **p**.
Force gridline (**g**) or pixel (**p**) node registration.
[Default is **g**\ (ridline)].
""",
"s": r"""
"skiprows": r"""
skiprows : bool or str
[*cols*][**+a**][**+r**].
Suppress output for records whose *z*-value equals NaN [Default
Expand All @@ -342,14 +342,14 @@
- **+a** to suppress the output of the record if just one or
more of the columns equal NaN [Default skips record only
if values in all specified *cols* equal NaN].""",
"t": """\
"transparency": """\
transparency : int or float
Set transparency level, in [0-100] percent range.
Default is 0, i.e., opaque.
Only visible when PDF or raster format output is selected.
Only the PNG format selection adds a transparency layer
in the image (for further processing). """,
"w": r"""
"wrap": r"""
wrap : str
**y**\|\ **a**\|\ **w**\|\ **d**\|\ **h**\|\ **m**\|\ **s**\|\
**c**\ *period*\ [/*phase*][**+c**\ *col*].
Expand All @@ -367,7 +367,7 @@
- **c** - custom cycle (normalized)

Full documentation is at :gmt-docs:`gmt.html#w-full`.""",
"x": r"""
"cores": r"""
cores : bool or int
[[**-**]\ *n*].
Limit the number of cores to be used in any OpenMP-enabled
Expand All @@ -391,17 +391,6 @@ def fmt_docstring(module_func):
* ``{aliases}``: Insert a section listing the parameter aliases defined by
decorator ``use_alias``.

The following are places for common parameter descriptions:

* ``{R}``: region (bounding box as west, east, south, north)
* ``{J}``: projection (coordinate system to use)
* ``{B}``: frame (map frame and axes parameters)
* ``{U}``: timestamp (insert time stamp logo)
* ``{CPT}``: cmap (the color palette table)
* ``{G}``: color
* ``{W}``: pen
* ``{n}``: interpolation

Parameters
----------
module_func : function
Expand All @@ -426,8 +415,8 @@ def fmt_docstring(module_func):
... data : str or {table-like}
... Pass in either a file name to an ASCII data table, a 2D
... {table-classes}.
... {R}
... {J}
... {region}
... {projection}
...
... {aliases}
... '''
Expand Down Expand Up @@ -481,7 +470,7 @@ def fmt_docstring(module_func):
" tabular data"
)

for marker, text in COMMON_OPTIONS.items():
for marker, text in COMMON_DOCSTRINGS.items():
# Remove the indentation and the first line break from the multiline
# strings so that it doesn't mess up the original docstring
filler_text[marker] = textwrap.dedent(text.lstrip("\n"))
Expand Down
20 changes: 10 additions & 10 deletions pygmt/src/basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def basemap(self, **kwargs):

Parameters
----------
{J}
{projection}
zscale/zsize : float or str
Set z-axis scaling or z-axis size.
{R}
{region}
*Required if this is the first plot command.*
{B}
{frame}
map_scale : str
[**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\
**+w**\ *length*.
Expand Down Expand Up @@ -82,13 +82,13 @@ def basemap(self, **kwargs):
compass : str
Draws a map magnetic rose on the map at the location defined by the
reference and anchor points
{U}
{V}
{XY}
{c}
{f}
{p}
{t}
{timestamp}
{verbose}
{xyshift}
{panel}
{coltypes}
{perspective}
{transparency}
Comment on lines +85 to +91
Copy link
Member

@weiji14 weiji14 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the long names, but then there's a small problem with sorting the parameters. Previously we sorted by asciibetical order (e.g. ABCabc), and it somewhat made sense since the small-letter GMT parameters like c/f/p/t were rarely used. Now that we switch to the long-form, do we still go with the original GMT sorting, or change to sorting by a long-parameter's first character?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a good answer for this, but packages like numpy and pandas don't sort their parameters alphabetically. I think we also don't have to do that.

"""
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
if not args_in_kwargs(args=["B", "L", "Td", "Tm", "c"], kwargs=kwargs):
Expand Down
16 changes: 8 additions & 8 deletions pygmt/src/binstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ def binstats(data, **kwargs):
computed while the count will be the sum of the weights instead of
number of points. If the weights are actually uncertainties
(one sigma) then append **+s** and weight = 1/sigma.
{I}
{R}
{V}
{a}
{b}
{h}
{i}
{r}
{spacing}
{region}
{verbose}
{aspatial}
{binary}
{header}
{incols}
{registration}

Returns
-------
Expand Down
Loading