File tree 3 files changed +47
-5
lines changed
3 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,15 @@ Miscellaneous
206
206
print_clib_info
207
207
show_versions
208
208
209
+ Common Parameters
210
+ -----------------
211
+
212
+ .. autosummary ::
213
+ :toctree: generated
214
+
215
+ params.Box
216
+
217
+
209
218
.. currentmodule :: pygmt
210
219
211
220
Datasets
Original file line number Diff line number Diff line change
1
+ """
2
+ General class for PyGMT parameters.
3
+ """
1
4
from __future__ import annotations
2
5
3
6
from typing import NamedTuple
6
9
7
10
8
11
class Alias (NamedTuple ):
12
+ """
13
+ Alias PyGMT long-form parameter to GMT single-letter option flag.
14
+ """
15
+
9
16
name : str
10
17
modifier : str
11
18
separator : str | None = None
12
19
13
20
14
21
class BaseParams :
15
22
"""
23
+ Base class for PyGMT parameters.
24
+
16
25
Examples
17
26
--------
18
27
>>> import dataclasses
19
28
>>> from pygmt.params.base import BaseParams
20
29
>>>
21
30
>>> @dataclasses.dataclass(repr=False)
22
31
... class Test(BaseParams):
23
- ... attr1 : Any = None
24
- ... attr2 : Any = None
25
- ... attr3 : Any = None
32
+ ... attr1: Any = None
33
+ ... attr2: Any = None
34
+ ... attr3: Any = None
26
35
...
27
36
... __aliases__ = [
28
37
... Alias("attr1", ""),
@@ -35,20 +44,27 @@ class BaseParams:
35
44
>>> repr(var)
36
45
"Test(attr1='val1')"
37
46
"""
47
+
38
48
def __str__ (self ):
49
+ """
50
+ String representation of the object that can be passed to GMT directly.
51
+ """
39
52
values = []
40
53
for alias in self .__aliases__ :
41
54
value = getattr (self , alias .name )
42
55
if value in (None , False ):
43
56
continue
44
- if value is True :
57
+ elif value is True :
45
58
value = ""
46
- if is_nonstr_iter (value ):
59
+ elif is_nonstr_iter (value ):
47
60
value = alias .separator .join (map (str , value ))
48
61
values .append (f"{ alias .modifier } { value } " )
49
62
return "" .join (values )
50
63
51
64
def __repr__ (self ):
65
+ """
66
+ String representation of the object.
67
+ """
52
68
string = []
53
69
for alias in self .__aliases__ :
54
70
value = getattr (self , alias .name )
Original file line number Diff line number Diff line change 11
11
12
12
@dataclass (repr = False )
13
13
class Box (BaseParams ):
14
+ """
15
+ Class for the box around GMT embellishments.
16
+
17
+ Attributes
18
+ ----------
19
+ clearance
20
+ Set clearances between the embellishment and the box border. Can be either a
21
+ scalar value or a list of two/four values.
22
+
23
+ - a scalar value means a uniform clearance in all four directions.
24
+ - a list of two values means separate clearances in x- and y- directions.
25
+ - a list of four values means separate clearances for left/right/bottom/top.
26
+ fill
27
+ Fill for the box. None means no fill.
28
+
29
+ """
30
+
14
31
clearance : float | str | Sequence [float | str ] | None = None
15
32
fill : str | None = None
16
33
innerborder : str | Sequence | None = None
You can’t perform that action at this time.
0 commit comments