Skip to content

Commit beb5670

Browse files
authored
Improve the display for class attributes of params (#4144)
1 parent 13fb1b2 commit beb5670

7 files changed

Lines changed: 77 additions & 81 deletions

File tree

doc/_templates/autosummary/class.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.. rubric:: Attributes
99

1010
{% for item in attributes %}
11-
.. autoproperty::
11+
.. autoattribute::
1212
{{ objname }}.{{ item }}
1313
{% endfor %}
1414
{% endif %}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{ fullname | escape | underline }}
2+
3+
.. currentmodule:: {{ module }}
4+
5+
.. autoclass:: {{ objname }}
6+
:members:
7+
:member-order: bysource
8+
9+
.. minigallery:: {{ fullname }}
10+
:add-heading:
11+
12+
.. raw:: html
13+
14+
<div style='clear:both'></div>

doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ Class-style Parameters
210210

211211
.. autosummary::
212212
:toctree: generated
213+
:template: autosummary/params.rst
213214

214215
Box
215216
Pattern

pygmt/datasets/load_remote_dataset.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,41 @@
1717
class Resolution(NamedTuple):
1818
"""
1919
Resolution code, the available grid registrations and whether it is tiled.
20-
21-
Attributes
22-
----------
23-
code
24-
The resolution code. E.g., "01d", "30m", "01s".
25-
registrations
26-
A list of the accepted registrations for a given resolution. Can be either
27-
"pixel" or "gridline".
28-
tiled
29-
States if the grid is tiled, which requires an argument for ``region``.
3020
"""
3121

22+
#: The resolution code. E.g., "01d", "30m", "01s".
3223
code: str
24+
25+
#: A list of the accepted registrations for a given resolution. Can be either
26+
#: "pixel" or "gridline".
3327
registrations: Sequence[str] = ["gridline", "pixel"]
28+
29+
#: States if the grid is tiled, which requires an argument for ``region``.
3430
tiled: bool = False
3531

3632

3733
class GMTRemoteDataset(NamedTuple):
3834
"""
3935
Standard information about a dataset and grid metadata.
40-
41-
Attributes
42-
----------
43-
description
44-
The name assigned as an attribute to the DataArray.
45-
kind
46-
The kind of the dataset source. Valid values are ``"grid"`` and ``"image"``.
47-
units
48-
The units of the values in the DataArray.
49-
resolutions
50-
Dictionary of available resolution as keys and Resolution objects as values.
51-
extra_attributes
52-
A dictionary of extra or unique attributes of the dataset.
53-
crs
54-
The coordinate reference system of the raster image. Need to be set for images,
55-
and should be ``None`` for grids.
5636
"""
5737

38+
#: The name assigned as an attribute to the DataArray.
5839
description: str
40+
41+
#: The kind of the dataset source. Valid values are ``"grid"`` and ``"image"``.
5942
kind: Literal["grid", "image"]
43+
44+
#: The units of the values in the DataArray.
6045
units: str | None
46+
47+
#: Dictionary of available resolution as keys and Resolution objects as values.
6148
resolutions: Mapping[str, Resolution]
49+
50+
#: A dictionary of extra or unique attributes of the dataset.
6251
extra_attributes: Mapping[str, Any]
52+
53+
#: The coordinate reference system of the raster image. Need to be set for images,
54+
#: and should be ``None`` for grids.
6355
crs: str | None = None
6456

6557

pygmt/datasets/samples.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,11 @@ def _load_earth_relief_holes() -> xr.DataArray:
209209
class GMTSampleData(NamedTuple):
210210
"""
211211
Information of a sample dataset.
212-
213-
Attributes
214-
----------
215-
func : callable
216-
The function that loads the sample dataset.
217-
description : str
218-
The description of the sample dataset.
219212
"""
220213

214+
#: The function that loads the sample dataset.
221215
func: Callable
216+
#: The description of the sample dataset.
222217
description: str
223218

224219

pygmt/params/box.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@ class Box(BaseParam):
1818
"""
1919
Class for specifying the box around GMT embellishments.
2020
21-
Parameters
22-
----------
23-
clearance
24-
Set clearances between the embellishment and the box border. It can be either a
25-
scalar value or a sequence of two/four values.
26-
27-
- a scalar value means a uniform clearance in all four directions.
28-
- a sequence of two values means separate clearances in x- and y-directions.
29-
- a sequence of four values means separate clearances for left/right/bottom/top.
30-
fill
31-
Fill for the box [Default is no fill].
32-
inner_gap
33-
Gap between the outer and inner borders [Default is ``"2p"``].
34-
inner_pen
35-
Pen attributes for the inner border [Default to :gmt-term:`MAP_DEFAULT_PEN`].
36-
pen
37-
Pen attributes for the box outline.
38-
radius
39-
Draw a rounded rectangular border instead of sharp. Passing a value with unit
40-
to control the corner radius [Default is ``"6p"``].
41-
shade_offset
42-
Place an offset background shaded region behind the box. A sequence of two
43-
values (dx, dy) indicates the shift relative to the foreground frame [Default is
44-
``("4p", "-4p")``].
45-
shade_fill
46-
Fill for the shaded region [Default is ``"gray50"``].
47-
4821
Examples
4922
--------
5023
>>> import pygmt
@@ -54,13 +27,36 @@ class Box(BaseParam):
5427
>>> fig.show()
5528
"""
5629

30+
#: Set clearances between the embellishment and the box border. It can be either a
31+
#: scalar value or a sequence of two/four values.
32+
#:
33+
#: - a scalar value means a uniform clearance in all four directions.
34+
#: - a sequence of two values means separate clearances in x- and y-directions.
35+
#: - a sequence of four values means separate clearances for left/right/bottom/top.
5736
clearance: float | str | Sequence[float | str] | None = None
37+
38+
#: Fill for the box [Default is no fill].
5839
fill: str | None = None
40+
41+
#: Gap between the outer and inner borders [Default is ``"2p"``].
5942
inner_gap: float | str | None = None
43+
44+
#: Pen attributes for the inner border [Default to :gmt-term:`MAP_DEFAULT_PEN`].
6045
inner_pen: str | None = None
46+
47+
#: Pen attributes for the box outline.
6148
pen: str | None = None
49+
50+
#: Draw a rounded rectangular border instead of sharp. Passing a value with unit to
51+
#: control the corner radius [Default is ``"6p"``].
6252
radius: str | bool = False
53+
54+
#: Place an offset background shaded region behind the box. A sequence of two values
55+
#: (dx, dy) indicates the shift relative to the foreground frame [Default is
56+
#: ``("4p", "-4p")``].
6357
shade_offset: Sequence[float | str] | None = None
58+
59+
#: Fill for the shaded region [Default is ``"gray50"``].
6460
shade_fill: str | None = None
6561

6662
def _validate(self):

pygmt/params/pattern.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,6 @@ class Pattern(BaseParam):
3131
:width: 75%
3232
:align: center
3333
34-
Parameters
35-
----------
36-
pattern
37-
The pattern to use. It can be specified in two forms:
38-
39-
- An integer in the range of 1-90, corresponding to one of 90 predefined 64x64
40-
bit-patterns. [Default is 1].
41-
- Name of a 1-, 8-, or 24-bit image raster file, to create customized, repeating
42-
images using image raster files.
43-
dpi
44-
Resolution of the pattern in dots per inch (DPI) [Default is 300].
45-
bgcolor/fgcolor
46-
The background/foreground color for predefined bit-patterns or 1-bit images.
47-
Setting either to an empty string will yield a transparent background/foreground
48-
where only the foreground/background pixels will be painted. [Default is white
49-
for background and black for foreground].
50-
invert
51-
If ``True``, the pattern will be bit-inverted, i.e., white and black areas will
52-
be interchanged (only applies to predefined bit-patterns or 1-bit images).
53-
5434
Examples
5535
--------
5636
Draw a global map with land areas filled with pattern 15 in a light red background
@@ -69,10 +49,28 @@ class Pattern(BaseParam):
6949
>>> fig.show()
7050
"""
7151

52+
#: The pattern to use. It can be specified in two forms:
53+
#:
54+
#: - An integer in the range of 1-90, corresponding to one of 90 predefined 64x64
55+
#: bit-patterns. [Default is 1].
56+
#: - Name of a 1-, 8-, or 24-bit image raster file, to create customized, repeating
57+
#: images using image raster files.
7258
pattern: int | PathLike = 1
59+
60+
#: Resolution of the pattern in dots per inch (DPI) [Default is 300].
7361
dpi: int | None = None
62+
63+
#: The background color for predefined bit-patterns or 1-bit images.
64+
#: Setting either ``bgcolor`` or ``fgcolor`` to an empty string will yield a
65+
#: transparent background/foreground where only the foreground/background pixels
66+
#: will be painted. [Default is white for background and black for foreground].
7467
bgcolor: str | None = None
68+
69+
#: The foreground color for predefined bit-patterns or 1-bit images.
7570
fgcolor: str | None = None
71+
72+
#: If ``True``, the pattern will be bit-inverted, i.e., white and black areas will
73+
#: be interchanged (only applies to predefined bit-patterns or 1-bit images).
7674
invert: bool = False
7775

7876
def _validate(self):

0 commit comments

Comments
 (0)